<template>
	<view class="content">
		<!-- <view class="search-wrap">
			<view class="search flex">
				<image src="../../static/icon/search.png" mode=""></image>
				<input type="text" placeholder="请输入关键词搜索" confirm-type="search" @confirm="search" v-model="keys"/>
			</view>
		</view> -->
		<view class="navbar">
			<view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: current === index }" @click="changeCurrent(index)">{{ item.tit }}</view>
		</view>
		<view style="height: 20rpx;">
		</view>
		<swiper :current="current" class="swiper-box" :style="{'height': height}" @change="chanageC">
			<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.detail}}
								</view>
								<view class="phone">
									{{items.real_name}} {{items.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.add_date}} {{items.last_date}}
								</view>
							</view>
						</view> -->
						<view class="item-yg">
							<view class="">
								商品信息：<text>{{items.goods.name}}</text>
							</view>
							<!-- <view class="">
								代理人：<text>李丹丹</text>
							</view> -->
						</view>
						<view class="item-btm flex">
							<view class="" v-if="item.status != 3">
								下单时间：{{items.add_date}}
							</view>
							<!-- cashback_money -->
							<view class="" v-if="item.status == 3">
								返现金额：{{items.cashback_money}}
							</view>
							<view class="u-btn" @click="cancelSubscribe(items.order_id)" v-if="items.status == 1">
								上传评价
							</view>
							<view class="u-btn" @click="pass(items)" v-if="items.status == 0">
								订单确认
							</view>
							<view class="u-btn" @click="lookimg(items)" v-if="items.status == 2 || items.status == 3">
								查看评价
							</view>
						</view>
					</view>
					<uni-load-more :status="item.loadingType" 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 { wuyouList,cancelSubscribe,agentOrder,agentOrderAuth,wuyouAgentOrderAuth} from '@/api/user.js'
	export default {
		components: {
			empty,
			uniLoadMore
		},
		data() {
			return {
				keys: '',
				height: '',
				current: 0,
				navList: [
					{
						tit: '待确认',
						status: 0,
						list: [],
						loadingType: 'more',
						loaded: true,
						page: 1,
						limit: 10
					},
					{
						tit: '待上传',
						status: 1,
						list: [],
						loadingType: 'more',
						loaded: false,
						page: 1,
						limit: 10
					},
					{
						tit: '已上传',
						status: 2,
						list: [],
						loadingType: 'more',
						loaded: false,
						page: 1,
						limit: 10
					},
					{
						tit: '已完成',
						status:3,
						list: [],
						loadingType: 'more',
						loaded: false,
						page: 1,
						limit: 10
					}
				]
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.getOrderList('re')
		},
		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: {
			lookimg(item) {
				let arr = item.auth_up_file.split(',')
				uni.previewImage({
					current: 0,
					loop: false,
					urls: arr,
					indicator: 'default'
				});
			},
			search() {
				this.getOrderList('re')
			},
			chanageC(e) {
				this.current = e.detail.current;
				this.getOrderList('tab')
			},
			changeCurrent(index) {
				if(index == this.current) return;
				this.current = index;
			},
			pass(item) {
				// agentOrderAuth({
				// 	id,
				// 	status: 0
				// }).then(res => {
				// 	uni.showToast({
				// 		title: '确认成功',
				// 		duration: 2000
				// 	});
				// })
				uni.navigateTo({
					url: '/pages/order/sht?id=' + item.order_id + '&type=' + item.goods.name
				})
			},
			cancelSubscribe(id) {
				uni.navigateTo({
					url: '/pages/order/upPj?id=' + id + '&type=1'
				})
			},
			getOrderList(type) {
				let that = this;
				let item = that.navList[that.current];
				if(type == 'tab' && item.loaded) return;
				if(type == 're') {
					item.loadingType = 'more'
					item.loaded = false
					item.page = 1
					item.list = []
				}
				if(item.loadingType == 'loading' || item.loadingType == 'noMore') return;
				item.loadingType = 'loading'
				wuyouList({
					page:item.page,
					limit:item.limit,
					status: item.status,
					key: this.keys
				}).then(res => {
					let arr = res.data.data
					item.list = item.list.concat(arr)
					if(arr.length == item.limit) {
						item.loadingType = 'more'
					}else {
						item.loadingType = 'noMore'
					}
					item.loaded = true
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.navbar {
		display: flex;
		height: 40px;
		padding: 0 5px;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
		position: relative;
		z-index: 10;
		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: $font-color-dark;
			position: relative;
	
			&.current {
				color: #000;
				font-weight: bold;
	
				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid $base-color;
				}
			}
		}
	}
	.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;
			background: #F5F5F5;
			font-size: 24rpx;
			color: #666666;
			padding: 20rpx 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;
			}
		}
	}
	.search-wrap {
		background-color: #ffffff;
		padding: 20rpx 0;
		.search {
			width: 702rpx;
			height: 64rpx;
			background: #F1F1F1;
			border-radius: 32rpx;
			margin: auto;
			padding: 0 30rpx;
			image {
				width: 31rpx;
				height: 32rpx;
				flex-shrink: 0;
			}
			input {
				height: 100%;
				flex-grow: 1;
				padding-left: 18rpx;
			}
		}
	}
	.u-btn {
		width: 144rpx;
		line-height: 55rpx;
		border-radius: 28rpx;
		border: 1px solid #FF4C4C;
		font-size: 26rpx;
		color: #FF4C4C;
		text-align: center;
	}
</style>