<template>
	<view class="pinglun">
		<view class="pinglun-title">
			全部评论 
		</view>
		<view class="pinglun-item hflex jbetween" v-for="(item,index) in pinglunlist" :key="index">
			<image class="user-img" :src="item.user.avatar" mode="aspectFill"></image>
			<view class="pinglun-right">
				<view class="pinglun-user hflex jbetween">
					<view class="pinglun-user-center">
						<text>{{item.user.username || '暂无昵称'}}</text>
					</view>
				</view>
				<view class="pinglun-text">
					{{item.content}}
				</view>
				<view class="hflex acenter jbetween">
					<view class="pinglun-time hflex acneter">
						<text>{{item.date}}</text>
						<text @click="reply(item)">回复</text>
					</view>
					<view class="hflex acenter pinglun-dianzan">
						<image v-if="item.is_like == 0" src="@/static/images/dianzan.png" mode="aspectFill"></image>
						<image v-else src="@/static/images/dianzan.png" mode="aspectFill"></image>
						<text>{{item.like_count || '0'}}</text>
						<image src="@/static/images/cai.png" mode="aspectFill"></image>
					</view>
				</view>
				<view v-if="item.children.length > 0">
					<view class="pinglun-item2 hflex" v-for="(a,b) in item.children" :key="b">
						<image class="user-img2" :src="a.user.avatar" mode="aspectFill"></image>
						<view class="pinglun-right">
							<view class="pinglun-user hflex">
								<view class="pinglun-user-center hflex acenter">
									<text>{{a.user.username}}</text>
									<u-icon name="play-right-fill" color="#999999" size="16"></u-icon>
									<text>{{a.parent_user.username}}</text>
								</view>
							</view>
							<view class="pinglun-text">
								{{a.content}}
							</view>
							<view class="hflex acenter jbetween">
								<view class="pinglun-time hflex acneter">
									<text>{{a.date}}</text>
									<text @click="reply(a)">回复</text>
								</view>
								<view class="hflex acenter pinglun-dianzan">
									<image v-if="a.is_like == 0" src="@/static/images/dianzan.png" mode="aspectFill"></image>
									<image v-else src="@/static/images/dianzan.png" mode=""></image>
									<text>{{a.like_count || '0'}}</text>
									<image src="@/static/images/cai.png" mode="aspectFill"></image>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="huifu hflex acenter jbetween" v-if="show">
			<image :src="user.avatar" mode="aspectFill"></image>
			<u-input v-model="comment" placeholder="添加新评论" border="none" adjustPosition focus></u-input>
			<text @click="send">发送</text>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	export default {
		props: {
			show_jianpan: {
				typeof: Boolean,
				default: false
			},
			type: {
				typeof: String,
				default: ''
			},
			id: {
				typeof: String,
				default: ''
			},
			user: {
				typeof: Object,
				default: {}
			}
		},
		
		
		watch: {
			show_jianpan(newval,oldval) {
				this.show = newval
			},
		},
		data() {
			return {
				comment: '',
				pinglunlist: [],
				show: false,
				limit: 10,
				parent_id: '0'
			}
		},
		mounted() {
			setTimeout(() => {
				this.getlist()
			},300)
		},
		methods: {
			reply(item) {
				this.show = true
				this.parent_id = item.id
			},
			send() {
				if(this.comment == '') {
					uni.$u.toast('请先输入内容')
					return
				}
				var _this = this
				$api.req({
					url: 'comment',
					method: 'post',
					data: {
						source_type: _this.type,
						source_id:  _this.id,
						content: _this.comment,
						parent_id: _this.parent_id
					}
				},function(res) {
					if(res.code == 10000) {
						uni.$u.toast('评论成功')
						_this.getlist()
					}
				})
			},
			getlist() {
				var _this = this
				$api.req({
					url: 'comment',
					method: 'GET',
					data: {
						limit: _this.limit,
						source_type: _this.type,
						source_id: _this.id,
						order_type: 'desc'
					}
				}, function(res) {
					if(res.code == 10000) {
						_this.pinglunlist = res.data
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.pinglun::v-deep {
		padding: 0 32rpx;
		box-sizing: border-box;
		.huifu {
			position: fixed;
			bottom: 0;
			left: 0;
			height: 160rpx;
			z-index: 999;
			background: #FFFFFF;
			// box-shadow: 0rpx 0rpx 0rpx 0rpx rgba(0,0,0,0.1);
			padding: 20rpx 28rpx;
			box-sizing: border-box;
			width: 100%;
			image {
				width: 56rpx !important;
				height: 56rpx;
				border-radius: 50%;
				margin: 0 20rpx 0 0;
			}
			text {
				font-size: 32rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				color: #999999;
			}
		}
		.pinglun-item {
			box-sizing: border-box;
			width: 100%;
	
			.pinglun-right {
				width: calc(100% - 88rpx);
				.pinglun-time {
					margin-bottom: 28rpx;
	
					text:first-child {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #777777;
						margin-right: 24rpx;
					}
	
					text:nth-child(2) {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #222222;
					}
				}
	
				.pinglun-text {
					padding: 0 36rpx 0 0;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					margin-bottom: 20rpx;
				}
				.pinglun-dianzan {
					margin-bottom: 28rpx;
					image {
						width: 32rpx;
						height: 32rpx;
						// margin-right: 4rpx;
					}
					
					text {
						font-size: 24rpx;
						font-family: ArialMT;
						padding: 0 24rpx 0 12rpx;
						color: #777777;
					}
				}
				.pinglun-user {
					margin-bottom: 24rpx;
	
					
	
	
	
					.pinglun-user-center {
						height: 68rpx;
						.u-icon {
							padding: 0 16rpx;
						}
						text {
							font-size: 28rpx;
							font-weight: 500;
							color: #222222;
						}
	
						
					}
				}
			}
	
			.user-img {
				width: 68rpx;
				height: 68rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}
	
		}
		.pinglun-item2 {
			box-sizing: border-box;
			width: 100%;
			
			.pinglun-right {
				width: calc(100% - 88rpx);
				.pinglun-time {
					margin-bottom: 28rpx;
			
					text:first-child {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #777777;
						margin-right: 24rpx;
					}
			
					text:nth-child(2) {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #222222;
					}
				}
			
				.pinglun-text {
					padding: 0 36rpx 0 0;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					margin-bottom: 20rpx;
				}
				.pinglun-dianzan {
					margin-bottom: 28rpx;
					image {
						width: 32rpx;
						height: 32rpx;
						// margin-right: 4rpx;
					}
					
					text {
						font-size: 24rpx;
						font-family: ArialMT;
						padding: 0 24rpx 0 12rpx;
						color: #777777;
					}
				}
				.pinglun-user {
					margin-bottom: 24rpx;
			
					
			
			
			
					.pinglun-user-center {
						height: 68rpx;
						.u-icon {
							padding: 0 16rpx;
						}
						text {
							font-size: 28rpx;
							font-weight: 500;
							color: #222222;
						}
			
						
					}
				}
			}
			
			.user-img2 {
				width: 68rpx;
				height: 68rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}
			
		}
	
		.pinglun-title {
			font-size: 32rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #222222;
			line-height: 112rpx;
		}
	}
</style>