<template>
	<view class="content">
		<view class="nav flex">
			<view class="item" v-for="(item,index) in navList" :class="{action: current == index}" @click="changeCurrent(index)">
				{{item.tit}}
			</view>
		</view>
		<swiper :current="current" class="swiper-box" :style="{'height': height}">
			<swiper-item v-for="item in navList">
				<scroll-view scroll-y="true" :style="{'height': height}">
					<empty v-if="item.loaded === true && item.list.length === 0"></empty>
					<view class="order-item" v-for="items in item.list" >
						<view class="item-top flex">
							<view class="order-type">
								预约订单
							</view>
							<view class="order-id">
								订单编号:{{items.order_id}}
							</view>
							<view class="order-status">
								{{items.status == 0?'待服务':(items.status == 1?'进行中':'已完成')}}
							</view>
						</view>
						<view class="item-user flex">
							<image src="../../static/icon/where.png" mode="" class="where"></image>
							<view class="">
								<view class="">
									{{items.user_address}}
								</view>
								<view class="phone">
									{{items.real_name}}{{items.user_phone |geTel}}
								</view>
							</view>
						</view>
						<view class="item-user flex">
							<image src="../../static/icon/time.png" mode="" class="where"></image>
							<view class="">
								<view class="">
									{{items.subscribe_day}} {{items.subscribe_time}}
								</view>
							</view>
						</view>
						<view class="item-yg">
							<view class="">
								服务类型：<text>{{items.type}}</text>
							</view>
							<!-- <view class="">
								代理人：<text>李丹丹</text>
							</view> -->
						</view>
						<view class="item-btm flex">
							<view class="">
								下单时间：{{items.add_time}}
							</view>
							<view class="u-btn" @click="cancelSubscribe(items.order_id)" v-if="items.status == 0">
								取消预约
							</view>
						</view>
					</view>
					<uni-load-more :status="item.loading" v-if="!(item.loaded === true && item.list.length === 0)"></uni-load-more>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from '@/components/empty';
	import { subscribeList,cancelSubscribe} from '@/api/user.js'
	export default {
		components: {
			empty,
			uniLoadMore
		},
		data() {
			return {
				height: '',
				current: 0,
				navList: [
					{
						tit: '待服务',
						status: 0,
						list: [],
						loading: 'more',
						loaded: true,
						page: 1,
						limit: 10,
					},
					{
						tit: '进行中',
						status: 1,
						list: [],
						loading: 'more',
						loaded: false,
						page: 1,
						limit: 10,
					},
					// {
					// 	tit: '已完成',
					// 	status: 2,
					// 	list: [],
					// 	loading: 'more',
					// 	loaded: false,
					// 	page: 1,
					// 	limit: 10
					// }
				]
			}
		},
		filters:{
			geTel(tel){
			    var reg = /^(\d{3})\d{4}(\d{4})$/;  
			    return tel.replace(reg, "$1****$2");
			}
		},
		onLoad() {
			this.getOrderList()
		},
		onShow() {
		},
		onReachBottom() {
			
		},
		onReady(res) {
					var that = this;
					uni.getSystemInfo({
						success: resu => {
							const query = uni.createSelectorQuery();
							query.select('.swiper-box').boundingClientRect();
							query.exec(function(res) {
								that.height = resu.windowHeight - res[0].top + 'px';
							});
						},
						fail: res => {}
					});
				},
		methods: {
			cancelSubscribe(id) {
				cancelSubscribe({
					order_id:id
				}).then(res=> {
					uni.showToast({
						title: '取消成功',
						duration: 2000
					});
					this.getOrderList('re')
				})
			},
			changeCurrent(index) {
				if(index == this.current) return;
				this.current = index;
				this.getOrderList()
			},
			getOrderList(type) {
				let that = this;
				let item = that.navList[that.current];
				if(type == 're') {
					item.list = []
					item.page = 1
					item.loading = 'more'
					item.loaded = false
				}
				if(item.loading == 'noMore' || item.loading == 'loading') return;
				item.loading = 'more'
				subscribeList({
					page:item.page,
					limit:item.limit,
					status: item.status
				}).then(res => {
					console.log(res.data.data);
					let arr = res.data.data
					item.list = item.list.concat(arr)
					if(arr.length == item.limit) {
						item.loading = 'more'
					}else {
						item.loading = 'noMore'
					}
					item.loaded = true
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding-top: 20rpx;
	}
	.nav {
		width: 690rpx;
		height: 64rpx;
		background: $base-color;
		border-radius: 30rpx;
		margin: auto;
		justify-content: space-around;
		margin-bottom: 30rpx;
		.item {
			width: 209rpx;
			line-height: 56rpx;
			border-radius: 28rpx;
			text-align: center;
			color: #FFFFFF;
		}
		.action {
			color: $base-color;
			background: #FFFFFF;
			// font-weight: bold;
		}
	}
	.swiper-box {
	}
	.order-item {
		padding:0 20rpx;
		background-color: #fff;
		width: 700rpx;
		margin: 0 auto 20rpx;
		border-radius: 20rpx;
		&:last-of-type {
			margin-bottom: 0;
		}
		.item-top {
			height: 92rpx;
			border-bottom: #f5f5f5 3rpx solid;
			font-weight: 500;
			.order-type {
				// padding: 10;
				padding: 8rpx 10rpx;
				
				background: #ffeae5;
				border-radius: 0rpx 10rpx 0rpx 10rpx;
				font-size: 20rpx;
				color: #FF4E00;
			}
			.order-id {
				flex-grow: 1;
				font-size: 22rpx;
				color: #A3A8BB;
				padding-left: 10rpx;
			}
			.order-status {
				font-size: 26rpx;
				color: #FF4E00;
			}
		}
		.item-yg {
			width: 660rpx;
			// height: 122rpx;
			background: #F5F5F5;
			font-size: 24rpx;
			color: #666666;
			padding: 25rpx 0 20rpx 20rpx;
			margin-bottom: 24rpx;
			text {
				font-weight: bold;
				color: #333333;
			}
		}
		.item-btm {
			height: 92rpx;
			font-size: 24rpx;
			color: #A3A8BB;
			border-top: #f5f5f5 3rpx solid;
		}
		.item-user {
			justify-content: flex-start;
			align-items: flex-start;
			font-weight: bold;
			font-size: 26rpx;
			color: #000000;
			margin: 30rpx 0;
			.where {
				width: 24rpx;
				height: 28rpx;
				margin-right: 23rpx;
			}
			.time {
				width: 24rpx;
				height: 24rpx;
				
			}
			image {
				flex-shrink: 0;
				margin-top:5rpx;
			}
			.phone {
				padding-top: 15rpx;
				font-size: 23rpx;
				color: #666666;
			}
		}
	}
	.u-btn {
		width: 144rpx;
		line-height: 55rpx;
		border-radius: 28rpx;
		border: 1px solid #FF4C4C;
		font-size: 26rpx;
		color: #FF4C4C;
		text-align: center;
	}
</style>