<template>
	<view class="container">
		<view>
			<!-- #ifdef MP-WEIXIN -->
			<NavigateBar title="订单查询" control="back" bgcolor="#a09cc4"></NavigateBar>
			<!-- #endif -->
			<!-- #ifdef MP-ALIPAY -->
			<NavigateBar title="订单查询" bgcolor="#a09cc4"></NavigateBar>
			<!-- #endif -->
		</view>
		<view class="text-item">
			<u-input v-model="name" clearable type="text" prefixIcon="account" prefixIconStyle="font-size: 60rpx;"
				shape="circle" placeholder="请输入姓名"></u-input>
		</view>
		<view class="text-item">
			<u-input v-model="phone" clearable type="number" prefixIcon="phone" prefixIconStyle="font-size: 60rpx;"
				shape="circle" placeholder="请输入电话号码" maxlength="11"></u-input>
		</view>
		<view class="btn">
			<u-button text="点击查询" color="#9e97c3" @click="gotoQueryOrderResult"></u-button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
	export default {
		components: {
			NavigateBar
		},
		data() {
			return {
				name: '',
				phone: '',
				orderList: []
			};
		},
		computed: {
			...mapState('m_user', ['userInfo']),
			...mapState('m_business', ['currentHotel'])
		},
		methods: {
			...mapMutations('m_business', ['updateReservationInfo', 'updateQueryOrderResult']),
			async gotoQueryOrderResult() {
				this.orderList = []
				if (!this.name && !this.phone) {
					uni.$showMsg('请填写信息！')
					return
				}

				let res = await uni.$http.post('/hotelOrder/queryByCondition', {
					name: this.name,
					phone: this.phone,
					hotelId: this.currentHotel.hotelId,
					deleted: false,
					status: 'ROOM_SELECTED',
					outDated: false,
					orderSource: 'PMS_GREEN_CLOUD',
					pageNo: 1,
					pageSize: 99
				})

				this.orderList = res.data.data.records
				if (this.orderList.length > 0) {
					this.orderList.forEach((order) => {
						order.isResv = true
					})
					this.updateQueryOrderResult(this.orderList)
					uni.navigateTo({
						url: '/subpkg_checkin/queryOrderResult/queryOrderResult'
					})
				} else {
					uni.$showMsg('未查询到预定信息！')
				}
			}
		},
		onLoad() {
			// this.name = this.userInfo.name
		},
		// #ifdef MP-WEIXIN
		onShareAppMessage(info) {
			return {
				title: '源享住',
				path: 'pages/login/login',
				imageUrl: "/static/logo.png"
			}
		}
		// #endif
	}
</script>

<style>
	page {
		background-color: #EFEFF4;
	}
</style>

<style lang="less" scoped>
	.container {
		display: flex;
		flex-direction: column;

		.text-item {
			width: 90vw;
			margin: 20rpx 40rpx 0;
			background-color: #FFFFFF;
			border-radius: 38rpx;
		}

		.btn {
			bottom: 340rpx;
			left: 40rpx;
			right: 40rpx;
			position: fixed;
		}
	}
</style>