<template>
	<view class="container">
		<!-- 分段器区域 -->
		<view class="segmented">
			<uni-segmented-control :current="activeCurrent" :values="headerList" style-type="text" active-color="#096562" @clickItem="onClickItem" />
		</view>

		<!-- 列表区域 -->
		<scroll-view class="body" scroll-y @scrolltolower="handlePull">
			<!-- 每一个盒子区域 -->
			<view class="box" v-for="(item, index) in list" :key="index" @click="handleGoDetail(item)">
				<!-- 头部区域 -->
				<view class="box_top" v-if="activeCurrent === 0">
					<img mode="aspectFill" src="../../static/my/hotel.png" />
					<view class="top_name">{{ item.hotelName }}</view>
					<view class="box_type">已消费</view>
				</view>

				<!-- 房间信息区域 -->
				<view class="box_center" v-if="activeCurrent === 0">
					<img mode="aspectFill" :src="item.url" />
					<view class="center_info">
						<view>{{ item.houseOrderNumber }}间，{{ item.houseName }}</view>
						<view v-if="item.checkOutTime">{{ item.liveTime.slice(0, 10) }} - {{ item.checkOutTime.slice(0, 10) }}</view>
						<view>总价：¥{{ item.payAccount }}</view>
					</view>
				</view>

				<!-- 按钮区域 -->
				<view class="box_btn" v-if="activeCurrent === 0">
					<view class="btn_eva" @click.stop="handleGoPage(item)">去评价</view>
				</view>

				<!-- 审核中 已驳回 已评价 样式区域 -->
				<view class="box_top2" v-if="activeCurrent !== 0">
					<view class="top_name">{{ item.commentTime.slice(0, 20) }}发表</view>
					<view class="box_type color" v-if="activeCurrent === 1">审核中</view>
					<view class="box_type color2" v-if="activeCurrent === 2">已驳回</view>
				</view>
				<view class="box_rate" v-if="activeCurrent !== 0">
					评分：
					<uni-rate readonly activeColor="#FFC300" :size="16" :value="item.score" />
				</view>
				<view class="box_content" v-if="activeCurrent !== 0">
					{{ item.content }}
				</view>

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

				<!-- 民宿信息区域 -->
				<view class="box_hotel" v-if="activeCurrent !== 0" @click.stop="">
					<img mode="aspectFill" :src="item.coverImg" />
					<view class="hotel_info">
						<view class="info_name">{{ item.hotelName }}</view>
						<view class="info_tags">{{ item.vo.houseOrderNumber }}间，{{ item.houseName }}</view>
						<view class="info_tags">{{ item.vo.liveTime.slice(0, 10) }} - {{ item.vo.checkOutTime.slice(0, 10) }}</view>
						<view class="info_tags">总价：￥{{ item.vo.payAccount }}</view>
					</view>
				</view>
				<view class="box_desc" v-if="activeCurrent === 2">
					<view class="desc_key">备注：</view>
					<view class="desc_value">{{ item.vo.remark }}</view>
				</view>
			</view>

			<view class="noData" v-if="list.length === 0">
				<img lazy-load :lazy-load-margin="0" src="../../static/images/noData.png" />
				{{ noDataMsg }}
			</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 分段器当前激活索引
			activeCurrent: 0,
			// 分段器数组
			headerList: ['待评价', '审核中', '已驳回', '已评价'],
			// 列表数据
			list: [],
			noDataMsg: '暂无待评价数据',
			// 当前页
			page: 1,
			// 每页多少条
			rows: 6,
			// 总条数
			total: null,
			status: 0,
			// 是否是全屏状态
			videoContext: null,
			isFullScreen: false
		}
	},
	onLoad() {
		this.getData()
	},
	methods: {
		async getData() {
			const res = await this.$myRequest({
				url: '/mhotel/abcapersonageComment.action',
				data: {
					usersId: uni.getStorageSync('userInfo').id,
					status: this.status,
					page: this.page,
					rows: this.rows
				}
			})
			// console.log(res)
			if (res.code === 200) {
				if (res.page.pageList) {
					this.list = [...this.list, ...res.page.pageList]
				}
				this.total = res.page.total
				this.headerList = [`待评价(${res.data.waitingCount})`, `审核中(${res.data.auditCount})`, `已驳回(${res.data.refuseAuditCount})`, `已评价(${res.data.ratedCount})`]
			}
		},
		// 切换分段器回调
		onClickItem(e) {
			this.activeCurrent = e.currentIndex
			if (e.currentIndex === 0) {
				this.noDataMsg = '暂无待评价数据'
				this.status = 0
			} else if (e.currentIndex === 1) {
				this.noDataMsg = '暂无审核中数据'
				this.status = 2
			} else if (e.currentIndex === 2) {
				this.noDataMsg = '暂无已驳回数据'
				this.status = 3
			} else if (e.currentIndex === 3) {
				this.noDataMsg = '暂无已评价数据'
				this.status = 1
			}
			this.list = []
			this.page = 1
			this.getData()
		},
		// 列表下拉到底部回调
		handlePull() {
			if (this.list.length < this.total) {
				this.page++
				this.getData()
			} else {
				uni.showToast({
					title: '没有更多数据了',
					icon: 'none'
				})
			}
		},
		//去评价按钮回调
		handleGoPage(item) {
			uni.navigateTo({
				url: `/pagesSub/evaluate/evaluate?bookingId=${item.id}&hotelId=${item.hotelId}&houseId=${item.houseId}`
			})
		},
		// 点击每一个评价订单的回调
		handleGoDetail(item) {
			if (this.activeCurrent !== 0) {
				uni.navigateTo({
					url: `/pagesSub/appraiseDetail/appraiseDetail?id=${item.id}`
				})
			} else {
				uni.navigateTo({
					url: `/pages/orderDetail/orderDetail?id=${item.id}`
				})
			}
		},
		// 点击图片回调
		handleLookImg(url, index) {
			if (this.videoContext) {
				this.videoContext.stop()
			}
			uni.previewImage({
				urls: [url],
				current: index
			})
		},
		// 点击视频控件时触发的回调
		handleClickVideo(id) {
			this.videoContext = uni.createVideoContext(id)
			if (this.isFullScreen) {
				this.videoContext.stop()
				this.videoContext.exitFullScreen()
			} else {
				this.videoContext.requestFullScreen()
				this.videoContext.play()
			}
		},
		// 进入全屏和退出全屏时触发的回调
		fullscreenchange(e) {
			this.isFullScreen = e.detail.fullScreen
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	height: 100vh;
	background-color: #f2f3f5;
	overflow: hidden;

	.segmented {
		box-sizing: border-box;
		padding: 0 50rpx;
		height: 100rpx;
		background-color: #fff;
	}

	.body {
		box-sizing: border-box;
		padding: 20rpx 0;
		height: calc(100vh - 100rpx);
		overflow-y: auto;

		.box {
			padding: 0 20rpx 20rpx;
			margin-bottom: 20rpx;
			background-color: #fff;

			.box_top {
				display: flex;
				align-items: center;
				height: 94rpx;

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

				.top_name {
					margin-left: 18rpx;
					font-size: 32rpx;
					font-weight: bold;
				}

				.box_type {
					margin-left: auto;
					color: #808080;
					font-size: 28rpx;
				}
			}

			.box_top2 {
				display: flex;
				align-items: center;
				height: 80rpx;
				border-bottom: 1rpx solid #e5e5e5;

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

				.top_name {
					font-size: 28rpx;
					font-weight: bold;
				}

				.box_type {
					margin-left: auto;
					color: #808080;
					font-size: 28rpx;
				}

				.color {
					color: #e6a23c;
				}

				.color2 {
					color: #f56c6c;
				}
			}

			.box_center {
				display: flex;

				img {
					width: 100rpx;
					height: 100rpx;
					border-radius: 10rpx;
				}

				.center_info {
					margin-top: -5rpx;
					margin-left: 18rpx;
					color: #808080;
					font-size: 28rpx;
				}
			}

			.box_btn {
				display: flex;
				justify-content: flex-end;
				margin-top: 35rpx;

				.btn_eva {
					display: flex;
					justify-content: center;
					align-items: center;
					margin-left: 20rpx;
					width: 178rpx;
					height: 68rpx;
					color: #808080;
					font-size: 28rpx;
					border-radius: 64rpx;
					border: 1rpx solid #808080;
				}
			}

			.box_rate {
				display: flex;
				align-items: center;
				height: 70rpx;
				color: #808080;
				font-size: 28rpx;
			}

			.box_content {
				font-size: 24rpx;
			}

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

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

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

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

			.box_hotel {
				display: flex;
				align-items: center;
				padding: 20rpx 0;
				border-top: 1rpx solid #e6e6e6;
				background-color: #fff;

				img {
					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;
						font-weight: bold;
					}
					.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;
						}
					}
				}
			}

			.box_desc {
				display: flex;
				padding-top: 15rpx;
				font-size: 28rpx;
				border-top: 1rpx solid #e6e6e6;

				.desc_key {
				}

				.desc_value {
					flex: 1;
					color: #808080;
				}
			}
		}

		.noData {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			padding-bottom: 20rpx;

			img {
				margin-top: 160rpx;
				width: 600rpx;
				height: 600rpx;
			}
		}
	}
}
</style>
