<!-- 问答评论区 --> 

<template>
	<view class="question-comment-box">
		<!-- 第一条评论 -->
		<view class="first-comment" v-if="data.comment">
			<!-- <img :src="comment_img" alt="" class="icon"> -->
			<view class="comment">
				{{data.comment_user_name}}：
				{{data.comment}}
			</view>
		</view>	
			
		<!--  -->
		<view class="question-comment-wrapper">
			<view class="commetn-item-wrap" @click="setLikeHandle(2)">
				<img :src="data.op_type===2?tease_act_img:tease_img" alt="" class="icon">
				<text v-if="data.tease_total">{{data.tease_total}}</text>
			</view>
			<view class="commetn-item-wrap" @click="openCommentHandle">
				<img :src="comment_img" alt="" class="icon"> 
				<text v-if="data.comment_total">{{data.comment_total}}</text>
			</view>
			<view class="commetn-item-wrap" @click="setLikeHandle(1)">
				<img :src="data.op_type===1?like_act_img:like_img" alt="" class="icon">
				<text v-if="data.like_total">{{data.like_total}}</text>
			</view>
		</view>
		
	</view>
</template>

<script>
   import * as $api from '@/api/question.js' 
	export default {
		props: {
			item: {
				type: Object,
			}
		},
		data() {
			return {
            data: this.item,
				tease_img: require('@/static/question/tease.png'),
				tease_act_img: require('@/static/question/tease_act.png'),
				like_img: require('@/static/question/like.png'),
				like_act_img: require('@/static/question/like_act.png'),
				comment_img: require('@/static/question/comment.png'),
			};
		},
		methods: {
			openCommentHandle() {
				this.$emit('show_comment',this.data)
			},
         
         /* 吐槽/点赞 */
         async setLikeHandle(type) {
            const { community_question_id } = this.data;
            const { data, code } = await $api.apiSetLike({
               op_type: type,
               community_question_id: community_question_id,
               enable: type === 1 ? Number(this.data.op_type!==1) : Number(this.data.op_type!==2)
            })
            
            if(code !== 200) return
            
            const { enabled,op_type,like_total,tease_total } = data;
            this.data.tease_total = tease_total;
            this.data.like_total = like_total;
            this.data.op_type = enabled === 0 ? 0 : op_type ;
            uni.showToast({
               title: enabled === 0 ? '取消成功' : op_type=== 1 ? '点赞成功' : '吐槽成功'
            })
         },
         
         
		}
	}
</script>

<style lang="scss" scoped>
.first-comment {
	.comment {
		color: #666;
		display: flex;
		flex-wrap: wrap;
		.commenter {
			color: #000;
		}
	}
}
.question-comment-wrapper {
	color: #999;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 30rpx 40rpx;
	.commetn-item-wrap {
		display: flex;
		align-items: center;
		.icon {
			width: 48rpx;
			height: 48rpx;
			margin-right: 10rpx;
		}
	}
}

</style>
