<template>
	<view class="page" :style="{'height':(h)+'px','padding-top':mt+'px'}">
		<c-nav-bar title="订单详情" showIcon="true" :titleStyle="titleStyle"></c-nav-bar>
		<view class="body">
			<!-- 个人信息 -->
			<view class="uname">
				<text style="margin-right: 20rpx;">{{orderInfo.guestName}}</text>
				<text>{{orderInfo.guestPhone}}</text>
			</view>
			<!-- 房间信息  -->
			<view class="room">
				<!-- 房间/预定信息 -->
				<view class="reservations">
					<text
						style="font-size: 30rpx; color: #333333; font-weight: 700;">{{orderInfo.houseBaseName}}-{{orderInfo.detailFormList[0].roomNumber}}</text>
					<text style="font-size: 24rpx; color: #39CE77;" v-if="isOrderPanding">{{getStatusText()}}</text>
				</view>
				<!-- 时间/价格 -->
				<view class="time-price">
					<text style="font-size: 30rpx; color: #777;">{{orderInfo.arriveDate}}入住 {{orderInfo.num}}晚</text>
					<text style="font-size: 30rpx; color: #245BED;">￥{{orderInfo.orderAmount}}</text>
				</view>
				<!-- 入住人数 -->
				<view class="house-person">
					<text style="font-size: 30rpx; color: #777;">入住人</text>
					<view class="right">
						<text style="font-size: 30rpx; color: #777; ">{{orderInfo.detailFormList[0].checkInPersonList.length}}人 </text>
						<u-icon name="arrow-right" @click.native="goStayCheck"></u-icon>
						<!-- <u-icon name="arrow-right" ></u-icon>  -->
					</view>
				</view>
			</view>
			<!-- 订单信息 -->

			<u-cell-group :border="false"
				customStyle="background-color: #fff;border-radius: 16rpx;width: 690rpx;margin:0 auto;">
				<u-cell>
					<text slot="icon" style="font-size: 30rpx; margin-right: 50rpx;">订单号</text>
					<view slot="title" class="title">
						<text>{{orderInfo.orderCode}}</text>
					</view>
				</u-cell>
				<u-cell>
					<text slot="icon" style="font-size: 30rpx; margin-right: 20rpx;">创建时间</text>
					<view slot="title" class="title">
						<text>{{orderInfo.orderTime}}</text>
					</view>
				</u-cell>
				<!-- <u-cell>
					<text slot="icon" style="font-size: 30rpx; margin-right: 20rpx;">办理员工</text>
					<view slot="title" class="title">
						<text>何伟婷</text>
					</view>
				</u-cell> -->
				<u-cell v-if="orderInfo.orderStatus==4">
					<text slot="icon" style="font-size: 30rpx; margin-right: 20rpx;">取消原因</text>
					<view slot="title" class="title">
						<text>{{orderInfo.refundReason}}</text>
					</view>
				</u-cell>
				<u-cell>
					<text slot="icon" style="font-size: 30rpx; margin-right: 80rpx;">备注</text>
					<view slot="title" class="title">
						<text>{{orderInfo.remarks}}</text>
					</view>
				</u-cell>


			</u-cell-group>
			<!-- 按钮 -->
			<view class="button">
				<!-- 待确认 -->
				<template v-if="orderInfo.orderStatus==-1">
					<button class="edit" @click="cancle()">取消订单</button>
					<button class="goRoom" @click="show2=true" v-if="orderInfo.status==1">确认订单</button>
				</template>
				<!-- 已预订 -->
				<template v-if="orderInfo.orderStatus==1">
					<button class="edit" @click="edit()">编辑订单</button>
					<button class="goRoom" @click="checkIn(2)">办理入住</button>
				</template>
				<!-- 已入住 -->
				<template v-if="orderInfo.orderStatus==2">
					<button class="edit" @click="edit()">编辑订单</button>
					<button class="goRoom" @click="show3=true">办理退房</button>
				</template>
			</view>
		</view>
		<!-- 取消订单 -->
		<u-modal :show="show" @confirm="confirmCheck" :show-cancel-button="true" @cancel="show=false">
			<view class="slot-content">
				<input type="text" v-model="check.refundReason" placeholder="请输入原因" />
				<!-- <u-cell-group :border="false" customStyle="margin:0 -30rpx">
					<u-cell>
						<view slot="title" class="title">
							<u--input border="none" class="input" inputAlign="right" placeholderStyle="font-size:26rpx"
								placeholder="请输入原因" v-model="check.refundReason"></u--input>
						</view>
					</u-cell>
				</u-cell-group> -->
			</view>
		</u-modal>
		<!-- 确认订单 -->
		<u-modal :show="show2" content="确定该操作?" @confirm="confirmOrder" :show-cancel-button="true" @cancel="show2=false">
		</u-modal>
		<!-- 办理退房 -->
		<u-modal :show="show3" content="确定该操作?" @confirm="checkoutRoom" :show-cancel-button="true" @cancel="show3=false">
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					fontSize: '34rpx',
					fontWeight: "bold",
				},
				h:uni.getSystemInfoSync().windowHeight - 87,
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				show: false,
				show2: false,
				show3: false,
				
				check: {
					initiator: 1,
					refundReason: "",
					status: -1,
					orderCode: "",
				},
				orderId: '',
				orderInfo: {}
			}
		},
		onLoad(opt) {
			if (opt.orderId) {
				this.orderId = opt.orderId;
				this.getOrderInfo()
			}
		},
		methods: {
			// 获取数据
			getOrderInfo() {
				this.$api.get(`/merchant/hotel/order/getOrderDetail/${this.orderId}`).then((res) => {
					if (res.data.code == 0) {
						this.orderInfo = res.data.data
						
					}
				})
			},
			// 客房状态
			getStatusText() {
				if (this.orderInfo.orderStatus === -1) {
					return '待确定'
				} else if (this.orderInfo.orderStatus === 1) {
					return '已预订'
				} else if (this.orderInfo.orderStatus === 2) {
					return '已入住'
				} else if (this.orderInfo.orderStatus === 3) {
					return '已退房'
				} else if (this.orderInfo.orderStatus === 4) {
					return '已取消'
				} else {
					return '状态异常'
				}
			},
			//添加入住人
			goStayCheck() {
				let list = JSON.stringify(this.orderInfo);
				uni.navigateTo({
					url: '/pages/house/stayCheck?orderInfo=' + list,
					events: {
						addSuccess: data => {
							this.orderInfo.detailFormList[0].checkInPersonList=data.data||[];
							console.log(this.orderInfo.detailFormList[0].checkInPersonList)
						}
					},
				})
			},
			// 确认订单
			confirmOrder() {
				this.$api
					.get(`/merchant/hotel/order/confirm/${this.orderInfo.id}`)
					.then((res) => {
						if (res.data.code !== 0) {
							return this.$showToast(res.data.msg);
						}
						this.show2 = false;
						this.$showToast('操作成功');
						setTimeout(() => {
							uni.reLaunch({
								url: '/pagesMy/orderList/orderList'
							})
						}, 1500)
					});
			},
			//取消订单
			cancle() {
				this.show = true;
				this.check.orderCode = this.orderInfo.orderCode;
			},
			//取消订单
			confirmCheck() {
				this.$api.post("/merchant/hotel/order/cancelOrder", this.check)
					.then((res) => {
						if (res.data.code !== 0) {
							return this.$showToast(res.data.msg);
						}
						this.show = false;
						this.$showToast('操作成功');
						setTimeout(() => {
							uni.reLaunch({
								url: '/pagesMy/orderList/orderList'
							})
						}, 1500)
					});
			},
			//办理入住
			checkIn(orderStatus) {
				uni.redirectTo({
					url: "/pages/house/createOrder?id=" + this.orderInfo.id + '&orderStatus=' + orderStatus
				})
			},
			// 编辑
			edit() {
				uni.redirectTo({
					url: "/pages/house/createOrder?id=" + this.orderInfo.id
				})
			},
			//办理退房
			checkoutRoom() {
				this.$api.get("/merchant/hotel/order/checkout/" + this.orderInfo.id)
					.then((res) => {
						if (res.data.code !== 0) {
							return this.$showToast(res.data.msg);
						}
						this.show = false;
						this.$showToast('操作成功');
						setTimeout(() => {
							uni.reLaunch({
								url: '/pagesMy/orderList/orderList'
							})
						}, 1500)
					});
			}
		},
		computed: {
			isOrderPanding() {
				return this.orderInfo.orderStatus === 1
			}
		}
	}
</script>

<style lang="scss">
	.page {
		background: #F3F4F4;
		padding-bottom: 260rpx;
		box-sizing: border-box;
		overflow-y: auto;
		overflow-x: auto;
	}

	.body {
		padding-top: 20rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
	}

	.uname {
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #fff;
		padding-left: 30rpx;
		font-size: 30rpx;
		border-radius: 10rpx;
		box-sizing: border-box;

	}

	.room {
		margin-top: 20rpx;
		width: 100%;
		height: 246rpx;
		background-color: #fff;
		margin-bottom: 20rpx;
		border-radius: 10rpx;
		padding: 30rpx;
		box-sizing: border-box;
	}

	.orderTip {
		padding: 30rpx;
		padding-top: 0;
		width: 690rpx;
		height: 514rpx;
		background-color: #fff;
		border-radius: 10rpx;

	}

	.button {
		position: fixed;
		bottom: 40rpx;
		height: 96rpx;
		width: 690rpx;
		// background-color: teal;
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		border-radius: 10rpx;
		z-index: 9;
	}

	.goRoom {
		// border-radius: ;
		width: 330rpx;
		height: 96rpx;
		border-radius: 48rpx;
		font-size: 34rpx;
		background-color: #1372FF;
		color: #fff;
	}

	.edit {
		width: 330rpx;
		height: 96rpx;
		border-radius: 48rpx;
		font-size: 34rpx;
		background-color: #E2EDFC;
		color: #1372FF;
	}

	.reservations {
		display: flex;
		justify-content: space-between;
	}

	.time-price {
		display: flex;
		justify-content: space-between;
		margin-top: 30rpx;
	}

	.house-person {
		display: flex;
		justify-content: space-between;
		margin-top: 30rpx;
	}

	.right {
		display: flex;
	}
</style>