<template>
	<view>
		<view class="tab">
			<u-tabs :list="tab" :scrollable="false" itemStyle="width:200px;height:50px" lineWidth="60" @click="click"></u-tabs>
		</view>
		<view class="goodsList">
			<view class="item" v-for="(item, index) in driverList" :key="index">
				<view class="title">{{item.createTime}}</view>
				<view class="state" v-if="item.driverResult == 0">
					<text class="icon">&#xe830;</text>
					<text>待确认</text>
				</view>
				<view class="state" v-if="item.driverResult == 1">
					<text class="icon" style="color: #13ce66">&#xe830;</text>
					<text>已确认</text>
				</view>
				<view class="state" v-if="item.driverResult == 2">
					<text class="icon" style="color: #f44336">&#xe830;</text>
					<text>已拒绝</text>
				</view>
				<!-- <image src="../../../../../static/news.jpg" mode="aspectFill" class="pic"></image> -->
				<view class="con">
					<view class="productName omit" style="display: flex;">
						<u-icon name="map" color="#2979ff" size="20"></u-icon>贸易地点：{{ item.tradeAreaName }}</view>
					<view class="productName omit"  style="display: flex; margin-top: 10px;">
						<u-icon name="bag" color="#FF7F00" size="22"></u-icon>运送货物：{{ item.goodsName }}
					</view>
				</view>
				<view class="clear"></view>
				<view class="op">
					<view class="date">2022-12-12:12:12</view>
					<template v-if="item.driverResult == 0">
						<view class="an" style="color: #f44336" @click.stop="confirm(item, 2, '确认拒绝？')">拒绝接单</view>
						<view class="an" style="color: #4581fb" @click.stop="confirm(item, 1, '确认接单？')">确认接单</view>
					</template>
				</view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && driverList.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tab: [
					{ name: '待确认', driverResult: 0},
					{ name: '已确认', driverResult: 1},
					{ name: '已拒绝', driverResult: 2},
				],
				param: { pageNo: 1, pageSize: 10},
				loadMore: true,
				driverList: [],
			}
		},
		onLoad() {
			this.getDriverOrderList()
		},
		methods: {
			// 司机查询订单 ?driverResult=
			getDriverOrderList(){
				this.http.request({
					url: '/transport-server/app/TbCarRecord/getAppList',
					loading: 'false',
					data: this.param,
					success: res => {
						this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
						if (res.data.data) {
							this.driverList.push(...res.data.data);
						}

						this.driverList.map(item => {
							if(item.createTime == this.util.getDate('day')){
								item.createTime = '今天'
							}
						})
					}
				});
			},
			//刷新数据
			refresh() {
				this.loadMore = true;
				this.param.pageNo = 1;
				this.driverList = [];
				this.getDriverOrderList();
			},
			//点击tab切换
			click(e) {
				this.param.driverResult = e.driverResult;
				this.refresh()
			},
			//司机处理
			confirm(item, type, content){
				let user = this.getUser()
				uni.showModal({
					title: '提示',
					content: content,
					success: res => {
						if (res.confirm) {
							if(type == 1){
								let params = {
								  carRecordId: item.id,
								  levelOneOrderId: item.orderId,
								  orderNo: 0,
								  loadingAddress: item.loadingAddress,
								  unloadingAddress: "",
								  comment: "",
								  tradeAreaId: item.tradeAreaId,
								  tradeAreaName: item.tradeAreaName,
								  driverId: item.driverId,
								  driverName: user.name,
								  driverPhone: user.phone,
								  vehicleId: item.vehicleId,
								  vehicleName: item.vehicleModel,
								  vehicleType: item.vehicleType
								}
								this.http.request({
									url: '/transport-server/app/TbDriver/driverAgree',
									data: params,
									method: 'POST',
									contentType: 'application/json;charset=UTF-8',
									success: resp => {
										uni.showToast({ title: '操作成功' });
										this.refresh();
									}
								});
							}else{
								let params = {
								  carRecordId: item.id,
								  enterpriseId: item.enterpriseId,
								  enterprisePhone: item.enterprisePhone,
								  levelOneOrderId: item.orderId
								}
								this.http.request({
									url: '/transport-server/app/TbDriver/driverRefuse',
									data: params,
									success: resp => {
										uni.showToast({ title: '操作成功' });
										this.refresh();
									}
								});
							}
						}
					}
				});
			}
		}
	}
</script>

<style>

</style>
