<template>
	<view class="container">
		<uni-navbar title="企业车辆" path="/pages/home/index"></uni-navbar>
		<view class="box" style="overflow: hidden;">
			<u-button class="commonMt custom-style" shape="circle" @click="addCar"
				color="linear-gradient(to top, #F59A02, #FFD334)">
				<!-- <u-icon class="iconStyle" color="#FFFFFF" name="plus-circle-fill"></u-icon>
				新增车辆 -->
				<view class="button-class">
					<image style="width: 29rpx;height: 29rpx;" src="../../static/images/transport/plus.png"
						mode="widthFix">
					</image>
					<text style="margin-left: 19rpx;">新增车辆</text>
				</view>
			</u-button>
			<view class="box2">
				<view class="commonMb">
					<view class="car-content" v-for="(item,index) in one" :key="index">
						<view class="car-content-one commonBj">
							<view class="content-top">
								<view class="text-part">
									<view class="car"></view>
									<text class="titleStyle" @click="carInfo(item)">{{ item.carNumber }}</text>
									<text
										:class="getClass(item.auditType)+' fontStyle'">{{item.auditType === 0?'待审核': item.auditType === -1?'驳回':'通过'}}</text>
								</view>
							</view>
							<view class="centenBox">
								<!-- <view class="link commonLine">
								</view> -->
								<view class="content-bottom listText" style="margin-top: 20rpx;">
									<view class="icon1 iconStyle2"></view>
									<text>车&emsp;型： {{item.carType}}</text>
								</view>
								<u-button v-if="item.auditType !== 1" class="buttonStyle2" shape="circle"
									color="linear-gradient(to top, #F59A02, #FFD334)" @tap="gotoEdit(item)">
									修改
								</u-button>
								<u-button v-if="item.auditType== 1 " @click="changeState(item)" class="buttonStyle2"
									shape="circle" :color="getColor(item.deleteFlag)">
									{{item.deleteFlag===0?'解绑':'绑定'}}
								</u-button>
							</view>
							<view class="content-bottom listText">
								<view class="icon2 iconStyle2"></view>
								<text>车&emsp;系： {{item.carSeries}}</text>
							</view>
							<view class="content-bottom listText">
								<view class="icon3 iconStyle2"></view>
								<text>载重量： {{item.carCarry}}</text>
							</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 '+(list.deleteFlag===0?'colorStyle2':'colorStyle1')">
						<text style="color: #333333;font-weight: bold;">{{list.chepaihao}}</text>
						<text>{{list.deleteFlag === 0? '解绑车辆后不可开始运输任务': '绑定车辆后即可开始运输任务'}}</text>
						<text> 是否{{list.deleteFlag === 0? '解绑': '绑定'}}?</text>
					</view>
					<u-button class="custom-style widthButton" shape="circle" @click="confirm(list)"
						color="linear-gradient(to top, #F59A02, #FFD334)">
						确定
					</u-button>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	import {
		carList,
		nobindingCar,
		bindingCar
	} from "../../api/company/car.js"
	export default {
		data() {
			return {
				one: [],
				show: false,
				list: {},
				queryParams: {
					pageNum: 1,
					pageSize: 1000
				},
				total: 0
			}
		},
		methods: {
			carInfo(item) {
				if (item.auditType !== 1) {
					return false;
				}
				this.$tab.navigateTo(`/pages/carInfo/index?id=${item.id}`)
			},
			addCar() {
				this.$tab.navigateTo('/pages/addCar/index')
			},
			// 绑定和解绑按钮
			async confirm(item) {
				// 解绑
				if (item.deleteFlag === 0) {
					const res = await nobindingCar(item.id)
					console.log('解绑', res);
					this.getList()
				}
				// 绑定
				if (item.deleteFlag === 1) {
					const res = await bindingCar(item.id)
					console.log('绑定', res);
					this.getList()
				}
				this.show = false;
			},
			// 点击修改按钮
			gotoEdit(item) {
				this.$tab.navigateTo('/pages/addCar/index?id=' + item.id)
				// uni.navigateTo({
				// 	url: '/pages/addCar/index?id=' + item.id,
				// 	success(res) {
				// 		res.eventChannel.emit('data', {
				// 			data: item
				// 		})
				// 	}
				// })
			},
			// 绑定或者解绑按钮
			changeState(item) {
				this.list = item
				this.show = true
			},
			getColor(state) {
				switch (state) {

					case 0:
						return 'linear-gradient(to top, #FF2D04 0%, #FFA53E 100%)';
						break;
					case 1:
						return 'linear-gradient(to top, #3FC377 0%, #83D992 100%)';
						break;
					default:
						return 'linear-gradient(to top, #F59A02, #FFD334)';
						break;
				}
			},
			getClass(state) {
				switch (state) {
					case -1:
						return 'color2';
						break;
					case 1:
						return 'color3';
						break;
					default:
						return 'color1';
						break;
				}

			},
			// 获取列表数据
			async getList() {
				const data = await carList(this.queryParams)
				this.one = data.rows
				this.total = data.total
				console.log(this.one, 'one');
			}
		},
		onLoad() {
			this.getList()
			// uni.getSystemInfo({
			// 	success: function(res) {
			// 		console.log(res, '111222')
			// 	}
			// });
		}
	}
</script>

<style lang="scss" scoped>
	.iconStyle {
		/* font-size:29rpx ; */
		margin-right: 18rpx;

	}

	/deep/ .u-icon__icon[data-v-2ee87dc9] {
		font-size: 29rpx !important;
		// line-height: 66rpx !important;
	}

	.fontStyle {
		font-size: 26rpx;
		font-weight: bold;
	}

	.color1 {
		color: #FBFE01;
	}

	.color2 {
		color: #FC5536;
	}

	.color3 {
		color: #148459;
	}

	.colorStyle1 {
		color: #007C3C;
	}

	.colorStyle2 {
		color: #F4644B;
	}

	.link {
		flex: 1;
		// width: 90%;
	}

	.buttonStyle2 {
		width: 120rpx;
		height: 60rpx;
		margin: inherit;
		font-size: 28rpx;
		font-weight: bold;
		color: #FFFFFF;
	}

	.centenBox {
		display: flex;
		justify-content: space-between;
	}

	.custom-style {
		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;
		}
	}

	.car-content-one {
		padding: 18rpx 40rpx;
	}

	.car-content {
		display: flex;
		flex-direction: column;
		margin-bottom: 30rpx;
		margin-top: 20rpx;
	}

	.content-top {
		display: flex;
		justify-content: space-between;
	}

	.car {
		width: 60rpx;
		height: 60rpx;
		background-image: url('@/static/images/car/lb_04.png');
		background-size: 100% 100%;
		margin-right: 26rpx;
	}

	.titleStyle {
		font-size: 28rpx;
		font-weight: bold;
		color: #333333;
		margin-right: 33rpx;
	}

	.text-part {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.stateStyle {
		text-align: center;
		line-height: 45rpx;
		width: 103rpx;
		height: 45rpx;
		border-radius: 15rpx;
		font-weight: bold;
		color: #FFFFFF;
	}


	.content-bottom {
		display: flex;
		align-items: center;

		margin-bottom: 15rpx;
	}

	.iconStyle2 {
		width: 22rpx;
		height: 22rpx;
		margin-right: 19rpx;
	}

	.icon1 {
		background-image: url('@/static/images/car/lb_01.png');
		background-size: 100% 100%;
	}

	.icon2 {
		background-image: url('@/static/images/car/lb_02.png');
		background-size: 100% 100%;
	}

	.icon3 {
		background-image: url('@/static/images/car/lb_03.png');
		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: 150rpx;
		margin-bottom: 53rpx;
	}

	.textBox {
		font-size: 28rpx;
		font-weight: bold;

		line-height: 60rpx;
		display: flex;
		flex-direction: column;
		text-align: center;
		margin-top: 67rpx;
		margin-bottom: 46rpx;
		letter-spacing: 8rpx;
	}
</style>
