<template>
	<view class="container" v-if="info">
		<!-- 评价信息区域 -->
		<view class="header">
			<!-- 用户信息区域 -->
			<view class="header_info">
				<img mode="aspectFill" :src="info.headPhoto" />
				<view class="info_msg">
					<view class="msg_name">{{ info.name }}</view>
					<view class="msg_star">
						<uni-rate readonly activeColor="#FFC300" :size="16" :value="info.score" />
					</view>
				</view>
				<view class="info_time">{{ info.commentTime }}</view>
			</view>

			<!-- 入住时间区域 -->
			<view class="header_time">{{ info.liveTime }}入住，{{ info.commentTime }}发表 | {{ info.houseName }}</view>

			<!-- 评价内容区域 -->
			<view class="header_content">{{ info.content }}</view>

			<!-- 图片列表区域 -->
			<view class="header_img">
				<img
					v-for="(ele, index) in info.url"
					:key="index"
					mode="aspectFill"
					v-if="ele.indexOf('jpg') !== -1 || ele.indexOf('png') !== -1"
					:src="ele"
					@click="handleLookImg(ele, index)"
				/>
				<video
					id="myVideo"
					class="video"
					:show-fullscreen-btn="false"
					:show-play-btn="false"
					v-for="(video, index2) in info.url"
					:key="index2"
					v-if="video.indexOf('mp4') !== -1"
					:src="video"
					@fullscreenchange="fullscreenchange"
					@click="handleClickVideo"
				></video>
			</view>
		</view>

		<!-- 民宿信息区域 -->
		<view class="hotel" @click="handleGoDetail">
			<img mode="aspectFill" :src="info.houseUrl[0]" />
			<view class="hotel_info">
				<view class="info_name">{{ info.hotelName }}</view>
				<!-- <view class="info_star">
					<uni-rate readonly activeColor="#FFC300" :size="12" :value="info.hotelScore * 1" />
					<view class="star_num">{{ info.hotelScore }}</view>
				</view> -->
				<!-- <view class="info_tags">
					<view class="tag_item">{{ info.hotelTownship }}</view>
					<view class="tag_item">{{ info.hotelType }}</view>
				</view> -->
				<view class="info_tags">{{ info.houseOrderNumber }}间，{{ info.houseName }}</view>
				<view class="info_tags">{{ info.liveTime }} - {{ info.checkOutTime }}</view>
				<view class="info_tags">总价：￥{{ info.payAccount }}</view>
			</view>
		</view>

		<!-- 评论回复区域 -->
		<view class="reply">
			<!-- 评论总条数区域 -->
			<view class="reply_title">
				<img src="../../static/index/comment.png" />
				评论({{ infoList.length }})
			</view>

			<!-- 评论列表区域 -->
			<view class="reply_box" v-if="infoList.length">
				<!-- 每一条评论区域 -->
				<view class="box_item" v-for="item in infoList" :key="item.id">
					<!-- 用户区域 -->
					<view class="item_user" @click="handleComment(item)">
						<img mode="aspectFill" :src="item.headPhoto" />
						<view class="user_info">
							<view class="info_top">{{ item.userName }}</view>
							<view class="info_bottom">{{ item.dateTime }}</view>
						</view>
					</view>
					<!-- 评价内容区域 -->
					<view class="item_content" @click="handleComment(item)">{{ item.content }}</view>

					<!-- 二级评论区域 -->
					<view class="item_child">
						<CommentChild v-if="item.commentVoList" :list="item.commentVoList" :commentParentId="info.id" />
					</view>
				</view>
			</view>

			<!-- 输入框区域 -->
			<view class="reply_input">
				<input type="text" confirm-type="send" placeholder="说点什么吧..." v-model="inputValue" @confirm="handleConfirm" />
			</view>
		</view>
	</view>
</template>

<script>
var dayjs = require('dayjs')
import CommentChild from '@/components/commentChild.vue'
export default {
	components: { CommentChild },
	data() {
		return {
			// 评价详情信息
			info: null,
			// 评价列表信息
			infoList: [],
			id: null,
			inputValue: '',
			videoContext: null,
			// 是否是全屏状态
			isFullScreen: false
		}
	},
	onReady() {
		this.videoContext = uni.createVideoContext('myVideo')
	},
	onLoad(options) {
		// console.log(options)
		this.id = options.id
		this.getData()
		uni.$on('getData', this.getData)
	},
	methods: {
		handleGoDetail() {
			uni.navigateTo({
				url: `/pages/orderDetail/orderDetail?id=${this.info.bookingId}`
			})
		},
		// 进入全屏和退出全屏时触发的回调
		fullscreenchange(e) {
			this.isFullScreen = e.detail.fullScreen
		},
		// 点击视频控件时触发的回调
		handleClickVideo() {
			if (this.isFullScreen) {
				this.videoContext.stop()
				this.videoContext.exitFullScreen()
			} else {
				this.videoContext.requestFullScreen()
				this.videoContext.play()
			}
		},
		handleComment(item) {
			uni.showModal({
				title: '请输入评论',
				editable: true,
				success: async (res) => {
					if (res.confirm) {
						const result = res.content
						if (!res.content) {
							uni.showToast({
								title: '评论内容不能为空',
								icon: 'none',
								mask: true
							})
							setTimeout(() => {
								this.handleComment()
							}, 1500)
						} else {
							let time = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
							const res = await this.$myRequest({
								url: '/mhotel/abcareplyComment.action',
								data: {
									commentId: item.id,
									commentParentId: this.info.id,
									commentName: item.userName,
									content: result,
									commentStatus: 1,
									createId: uni.getStorageSync('userInfo').id,
									createUsername: uni.getStorageSync('userInfo').user_name,
									createDate: time,
									modifyDate: time
								}
							})
							// console.log(res);
							if (res.code === 200) {
								uni.showToast({
									title: '评论成功，审核通过后展示',
									icon: 'none',
									mask: true
								})
								setTimeout(() => {
									this.getData()
								}, 1500)
							}
						}
					}
				}
			})
		},
		// 获取详情数据
		async getData() {
			const res = await this.$myRequest({
				url: '/mhotel/abcapersonageDetails.action',
				data: {
					bookingCommentId: this.id
				}
			})
			// console.log(res)
			if (res.code === 200) {
				this.info = res.commentDetails
				this.infoList = res.comment || []
			}
		},
		async handleConfirm() {
			if (!this.inputValue) {
				return
			}
			let time = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
			const res = await this.$myRequest({
				url: '/mhotel/abcareplyComment.action',
				data: {
					commentId: this.info.id,
					commentParentId: this.info.id,
					commentName: this.info.name,
					content: this.inputValue,
					commentStatus: 1,
					createId: uni.getStorageSync('userInfo').id,
					createUsername: uni.getStorageSync('userInfo').user_name,
					createDate: time,
					modifyDate: time
				}
			})
			// console.log(res);
			if (res.code === 200) {
				uni.showToast({
					title: '评论成功，审核通过后展示',
					icon: 'success',
					mask: true
				})
				this.inputValue = ''
				setTimeout(() => {
					this.getData()
				}, 1500)
			}
		},
		// 点击图片回调
		handleLookImg(url, current) {
			this.videoContext.stop()
			uni.previewImage({
				urls: [url],
				current
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	background-color: #f2f3f5;

	.header {
		margin-top: 1rpx;
		padding: 0 20rpx;
		background-color: #fff;

		.header_info {
			display: flex;
			align-items: center;
			height: 115rpx;

			img {
				width: 70rpx;
				height: 70rpx;
				border-radius: 50%;
			}

			.info_msg {
				margin-left: 18rpx;

				.msg_name {
					font-size: 28rpx;
				}

				.msg_star {
					margin-left: -5rpx;
					margin-top: 5rpx;
				}
			}

			.info_time {
				margin-top: 25rpx;
				margin-left: auto;
				color: #a6a6a6;
				font-size: 24rpx;
			}
		}

		.header_time {
			color: #a6a6a6;
			font-size: 24rpx;
		}

		.header_content {
			margin-top: 18rpx;
			font-size: 24rpx;
		}

		.header_img {
			display: grid;
			grid-template-columns: 1fr 1fr 1fr;
			grid-auto-rows: auto;
			padding: 20rpx 20rpx 40rpx;
			gap: 10rpx;

			img {
				width: 216rpx;
				height: 216rpx;
				border-radius: 20rpx;
			}

			.video {
				width: 216rpx;
				height: 216rpx;
				border-radius: 20rpx;
			}
		}
	}

	.hotel {
		display: flex;
		align-items: center;
		padding: 20rpx 0;
		margin-top: 20rpx;
		// height: 160rpx;
		background-color: #fff;

		img {
			margin-left: 20rpx;
			width: 120rpx;
			height: 170rpx;
			border-radius: 7rpx;
		}

		.hotel_info {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin-left: 20rpx;
			height: 170rpx;

			.info_name {
				font-size: 32rpx;
			}
			.info_star {
				display: flex;
				align-items: center;

				.star_num {
					margin-left: 10rpx;
					color: #ffc300;
					font-size: 24rpx;
				}
			}

			.info_tags {
				display: flex;
				color: #a6a6a6;
				font-size: 24rpx;

				.tag_item {
					margin-right: 20rpx;
				}
			}
		}
	}

	.reply {
		margin-top: 20rpx;
		background-color: #fff;

		.reply_title {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			padding-right: 35rpx;
			height: 90rpx;
			font-size: 24rpx;
			border-bottom: 1rpx solid #e6e6e6;

			img {
				margin-right: 12rpx;
				width: 25rpx;
				height: 21rpx;
			}
		}

		.reply_box {
			padding: 0 20rpx 30rpx;

			.box_item {
				margin-bottom: 10rpx;
				padding-bottom: 10rpx;
				border-bottom: 1rpx solid #e6e6e6;

				.item_user {
					display: flex;
					align-items: center;
					height: 120rpx;

					img {
						width: 70rpx;
						height: 70rpx;
						border-radius: 50%;
					}

					.user_info {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						margin-left: 18rpx;
						height: 70rpx;

						.info_top {
							font-size: 28rpx;
						}
						.info_bottom {
							color: #a6a6a6;
							font-size: 24rpx;
						}
					}
				}

				.item_content {
					font-size: 24rpx;

					.content_key {
						color: #808080;
					}
				}

				.item_child {
					margin-left: 50rpx;
				}
			}
		}

		.reply_input {
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 0 33rpx;
			margin: 15rpx auto 54rpx;
			width: 710rpx;
			height: 78rpx;
			font-size: 24rpx;
			border-radius: 44rpx;
			background-color: #e6e6e6;

			input {
				width: 100%;
			}
		}
	}
}
</style>
