<template>
	<view class="content">
		
		<view class="head flex-sb">
			<view class="items">
				<view class="item-tab flex">
					<view @click="clickTabOne">施工前</view>
					<view @click="clickTabTwo">施工中</view>
					<view @click="clickTabThr">施工后</view>
				</view>
				<view class="item-active" :style="{'--step': step + 'rpx'}"></view>
			</view>
		</view>
		
		<view class="m20">
			<view class="re-empty" v-if="item.length<1">
				<view>暂无数据</view>
			</view>
			<view v-for="e in item" class="b-relative item-card mb20">
				<view class="m10 flex-sb">
					<view class="item-tip">请于施工前30分钟内到达现场</view>
					<view style="color: #aaa;" @click="clickDetail(e.id)">
						<span v-if="+e.step===0">待开工</span>
						<span v-if="+e.step===1">施工中</span>
						<span v-if="+e.step===2">已完成</span>
						<uni-icons type="right" color="#aaa" size="12"></uni-icons>
					</view>
				</view>
				<view class="mt20">
					<view>
						<view class="item-icon"/>
						<span>到场时间：{{ $timeUtils.formatTime2Day(e.in_time) }}</span>
					</view>
					<view @click="openMap(e)">
						<view class="item-icon"/>
						<span>施工地点：{{ e.address }}</span>
						<uni-icons type="paperplane" color="#333" size="12"></uni-icons>
					</view>
					<view>
						<view class="item-icon" style="border-color: #e5b746;"/>
						<span>施工已开始</span>
					</view>
				</view>
				<view class="mt20 flex-reverse">
					<button class="item-button" @click="clickStep(e.id)">拍摄照片</button>
					<button class="item-button jr" open-type="contact" v-if="+e.step===0">我要拒单</button>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				step: 8,
				item: [],
				status: 0
			}
		},
		onShow() {
			this.clickTabOne()
		},
		methods: {
			clickDetail(id){ uni.navigateTo({ url: `/pages/user/orderd?id=${id}` }) },
			clickBanner(){ uni.navigateTo({ url: '/pages/login/login' }) },
			clickTabOne(){ 
				this.step=8 
				this.status = 0
				this.loadList()
			},
			clickTabTwo(){ 
				this.step=221 
				this.status = 1
				this.loadList()
			},
			clickTabThr(){ 
				this.step=432
				this.status = 2
				this.loadList()
			},
			loadList(){
				this.item = []
				uni.showLoading({})
				this.$httpGet("/api/order/mine", {status: this.status}, (res) => {
					uni.hideLoading({})
					console.log('[/order/mine]', res);
					if(res.data){
						this.item = this.$utils.toArray(res.data)
					} 
				})
			},
			clickStep(id){
				var stepUri = "/pages/user/step"
				if(+this.status === 0){
					stepUri = stepUri + "0"
				} else if(+this.status === 1){
					stepUri = stepUri + "1"
				} else if(+this.status === 2){
					stepUri = stepUri + "2"
				}
				uni.navigateTo({
					url: `${stepUri}?id=${id}`
				})
			},
			openMap(row){
				uni.openLocation({
					latitude: parseFloat(row.latitude),
					longitude:parseFloat(row.longitude),
					scale: 18,
					name: row.address || '未命名地址'
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #f5f5f5;
		--step: 1; /* 0.05 1 1.88 */
		--color: #F40000;
	}

	.head{
		height: 68rpx; 
		padding: 10rpx 40rpx; 
		background-color: #fff;
	}
	.items{
		width: 687rpx;
		height: 52rpx;
		padding: 8rpx 8rpx;
		border-radius: 34rpx;
		background-color: #f2f4f9;
		position: relative;
	}
	.item-tab{
		line-height: 52rpx;
		background-color: transparent;
	}
	.item-tab view{
		width: 33%;
		text-align: center;
		font-size: 26rpx;
		font-weight: normal;
		text-align: center;
		letter-spacing: -0.16px;
		color: #152748;
		background-color: transparent;
		z-index: 1;
	}
	.item-active{
		width: 229rpx;
		height: 52rpx;
		border-radius: 26rpx;
		background-color: #ffffff;
		position: absolute;
		left: var(--step);
		top: 8rpx;
		transition: .3s ease-in;
		z-index: 0;
	}
	
	
	
	.item-card{
		width: calc(100vw - 120rpx);
		height: calc(414rpx - 60rpx);
		background: #ffffff;
		padding: 30rpx;
		margin: 30rpx;
		border-radius: 24rpx;
		
		font-size: 24rpx;
		line-height: 52rpx;
		color: #333333;
	}
	.item-tip{
		padding: 0 10rpx; 
		background-color: #F2F5F9;
		border-radius: 8rpx;
		
		font-size: 20rpx;
		font-weight: normal;
		letter-spacing: 0px;
		color: #152748;
	}
	.item-icon {
		width: 24rpx;
		height: 24rpx;
		box-sizing: border-box;
		border: 6rpx solid #68B04F;
		border-radius: 50%;
		display: inline-block;
		margin: 10rpx 15rpx -2rpx 0;
	}
	.item-button{
		width: 160rpx;
		height: 64rpx;
		line-height: 64rpx;
		border-radius: 32rpx;
			
		box-sizing: border-box;
		border: 2rpx solid #F40000;
	
		font-size: 28rpx;
		font-weight: normal;
		text-align: center;
		letter-spacing: 0px;
		color: #F40000;
		
		padding: 0 !important;
		margin: 0 !important;
		background-color: transparent !important; 
		margin-left: 10rpx !important;
	}
	
	.jr{
		border-color: #aaa;
		color: #aaa;
	}
</style>
