<template>
	<view>
		<PostView :postValue="postValue" :postViewIndex="1" :postViewType="1"></PostView>
		<view class="center-content-focus-line"></view>
		<view class="comment">
			<view class="flex justifyBetween alignCenter commentTop">
				<text class="commentLabel">全部评论（4）</text>
				<text class="report">举报</text>
			</view>
			<view v-if="!postList" class="no-comment">
				<image class="no-comment-img" src="../../../static/images/icon/no_comment.png" mode=""></image>
				<text class="no-comment-text">暂无评论，快去做评论第一人吧！</text>
				<view class="no-comment-bt">
					<text class="no-comment-bt-text">快去抢沙发</text>
				</view>
			</view>
			<view v-else class="have-comment" v-for="(item, index) in postList" :key="index">
				<view class="flex alignCenter">
					<!-- 头像 -->
					<view class="have-comment-avatar-container">
					    <u-avatar class="have-comment-avatar-1" size="60rpx" :src="item.avatar"></u-avatar>
					    <image v-if="item.isOfficial" class="have-comment-official-1" src="../../../static/images/icon/tu3-6.png"></image>
					</view>
					<view class="flex flexColumn">
						<text class="have-comment-uname">{{item.uname}}</text>
						<text class="have-comment-address">{{item.address}}</text>
					</view>
				</view>
				<view class="have-comment-content">
					<text class="have-comment-content-text-1">{{item.content}}</text>
					<view class="have-comment-content-text-2">
						<text>{{item.createTime}}</text>
						<text class="have-comment-content-text-2-hf" @click="toAnswer(item.uname)">回复</text>
					</view>
				</view>
				<view class="" v-if="item.answerCommentList.length != 0">
					<text v-if="!item.isDeployment" class="deploymentAnswer-text" @click="deploymentAnswer(index)">---展开回复</text>
					<view v-if="item.isDeployment" class="have-comment-answer" v-for="answer in item.answerCommentList" :key="answer">
						<view class="flex alignCenter">
							<!-- 头像 -->
							<view class="have-comment-answer-avatar-container">
							    <u-avatar class="have-comment-answer-avatar-1" size="48rpx" :src="answer.avatar"></u-avatar>
							    <image v-if="answer.isOfficial" class="have-comment-answer-official-1" src="../../../static/images/icon/tu3-6.png"></image>
							</view>
							<text class="have-comment-answer-uname">{{answer.uname}}</text>
							<text v-if="answer.toUserName" class="have-comment-answer-uname">-></text>
							<text v-if="answer.toUserName" class="have-comment-answer-uname">{{answer.toUserName}}</text>
						</view>
						<view class="have-comment-answer-content">
							<text class="have-comment-answer-content-text-1">{{answer.content}}</text>
							<view class="have-comment-answer-content-text-2">
								<text>{{answer.createTime}}</text>
								<text class="have-comment-answer-content-text-2-hf" @click="toAnswer(answer.uname)">回复</text>
							</view>
						</view>
					</view>
					<text v-if="item.isDeployment" class="deploymentAnswer-text"  @click="putAnswer(index)">---收起</text>
				</view>
			</view>
		</view>
	</view>
	<!-- 评论区输入框 -->
	<up-popup :show="showInput" duration="0" @close="close" @open="open" class="comment-po">
		<view class="flex justifyBetween comment-input" :style="{ marginBottom: bottomVal + 'px' }">
			<view class="input-in flex alignCenter justifyCenter">
				<input class="input-in-text" v-if="showInputText" focus="true" maxlength="55" :placeholder="placeholderInput" :adjust-position="false" />
			</view>
			<view class="input-bt flex alignCenter justifyCenter">
				<text class="input-bt-text">发送</text>
			</view>
		</view>
	</up-popup>
	<!-- 底部操作栏 -->
	<up-tabbar
		:fixed="true"
		:placeholder="true"
		:safeAreaInsetBottom="true"
	>
		<!-- <view class="flex justifyCenter"> -->
		<view class="flex alignCenter justifyCenter">
			<view class="flex justifyCenter alignCenter commentInput" @click="toInput()">
				<image class="commentInput-img" src="../../../static/logo.png" mode=""></image>
				<text class="commentInput-text">友好评论~</text>
			</view>
		</view>
			
			<view v-if="postValue.isLike" @click.stop="cancelCollection()" class="flex alignCenter justifyCenter flexColumn">
				<image class="commentInput-img" src="../../../static/images/icon/tu3-8.png" mode=""></image>
				<text class="commentInput-txt-like">{{postValue.likeCount}}</text>
			</view>
			<view v-if="!postValue.isLike" @click.stop="addCollection()" class="flex alignCenter justifyCenter flexColumn">
				<image class="commentInput-img" src="../../../static/images/icon/tu3-7.png" mode=""></image>
				<text class="commentInput-txt">{{postValue.likeCount}}</text>
			</view>
			
			<view v-if="postValue.ifFavorite" @click.stop="cancelFavorite()" class="flex alignCenter justifyCenter flexColumn">
				<image class="commentInput-img" src="../../../static/images/icon/tu3-2.png" mode=""></image>
				<text class="commentInput-txt-favorite">{{postValue.favoriteCount}}</text>
			</view>
			<view v-if="!postValue.ifFavorite" @click.stop="addFavorite()" class="flex alignCenter justifyCenter flexColumn">
				<image class="commentInput-img" src="../../../static/images/icon/tu3-1.png" mode=""></image>
				<text class="commentInput-txt">{{postValue.favoriteCount}}</text>
			</view>
			
			<view class="flex alignCenter justifyCenter flexColumn">
				<image class="commentInput-img" src="../../../static/images/icon/tu2-9.png" mode=""></image>
				<text class="commentInput-txt">转发</text>
			</view>
		<!-- </view> -->
	</up-tabbar>
</template>

<script setup>
	import { ref, reactive, computed, onMounted, onBeforeUnmount, getCurrentInstance } from 'vue';
	import PostView from "@/pages/common/postview/index.vue";
	
	const bottomVal = ref(0);
	
	// 监听键盘高度变化
	onMounted(async () => {
	  // if (!data.value) {
	    uni.onKeyboardHeightChange(res => {
	    	if(res.height == 0) {
	    		bottomVal.value = 0;
	    		return;
	    	}
	      bottomVal.value = res.height - 20;
	      console.log(bottomVal.value)
	    });
	  // }
	})
	
	onBeforeUnmount(async () => {
      uni.offKeyboardHeightChange();
    });
	
	
	const postList = reactive([{
		avatar: 'https://k.sinaimg.cn/n/sports/transform/400/w600h600/20220130/dd38-eed53ba750d1d8c87eca8b57eda879a5.jpg/w700d1q75cms.jpg?by=cms_fixed_width',
		uname: '爱吃饭的小张',
		address: '南开大学',
		content: '大家来评论',
		createTime: '7分钟前',
		isOfficial: true,
		isDeployment: false,
		answerCommentList: [{
			avatar: 'https://picx.zhimg.com/v2-02f89d05a781ffed9fd2e32654d93135_720w.jpg?source=172ae18b',
			uname: '恋爱60秒',
			createTime: '2024.05.04',
			isOfficial: false,
			address: '理工大学',
			content: '来了',
		},
		{
			avatar: 'https://oss.1381801.com/forum/202308/11/093616ccxkx99wchwrrw1a.jpg',
			uname: '喜欢你没道理',
			createTime: '2024.05.04',
			isOfficial: false,
			address: '理工大学',
			content: '你干嘛～',
			toUserName: '恋爱60秒',
		},
		]
	},
	{
		avatar: 'https://picx.zhimg.com/v2-02f89d05a781ffed9fd2e32654d93135_720w.jpg?source=172ae18b',
		uname: '恋爱60秒',
		createTime: '2024.05.04',
		isOfficial: false,
		isDeployment: false,
		address: '理工大学',
		content: '评论区上线了',
		answerCommentList: []
	}]);
	
	const postValue = reactive(
		{
			avatar: 'https://k.sinaimg.cn/n/sports/transform/400/w600h600/20220130/dd38-eed53ba750d1d8c87eca8b57eda879a5.jpg/w700d1q75cms.jpg?by=cms_fixed_width',
			uname: '爱吃饭的小张',
			createTime: '11分钟前',
			address: '南开大学',
			isFocus: false,
			isOfficial: true,
			title: '怎么评论爱德华·艾尔加这位音乐家及其他的作品,欢迎大家发表自己的看法？',
			content: '八年前，学弟在工地上杀了一个工友，上杀了一个工友，杀人前，他给警察打了电话，预告杀人的时间和地点，和地点，并......',
			type: '1',
			media: [
				'https://tu.sioe.cn/gj/qiege/image.jpg',
				'https://picx.zhimg.com/v2-3b4fc7e3a1195a081d0259246c38debc_720w.jpg?source=172ae18b',
				'https://bpic.51yuansu.com/backgd/cover/00/63/09/64b52b1426fff_800.jpg?x-oss-process=image/resize,w_780/sharpen,100',
				'https://tu.sioe.cn/gj/qiege/image.jpg',
			],
			tab: ['学术讨论组', '校园风景'],
			transmitCount: 136,
			isLike: true,
			likeCount: 999,
			commentCount: 136,
			ifFavorite: true,
			favoriteCount: 136
		}
	);
	
	const placeholderInput = ref('')
	
	// 创建响应式数据  
	const showInput = ref(false);  
	const showInputText = ref(false)
	// 定义方法  
	function open() {  
	  // 打开逻辑，比如设置 show 为 true  
	  showInput.value = true; 
	setTimeout(() => {
	    showInputText.value = true;
	  }, 50);
	  // console.log('open');  
	}  
	  
	function close() {  
	  // 关闭逻辑，设置 show 为 false  
	  showInput.value = false;  
	  showInputText.value = false;
	  // console.log('close');  
	}
	
	const toInput = () => {
		placeholderInput.value = '发布评论'
		open();
	}
	
	const toAnswer = (toUser) => {
		placeholderInput.value = '回复：' + toUser;
		open();
	} 
	
	const cancelCollection = () => {
		postValue.likeCount -= 1;
		postValue.isLike = !postValue.isLike;
	};
	
	const addCollection = () => {
		postValue.likeCount += 1;
		postValue.isLike = !postValue.isLike;
	};
	
	const cancelFavorite = () => {
		postValue.favoriteCount -= 1;
		postValue.ifFavorite = !postValue.ifFavorite;
	};
	
	const addFavorite = () => {
		postValue.favoriteCount += 1;
		postValue.ifFavorite = !postValue.ifFavorite;
	};
	
	const deploymentAnswer = (index) => {
		postList[index].isDeployment = true;
	};
	
	const putAnswer = (index) => {
		postList[index].isDeployment = false;
	};
</script>

<style lang="scss">
page{
    background-color: #ffffff;

}
	.data-v-6fcabaad {
			border-radius: 20rpx 20rpx 20rpx 20rpx !important;
	/* 		width: 200rpx !important;
			height: 200rpx !important; */
	}
	
	.center-content-focus-line{
		height: 8rpx;
		background: #f4f5f6;
	}
	
	.comment{
		padding: 32rpx;
	}
	
	.commentLabel{
		font-weight: 400;
		/* width: 265rpx; */
		/* height: 38rpx; */
		font-size: 36rpx;
		/* text-align: left; */
		color: #000000;
		
	}
	
	.report{
		font-weight: 400;
		/* width: 52rpx; */
		/* height: 26rpx; */
		font-size: 26rpx;
		/* text-align: left; */
		color: #999999;
	}
	
	.no-comment {
	    display: flex;
	    flex-direction: column;
	    align-items: center; /* 水平居中 */
	    justify-content: center; /* 垂直居中 */
	}
	
	.no-comment-img{
		margin-top: 44rpx;
		width: 200rpx;
		height: 145rpx;
	}
	
	.no-comment-text{
		margin-top: 8rpx;
		font-weight: 400;
		font-size: 26rpx;
		color: #999999;
	}
	
	.no-comment-bt{
		margin-top: 36rpx;
		width: 308rpx;
		height: 82rpx;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		border-width: 2rpx;
		border-color: #C9F6F5;
		background: #ffffff;	
		display: flex;
		align-items: center; /* 垂直居中 */
		justify-content: center; /* 水平居中 */
	}
	
	.no-comment-bt-text{
		font-weight: 400;
		font-size: 32rpx;
		color: #CBF6F5;
	}
	
	.commentInput{
		width: 364rpx;
		height: 80rpx;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		background: #f7f8fa;
	}
	
	.commentInput-img{
		width: 40rpx;
		height: 40rpx;
	}
	
	.commentInput-text{
		font-weight: 400;
		font-size: 30rpx;
		color: #999999;
	}
	
	.commentInput-txt{
		font-weight: 400;
		font-size: 28rpx;
		color: #787878;
	}
	
	.commentInput-txt-like{
		font-weight: 400;
		font-size: 28rpx;
		color: #FA3939;
	}
	
	.commentInput-txt-favorite{
		font-weight: 400;
		font-size: 28rpx;
		color: #FFC729;
	}
	
	.have-comment{
		margin-top: 30rpx;
	}
	
	.have-comment-avatar-container {
	    position: relative;
		width: 60rpx;
		margin-right: 20rpx;
	}
	
	.have-comment-avatar-1 {
	    position: relative;
	}
	
	.have-comment-official-1 {
	    position: absolute;
	    width: 24rpx;
	    height: 24rpx;
	    bottom: 0;
	    right: 0;
	}
	
	.have-comment-uname{
		font-weight: 400;
		font-size: 26rpx;
		color: #999999;
	}
	
	.have-comment-address{
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
	}
	
	.have-comment-content{
		margin-left: 80rpx;
		margin-top: 10rpx;
	}
	
	.have-comment-content-text-1 {
		font-weight: 400;
		font-size: 30rpx;
		color: #333333;
	}
	
	.have-comment-content-text-2 {
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		margin-top: 12rpx;
	}
	
	.have-comment-content-text-2-hf {
		margin-left: 32rpx;
	}
	
	.have-comment-answer{
		margin-top: 24rpx;
		margin-left: 80rpx;
	}
	
	.have-comment-answer-avatar-container {
	    position: relative;
		width: 48rpx;
		margin-right: 20rpx;
	}
	
	.have-comment-answer-avatar-1 {
	    position: relative;
	}
	
	.have-comment-answer-official-1 {
	    position: absolute;
	    width: 16rpx;
	    height: 16rpx;
	    bottom: 0;
	    right: 0;
	}
	
	.have-comment-answer-uname{
		font-weight: 400;
		font-size: 26rpx;
		color: #999999;
	}
	
	.have-comment-answer-content{
		margin-left: 80rpx;
		margin-top: 10rpx;
	}
	
	.have-comment-answer-content-text-1 {
		font-weight: 400;
		font-size: 30rpx;
		color: #333333;
	}
	
	.have-comment-answer-content-text-2 {
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		margin-top: 12rpx;
	}
	
	.have-comment-answer-content-text-2-hf {
		margin-left: 32rpx;
	}
	
	.deploymentAnswer-text{
		margin-left: 80rpx;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
	}
	
	.input-in{
		width: 560rpx;
		height: 70rpx;
		border-radius: 37rpx 37rpx 37rpx 37rpx;
		background: #f7f8fa;
	}
	
	.input-in-text{
		width: 520rpx;
	}
	
	.input-bt{
		width: 120rpx;
		height: 74rpx;
		border-radius: 37rpx 37rpx 37rpx 37rpx;
		background: #3477fc;
	}
	
	.input-text{
		font-weight: 400;
		font-size: 30rpx;
		color: #FFFFFF;
	}
	
	.comment-input{
		padding: 24rpx;
		// margin-bottom: 800rpx;
	}
	
	.comment-po{
		// height: 500rpx;
	}
</style>

