<template>
	<view class="container" v-if="orderInfo">
		<!-- 顶部订单状态信息区域 -->
		<view class="header">
			<!-- 背景图片区域 -->
			<img src="https://chtech.ncjti.edu.cn/hotelReservation/image/18.png" />
			<!-- 标题区域 -->
			<view class="header_title" :style="{ height: customBarH * 2 + 'rpx', paddingTop: statusBarH * 2 + 'rpx' }">订单详情</view>
			<!-- 返回图标区域 -->
			<!-- <img class="header_icon" src="../../static/index/left.png" @click="handleBack" /> -->

			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '1'">待支付</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '2'">已支付</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '3'">待入住</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '4'">已入住</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '5'">已消费</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '6'">支付超时</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '7'">已取消</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '8'">已退单</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '9'">已退款</view>
			<view class="header_type" :style="{ paddingTop: statusBarH * 2 + 72 + 'rpx' }" v-if="orderInfo.orderStatus === '10'">退款中</view>
			<view class="header_info" :style="{ paddingTop: statusBarH * 2 + 145 + 'rpx' }">订单号：{{ orderInfo.orderNum }}</view>
		</view>

		<!-- 主体内容区域 -->
		<view class="body">
			<!-- 房型信息和用户信息区域 -->
			<view class="body_box2">
				<view class="info_time">
					{{ getTime((orderInfo.orderStartTime || '').slice(0, 19)) }}
					<text class="gap">{{ getWeek((orderInfo.orderStartTime || '').slice(0, 19)) }}</text>
					<view class="time_line"></view>
					<view class="time_num">{{ orderInfo.orderLiveTime }}</view>
					<view class="time_line"></view>
					<view class="gap">{{ getTime((orderInfo.orderEndTime || '').slice(0, 19)) }}</view>
					<text>{{ getWeek((orderInfo.orderEndTime || '').slice(0, 19)) }}</text>
				</view>
				<view class="info_msg">{{ orderInfo.houseName }}</view>
				<view class="info_type">
					<view class="type_item">{{ orderInfo.hotelType }}型</view>
				</view>
				<view class="info_tag">
					<view class="tag_item" v-if="orderInfo.houseAreas">{{ orderInfo.houseAreas }}㎡</view>
					<view class="tag_item">双人床</view>
					<view class="tag_item">窗户位于走廊/窗户较小</view>
				</view>
				<view class="info_box">
					<view class="box_key">住客姓名</view>
					<view class="box_value">{{ orderInfo.userName }}</view>
				</view>
				<view class="info_box">
					<view class="box_key">联系电话</view>
					<view class="box_value">{{ orderInfo.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 price">¥{{ orderInfo.houseTotalPrice }}</view>
				</view>
				<view class="box_container">
					<view class="container_key">发票报销</view>
					<view class="container_value">如需发票，请先与酒店确认</view>
				</view>
			</view>

			<!-- 按钮区域 -->

			<view class="body_btn">
				<view class="btn_item type" @click="handleOrder(4)">退单</view>
				<view class="btn_item type2" v-if="orderInfo.orderStatus === '2'" @click="handleOrder(1)">接单</view>
			</view>
		</view>

		<!-- 状态弹窗区域 -->
		<uni-popup ref="popup" :is-mask-click="false" type="center">
			<view class="popup_body">
				<img src="../../static/index/success.png" />
				<view class="msg">{{ msg }}</view>
				<navigator class="btn" target="miniProgram" open-type="exit">确定</navigator>
			</view>
		</uni-popup>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 订单id
			id: '',
			// 订单信息
			orderInfo: null,
			// 弹窗信息
			msg: '',
			// 状态栏高度
			statusBarH: 0,
			// 胶囊按钮栏高度
			customBarH: 0
		}
	},
	created() {
		// 获取系统信息
		uni.getSystemInfo({
			success: (e) => {
				// 获取状态栏高度
				this.statusBarH = e.statusBarHeight + 10
				// // 获取菜单按钮栏高度
				let custom = uni.getMenuButtonBoundingClientRect()
				this.customBarH = custom.height + 10
			}
		})
	},
	onLoad(options) {
		this.id = options.id
		this.getData()
	},
	methods: {
		// 获取订单信息
		async getData() {
			const res = await this.$myRequest({
				url: '/mhotel/ampgetBookingById.action',
				data: {
					bookingId: this.id
				}
			})
			// console.log(res)
			if (res.code === 200) {
				this.orderInfo = res.data
			}
		},
		// 点击 退单 接单 按钮回调
		handleOrder(type) {
			// 1 接单  4 退单
			uni.showModal({
				title: '提示',
				content: `确定${type === 1 ? '接单' : '退单'}吗？`,
				success: (res) => {
					if (res.confirm) {
						if (type === 1) {
							// 接单请求
							this.receiving()
						} else {
							// 退单请求
							this.chargeback()
						}
					}
				}
			})
		},
		async receiving() {
			const res = await this.$myRequest({
				url: '/mhotel/bookupdateBookStatus.action',
				data: {
					id: this.id,
					type: 1
				}
			})
			// console.log(res)
			if (res.code === 200) {
				this.msg = '接单成功'
				this.$refs.popup.open()
			}
		},
		async chargeback() {
			const res = await this.$myRequest({
				url: '/mhotel/abkchargeback.action',
				data: {
					bookingId: this.id
				}
			})
			// console.log(res)
			if (res.code === 200) {
				this.msg = '退单成功'
				this.$refs.popup.open()
			}
		},
		// 点击左上角返回按钮回调
		handleBack() {
			uni.switchTab({
				url: '/pages/home3/home3'
			})
		},
		getWeek(time) {
			let date = new Date(time)
			// 获取星期
			let week = date.getDay()
			let weekList = ['日', '一', '二', '三', '四', '五', '六']

			let res = '周' + weekList[week]
			return res
		},
		getTime(time) {
			let date = new Date(time)
			// 获取月份
			let M = date.getMonth() + 1
			// 获取日期
			let D = date.getDate()

			let res = M + '月' + D + '日'
			return res
		}
	}
}
</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: 0;
			left: 308rpx;
			color: #fff;
			font-size: 28rpx;
		}

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

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

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

	.body {
		position: absolute;
		top: 320rpx;
		left: 0;
		right: 0;
		box-sizing: border-box;
		padding: 20rpx 20rpx 60rpx;
		height: calc(100vh - 320rpx);
		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 {
				}
			}
		}

		.body_btn {
			box-sizing: border-box;
			padding: 0 32rpx;
			margin-top: 140rpx;
			display: flex;
			justify-content: space-between;
			height: 96rpx;

			.btn_item {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 300rpx;
				height: 96rpx;
				border-radius: 64rpx;
				font-size: 32rpx;
			}

			.type {
				color: #d43030;
				border: 1rpx solid #d43030;
			}

			.type2 {
				color: #fff;
				background-color: #096562;
			}
		}

		.close_btn {
			margin: 32rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 300rpx;
			height: 96rpx;
			border-radius: 64rpx;
			font-size: 32rpx;
			color: #d43030;
			border: 1rpx solid #d43030;
		}
	}

	.popup_body {
		display: flex;
		flex-direction: column;
		justify-content: space-evenly;
		align-items: center;
		width: 481rpx;
		height: 404rpx;
		border-radius: 23rpx;
		background-color: #fff;

		img {
			width: 134rpx;
			height: 134rpx;
		}

		.msg {
			font-size: 26rpx;
		}

		.btn {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 200rpx;
			height: 76rpx;
			font-size: 26rpx;
			color: #fff;
			border-radius: 43rpx;
			background: linear-gradient(90deg, rgba(11, 193, 150, 1) 0%, rgba(9, 101, 98, 1) 100%);
		}
	}
}
</style>
