<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 class="header_type" v-if="info.orderStatus === '1'">待支付</view>
			<view class="header_info" v-if="info.orderStatus === '1'">超时后，订单将会自动取消</view>
			<view class="header_type" v-if="info.orderStatus === '2'">已支付</view>
			<view class="header_info" v-if="info.orderStatus === '2'">订单已支付，请等待商家接单</view>
			<view class="header_type" v-if="info.orderStatus === '3'">待入住</view>
			<view class="header_info" v-if="info.orderStatus === '3'">订单已被商家接单，请前往办理入住</view>
			<view class="header_type" v-if="info.orderStatus === '4'">已入住</view>
			<view class="header_info" v-if="info.orderStatus === '4'">订单已办理入住</view>
			<view class="header_type" v-if="info.orderStatus === '5'">已消费</view>
			<view class="header_info" v-if="info.orderStatus === '5'">您的订单已消费，期待您再次预定哦</view>
			<view class="header_type" v-if="info.orderStatus === '6'">支付超时</view>
			<view class="header_info" v-if="info.orderStatus === '6'">订单已超过可支付时间，请重新下单</view>
			<view class="header_type" v-if="info.orderStatus === '7'">已取消</view>
			<view class="header_info" v-if="info.orderStatus === '7'">订单已取消，请重新下单</view>
			<view class="header_type" v-if="info.orderStatus === '8'">已退单</view>
			<view class="header_info" v-if="info.orderStatus === '8'">订单已被商家退单，请重新下单</view>
			<view class="header_type" v-if="info.orderStatus === '9'">已退款</view>
			<view class="header_info" v-if="info.orderStatus === '9'">订单已被商家退款</view>
			<view class="header_type" v-if="info.orderStatus === '10'">退款中</view>
			<view class="header_info" v-if="info.orderStatus === '10'">正在退款中...</view>

			<view class="header_btn">
				<!-- hotelIsCanorder  1可取消，0不可 -->
				<view class="btn_box" v-if="info.orderStatus === '1'" @click="handlePay">去支付 ￥{{ info.houseTotalPrice }}.00</view>
				<view class="btn_box" v-if="((info.orderStatus === '2' || info.orderStatus === '3') && info.hotelIsCanorder=='1') || info.orderStatus === '1'" @click="handleCancel">取消订单</view>
				<view class="btn_box" v-if="info.orderStatus * 1 > 3" @click="handleAgain">再次预定</view>
				<view class="btn_box" @click="handleDelete" v-if="info.orderStatus === '5' || info.orderStatus === '7' || info.orderStatus === '8' || info.orderStatus === '9'">删除订单</view>
			</view>

			<view class="header_msg" v-if="info.orderStatus === '1'">预定成功后，07月26日12:00前可免费取消</view>
			<view class="header_msg" v-if="info.orderStatus === '3' || info.orderStatus === '6'">办理入住前，您均可取消订单</view>
			<view class="header_msg" v-if="info.orderStatus === '8'">您的订单被商家退款了，请重新预定</view>
		</view>

		<!-- 主体内容区域 -->
		<view class="body">
			<!-- 费用信息区域 -->
			<view class="body_box">
				<view class="box_title">费用信息</view>
				<view class="box_container">
					<view class="container_key">在线支付</view>
					<view class="container_value price">¥{{ info.houseTotalPrice }}</view>
				</view>
				<view class="box_container">
					<view class="container_key">发票报销</view>
					<view class="container_value">如需发票，请先与酒店确认</view>
				</view>
			</view>

			<!-- 民宿信息区域 -->
			<view class="body_box">
				<view class="box_info">
					<img src="../../static/index/banner.png" />
					<view class="info_msg">
						<view class="msg_name">{{ info.hotelName }}</view>
						<view class="msg_address">{{ info.hotelHposition }}</view>
					</view>
				</view>
				<view class="box_btn">
					<view class="btn_item" @click="handleMap">
						<img class="img" src="../../static/my/map.png" />
						地图/导航
					</view>
					<view class="btn_item" @click="handlePhone(info.hotelPhone)">
						<img class="img2" src="../../static/my/phone.png" />
						联系商家
					</view>
				</view>
			</view>

			<!-- 房型信息和用户信息区域 -->
			<view class="body_box2">
				<view class="info_time">
					{{info.orderStartTime.slice(5,7)}}月{{info.orderStartTime.slice(8,10)}}日
					<!-- <text class="gap">今天</text> -->
					<view class="time_line"></view>
					<view class="time_num">{{info.houseOrderNumber}}晚</view>
					<view class="time_line"></view>
					<view class="gap">{{info.checkOutTime.slice(5,7)}}月{{info.checkOutTime.slice(8,10)}}日</view>
					<!-- <text>明天</text> -->
				</view>
				<view class="info_msg">{{info.houseName}}</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">{{info.houseAreas}}㎡</view>
					<view class="tag_item">{{info.houseName}}</view>
					<view class="tag_item">窗户位于走廊/窗户较小</view>
				</view>
				<view class="info_box">
					<view class="box_key">住客姓名</view>
					<view class="box_value">{{ info.userName }}</view>
				</view>
				<view class="info_box">
					<view class="box_key">联系电话</view>
					<view class="box_value">{{ info.userPhone }}</view>
				</view>
				<view class="info_box">
					<view class="box_key">预计到店</view>
					<view class="box_value">7月26日14:00之前</view>
				</view>
			</view>

			<!-- 订单信息区域 -->
			<view class="body_box">
				<view class="box_title">订单信息</view>
				<view class="box_container">
					<view class="container_key">订单号</view>
					<view class="container_value">{{info.orderNum}}</view>
					<view class="container_copy" @click="handleCopy(info.orderNum)">复制</view>
				</view>
				<view class="box_container">
					<view class="container_key">下单时间</view>
					<view class="container_value">{{ info.createTime }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 详细信息
			info: {}
		}
	},
	onLoad(options) {
		console.log(options)
		this.info = JSON.parse(options.info)
		console.log(this.info)
	},
	methods: {
		// 点击复制文字回调
		handleCopy(text) {
			uni.setClipboardData({
				data: text,
				success: () => {}
			})
		},
		handleBack() {
			uni.navigateBack(1)
		},
		// 点击地图/导航文字回调
		handleMap() {
			uni.getSetting({
				success: (res) => {
					if (res.authSetting['scope.userLocation']) {
						let lat = this.info.hotelHpositionWens.split(',')[0] * 1
						let lng = this.info.hotelHpositionWens.split(',')[1] * 1
						uni.openLocation({
							latitude: lat,
							longitude: lng,
							name: this.info.hotelName,
							address: this.info.hotelHposition,
							success: () => {}
						})
					} else {
						uni.showModal({
							content: '当前没有定位权限，是否去设置打开？',
							confirmText: '确认',
							cancelText: '取消',
							success: (res) => {
								if (res.confirm) {
									uni.openSetting({
										success: (res) => {
											this.handleMap()
										}
									})
								} else {
									uni.showToast({
										title: '获取定位权限失败',
										icon: 'none',
										mask: true
									})
								}
							}
						})
					}
				}
			})
		},
		// 点击联系商家文字回调
		handlePhone(phone) {
			uni.makePhoneCall({
				phoneNumber: phone
			})
		},
		// 点击去支付按钮回调
		handlePay() {
			uni.navigateTo({
				url: '/pages/pay/pay'
			})
		},
		// 点击取消订单按钮回调
		handleCancel() {
			uni.showModal({
				title: '提示',
				content: '确定取消该订单吗？',
				success: async (res) => {
					if (res.confirm) {
						const result = await this.$myRequest({
							url: '/mhotel/abkcancelBooking.action',
							data: {
								bookingId:this.info.id,
							}
						})
						if (result.code === 200) {
							uni.showToast({
								title: '取消成功',
								icon: 'success',
								mask: true
							})
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages/orderManage/orderManage'
								})
							}, 1500)
						}
					}
				}
			})
		},
		// 点击再次预定按钮回调
		handleAgain() {
			uni.navigateTo({
				url: '/pages/detail/detail'
			})
		},
		// 点击删除订单按钮回调
		handleDelete() {
			uni.showModal({
				title: '提示',
				content: '确定删除该订单吗？',
				success: async (res) => {
					if (res.confirm) {
						const result = await this.$myRequest({
							url: '/mhotel/abkdelBooking.action',
							data: {
								bookingId:this.info.id,
							}
						})
						if (result.code === 200) {
							uni.showToast({
								title: '删除成功',
								icon: 'success',
								mask: true
							})
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages/orderManage/orderManage'
								})
							}, 1500)
						}
					}
				}
			})
		}
	}
}
</script>

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

	.header {
		height: 480rpx;
		color: #fff;

		img {
			width: 100%;
		}

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

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

		.header_type {
			position: absolute;
			top: 162rpx;
			left: 30rpx;
			font-size: 40rpx;
			font-weight: bold;
		}

		.header_info {
			position: absolute;
			top: 235rpx;
			left: 30rpx;
			font-size: 24rpx;
		}

		.header_btn {
			position: absolute;
			top: 290rpx;
			left: 30rpx;
			right: 30rpx;
			display: flex;
			justify-content: space-between;

			.btn_box {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 335rpx;
				height: 72rpx;
				border-radius: 10rpx;
				color: #096562;
				font-size: 28rpx;
				background-color: #fff;
			}
		}

		.header_msg {
			position: absolute;
			top: 378rpx;
			left: 30rpx;
			font-size: 24rpx;
		}
	}

	.body {
		position: absolute;
		top: 430rpx;
		left: 0;
		right: 0;
		box-sizing: border-box;
		padding: 20rpx;
		height: calc(100vh - 430rpx);
		border-radius: 20rpx 20rpx 0 0;
		background-color: #ebeced;
		overflow-y: auto;

		.body_box {
			box-sizing: border-box;
			padding: 0 30rpx;
			margin-bottom: 20rpx;
			display: flex;
			flex-direction: column;
			height: 240rpx;
			border-radius: 14rpx;
			background-color: #fff;

			.box_title {
				line-height: 90rpx;
				font-size: 28rpx;
				font-weight: bold;
				border-bottom: 1rpx solid #e5e5e5;
			}

			.box_container {
				display: flex;
				margin-top: 25rpx;
				font-size: 28rpx;

				.container_key {
					width: 160rpx;
					color: #808080;
				}

				.container_value {
				}

				.container_copy {
					margin-left: auto;
					color: #096562;
				}

				.price {
					color: #ff5733;
				}
			}

			.box_info {
				display: flex;
				margin-top: 20rpx;
				height: 130rpx;

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

				.info_msg {
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					margin-top: -10rpx;
					margin-left: 18rpx;
					width: 540rpx;

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

					.msg_address {
						color: #808080;
						font-size: 24rpx;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}
				}
			}

			.box_btn {
				display: flex;
				justify-content: space-around;
				align-items: center;
				height: 110rpx;

				.btn_item {
					display: flex;
					align-items: center;
					width: 200rpx;

					.img {
						margin-right: 14rpx;
						width: 38rpx;
						height: 38rpx;
					}

					.img2 {
						width: 66rpx;
						height: 66rpx;
					}
				}
			}
		}

		.body_box2 {
			display: flex;
			flex-direction: column;
			box-sizing: border-box;
			padding: 0 30rpx;
			margin-bottom: 20rpx;
			height: 478rpx;
			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 0;
				box-sizing: border-box;
				padding-bottom: 30rpx;
				color: #808080;
				font-size: 24rpx;
				border-bottom: 1rpx solid #e5e5e5;

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

			.info_box {
				display: flex;
				margin-top: 23rpx;
				font-size: 28rpx;

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

				.box_value {
				}
			}
		}
	}
}
</style>
