<template>
	<view class="container">
		<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-item">
			<u-button text="点击查询" color="#7796F5" @click="queryOrder"></u-button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				name: '',
				phone: ''
			};
		},
		computed: {
			...mapState('m_business', ['reservationInfo']),
			...mapState('m_user', ['userInfo'])
		},
		methods: {
			...mapMutations('m_business', ['updateReservationInfo']),
			async queryOrder() {
				if (this.name == '' && this.phone == '') {
					uni.$showMsg('请填写信息！')
					return
				}
				let res = await uni.$http.post('/hotelOrder/queryByCondition', {
					name: this.name,
					phone: this.phone,
					deleted: false,
					status: 1,
					pageNo: 1,
					pageSize: 1
				})
				console.log(res)
				if (res.data.data.records.length == 1) {
					this.updateReservationInfo(Object.assign(this.reservationInfo, {
						orderInfo: res.data.data.records[0]
					}))
					uni.navigateTo({
						url: '/subpkg_checkin/orderDetail/orderDetail'
					})
				} else {
					uni.$showMsg('未查询到预订信息！')
				}
			}
		},
		onLoad() {
			this.name = this.userInfo.name
		}
	}
</script>

<style lang="less">
	page {
		background-color: #EFEFF4;
	}

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

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