<!-- 邻里圈 -->
<template>
	<view>
		<view style="width: 100%;height: 600rpx;position: relative;">
			<image src="../../static/care_family.png" style="width: 100%;height:100%;" @longpress="changeBgImg"></image>
			<view style="height:44rpx;font-size:32rpx;font-family:PingFang SC;font-weight:bold;color:rgba(255,255,255,1);position: absolute;bottom: 20rpx;right: 194rpx;">{{userName}}</view>
			<view style="width: 132rpx;height: 132rpx;position: absolute;right: 34rpx;bottom: -30rpx;" @tap="seeMyInfo">
				<image :src="headImg" style="width: 100%;height: 100%;border-radius:14rpx;"></image>
			</view>
		</view>
		<view class="content">
			<view class="navTitle" :style="{marginTop:phoneHeight + 'px'}" style="padding-top: 20rpx;">邻里圈</view>
			<image src="../../static/camera.png" style="width: 39rpx;height: 31rpx;margin-top: 30rpx;margin-left: 660rpx;" @tap="publish()"></image>
		</view>
		<!-- 邻里圈内容 -->
		<view class="main">
			<view v-for="(item,index) in data" :key="index" class="mainInfo">
				<view class="item">
					<!-- 头像 -->
					<view class="left">
						<image src="../../static/qingShao.png" style="width: 86rpx;height:86rpx;"></image>
					</view>
					<!-- 发布内容 -->
					<view class="right">
						<view class="name">{{item.createBy}}</view>
						<view class="text" v-show="item.content">
							{{item.content}}
						</view>
						<!-- 图片内容 -->
						<!-- <view class="img" v-if="item.photosUrlList.length==1" v-show="item.photosUrlList.length>0" >
							<image :src="img" style="width: 246rpx;height: 420rpx;" v-for="(img,index2) in item.photosUrlList" :key="index2" mode="aspectFill"  @tap="previewImage(item.photosUrlList,index2)"></image>
						</view> -->
						<view class="img"  style="display: flex;flex-wrap: wrap;" v-show="item.photosUrlList.length>0" >
							<image :src="img"  @tap="previewImage(item.photosUrlList,index2)" mode="aspectFill" style="width:180rpx;height:180rpx;margin-bottom: 10rpx;" v-for="(img,index2) in item.photosUrlList"
							 :key="index2"></image>
						</view>
						<!-- 点赞 -->
						<view style="width: 100%;height: 42rpx;display:flex;position: relative; margin-bottom: 20rpx;">
							<view class="zanNumber" v-show="item.likenumInt">
								{{item.likenumInt}}
							</view>
							<view style="width: 42rpx;height: 37rpx;position: absolute;right:82rpx ;" @tap="clickZan(item)">
								<image src="../../static/circle_icon_heart_set@2x.png" style="width: 100%;height: 100%;"></image>
								<!-- <image src="../../static/dzed.png" style="width: 100%;height: 100%;" v-else-if="item.likenumInt>=1"></image> -->
							</view>
							<!-- 评论 -->
							<view class="meau" @tap="talk(item.circleId)">
								<image src="../../static/talk.png" style="width: 100%;height: 100%;"></image>
							</view>
						</view>
						<!-- 评论列表 -->
						<view class="list" v-if="item.commentsList.length>0">
							<view class="replayContent">
								<view style="margin-left: 16rpx;margin-top: 10rpx;" v-for="(list,index) in item.commentsList" :key="index">
									<view class="talk">
										<text>{{list.comCreateBy}} <text style="color: #333333;font-size: 28rpx;">: {{list.commentConten}}</text></text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- <uni-load-more :status="status"></uni-load-more> -->
			<view v-show="isUpLoading" class="s-pull-up-wrap">
				<view class="s-pull-loading-icon s-pull-loading-rotate"></view>
				<view>{{upLoadingText}}</view>
			</view>
			<view v-show="isUpFinish" class="s-pull-up-wrap">
				<view class="s-pull-tip-wrap">{{upFinishText}}</view>
			</view>
		</view>

		<!-- 评论 -->
		<!-- :style="{bottom:height==''?0:height + 'rpx' } " -->
		<view class="talkAbout" v-show="isTalk">
			<!-- 评论弹出框-->
			<view class="leftContent">
				<input type="text" style="width: 100%;height: 100%;padding-left: 16rpx;" placeholder="评论" cursor-spacing="2"
				 @confirm="send" :focus="isFouce" @blur="bindBlur" v-model="talkInfo">
			</view>
			<view @tap="send" class="sendBtn">发送</view>
		</view>
		<!-- 认证房屋是否通过提示 -->
		<uniPopup ref='popup' type="center">
			<view style="width: 600rpx;height: 522rpx;background-color: #fff;border-radius: 10rpx;" class="popupBox">
				<image src="../../static/auditing_popup.png" style="width:85%;height: 100%;margin-top: -50rpx;margin-left: 30rpx;"></image>
				<view class="popupTitle" v-if="houseStatus==1">当前认证房屋正在审核中</view>
				<view class="popupTitle" v-else-if="houseStatus==4">当前暂无房屋绑定,请重新认证</view>
				<button class="popupBtn" @tap="popupClose" v-if="houseStatus==1">我知道了</button>
				<button class="popupBtn" @tap="goTapHouse" v-else-if="houseStatus==4">去认证</button>
			</view>
		</uniPopup>
	</view>
</template>
<script>
	var a
	var _self, page = 1 //定义初始页数;
	import uLiLoadMore from "../../components/uLi-load-more/uLi-load-more.vue"
	export default {
		data() {
			return {
				houseStatus: '',
				userName: uni.getStorageSync('createBy'),
				headImg: uni.getStorageSync('headImg'),
				userPhone: uni.getStorageSync('userPhone'),
				circleId: '', //朋友圈Id
				isUpFinish: false,
				// 上拉加载时文案
				upLoadingText: '加载中 ...',
				upFinishText: '暂无更多了',
				isUpLoading: false,
				status: 'more', //上拉状态
				Url: "http://bpic.588ku.com/element_origin_min_pic/16/10/30/528aa13209e86d5d9839890967a6b9c1.jpg",
				talkInfo: '', //评论内容
				talkIndex: 0,
				phoneHeight: 0, //手机状态栏的高度
				visible: false, //判断弹窗显隐
				isShow: true, //判断点赞还是取消点赞
				isTalk: false, //
				isFouce: false, //判断是否聚焦
				height: '',
				//页面数据
				list: [],
				data: [

				]
			}
		},
		onTabItemTap() {
			uni.pageScrollTo({
			    scrollTop: 0,
			    duration: 300
			});
			_self = this;
			page = 1
			this.getData()
		},
		onShow() {
			this.houseStatus = uni.getStorageSync('houseStatus')
			this.userName =uni.getStorageSync('createBy')
			this.headImg=uni.getStorageSync('headImg')
			if(a){
				a=false
				return
			}else{
				_self = this;
				page = 1
				this.getData()
			}
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中',
				mask: true
			})
			_self = this;
			page = 1
			this.getData()
		},
		onReachBottom() {
			this.getmorelist();
		},
		components: {
			uLiLoadMore
		},
		created() {
			// 获取状态栏的高度
			this.phoneHeight = uni.getSystemInfoSync().statusBarHeight
		},
		onLoad() {
			uni.showLoading({
				title: '加载中',
				mask: true
			})
			_self = this;
			page = 1
			this.getData()
			this.houseStatus = uni.getStorageSync('houseStatus')
			this.userName =uni.getStorageSync('createBy')
			this.headImg=uni.getStorageSync('headImg')
		},
		methods: {
			//重新认证房屋
			goTapHouse(){
				uni.navigateTo({
					url:'../authentication/city'
				})
				this.$refs.popup.close()
			},
			// 关闭弹窗
			popupClose() {
				this.$refs.popup.close()
			},
			//查看我的信息
			seeMyInfo() {
				if (this.houseStatus == 1||this.houseStatus==4) {
					this.$refs.popup.open()
					return
				}
				uni.navigateTo({
					url: '../mine/myInfo'
				})
			},
			//获取列表数据
			getData() {
				uni.showLoading({
					mask:true,
					title:'加载中'
				})
				this.http.httpRequest('/wxapplet/prop/comtycircle/list', 'get', {
					pageNum: page,
					comtyId: uni.getStorageSync('comtyId'),
					pageSize: 10,
				}, true).then((res) => {
					console.log(res)
					if (res.code == 0) {
						this.data = res.data.rows
						setTimeout(() => {
							uni.hideLoading()
							uni.stopPullDownRefresh()
						}, 1500)
					} else {
						uni.hideLoading()
						uni.showToast({
							title: res.msg,
							'icon': 'none'
						})
					}
				}).catch(() => {
					uni.hideLoading()
				})
			},
			//加载更多数据获取
			getmorelist() {
				this.isUpLoading = true
				this.http.httpRequest('/wxapplet/prop/comtycircle/list', 'get', {
					pageNum: page + 1,
					comtyId: uni.getStorageSync('comtyId'),
					pageSize: 10,
				}, true).then((res) => {
					console.log(res)
					if (res.code == 0) {
						// 判断当前数据是否加载完毕
						if (this.data.length >= res.data.total) {
							this.isUpLoading = false
							this.isUpFinish = true
							return
						} else {
							this.isUpFinish = false
							setTimeout(() => {
								page++; //每加载一次 页数+1
								this.data = this.data.concat(res.data.rows); //将数据拼接在一起
								this.isUpLoading = false
							}, 500)
						}
					} else {
						uni.showToast({
							title: res.msg,
							'icon': 'none'
						})
					}
				}).catch(() => {
					this.isUpLoading = false
				})

			},
			// 预览图片
			previewImage(item,index) {
				a=true
				uni.previewImage({
					current:item[index],
					urls: item,
					success: (res) => {
						console.log(res)
						uni.stopPullDownRefresh()
						// uni.hideLoading()
					}
				})
			},
			// 切换背景图片
			changeBgImg() {
				// uni.chooseImage({
				// 	count: 1, //默认9
				// 	sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				// 	success: (res) => {
				// 		console.log(res.tempFiles[0].path)
				// 	}
				// });
			},
			// 发送评论失去焦点
			bindBlur() {
				this.isTalk = false
				this.isFouce = false
			},
			// 获取焦点
			bindFouce(e) {
				console.log(e)
				this.height = e.detail.height

			},
			// 发送评论
			send() {
				let talkInfo = this.talkInfo
				console.log(talkInfo)
				//判断评论是否为空
				if (!this.talkInfo) {
					return
				}
				this.http.httpRequest('/wxapplet/prop/comment/add', 'post', {
					circleId: this.circleId,
					commentConten: this.talkInfo,
					createBy: uni.getStorageSync('createBy')
				}, true).then((res) => {
					if (res.code == 0) {
						this.data.forEach((item, index) => {
							// 判断当前评论的时哪条信息
							if (item.circleId == this.circleId) {
								this.data[index].commentsList.push({
									commentConten: talkInfo,
									comCreateBy: uni.getStorageSync('createBy')
								})
								// temp.commentConten = talkInfo,
								// 	temp.comCreateBy = uni.getStorageSync('createBy')
								// item.commentsList.push(temp)
							}
						})
						console.log(this.data)
					} else {
						uni.showToast({
							title: res.msg,
							'icon': 'none'
						})
					}
				})
				this.isTalk = false
				this.isFouce = false
				this.talkInfo = ''
			},
			// 评论
			talk(id) {
				if (this.houseStatus == 1||this.houseStatus==4) {
					this.$refs.popup.open()
					return
				}
				this.circleId = id
				this.visible = false
				this.isTalk = true
				this.isFouce = true

			},
			// 打开点赞弹窗
			openDailog(index) {
				this.talkIndex = index
				this.visible = !this.visible
				// this.data[index].show=!this.data[index].show
			},
			//点赞
			clickZan(item) {
				if (this.houseStatus == 1||this.houseStatus==4) {
					this.$refs.popup.open()
					return
				}
				this.http.httpRequest('/wxapplet/prop/comtycircle/edit', 'post', {
					pLikeUserId: item.userId,
					circleId: item.circleId
				}, true).then((res) => {
					console.log(res)
					if (res.code == 0) {
						// uni.showToast({
						// 	title: '点赞成功',
						// 	'icon': 'success'
						// })
						// setTimeout(() => {
						// 	this.getData()
						// }, 500)
						this.data.forEach((ele) => {
							// 判断当前评论的时哪条信息
							if (ele.circleId == item.circleId) {
								ele.likenumInt = 1
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							'icon': 'none'
						})
					}

				})

			},
			// 点击其他地方关闭弹窗
			closeDialog() {
				this.visible = false
			},
			// 发布
			publish() {
				if (this.houseStatus == 1||this.houseStatus==4) {
					this.$refs.popup.open()
					return
				}
				uni.navigateTo({
					url: "publish"
				})
			}

		}
	}
</script>

<style lang="scss">
	.img image{
		padding-right: 10rpx;
	}
	.img image:nth-child(3n){
		padding-right: 0rpx;
	}
	.popupClose {
		width: 44rpx;
		height: 44rpx;
		position: absolute;
		right: 20rpx;
		top: 20rpx;

	}

	.popupBtn {
		width: 342rpx;
		height: 80rpx;
		position: absolute;
		bottom: 80rpx;
		left: 128rpx;
		background: rgba(41, 138, 253, 1);
		color: #FFFFFF;
		font-size: 32rpx;
	}

	.popupTitle {
		width: 400rpx;
		height: 40rpx;
		font-size: 28rpx;
		color: #999999;
		position: absolute;
		bottom: 232rpx;
		left: 170rpx;
	}

	.popupImage {
		width: 100%;
		height: 300rpx;
		/* 	background-image: url(../../static/success_popup@2x.png);
	 position: absolute;
	 top: -64rpx; */

	}

	.zanNumber {
		position: absolute;
		right: 135rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(41, 138, 253, 1);
		// margin-right: 8rpx;
	}

	.sendBtn {
		width: 150rpx;
		font-size: 28rpx;
		height: 60rpx;
		border-radius: 30rpx;
		text-align: center;
		background: rgba(87, 224, 135, 1);
		line-height: 60rpx;
		margin-left: 15rpx;
		margin-top: 35rpx;
		color: #FFFFFF;
	}

	.talkAbout {
		width: 100%;
		height: 130rpx;
		display: flex;
		position: fixed;
		bottom: 20rpx;
		background: rgba(247, 247, 247, 1);
		border-top: 1rpx solid #C0C0C0;
		// margin-left: 10rpx;
	}

	.leftContent {
		width: 550rpx;
		height: 100rpx;
		background: #FFFFFF;
		margin-top: 15rpx;
		margin-left: 15rpx;
	}

	.leftIcon-text {
		max-width: 58px;
		height: 40px;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(255, 255, 255, 1);
		margin-top: 10rpx;
		margin-left: 8rpx;

	}

	.mainInfo {
		width: 100%;
		border-bottom: 2rpx solid rgba(247, 247, 247, 1);
	}

	.rightIcon {
		width: 49%;
		height: 56rpx;
		display: flex;
		margin-top: 24rpx;
	}

	.dailog {
		width: 406rpx;
		height: 100rpx;
		background: rgba(47, 47, 47, 1);
		opacity: 1;
		border-radius: 10rpx;
		position: absolute;
		right: 88rpx;
		bottom: -25rpx;
		display: flex;
	}

	.leftIcon {
		width: 49%;
		height: 56rpx;
		display: flex;
		margin-top: 24rpx;
		border-right: 2px solid rgba(112, 112, 112, 1);
	}

	.textInfo {
		height: 44rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(41, 138, 253, 1);
	}

	.talk {
		width: 100%;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(41, 138, 253, 1);
	}

	.replayContent {
		width: 100%;
		padding-bottom: 20rpx;
	}

	.zanList {
		width: 100%;
		background: rgba(247, 247, 247, 1);
		opacity: 1;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(41, 138, 253, 1);
		overflow: hidden;
		border-bottom: 2rpx solid rgba(221, 221, 221, 1);
	}

	.list {
		width: 100%;
		background: rgba(247, 247, 247, 1);
		opacity: 1;
		margin-bottom: 15rpx;
	}

	.meau {
		width: 42rpx;
		height: 37rpx;
		position: absolute;
		right: 0;
	}

	.leftDate {
		width: 104rpx;
		height: 34rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
		margin-top: 4rpx;
	}

	.img {
		width: 100%;
		padding-top: 20rpx;
	}

	.text {
		width: 100%;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(51, 51, 51, 1);
		margin-top: 10rpx;
	}

	.name {
		width: 100%;
		height: 44rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(41, 138, 253, 1);
	}

	.left {
		width: 86rpx;
		border-radius: 10rpx;
	}

	.right {
		width: 100%;
		margin-left: 16rpx;
	}

	.main {
		width: 100%;

		position: absolute;
		top: 722rpx;
	}

	.item {
		width: 666rpx;
		margin: 0 auto;
		display: flex;
		padding-top: 20rpx;

	}

	.content {
		width: 100%;
		position: absolute;
		top: 0;
		/* position: relative; */
	}

	.navTitle {
		width: 104rpx;
		height: 48rpx;
		font-size: 34rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: rgba(255, 255, 255, 1);
		margin: 0 auto;
	}

	.s-pull-down-wrap,
	.s-pull-up-wrap,
	.s-pull-tip-wrap {
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 28rpx;
		color: #969799;
	}

	.s-pull-down-wrap {
		position: absolute;
		left: 0;
		width: 100%;
		transform: translateY(-100%);
	}

	.s-pull-up-wrap,
	.s-pull-tip-wrap {
		height: 100rpx;
	}

	/* 旋转loading */
	.s-pull-loading-icon {
		width: 30rpx;
		height: 30rpx;
		display: inline-block;
		vertical-align: middle;
		border-radius: 50%;
		border: 2rpx solid #969799;
		border-bottom-color: transparent;
		box-sizing: border-box;

		&:first-child {
			margin-right: 16rpx;
		}
	}

	/* 旋转动画 */
	.s-pull-loading-rotate {
		animation: s-pull-loading-rotate 0.6s linear infinite;
	}

	@keyframes s-pull-loading-rotate {
		0% {
			transform: rotate(0deg);
		}

		100% {
			transform: rotate(360deg);
		}
	}
</style>
