<template>
	<view class="container" v-if="orderInfo">
		<!-- 顶部订单状态信息区域 -->
		<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="orderInfo.orderStatus === '1'">待支付</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '2'">已支付</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '3'">待入住</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '4'">已入住</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '5'">已消费</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '6'">支付超时</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '7'">已取消</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '8'">已退单</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '9'">已退款</view>
			<view class="header_type" v-if="orderInfo.orderStatus === '10'">退款中</view>
			<view class="header_info">订单号：{{ 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>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 订单id
			id: '',
			// 订单信息
			orderInfo: null
		}
	},
	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) {
				uni.showToast({
					title: `接单成功`,
					icon: 'success',
					mask: true
				})
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/home/home'
					})
				}, 1500)
			}
		},
		async chargeback() {
			const res = await this.$myRequest({
				url: '/mhotel/abkchargeback.action',
				data: {
					bookingId: this.id
				}
			})
			// console.log(res)
			if (res.code === 200) {
				uni.showToast({
					title: res.message,
					icon: 'none',
					mask: true
				})
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/home/home'
					})
				}, 1500)
			}
		},
		// 点击左上角返回按钮回调
		handleBack() {
			uni.switchTab({
				url: '/pages/home/home'
			})
		},
		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: 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: 144rpx;
			left: 30rpx;
			font-size: 40rpx;
			font-weight: bold;
		}

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

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