<template>
	<view>
		<view class="top-subsection">
			<u-subsection :list="orderTypelist" :current="current" mode="subsection" @change="sectionChange"
				inactiveColor="#509AFE" activeColor="#509AFE"></u-subsection>
		</view>
		<view class="order-item" v-for="order in orderList">
			<view class="one-order">
				<view class="order--no">
					<view class="order--no__no">
						<view>订单号：</view>
						<view>{{ order.orderId.toUpperCase() }}</view>
					</view>
					<view class="order--no__status"></view>
				</view>

				<view class="order--room">
					<view class="order--room__pic">
						<u-image :src="getPicPath(order.roomPicPath)" width="180rpx" height="180rpx"></u-image>
					</view>
					<view class="order--room__desc">
						{{ order.roomTypeName }}
					</view>
					<view class="order--room__price">
						{{ "￥"+ order.price }}
					</view>
				</view>

				<view class="order--duration">
					<view class="order--duration__start">
						<view class="order--duration__start-title">入住日期</view>
						<view class="order--duration__start-date">
							<view>{{ formatTime(order.startTime) }}</view>
							<view>{{ getWeek(order.startTime) }}</view>
						</view>
					</view>
					<view class="order--duration__end">
						<view class="order--duration__end-title">离店日期</view>
						<view class="order--duration__end-date">
							<view>{{ formatTime(order.endTime) }}</view>
							<view>{{ getWeek(order.endTime) }}</view>
						</view>
					</view>
					<view class="order--duration__total">
						{{ `共${order.dayNum}晚` }}
					</view>
				</view>

				<view class="order--option"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import moment from "moment";
	import {
		IMG_BASE_URL
	} from "../../config"
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				orderList: [],
				orderTypelist: ['全部', '已支付', '待支付'],
				current: 0
			};
		},
		computed: {
			...mapState('m_user', ['userInfo']),
			...mapState('m_business', ['currentHotelId', 'reservationInfo']),
		},
		methods: {
			async sectionChange(index) {
				this.current = index
				let status
				if (index == 0) {
					let res = await uni.$http.post('/hotelOrder/queryByCondition', {
						name: this.userInfo.name,
						phone: this.userInfo.phone,
						deleted: false,
						pageNo: 1,
						pageSize: 999
					})
					this.orderList = res.data.data.records
				} else if (index == 1) {
					let res = await uni.$http.post('/hotelOrder/queryByCondition', {
						name: this.userInfo.name,
						phone: this.userInfo.phone,
						deleted: false,
						pageNo: 1,
						pageSize: 999,
						status: 1
					})
					this.orderList = res.data.data.records
					res = await uni.$http.post('/hotelOrder/queryByCondition', {
						name: this.userInfo.name,
						phone: this.userInfo.phone,
						deleted: false,
						pageNo: 1,
						pageSize: 999,
						status: 2
					})
					this.orderList = [...this.orderList, ...res.data.data.records]
				} else {
					let res = await uni.$http.post('/hotelOrder/queryByCondition', {
						name: this.userInfo.name,
						phone: this.userInfo.phone,
						deleted: false,
						pageNo: 1,
						pageSize: 999,
						status: 0
					})
					this.orderList = res.data.data.records
				}

			},
			async queryAllOrders() {
				let res = await uni.$http.post('/hotelOrder/queryByCondition', {
					name: this.userInfo.name,
					phone: this.userInfo.phone,
					deleted: false,
					pageNo: 1,
					pageSize: 999
				})
				console.log(res)
				this.orderList = res.data.data.records
			},
			formatTime(text) {
				return moment(text).format("MM月DD日HH时")
			},
			getWeek(date) {
				let week = moment(date).day()
				switch (week) {
					case 1:
						return "周一"
					case 2:
						return "周二"
					case 3:
						return "周三"
					case 4:
						return "周四"
					case 5:
						return "周五"
					case 6:
						return "周六"
					case 0:
						return "周日"
					default:
						break;
				}
			},
			getPicPath(path) {
				return IMG_BASE_URL + '/' + path
			}
		},
		onLoad() {
			this.queryAllOrders()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #EBEAF0;
		position: absolute;

		.top-subsection {
			top: 0;
			position: sticky;
			background-color: #EBEAF0;
			z-index: 99;
		}

		.order-item {
			width: 100%;
			display: flex;
			flex-direction: column;

			&:first-child {
				margin-top: 80rpx;
			}

			.one-order {
				display: flex;
				flex-direction: column;
				background-color: #ffffff;
				margin-top: 2*5rpx;
				margin-left: 2*10rpx;
				margin-right: 2*10rpx;
				margin-bottom: 2*5rpx;
				border-radius: 2*12rpx;

				.order--no {
					display: flex;
					flex-direction: row;
					font-size: 28rpx;
					margin-top: 2*10rpx;
					margin-left: 2*10rpx;
					margin-right: 2*10rpx;
					margin-bottom: 2*5rpx;

					.order--no__no {
						display: flex;
						flex-direction: row;
					}
				}

				.order--room {
					display: flex;
					flex-direction: row;
					background-color: #f1f1f4;
					margin-left: 2*10rpx;
					margin-right: 2*10rpx;
					margin-top: 2*5rpx;
					margin-bottom: 2*5rpx;
					padding-top: 2*12rpx;
					padding-bottom: 2*12rpx;
					border-radius: 2*8rpx;

					.order--room__pic {
						padding-left: 5rpx;
						width: 190rpx;
					}

					.order--room__desc {
						display: flex;
						align-items: center;
						width: 100%;
						padding-left: 20rpx;
					}

					.order--room__price {
						display: flex;
						align-items: center;
						justify-content: end;
						width: 200rpx;
						padding-right: 20rpx;
						color: red;
						font-size: 40rpx;
					}
				}

				.order--duration {
					display: flex;
					flex-direction: row;
					background-color: #f1f1f4;
					margin-left: 2*10rpx;
					margin-right: 2*10rpx;
					margin-top: 2*5rpx;
					margin-bottom: 2*5rpx;
					border-radius: 2*8rpx;

					.order--duration__start {
						display: flex;
						flex-direction: column;
						width: 1000rpx;
						margin-top: 2*5rpx;
						margin-bottom: 2*10rpx;
						margin-left: 2*5rpx;
						margin-right: 2*5rpx;

						.order--duration__start-title {
							display: flex;
							font-size: 28rpx;
							height: 60rpx;
							align-items: center;
						}

						.order--duration__start-date {
							display: flex;
							flex-direction: row;
							justify-content: space-between;
							height: 50rpx;
							align-items: center;
							font-size: 24rpx;
						}
					}

					.order--duration__end {
						display: flex;
						flex-direction: column;
						width: 1000rpx;
						margin-top: 2*5rpx;
						margin-bottom: 2*10rpx;
						margin-left: 2*30rpx;
						margin-right: 2*5rpx;

						.order--duration__end-title {
							display: flex;
							font-size: 28rpx;
							height: 60rpx;
							align-items: center;
						}

						.order--duration__end-date {
							display: flex;
							flex-direction: row;
							justify-content: space-between;
							height: 50rpx;
							align-items: center;
							font-size: 24rpx;
						}
					}

					.order--duration__total {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: flex-end;
						padding-right: 20rpx;
						font-weight: bold;
					}
				}

				.order--option {
					display: flex;
					flex-direction: row;
					margin-left: 2*10rpx;
					margin-right: 2*10rpx;
					margin-top: 2*5rpx;
					margin-bottom: 2*5rpx;
				}
			}

			.card-item {
				margin-top: 10rpx;
				margin-bottom: 10rpx;
				display: flex;

				.card-item-left {
					width: 140rpx;
				}
			}
		}
	}
</style>