<template>
	<view class="container">
		<uni-navbar title="启动运输"></uni-navbar>
		<view class="box" style="overflow: hidden;">
			<!-- <u-button class="commonMt custom-style" shape="circle" @click="addLine"
				color="linear-gradient(to top, #F59A02, #FFD334)">
				<view class="button-class">
					<text style="margin-left: 19rpx;">启动运输</text>
					<view class="down" ></view>
				</view>
			</u-button> -->
			<!-- 按钮区域 -->
			<view class="button-box commonMt">
				<view :class="'car-box ' + (isCarInfo==='0'?'active':'')" @click="carbButtonClick">
					<image style="width: 28rpx;height: 28rpx;" src="../../static/images/record/state1.png"
						mode="widthFix"></image>
					<text>启动运输</text>
				</view>
				<view :class="'car-box ' + (isCarInfo==='1'?'active':'')" @click="personbButtonClick">
					<image style="width: 28rpx;height: 28rpx;" src="../../static/images/record/state2.png"
						mode="widthFix"></image>
					<text>超期未执行</text>
				</view>
			</view>
			<view class="box2">
				<view class="commonMb">
					<view class="small-box commonBj" v-for="(item,index) in list" :key="item.id">
						<view class="small-box-top">
							<view class="small-box-top-left">
								<image style="width: 51rpx;height: 51rpx;margin-left: 11rpx;"
									src="../../static/images/driverHome/sj_06.png" mode="widthFix">
								</image>
								<text style="width: 80%;">{{ item.transportName }}</text>
							</view>
							<view v-if="isCarInfo==='0'">
								<!-- <u-button v-if="item.runState=='0'" @click="starTransport(item)"
									class="miniButton miniButtonWidth1" shape="circle"
									color="linear-gradient(to right, #F59A02, #FFD334 )">启 动</u-button>
								<u-button v-else @click="starTransport(item)" class="miniButton miniButtonWidth2"
									shape="circle" color="linear-gradient(to right, #FF2D04, #FFA53E )">恢复运输</u-button> -->
							</view>
							<view v-else>
								<u-button class="miniButton miniButtonWidth3"
									color="linear-gradient(to right, #FF2D04, #FFA53E )">已超期</u-button>
							</view>

							<!-- <view :class="changeStateClass(item.auditState)" class="small-box-top-right">
								<text>{{item.auditState===0? '待审核':item.auditState===-1?'驳 回':'通 过'}}</text>
							</view> -->
						</view>
						<view class="small-box-middle mt20">
							<view class="middle-left">
								<view class="circle-green circle-style">
									起
								</view>
								<view class="small-box-middle-line-left">
								</view>
								<view class="circle-red circle-style">
									终
								</view>
							</view>
							<view class="middle-middle">
								<view class="position-start">
									<view class="green bold size24 textStyle">{{item.startName}}</view>
								</view>
								<view class="position-end">
									<text class="red bold size24 textStyle ">{{item.endName}}</text>
								</view>
							</view>
							<view v-if="isCarInfo==='0'" class="rightBox">
								<u-button v-if="item.runState=='0'" @click="starTransport(item)"
									class="miniButton miniButtonWidth1" shape="circle"
									color="linear-gradient(to right, #F59A02, #FFD334 )">启 动</u-button>
								<u-button v-else @click="starTransport(item)" class="miniButton miniButtonWidth2"
									shape="circle" color="linear-gradient(to right, #FF2D04, #FFA53E )">恢复运输</u-button>
							</view>
						</view>
						<view class="small-box-date">
							<image style="width: 24rpx;height: 24rpx;margin-left: 10rpx;"
								src="../../static/images/transport/rili.png" mode="widthFix">
							</image>
							<text class="ml19 font-size-style">
								日期：{{changeDate(item.startDate)}} — {{changeDate(item.endDate)}}
							</text>
						</view>
						<view class="small-box-bottom mt23">
							<view class="small-box-bottom-left">
								<image style="width: 25rpx;height: 25rpx;margin-left: 10rpx;"
									src="../../static/images/transport/time.png" mode="widthFix"></image>
								<text class="ml19 font-size-style">
									时间：{{changeTime(item.startTime)}} — {{changeTime(item.endTime)}}
								</text>
							</view>
							<!-- <view class="small-box-bottom-left">
								<image style="width: 25rpx;height: 25rpx;" src="../../static/images/transport/lb_01.png"
									mode="">
								</image>
								<text class="mr15 ml19 font-size-style">计划使用车辆数：{{item.expectCar}} 辆</text>
							</view> -->
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="show" mode="center">
			<view class="model">
				<view class="modelTitle">提 示 <view class="close" @click="show=false"></view>
				</view>
				<view class="textBox colorStyle2">
					<text>您有正在运输中的任务</text>
					<text>不可开始新任务</text>
				</view>
				<u-button class="custom-style6 widthButton" shape="circle" @click="look()"
					color="linear-gradient(to top, #F59A02, #FFD334)">
					返 回 任 务
				</u-button>
			</view>
		</u-popup>
		<selectNew :isShow="isShow" :valueData="queryParams.driverId" :oldList="companyList" @changSelect="changSelect">
		</selectNew>
	</view>
</template>

<script>
	import {
		driverCompany,
		passList,
		userRunPort,
		timeOutList
	} from "../../api/company/transport.js"
	export default {
		data() {
			return {
				list: [],
				queryParams: {
					// pageSize: 1000,
					// pageNum: 1
					// userId:this.$store.state.user.userId,
					companyId: '',
					driverId: '',
				},
				companyList: [],
				total: 0,
				isShow: false,
				show: false,
				id: null,
				isCarInfo: '0',
			}
		},
		methods: {
			timeOutList() {
				timeOutList(this.queryParams).then(res => {
					this.list = res.rows;
				})
			},
			// 运输记录和驳回就的点击事件
			carbButtonClick() {
				this.isCarInfo = '0';
				this.getList();
			},
			personbButtonClick() {
				this.isCarInfo = '1';
				this.timeOutList();
			},
			look() {
				this.show = false;
				this.$tab.navigateTo(`/pages/driverStartTransportDoPath/index?id=${this.id}`)
			},
			changSelect(data) {
				this.isShow = false
				if (data && data.value) {
					this.queryParams.companyId = data.companyId;
					this.queryParams.driverId = data.id;
					this.getList();
				}
			},
			userRunPort(item) {
				userRunPort().then(res => {
					console.log(res, 'res');
					if (!res.data) {
						this.$tab.navigateTo(`/pages/driverStartTransportInfo/index?id=${item.id}`)
					} else {
						this.id = res.data.id;
						this.show = true;
					}
				})
			},
			starTransport(item) {
				if (item.runState == '0') {
					this.userRunPort(item);
				} else {
					this.$tab.navigateTo(`/pages/driverStartTransportDoPath/index?id=${item.processId}`)
				}

			},
			addLine() {
				// this.$tab.navigateTo('/pages/addTransport/index')
				this.isShow = true;
			},
			changeStateClass(state) {
				switch (state) {
					case 0:
						return 'state-class1'
					case -1:
						return 'state-class2'
					case 1:
						return 'state-class3'
				}
			},
			changeDate(date) {
				return date.substring(0, 4) + '年' + date.substring(5, 7) + '月' + date.substring(8, 10) + '日'
			},
			changeTime(time) {
				return time.slice(0, 5)
			},
			// 获取运输列表
			getList() {
				passList(this.queryParams).then(res => {
					// console.log(res,'111');
					this.list = res.rows;
				})

			},
			driverCompany() {
				// await driverCompany().then(res=>{
				this.queryParams.companyId = this.$store.state.user.companyId;
				this.queryParams.driverId = this.$store.state.user.driverId;
				// this.companyList=res.data.map(item=>{
				//  return {
				//  	name: item.companyName,
				//  	value: item.id,
				// 	...item
				//  }
				// })
				if (this.isCarInfo == '0') {
					this.getList();
				} else {
					this.timeOutList();
				}

				// })
			},
		},
		onShow() {
			console.log(this.$store.state.user.companyId, '公司Id')
			this.driverCompany()
		}
	}
</script>

<style lang="scss" scoped>
	.active {
		background: linear-gradient(0deg, #F59A02 0%, #FFD334 100%) !important;
		box-shadow: 0px 2rpx 13rpx 0px rgba(27, 43, 95, 0.25) !important;
	}

	.button-box {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 24rpx;


		.car-box {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 330rpx;
			height: 66rpx;
			background: rgba(255, 255, 255, 0.6);
			border: 0;
			// box-shadow: 0px 0px 24rpx 6rpx rgba(109, 160, 251, 0.6);
			border-radius: 33rpx;

			uni-text {
				margin-left: 18rpx;
				font-size: 28rpx;
				font-weight: bold;
				color: #FFFFFF;
			}
		}
	}

	.deepRed {
		color: #E54504
	}

	.deepGreen {
		color: #088243
	}

	.custom-style6 {
		font-size: 28rpx;
		height: 66rpx;
		line-height: 66rpx;
		font-size: 28rpx;
		font-weight: bold;
		color: #FFFFFF;
		margin-bottom: 25rpx;

		.button-class {
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.small-box {
		margin-bottom: 31rpx;
		padding: 22rpx;

		.small-box-top {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.small-box-top-left {
				display: flex;
				align-items: center;

				uni-text {
					font-size: 28rpx;
					font-weight: bold;
					color: #333333;
					margin-left: 18rpx;
				}

			}

			.small-box-top-right {
				text-align: center;
				width: 103rpx;
				height: 45rpx;
				border-radius: 15rpx;
				font-size: 26rpx;
				font-weight: bold;
				color: #FFFFFF;
				line-height: 45rpx;
			}
		}

		.mt20 {
			margin-top: 20rpx;
		}


		.small-box-date {
			display: flex;
			align-items: center;
			margin-top: 24rpx;
		}

		.small-box-bottom {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.small-box-bottom-left {
				display: flex;
				align-items: center;
			}
		}
	}


	.ml19 {
		margin-left: 10rpx;
	}

	.mt23 {
		margin-top: 23rpx;
	}

	.mr15 {
		margin-right: 15rpx;
	}

	.font-size-style {
		font-size: 24rpx;
		font-weight: 400;
		color: #485B93;
	}

	.state-class1 {
		background: linear-gradient(90deg, #F59A02 0%, #FFD334 100%);
	}

	.state-class2 {

		background: linear-gradient(90deg, #FF2D04 0%, #FFA53E 100%);
	}

	.state-class3 {

		background: linear-gradient(90deg, #3FC377 0%, #83D992 100%);
	}

	.miniButton {
		height: 48rpx;
		font-size: 26rpx;
		font-weight: bold;
		color: #FFFFFF;
		margin-right: 0;
		padding: 0;
	}

	.miniButtonWidth1 {
		width: 120rpx;
	}

	.miniButtonWidth2 {
		width: 140rpx;
	}

	.miniButtonWidth3 {
		width: 133rpx;
		border-radius: 28rpx;
	}

	.down {
		width: 29rpx;
		height: 15rpx;
		position: absolute;
		right: 32rpx;
		// border: solid 1px red;
		background: url('../../static/images/transport/down.png') no-repeat;
		background-size: 100% 100%;
	}

	// 弹框样式
	/deep/ .u-popup__content {
		background-color: rgba(0, 0, 0, 0);
	}

	.model {
		width: 542rpx;
		// height: 441rpx;
		background: rgba(255, 255, 255, 0.7);
		border: 2rpx solid #77A8FF;
		box-shadow: 0px 0px 24rpx 6rpx rgba(109, 160, 251, 0.6);
		border-radius: 34rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

	}

	.modelTitle {
		width: 542rpx;
		height: 80rpx;
		background: #7FB5FF;
		border-radius: 28rpx 28rpx 0px 0px;
		font-size: 28rpx;
		line-height: 80rpx;
		font-weight: bold;
		text-align: center;
		color: #FFFFFF;
		position: relative;
	}

	.close {
		width: 30rpx;
		height: 30rpx;
		// border: 1px salmon solid;
		position: absolute;
		right: 25rpx;
		top: 50%;
		transform: translateY(-50%);
		background-image: url('@/static/images/close.png');
		background-size: 100% 100%;
	}

	.widthButton {
		width: 200rpx;
		margin-bottom: 53rpx;
	}

	.textBox {
		font-size: 30rpx;
		font-weight: bold;
		line-height: 60rpx;
		display: flex;
		flex-direction: column;
		text-align: center;
		margin-top: 67rpx;
		margin-bottom: 46rpx;
		letter-spacing: 8rpx;
	}

	.colorStyle2 {
		color: #F4644B;
	}
	
	.rightBox{
		position: absolute;
		right: 20rpx;
		top:49%;
		transform: translateY(-50%);
	}
	.textStyle{
		width: 360rpx;
	}
</style>
