<template>
	<view class="container">
		<!-- 导航栏图片区域 -->
		<view class="header">
			<img src="../../static/my/headerImg.png" />

			<!-- 标题区域 -->
			<view class="header_title">民宿名称</view>
			<!-- 返回图标区域 -->
			<img class="header_icon" src="../../static/index/left.png" @click="handleBack" />
		</view>

		<view class="body">
			<!-- 房间信息区域 -->
			<view class="info">
				<view class="info_time">
					{{ info.startTimeMonth }}月{{ info.startTimeMonth }}日
					<text class="gap">星期{{ info.startTimeWeek }}</text>
					<view class="time_line"></view>
					<view class="time_num">{{ info.nightNum }}晚</view>
					<view class="time_line"></view>
					<view class="gap">{{ info.endTimeMonth }}月{{ info.endTimeDay }}日</view>
					<text>星期{{ info.endTimeWeek }}</text>
				</view>
				<view class="info_msg">大床房</view>
				<view class="info_type">
					<view class="type_item">包吃住型</view>
					<view class="type_item">包吃住型</view>
					<view class="type_item">包吃住型</view>
				</view>
				<view class="info_tag">
					<view class="tag_item">16-20㎡</view>
					<view class="tag_item">双人床</view>
					<view class="tag_item">窗户位于走廊/窗户较小</view>
				</view>
			</view>

			<!-- 入住信息区域 -->
			<view class="msg">
				<view class="msg_title">入住信息</view>
				<view class="msg_box">
					<view class="box_key">房间数量</view>
					<view class="box_value">{{ roomCount }}间</view>
					<view class="box_icon">
						<img class="img" src="../../static/index/add.png" @click="handleAdd" />
						<img class="img2" src="../../static/index/minus.png" @click="handleMinus" />
					</view>
				</view>
				<view class="msg_box">
					<view class="box_key">住客姓名</view>
					<view class="box_value">
						<input type="text" placeholder="请输入住客姓名" v-model="clientName" />
					</view>
					<view class="box_icon" @click="handleSelectClient">
						<img class="img2" src="../../static/index/people.png" />
					</view>
				</view>
				<view class="msg_box">
					<view class="box_key">联系电话</view>
					<view class="box_value">
						<input type="number" maxlength="11" placeholder="请输入联系电话" v-model="clientPhone" />
					</view>
				</view>
				<view class="msg_box" @click="handleSelectTime">
					<view class="box_key">预计到店</view>
					<view class="box_value" :class="{ color: !arriveTime }">{{ arriveTime ? arriveTime : '请选择预计到店时间' }}</view>
					<view class="box_icon">
						<img class="img3" src="../../static/index/right2.png" />
					</view>
				</view>

				<uv-datetime-picker
					ref="datetimePicker"
					v-model="timeValue"
					mode="datetime"
					:closeOnClickOverlay="false"
					confirmColor="#096562"
					:formatter="formatter"
					@confirm="confirm"
				></uv-datetime-picker>
			</view>

			<!-- 费用信息区域 -->
			<view class="price">
				<view class="price_title">费用明细</view>
				<view class="price_box">
					<view class="box_key">在线支付</view>
					<view class="box_value">
						1间1晚 共
						<text>¥</text>
						<span>280.00</span>
					</view>
				</view>
			</view>

			<view class="all">
				<view class="all_title">
					<text>房费</text>
					<text class="mr_30">¥280</text>
				</view>

				<view class="all_box">
					<view class="box_list">
						<view class="list_item">2023-08-01</view>
						<view class="list_item">2023-08-02</view>
					</view>
					<view class="box_total">1 x ¥280</view>
				</view>
			</view>
		</view>

		<!-- 底部提交订单区域 -->
		<view class="foot">
			<view class="foot_left">
				<text>¥</text>
				{{ info.price }}
			</view>
			<view class="foot_right" @click="goPagePay">提交订单</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			info: {},
			// 预定房间数量
			roomCount: 1,
			// 住客姓名
			clientName: '张三',
			// 联系电话
			clientPhone: '13659865896',
			// 预计到店时间
			arriveTime: '',
			timeValue: Number(new Date())
		}
	},
	onLoad(options) {
		this.info = JSON.parse(options.info)
		// console.log(this.info)
		uni.$on('change', this.change)
	},
	methods: {
		change(e) {
			this.clientName = e.name
		},
		handleSelectClient() {
			uni.navigateTo({
				url: '/pages/common/common?type=1'
			})
		},
		confirm(e) {
			// console.log(e.value)
			let date = new Date(e.value)
			let month = date.getMonth() + 1
			let day = date.getDate()
			let H = date.getHours()
			let M = date.getMinutes()
			this.arriveTime = `${month}月${day}日${H}:${M}分之前`
		},
		formatter(type, value) {
			if (type === 'year') {
				return `${value}年`
			}
			if (type === 'month') {
				return `${value}月`
			}
			if (type === 'day') {
				return `${value}日`
			}
			return value
		},
		handleSelectTime() {
			this.$refs.datetimePicker.open()
		},
		handleAdd() {
			this.roomCount++
		},
		handleMinus() {
			if (this.roomCount > 1) {
				this.roomCount--
			} else {
				uni.showToast({
					title: '至少需要预定1间',
					icon: 'none'
				})
			}
		},
		// 提交订单按钮回调
		goPagePay() {
			let info = JSON.stringify(this.info)
			uni.navigateTo({
				url: `/pages/pay/pay?info=${info}`
			})
		},
		handleBack() {
			uni.navigateBack(1)
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	position: relative;
	display: flex;
	flex-direction: column;
	height: 100vh;
	overflow: hidden;
	background-color: #ebeced;

	.header {
		position: relative;
		height: 145rpx;
		overflow: hidden;

		img {
			width: 100%;
		}

		.header_title {
			position: absolute;
			top: 65rpx;
			left: 308rpx;
			color: #fff;
			font-size: 28rpx;
		}

		.header_icon {
			position: absolute;
			top: 76rpx;
			left: 5rpx;
			width: 47rpx;
			height: 47rpx;
		}
	}

	.body {
		height: calc(100vh - 271rpx);
		overflow-y: auto;

		.info {
			display: flex;
			flex-direction: column;
			box-sizing: border-box;
			padding: 0 30rpx;
			margin: 0 auto;
			margin-top: 18rpx;
			width: 710rpx;
			border-radius: 15rpx;
			background-color: #fff;

			.info_time {
				display: flex;
				align-items: center;
				margin-top: 20rpx;
				font-size: 32rpx;
				font-weight: bold;

				.time_line {
					width: 17rpx;
					height: 1rpx;
					background-color: #096562;
				}

				.time_num {
					box-sizing: border-box;
					padding: 0 15rpx;
					height: 46rpx;
					line-height: 46rpx;
					font-size: 24rpx;
					font-weight: 400;
					border-radius: 66rpx;
					border: 1rpx solid #096562;
					background-color: #f0f2f5;
				}

				.gap {
					margin: 0 10rpx;
				}

				text {
					font-size: 24rpx;
					font-weight: 400;
				}
			}

			.info_msg {
				margin-top: 15rpx;
				font-size: 28rpx;
				font-weight: bold;
			}
			.info_type {
				display: flex;
				flex-wrap: wrap;
				margin-top: 15rpx;

				.type_item {
					box-sizing: border-box;
					padding: 0 15rpx;
					margin-right: 20rpx;
					height: 41rpx;
					line-height: 41rpx;
					font-size: 24rpx;
					color: #fff;
					border-radius: 34rpx;
					background-color: #096562;
				}
			}

			.info_tag {
				display: flex;
				flex-wrap: wrap;
				margin: 18rpx 0 30rpx;
				color: #808080;
				font-size: 24rpx;

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

		.msg {
			box-sizing: border-box;
			padding-left: 26rpx;
			margin: auto;
			margin-top: 20rpx;
			width: 710rpx;
			border-radius: 15rpx;
			background-color: #fff;

			.msg_title {
				height: 87rpx;
				line-height: 87rpx;
				font-size: 28rpx;
				font-weight: bold;
				border-bottom: 1rpx solid #e6e6e6;
			}

			.msg_box {
				display: flex;
				align-items: center;
				height: 97rpx;
				font-size: 28rpx;
				border-bottom: 1rpx solid #e6e6e6;

				.box_key {
					width: 120rpx;
					color: #808080;
				}

				.box_value {
					margin-left: 30rpx;
					flex: 1;

					input {
						box-sizing: border-box;
						padding-right: 30rpx;
						width: 100%;
					}
				}

				.color {
					color: #808080;
				}

				.box_icon {
					display: flex;
					align-items: center;

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

					.img2 {
						margin: 0 30rpx;
						width: 37rpx;
						height: 37rpx;
					}

					.img3 {
						margin: 0 30rpx;
						width: 40rpx;
						height: 40rpx;
					}
				}
			}
		}

		.price {
			box-sizing: border-box;
			padding-left: 26rpx;
			margin: 20rpx auto;
			width: 710rpx;
			height: 197rpx;
			border-radius: 15rpx;
			background-color: #fff;

			.price_title {
				line-height: 92rpx;
				font-size: 28rpx;
				font-weight: bold;
				border-bottom: 1rpx solid #e6e6e6;
			}

			.price_box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 92rpx;
				font-size: 28rpx;

				.box_key {
					color: #808080;
				}

				.box_value {
					display: flex;
					align-items: center;

					text {
						color: #ff5733;
						font-size: 24rpx;
					}

					span {
						margin-right: 30rpx;
						color: #ff5733;
					}
				}
			}
		}

		.all {
			box-sizing: border-box;
			padding-left: 26rpx;
			margin: 0 auto 60rpx;
			width: 710rpx;
			border-radius: 15rpx;
			background-color: #fff;

			.all_title {
				display: flex;
				height: 92rpx;
				justify-content: space-between;
				align-items: center;
				font-size: 28rpx;
				font-weight: bold;
				border-bottom: 1rpx solid #e6e6e6;

				.mr_30 {
					margin-right: 30rpx;
				}
			}

			.all_box {
				box-sizing: border-box;
				padding-right: 26rpx;
				display: flex;
				justify-content: space-between;
				font-size: 28rpx;

				.box_list {
					margin-bottom: 28rpx;
					color: #808080;

					.list_item {
						margin-top: 30rpx;
					}
				}

				.box_total {
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
		}
	}

	.foot {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		padding: 0 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 126rpx;
		background-color: #fff;

		.foot_left {
			margin-top: -10rpx;
			font-size: 40rpx;
			color: #ff5733;

			text {
				font-size: 24rpx;
			}
		}

		.foot_right {
			margin-top: -10rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 238rpx;
			height: 80rpx;
			color: #fff;
			font-size: 32rpx;
			border-radius: 64rpx;
			background-color: #096562;
		}
	}
}
</style>
