<template>
	<view class="container">
		<!-- 评价状态区域 -->
		<view class="status">
			<img v-if="status === '1'" src="../../static/index/success.png" />
			<img v-if="status === '2'" src="../../static/index/fail.png" />
			<view class="status_msg">{{ msg }}</view>
			<view class="status_btn" @click="handleClickBtn">{{ btnMsg }}</view>
		</view>

		<!-- 民宿信息区域 -->
		<view class="info" @click="handleGoDetail">
			<img mode="aspectFill" :src="coverImg" />
			<view class="info_name">
				<view class="top">{{ hotelName }}</view>
				<view class="bottom">{{ collectNum }}人收藏</view>
			</view>
			<view :class="isCollect ? 'info_btn2' : 'info_btn'" @click="changeCollect(isCollect)">{{ isCollect ? '已收藏' : '收藏' }}</view>
		</view>

		<!-- 订单列表区域 -->
		<view class="body">
			<!-- 每一个订单区域 -->
			<view class="body_box" v-for="(item, index) in list" :key="index">
				<!-- 标题区域 -->
				<view class="box_header">
					<img class="img" src="../../static/my/hotel.png" />
					<view class="title">{{ item.hotelName }}</view>
					<view class="type">已消费</view>
				</view>

				<!-- 酒店信息区域 -->
				<view class="box_info">
					<img class="img" mode="aspectFill" :src="item.url" />
					<view class="info_right">
						<view class="info_right_item">{{ item.houseOrderNumber }}间，{{ item.houseName }}</view>
						<view class="info_right_item">{{ item.liveTime.slice(0, 10) }} - {{ item.checkOutTime.slice(0, 10) }}</view>
						<view class="info_right_item">总价：¥{{ item.payAccount }}</view>
					</view>
				</view>

				<!-- 按钮区域 -->
				<view class="box_btn">
					<view class="btn_item" @click="handleEvaluate(item)">去评价</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 评价是否成功 1成功 2失败
			status: null,
			// 评价状态信息
			msg: '',
			// 按钮文字信息
			btnMsg: '',
			// 民宿ID
			hotelId: '',
			// 当前页
			page: 1,
			// 每页多少条
			rows: 6,
			// 总条数
			total: null,
			// 数据列表
			list: [],
			// 民宿封面图
			coverImg: '',
			// 民宿名称
			hotelName: '',
			// 收藏人数
			collectNum: 0,
			// 是否收藏
			isCollect: false
		}
	},
	onLoad(options) {
		// console.log(options)
		this.status = options.status
		this.hotelId = options.hotelId
		if (this.status === '1') {
			uni.setNavigationBarTitle({
				title: '评价成功'
			})
			this.msg = '评价成功'
			this.btnMsg = '查看我的评价'
		} else {
			uni.setNavigationBarTitle({
				title: '评价失败'
			})
			this.msg = '评价失败'
			this.btnMsg = '重新评价'
		}
		this.getData()
	},
	onReachBottom() {
		if (this.list.length < this.total) {
			this.page++
			this.getData()
		} else {
			uni.showToast({
				title: '没有更多数据了',
				icon: 'none',
				mask: true
			})
		}
	},
	methods: {
		handleGoDetail() {
			uni.navigateTo({
				url: `/pages/detail/detail?id=${this.hotelId}`
			})
		},
		async getData() {
			const res = await this.$myRequest({
				url: '/mhotel/abcaunevaluatedOrder.action',
				data: {
					userId: uni.getStorageSync('userInfo').id,
					hotelId: this.hotelId,
					page: this.page,
					rows: this.rows
				}
			})
			// console.log(res)
			if (res.code === 200) {
				this.coverImg = res.data.url
				this.hotelName = res.data.name
				this.collectNum = res.data.count
				this.isCollect = res.data.isCollect
				this.total = res.data.page.total
				this.list = [...this.list, ...res.data.page.pageList]
			}
		},
		async changeCollect(isCollect) {
			const res = await this.$myRequest({
				url: isCollect ? '/mhotel/ahpdelCollectHotel.action' : '/mhotel/ahpcollectHotel.action',
				data: {
					userId: uni.getStorageSync('userInfo').id,
					hotelId: this.hotelId
				}
			})
			// console.log(res)
			if (res.code === 200) {
				uni.showToast({
					title: isCollect ? '取消收藏成功' : '收藏成功',
					icon: 'success',
					mask: true
				})
				this.isCollect = !this.isCollect
				this.list = []
				this.page = 1
				this.getData()
			}
		},
		handleEvaluate(item) {
			uni.navigateTo({
				url: `/pages/evaluate/evaluate?bookingId=${item.id}&hotelId=${item.hotelId}&houseId=${item.houseId}`
			})
		},
		// 点击按钮回调
		handleClickBtn() {
			if (this.status === '1') {
				uni.reLaunch({
					url: '/pages/myEvaluate/myEvaluate'
				})
			} else {
				uni.navigateBack(1)
			}
		}
	}
}
</script>

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

	.status {
		display: flex;
		flex-direction: column;
		align-items: center;
		height: 554rpx;
		background-color: #fff;

		img {
			margin: 80rpx 0 40rpx;
			width: 134rpx;
			height: 134rpx;
		}

		.status_msg {
			font-size: 32rpx;
		}

		.status_btn {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 87rpx;
			width: 330rpx;
			height: 84rpx;
			color: #fff;
			font-size: 28rpx;
			border-radius: 22rpx;
			background-color: #096562;
		}
	}

	.info {
		display: flex;
		align-items: center;
		margin: 20rpx 0;
		padding: 0 30rpx;
		height: 144rpx;
		background-color: #fff;

		img {
			width: 80rpx;
			height: 80rpx;
			border-radius: 9rpx;
		}

		.info_name {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin-left: 24rpx;
			height: 80rpx;

			.top {
				font-weight: bold;
				font-size: 32rpx;
			}
			.bottom {
				color: #a6a6a6;
				font-size: 24rpx;
			}
		}

		.info_btn {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-left: auto;
			width: 137rpx;
			height: 71rpx;
			color: #fff;
			font-size: 28rpx;
			border-radius: 22rpx;
			background-color: #096562;
		}

		.info_btn2 {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-left: auto;
			width: 137rpx;
			height: 71rpx;
			color: #096562;
			font-size: 28rpx;
			border: 1rpx solid #096562;
			border-radius: 22rpx;
			background-color: #fff;
		}
	}

	.body {
		padding-bottom: 20rpx;

		.body_box {
			margin-top: 20rpx;
			box-sizing: border-box;
			padding: 0 40rpx;
			background-color: #fff;

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

				.img {
					width: 47rpx;
					height: 47rpx;
				}

				.title {
					margin-left: 16rpx;
					width: 350rpx;
					font-size: 32rpx;
					font-weight: bold;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.type {
					display: flex;
					justify-content: flex-end;
					align-items: center;
					margin-left: auto;
					margin-right: 25rpx;
					width: 285rpx;
					color: #808080;
					font-size: 28rpx;
				}
			}

			.box_info {
				display: flex;
				height: 140rpx;

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

				.info_right {
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					margin-top: -5rpx;
					margin-left: 18rpx;
					height: 120rpx;
					color: #808080;
					font-size: 28rpx;

					.info_right_item {
						flex: 1;
					}
				}
			}

			.box_btn {
				display: flex;
				justify-content: flex-end;
				margin-top: -10rpx;
				height: 100rpx;

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