<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 userList" :key="index">
						<view class="car-content-one commonBj">
							<view class="content-top">
								<view class="text-part">
									<view class="car"></view>
									<text class="titleStyle" @click="lookInfo(item)">{{ item.driverName }}</text>
									<!-- <text :class="getClass(item.state)+' fontStyle'">{{item .stateName}}</text> -->
								</view>
							</view>
							<view class="centenBox">
								<!-- 	<view class="link">
						</view> -->
								<view class="content-bottom listText" style="margin-top: 20rpx;">
									<view class="icon1 iconStyle2"></view>
									<text>车牌号： {{item.carNumber ?item.carNumber :'未绑定车辆'}}</text>
								</view>
								<u-button @click="changeState(item)" class="buttonStyle2" shape="circle"
									:color="getColor(item.deleteFlag=='0')">
									{{item.deleteFlag=='0'?'解绑':'绑定'}}
								</u-button>
							</view>


							<view class="content-bottom listText">
								<view class="icon2 iconStyle2"></view>
								<text>电&emsp;话： {{item.phone}}</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 style="color: #333333;font-weight: bold;">{{list.driverName}}</text>绑定关系？</text>
					<text>解除后将不能参与运输任务</text>
				</view>
				<u-button class="custom-style widthButton" shape="circle" @click="confirm()"
					color="linear-gradient(to top, #F59A02, #FFD334)">
					确定
				</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getUserState,driverJb
	} from '@/api/company/user.js'
	export default {
		data() {
			return {
				userList: [],
				show: false,
				list: {},

			}
		},
		methods: {
			lookInfo(item) {
				this.$tab.navigateTo('/pages/userInfo/index?id='+item.id)
			},
			addCar() {
				this.$tab.navigateTo('/pages/addUser/index')
			},
			confirm() {
				console.log('确定了')
				this.driverJb();
			},
			driverJb(){
				driverJb(this.list.id).then(res=>{
					this.show = false;
					this.getUserState();
				})
			},
			changeState(item) {
				if (item.deleteFlag=='0') {
					this.list = item;
					this.show = true;
				} else {
					this.$tab.navigateTo('/pages/userInfo/index?isInfo=true&id='+item.id)
				}

			},
			getColor(carNumber ) {
				if (carNumber) {
					return 'linear-gradient(to top, #FF2D04 0%, #FFA53E 100%)';
				} else {
					return 'linear-gradient(to top, #3FC377 0%, #83D992 100%)';
				}

			},
			getClass(state) {
				switch (state) {
					case '2':
						return 'color2';
						break;
					case '3':
					case '4':
						return 'color3';
						break;
					default:
						return 'color1';
						break;
				}

			},
		    getUserState()
			{
				getUserState({pageNum:1,pageSize:10000}).then(res => {
					console.log(res.rows,'res')
					// deleteFlag 0是綁定，1是解綁
					this.userList=res.rows
				})
			}
		},
	   onShow() {
	   	this.getUserState();
	   }
	}
</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 {
		height: 1px;
		background: #E3E4E8;
		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 {
		font-size: 28rpx;
		height: 66rpx;
		line-height: 66rpx;
		font-size: 28rpx;
		font-weight: bold;
		color: #FFFFFF;
		margin-bottom: 25rpx;
		// margin: 25rpx 0;
		
		.button-class {
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.car-content-one {
		// width: 678rpx;
		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: 62rpx;
		background-image: url('@/static/images/user/user.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/user/phone.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>
