<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 in list" :key="item.bookingCommentId" @click="handleGoDetail(item)">
				<!-- 头部区域 -->
				<view class="box_top">
					<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">
					<img mode="aspectFill" src="https://img1.baidu.com/it/u=4085584268,3308739054&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=375" />
					<view class="center_info">
						<view>{{ item.houseOrderNumber }}间，{{ item.houseName }}</view>
						<view>{{ item.checkOutTime.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">去评价</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
		}
	},
	onLoad() {
		this.getData()
	},
	methods: {
		getData() {
			uni.request({
				url: 'http://192.168.161.224:8088/mhotel/abcapersonageComment.action',
				data: {
					usersId: uni.getStorageSync('userInfo').id,
					status: this.activeCurrent,
					page: this.page,
					rows: this.rows
				},
				success: (res) => {
					// console.log(res.data)
					if (res.data.code === 200 && res.data.page.pageList) {
						this.list = [...this.list, ...res.data.page.pageList]
						this.total = res.data.total
					}
				}
			})
		},
		// 切换分段器回调
		onClickItem(e) {
			this.activeCurrent = e.currentIndex
			if (this.activeCurrent === 0) {
				this.noDataMsg = '暂无待评价数据'
			} else {
				this.noDataMsg = '暂无已评价数据'
			}
			this.list = []
			this.page = 1
			this.getData()
		},
		// 列表下拉到底部回调
		handlePull() {
			console.log(111)
			if (this.list.length < this.total) {
				this.page++
				this.getData()
			} else {
				uni.showToast({
					title: '没有更多数据了',
					icon: 'none'
				})
			}
		},
		//去评价按钮回调
		handleGoPage() {
			uni.navigateTo({
				url: '/pages/evaluate/evaluate'
			})
		},
		// 点击每一个评价订单的回调
		handleGoDetail(item) {
			if (this.activeCurrent === 1) {
				uni.navigateTo({
					url: `/pages/appraiseDetail/appraiseDetail?id=${item.bookingCommentId}`
				})
			}
		}
	}
}
</script>

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

	.segmented {
		box-sizing: border-box;
		padding-bottom: 28rpx;
		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_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;
				}
			}
		}

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

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