<template>
	<view>
		<u-tabs :list="tab" active-color="#c74547" :is-scroll="false" :current="current" @change="change"></u-tabs>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
				<view class="order_title">
					<text>{{ item.shopName }}</text>
					<text class="icon">&#xe62d;</text>
					<view class="zhu">
						<text class="theme_bg" v-if="item.state == 0">待受理</text>
						<text v-if="item.state == 1" style="color:#4CAF50;">已受理</text>
						<text v-if="item.state == 2" style="color:orange;">订单取消</text>
					</view>
				</view>
				<view class="r_item">
					<image :src="ip + item.shopRoom.pic" mode="aspectFill" class="pic"></image>
					<view class="con">
						<view class="title omit">{{ item.shopRoom.title }}</view>
						<view class="ms">
							<text class="rmb">¥{{ item.shopRoom.price }}</text>
							<text>起</text>
						</view>
						<view class="ms"><view class="icon phone">&#xe619;</view></view>
					</view>
					<view class="clear"></view>
				</view>
				<view class="hj">{{ item.createTime }}</view>
				<view class="clear"></view>
				<view class="tk" v-if="item.state == 2">抱歉，由于酒店房间客满的原因，我们无法提供服务。</view>
			</view>
			<view class="loading"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
		</view>
		<!--预订订单信息-->
		<u-popup v-model="popup_show" :mask-close-able="false" mode="center" border-radius="14" width="90%" height="auto" :closeable="true">
			<view class="u-popup">
				<view class="tttt" style="font-weight: bolder;">预订房间</view>
				<u-steps :list="numList" mode="number" :current="0" active-color="#c74547" style="margin: 20px 0px 20px 0px;"></u-steps>
				<view class="form_group hr">
					<view class="lable">客户姓名</view>
					<input v-model="book.name" :disabled="true" style="margin-left: -9px;" />
				</view>
				<view class="form_group hr">
					<view class="lable">联系方式</view>
					<input type="number" v-model="book.phone" :disabled="true" />
					<text class="call" @click="call()">拨打</text>
				</view>
				<view class="form_group hr">
					<view class="lable">入住日期</view>
					<input v-model="book.day" :disabled="true" style="margin-left: -9px;flex: 0.67;" />
				</view>
				<view class="form_group">
					<view class="lable">入住天数</view>
					<input :value="book.days + '天'" :disabled="true" style="margin-left: -9px;" />
				</view>
				<u-divider style="padding-top: 10px;">订单处理</u-divider>
				<button class="btn" style="background-color:#607D8B;" @click="op(1)">受理</button>
				<button class="btn" @click="op(2)">取消</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
export default {
	data() {
		return {
			ip: this.$http.urls.ip,
			tab: [{ name: '所有预订', state: '' }, { name: '待受理', state: 0 }, { name: '已完成', state: 1 }],
			numList: [{ name: '客户资料' }, { name: '订单确认' }, { name: '登记入住' }],
			current: 0,
			list: [],
			param: { pageNum: 1, state: '', role: 'sale', orderByColumn: 'id', isAsc: 'desc' },
			loadMore: true,
			popup_show: false,
			book: {}
		};
	},
	onLoad() {
		this.getData();
	},
	methods: {
		//获取数据
		getData() {
			this.$http.request({
				url: this.$http.urls.order,
				data: this.param,
				loading: 'false',
				success: res => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					res.data.rows.forEach(item => {
						item.createTime = this.$u.timeFrom(new Date(item.createTime.replace(/\-/g, '/')).getTime());
						this.list.push(item);
					});
				}
			});
		},
		change(index) {
			this.current = index;
			this.param.state = this.tab[index].state;
			this.refresh();
		},
		detail(item) {
			this.book = item;
			this.book.day = item.min + ' 至 ' + item.max;
			this.popup_show = true;
		},
		call() {},
		//处理订单
		op(index) {
			uni.showModal({
				title: '提示',
				content: '是否处理该订单?',
				success: res => {
					if (res.confirm) {
						this.$http.request({
							url: this.$http.urls.orderDeal,
							data: { id: this.book.id, state: index },
							method: 'POST',
							success: res => {
								uni.showToast({ title: '操作成功' });
								this.popup_show = false;
								this.refresh();
							}
						});
					}
				}
			});
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			uni.stopPullDownRefresh();
			this.refresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: $page;
}
.list {
	padding: 0px 10px 25px 10px;
	.item {
		background-color: white;
		padding: 5px 13px 13px 13px;
		margin-top: 10px;
		border-radius: 4px;
		.hj {
			text-align: right;
			padding-top: 13px;
			color: $dar2;
		}
	}
}
.call {
	color: #03a9f4;
}
.del {
	text-align: center;
	margin-top: 15px;
	color: $theme-color;
}
</style>
