<template>
	<view class="content">
		
		<view class="head flex-sb sticky box-shadow-light">
			<view class="flex" @click="seacher">
				<view class="mr5"><uni-icons type="search" size="18"/></view>
				<view  v-if="+seacht===0" style="font-size: 28rpx;">筛选</view>
				<input v-model="input" :class="{'active':+seacht===1}" maxlength="10" 
					class="search-input" type="text" confirm-type="search" @confirm="loadPage"/>
			</view>
			<view class="flex status">
				<view :class="{ 'active': +status===0 }" @click="status=0;this.loadPage()">待接单</view>
				<view :class="{ 'active': +status===1 }" @click="status=1;this.loadPage()">进行中</view>
				<view :class="{ 'active': +status===2 }" @click="status=2;this.loadPage()">已完成</view>
			</view>
		</view>
		
		<view class="m20" v-if="+status===0">
			<view class="re-empty" v-if="waits.length<1">
				<view>暂无数据</view>
			</view>
			<view v-for="e in waits" class="b-relative item-card mb20">
				<view class="m10 flex-sb">
					<view class="ellipsis">{{e.address}}</view>
					<view class="item-time">{{ $timeUtils.formatTime(e.create_time) }}</view>
				</view>
				<view>到场时间：{{$timeUtils.formatTime2Day(e.in_time)}}</view>
				<view>计划数量：{{e.mi}}m³/趟</view>
				<view class="item-button" @click="clickDetail(e.id)">查看</view>
			</view>
		</view>
		<view class="m20" v-if="+status===1">
			<view class="re-empty" v-if="runns.length<1">
				<view>暂无数据</view>
			</view>
			<view v-for="e in runns" class="b-relative item-card mb20">
				<view class="m10 flex-sb">
					<view class="ellipsis">{{e.address}}</view>
					<view class="item-time">{{ $timeUtils.formatTime(e.create_time) }}</view>
				</view>
				<view>到场时间：{{$timeUtils.formatTime2Day(e.in_time)}}</view>
				<view>计划数量：{{e.mi}}m³/趟</view>
				<view class="item-button" @click="clickDetail(e.id)">查看</view>
			</view>
		</view>
		<view class="m20" v-if="+status===2">
			<view class="re-empty" v-if="endes.length<1">
				<view>暂无数据</view>
			</view>
			<view v-for="e in endes" class="b-relative item-card mb20">
				<view class="m10 flex-sb">
					<view class="ellipsis">{{e.address}}</view>
					<view class="item-time">{{ $timeUtils.formatTime(e.create_time) }}</view>
				</view>
				<view>到场时间：{{$timeUtils.formatTime2Day(e.in_time)}}</view>
				<view>计划数量：{{e.mi}}m³/趟</view>
				<view class="item-button btn1" @click="clickDetail(e.id)">查看</view>
				<view class="item-button btn2" @click="clickStep(e.id)">进度</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 0,
				seacht: 0,
				waits: [],
				runns: [],
				endes: [],
				input: ''
			}
		},
		mounted() {
			this.seacht = 0
			this.loadPage()
		},
		methods: {
			clickDetail(id){ uni.navigateTo({ url: `/pages/user/orderd?id=${id}` }) },
			clickStep(id){ uni.navigateTo({ url: `/pages/user/steps?id=${id}` }) },
			seacher() { this.seacht = 1 },
			loadPage(){
				this.seacht = 0
				uni.showLoading({})
				let uri = "/api/order/enter";
				let useridp = "";
				if(uni.getStorageSync("role")==="1"){
					useridp = uni.getStorageSync("userid")
				} else if(uni.getStorageSync("role")==="2"){
					
				} else {
					uri = "/api/order/all";
				}
				this.$httpGet(uri, {
					status: this.status, 
					seo: this.input, 
					useridp: useridp, 
					enter_id: uni.getStorageSync("enter_id") 
				}, (res) => {
					console.log('[/order/enter]', res);
					uni.hideLoading({})
					this.waits = []
					this.runns = []
					this.endes = []
					if(res.data){
						if (+this.status === 0){
							this.waits = this.$utils.toArray(res.data)
						} else if (+this.status === 1){
							this.runns = this.$utils.toArray(res.data)
						} else if (+this.status === 2){
							this.endes = this.$utils.toArray(res.data)
						}
					} 
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #f5f5f5;
	}
	
	.search-input{
		font-size: 28rpx;
		margin-top: 10rpx;
		line-height: 32rpx;
		border-bottom: 2rpx solid #999;
		width: 0;
		transition: .3s ease-in-out;
	}
	.active{
		width: 70%;
		padding-left: 10rpx;
	}
	
	.head{
		height: 60rpx; 
		line-height: 60rpx; 
		padding: 0 40rpx; 
		background-color: #fff;
	}
	
	.status{
		font-size: 28rpx;
		font-weight: 400;
		color: #9e9e9e;
		padding: 20rpx 0 12rpx;
	}
	.status view{
		padding-right: 5rpx;
		margin-right: 5rpx;
		border-right: 2rpx solid #9e9e9e;
		width: 88rpx;
		height: 28rpx;
		line-height: 28rpx;
		transition: .3s ease-in-out;
	}
	.status view:last-child{
		padding-right: 0;
		margin-right: 0;
		border-right: none;
	}
	.status .active{
		color: #f40000;
		font-weight: 600;
		text-decoration-line: underline;
	}
	
	
	
	
	.item-card{
		width: calc(100vw - 60rpx);
		height: calc(236rpx - 60rpx);
		background: #ffffff;
		padding: 30rpx;
		
		font-size: 24rpx;
		line-height: 42rpx;
		color: #333333;
	}
	.item-button{
		position: absolute;
		left: 533rpx;
		top: 134.42rpx;
		width: 182rpx;
		height: 52rpx;
		line-height: 52rpx;
		border-radius: 8rpx;
		opacity: 1;
			
		box-sizing: border-box;
		border: 2rpx solid #F70303;
	
		font-size: 28rpx;
		font-weight: normal;
		
		text-align: center;
		letter-spacing: 0px;
		color: #F70303;
	}
	.btn1{
		left: 463rpx;
		width: 122rpx;
	}
	.btn2{
		left: 603rpx;
		width: 122rpx;
	}
	.item-time{
		color: #aaa;
		width: 160rpx; 
		text-align: right;
	}
</style>
