<template>
	<view class="pages">
		<!-- <TopTabs :list="tabList" @changeTab="changeTab">
		</TopTabs> -->
		<view class="tb">
			<view class="tabs">
				<view v-for="(item,index) in tabList" :key="index" @tap="changeTab1(index)">
					<text :class="index==current?'active':''">{{item.name}}</text>
				</view>
			</view>
		</view>
		<view class="mainContain">
			<view v-if="dataList.length>0" class="card" v-for="item,index  in dataList" :key="index">
				<view class="header">
					<span style="font-weight: 700;">订单号：{{item.orderCode}}</span>
					<text v-if='item.orderStatus==-1&&item.status==1' class="orange">待确认</text>
					<text v-else-if='item.status==0&&item.orderStatus==-1' class="red">待支付</text>
					<text v-else-if='item.orderStatus==1&&item.status==1' class="green">已预订</text>
					<text v-else :class="statusClass[item.orderStatus]">{{status[item.orderStatus]}}</text>
				</view>
				<view class="mainContent">
					<image class="image" :src="item.cover" mode="aspectFill"></image>
					<view class="middle">
						<span class="title">{{item.houseBaseName}}-{{item.roomNumber}}</span>
						<span class='info'>
							<span>{{item.guestName}}</span>
							<span>{{item.guestPhone}}</span>
							<span>{{item.arriveDate}}到{{item.leaveDate}} </span>
						</span>
					</view>
					<view class="price">
						￥{{item.orderAmount}}
					</view>
				</view>
				<!-- <view class="bottom"  v-if="item.orderStatus==-1">
					<view class="refuse">
						拒绝
					</view>
					<view class="btn">
						确认订单
					</view>
				</view>
				<view class="bottom"  v-else-if="item.orderStatus==1">
					<view class="btn">
						办理入住
					</view>
				</view>
				<view class="bottom" v-else-if="item.orderStatus==2">
					<view class="btn">
						办理退房
					</view>
				</view> -->
				<view class="bottom" @click="handleDetail(item)">
					<view class="detail">
						详情
					</view>
				</view>
				<!-- <view class="bottom" @click="handleDetail(item)" v-else-if="item.orderStatus==4">
					<view class="detail">
						详情
					</view>
				</view> -->
			</view>
			<view class="nodata" v-if='dataList.length==0'>
				<NoData></NoData>
			</view>
		</view>
	</view>
</template>

<script>
	import TopTabs from '../../components/TopTabs/topTabs.vue';
	// import NoData from '../../components/NoData/index.vue';
	export default {
		components: {
			TopTabs,
			// NoData
		},
		data() {
			return {
				current: 0,
				mysearch: '',
				dataList: [],
				limit: 10,
				page: 1,
				homestayId: uni.getStorageSync('homestayId'),
				statusClass: [
					'',
					'green',
					'blue',
					'grey',
					'grey',
				],
				status: [
					'',
					'已预订',
					'已入住',
					'已退房',
					'已取消',
				],
				// mt: uni.getSystemInfoSync().statusBarHeight + 44,
				tabList: [{
						name: '全部'
					},
					{
						name: '待确认'
					},
					{
						name: '待支付'
					},
					{
						name: '已预订'
					},
					{
						name: '已取消'
					},
				],
			}
		},
		onLoad(option) {
			if (option.Type) {
				const type = parseInt(option.Type) + 1
				this.changeTab1(type)
			} else {
				this.getOrderList()
			}
		},
		methods: {
			changeTab1(index) {
				this.current = index;
				this.changeTab(index)
			},
			getOrderList(orderStatus) {
				this.$api.get('/merchant/hotel/order/getMerchantOrderPageList', {
					homestayId: this.homestayId,
					limit: this.limit,
					page: this.page,
					orderStatus: orderStatus ? orderStatus : ''
				}).then((res => {
					if (res.data.code == 0) {
						this.dataList = res.data.data.list
						this.dataList.forEach((i, index) => {
							this.dataList[index].arriveDate = i.arriveDate.slice(0, 10)
							this.dataList[index].leaveDate = i.leaveDate.slice(0, 10)
						})
						console.log(this.dataList,'this.dataList');
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}


				}))
			},
			getOrderByStatusList() {
				this.$api.get('/merchant/hotel/order/getMerchantOrderPageList', {
					homestayId: this.homestayId,
					limit: this.limit,
					page: this.page,
					status: 0
				}).then((res => {
					if (res.data.code == 0) {
						this.dataList = res.data.data.list
						this.dataList.forEach((i, index) => {
							this.dataList[index].arriveDate = i.arriveDate.slice(0, 10)
							this.dataList[index].leaveDate = i.leaveDate.slice(0, 10)
						})
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}


				}))
			},
			handleDetail(item) {
				uni.navigateTo({
					url: '/pages/house/orderInfo?orderId=' + item.id
				})
			},
			changeTab(index) {
				console.log(index, 'index------');
				this.tabIdx = index;
				switch (index) {
					case 0:
						this.getOrderList()
						break
					case 1:
						this.getOrderList(-1)
						break
					case 2:
						this.getOrderByStatusList()
						break
					case 3:
						this.getOrderList(1)
						break
					case 4:
						this.getOrderList(4)
						break
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pages {
		background: #F9FAFC;

		.tb {
			width: 100%;

			top: 0;
			left: 0;
			z-index: 999;

			.searchBoxParent {
				width: 100%;
				background: #fff;
				padding: 20rpx 24rpx 6rpx;
				box-sizing: border-box;

				.searchBox {
					width: 100%;
					background-color: #fff;
				}
			}

			.tabs {
				background: #fff;
				padding: 26rpx 0;
				display: flex;
				align-items: center;
				width: 100%;

				&>view {
					width: 25%;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: black;
					line-height: 40rpx;
					position: relative;
					text-align: center;
				}

				.active {
					font-size: 32rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: black;
					line-height: 45rpx;
				}

				.active::after {
					position: absolute;
					content: '';
					width: 50rpx;
					height: 8rpx;
					background: #1372FF;
					bottom: -26rpx;
					left: 60%;
					margin-left: -42rpx;
				}
			}
		}

		.green {}

		.mainContain {
			display: flex;
			flex-direction: column;
			padding: 0 20rpx;

			.nodata {
				background: white;

			}

			.card {
				background: #fff;
				border-radius: 16rpx;
				margin: 20rpx 0;
				padding: 20rpx;

				.header {
					display: flex;
					justify-content: space-between;
					border-bottom: 1px #f3f3f3 solid;
					padding: 20rpx;

					.red {
						color: indianred;
					}

					.green {
						color: #39CE77;
					}

					.blue {
						color: #1372FF;
					}

					.grey {
						color: #4C5F76;
					}

					.orange {
						color: #FF9100;
					}
				}

				.mainContent {
					border-bottom: 1px #f3f3f3 solid;
					display: flex;
					padding: 20rpx 0;


					justify-content: space-evenly;

					.image {
						background-repeat: no-repeat;
						background-size: cover;
						width: 198rpx;
						height: 180rpx;
						border-radius: 16rpx;
					}

					.middle {
						color: #777777;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						margin-left: 25rpx;


						.title {
							font-weight: 700;
							font-size: 32rpx;
							color: black;
						}

						.info {
							color: #777777;
							display: flex;
							flex-direction: column;

							&>span {
								margin-top: 10rpx;

							}
						}
					}

					.price {
						color: red;
						text-align: center;
						height: 100%;
						align-items: center;
						align-self: center;
						font-size: 29rpx;
						font-weight: 700;
					}

				}

				.bottom {
					padding: 30rpx 20rpx;
					display: flex;
					justify-content: flex-end;

					.refuse {
						margin-right: 30rpxs;
						border: 1rpx solid orangered;
						border-radius: 35rpx;
						color: orangered;
						padding: 13rpx 34rpx;
					}

					.btn {
						background: #1372FF;
						border-radius: 35rpx;
						color: white;
						padding: 13rpx 34rpx;
						margin-left: 30rpx;

					}

					.detail {

						border: 1rpx solid darkgrey;
						border-radius: 35rpx;
						color: darkgrey;
						padding: 13rpx 34rpx;
					}
				}

			}
		}
	}
</style>