<template>
	<view class="fullHeight">
		<headers :showBack="true">
			<view class="headerName">
				{{ pageTitle }}
			</view>
		</headers>
		<view class="formBox">
			<form @submit="formSubmit">
				<view class="uni-form-item">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						编号
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="num" :value="form.num"
							placeholder="请输入" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						单位
					</view>
					<!-- enterpriseId -->
					<view class="uni-form-input">
						<picker @change="bindPickerChange5" :value="selectIndexQy" :range="qyList"
							range-key="enterpriseName">
							<view class="uni-input uni-select cl" v-if="selectIndexQy==null">
								请选择
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
							<view class="uni-input uni-select" v-else>{{ qyList[selectIndexQy].enterpriseName }}
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
						</picker>
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<text class="star">*</text>
						车辆类型
					</view>
					<view class="uni-form-input">
						<!-- <u-radio-group v-model="form.carModuleType">
							<u-radio :name="1">
								固定车辆
							</u-radio>
							<u-radio :name="2">
								长期车辆
							</u-radio>
							<u-radio :name="3">
								临时车辆
							</u-radio>
						</u-radio-group> -->
						<radio-group @change="radioCarModuleChange">
							<label style="margin-right: 30rpx;" class="radio">
								<radio :value="1" :checked="form.carModuleType==1" />
								固定车辆
							</label>
							<label class="radio">
								<radio :value="2" :checked="form.carModuleType==2" />
								长期车辆
							</label>
							<label class="radio">
								<radio :value="3" :checked="form.carModuleType==3" />
								临时车辆
							</label>
						</radio-group>
					</view>
				</view>
				<view class="uni-form-item" v-show="[2,3].includes(form.carModuleType)">
					<view class="uni-form-label">
						<text class="star">*</text>
						预约开始时间
					</view>
					<view class="uni-form-input">
						<!-- <view class="uni-input def" :class="{text:form.reserveStartTime}"
							@click="showTime=true;key='reserveStartTime'">
							{{ form.reserveStartTime || '请选择' }}
						</view>
						<u-picker mode="time" v-model="showTime" :params="params" @confirm="confirm"></u-picker> -->
						<uni-datetime-picker class="uni-input def w-form-input" date-format="yyyy-MM-dd HH:mm:ss" :border="false" type="datetime" ref="reserveStartTime"
				:clear-icon="false" v-model="form.reserveStartTime" />
					</view>
				</view>
				<view class="uni-form-item" v-show="[2,3].includes(form.carModuleType)">
					<view class="uni-form-label">
						<text class="star">*</text>
						预约结束时间
					</view>
					<view class="uni-form-input">
						<!-- <view class="uni-input def" :class="{text:form.reserveEndTime}"
							@click="showTime=true;key='reserveEndTime'">
							{{ form.reserveEndTime || '请选择' }}
						</view> -->
						<uni-datetime-picker class="uni-input def w-form-input" date-format="yyyy-MM-dd HH:mm:ss" :border="false" type="datetime" ref="reserveEndTime"
				:clear-icon="false" v-model="form.reserveEndTime" />
					</view>
				</view>
				<view class="uni-form-item" v-show="[2,3].includes(form.carModuleType)">
					<view class="uni-form-label">
						<text class="star">*</text>
						允许进出入次数
					</view>
					<view class="uni-form-input">
						<!-- <u-radio-group v-model="form.entryAndExitPermit">
							<u-radio :name="0">
								单次
							</u-radio>
							<u-radio :name="1">
								多次
							</u-radio>
						</u-radio-group> -->
						<radio-group @change="radioEntryAndExitChange">
							<label style="margin-right: 30rpx;" class="radio">
								<radio :value="0" :checked="form.entryAndExitPermit==0" />
								单次
							</label>
							<label class="radio">
								<radio :value="1" :checked="form.entryAndExitPermit==1" />
								多次
							</label>
						</radio-group>
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<text class="star">*</text>
						车牌号
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="carNumber" :value="form.carNumber"
							placeholder="请输入" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						到检日期
					</view>
					<view class="uni-form-input">
						<uni-datetime-picker class="uni-input def w-form-input" date-format="yyyy-MM-dd" :border="false" type="date" :clear-icon="false" v-model="form.inspectionDate" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						保险终止日
					</view>
					<view class="uni-form-input">
						<uni-datetime-picker class="uni-input def w-form-input" date-format="yyyy-MM-dd" :border="false" type="date" :clear-icon="false" v-model="form.insuranceTerminationDate" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						行驶证有效期开始
					</view>
					<view class="uni-form-input">
						<uni-datetime-picker class="uni-input def w-form-input" date-format="yyyy-MM-dd" :border="false" type="date" :clear-icon="false" v-model="form.xszBeginDate" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						行驶证有效期结束
					</view>
					<view class="uni-form-input">
						<uni-datetime-picker class="uni-input def w-form-input" date-format="yyyy-MM-dd" :border="false" type="date" :clear-icon="false" v-model="form.xszEndDate" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						计划入场时间截止
					</view>
					<view class="uni-form-input">
						<uni-datetime-picker class="uni-input def w-form-input" date-format="yyyy-MM-dd" :border="false" type="date" :clear-icon="false" v-model="form.enterFactoryEndDate" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						车牌照片
					</view>
					<view class="uni-form-input" style="display: flex;align-items: center;flex-wrap: wrap;">
						<view class="imgBox" v-for="(item,index) in form.carPhotosUrl" :key="index">
							<image :src="url_config+'image/'+item.url" class="img"></image>
							<uni-icons2 @click="deleteImg(1,index)" class="deleteImg" type="clear"
								size="24"></uni-icons2>
						</view>
						<view class="addImgBox" @click="selectImg(1)">
							<image src="/static/icon-add.png" class="icon-add"></image>
						</view>
					</view>
				</view>
				<view class="uni-form-item" v-show="[2,3].includes(form.carModuleType)">
					<view class="uni-form-label">
						驾驶证
					</view>
					<view class="uni-form-input" style="display: flex;align-items: center;flex-wrap: wrap;">
						<view class="imgBox" v-for="(item,index) in form.jsz" :key="index">
							<image :src="url_config+'image/'+item.url" class="img"></image>
							<uni-icons2 @click="deleteImg(2,index)" class="deleteImg" type="clear"
								size="24"></uni-icons2>
						</view>
						<view class="addImgBox" @click="selectImg(2)">
							<image src="/static/icon-add.png" class="icon-add"></image>
						</view>
					</view>
				</view>
				<view class="uni-form-item" v-show="[2,3].includes(form.carModuleType)">
					<view class="uni-form-label">
						行驶证
					</view>
					<view class="uni-form-input" style="display: flex;align-items: center;flex-wrap: wrap;">
						<view class="imgBox" v-for="(item,index) in form.xsz" :key="index">
							<image :src="url_config+'image/'+item.url" class="img"></image>
							<uni-icons2 @click="deleteImg(3,index)" class="deleteImg" type="clear"
								size="24"></uni-icons2>
						</view>
						<view class="addImgBox" @click="selectImg(3)">
							<image src="/static/icon-add.png" class="icon-add"></image>
						</view>
					</view>
				</view>
				<view class="uni-form-item" v-show="[2,3].includes(form.carModuleType)">
					<view class="uni-form-label">
						交强险
					</view>
					<view class="uni-form-input" style="display: flex;align-items: center;flex-wrap: wrap;">
						<view class="imgBox" v-for="(item,index) in form.jqx" :key="index">
							<image :src="url_config+'image/'+item.url" class="img"></image>
							<uni-icons2 @click="deleteImg(4,index)" class="deleteImg" type="clear"
								size="24"></uni-icons2>
						</view>
						<view class="addImgBox" @click="selectImg(4)">
							<image src="/static/icon-add.png" class="icon-add"></image>
						</view>
					</view>
				</view>
				<view class="uni-form-item" v-show="[2,3].includes(form.carModuleType)">
					<view class="uni-form-label">
						其他证明
					</view>
					<view class="uni-form-input" style="display: flex;align-items: center;flex-wrap: wrap;">
						<view class="imgBox" v-for="(item,index) in form.otherProve" :key="index">
							<image :src="url_config+'image/'+item.url" class="img"></image>
							<uni-icons2 @click="deleteImg(5,index)" class="deleteImg" type="clear"
								size="24"></uni-icons2>
						</view>
						<view class="addImgBox" @click="selectImg(5)">
							<image src="/static/icon-add.png" class="icon-add"></image>
						</view>
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<text class="star">*</text>
						车辆颜色
					</view>
					<view class="uni-form-input">
						<picker @change="bindPickerChange" :value="selectIndex" :range="colorList"
							range-key="locationName">
							<view class="uni-input uni-select cl" v-if="selectIndex==null">
								请选择
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
							<view class="uni-input uni-select" v-else>{{ colorList[selectIndex] }}
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
						</picker>
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<text class="star">*</text>
						车种类型
					</view>
					<view class="uni-form-input">
						<picker @change="bindPickerChange2" :value="carTypeIndex" :range="carTypeList"
							range-key="carTypeName">
							<view class="uni-input uni-select cl" v-if="carTypeIndex==null">
								请选择
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
							<view class="uni-input uni-select" v-else>{{ carTypeList[carTypeIndex].carTypeName }}
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
						</picker>
					</view>
				</view>

				<view class="uni-form-item" v-show="[1,2].includes(form.carModuleType)">
					<view class="uni-form-label">
						<text class="star">*</text>
						司机姓名
					</view>
					<view class="uni-form-input">
						<picker @change="bindPickerChange3" :value="driverNameIndex" :range="driverNameList"
							range-key="workerName">
							<view class="uni-input uni-select cl" v-if="driverNameIndex==null">
								请选择
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
							<view class="uni-input uni-select" v-else>{{ driverNameList[driverNameIndex].workerName }}
								<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
							</view>
						</picker>
					</view>
					<!-- <view class="uni-form-input">
            <input class="uni-input" placeholder-class="cl" name="driverName" :value="form.driverName"
              placeholder="请输入" />
          </view> -->
				</view>
				<view class="uni-form-item" v-show="[3].includes(form.carModuleType)">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						司机姓名
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="driverWorkerName"
							:value="form.driverWorkerName" placeholder="请输入" />
					</view>
				</view>
				<view class="uni-form-item" v-show="[3].includes(form.carModuleType)">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						人员身份证号
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="outsideDriverIdCard"
							:value="form.outsideDriverIdCard" placeholder="请输入" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<!-- <text class="star">*</text> -->
						司机电话
					</view>
					<view class="uni-form-input">
						<input class="uni-input" placeholder-class="cl" name="driverTelephone"
							:value="form.driverTelephone" placeholder="请输入" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="uni-form-label">
						<text class="star">*</text>
						是否黑名单
					</view>
					<view class="uni-form-input">
						<radio-group @change="radioChange" name="isBlack">
							<label style="margin-right: 30rpx;" class="radio">
								<radio :value="0" :checked="form.isBlack==0" />
								白名单
							</label>
							<label class="radio">
								<radio :value="1" :checked="form.isBlack==1" />
								黑名单
							</label>
						</radio-group>
					</view>
				</view>
				<!-- <view class="uni-form-item">
					<view class="uni-form-label">
						<text class="star">*</text>
						是否黑名单
					</view>
					<view class="uni-form-input">
						<u-radio-group v-model="form.isBlack">
							<u-radio :name="0">
								白名单
							</u-radio>
							<u-radio :name="1">
								黑名单
							</u-radio>
						</u-radio-group>
					</view>
				</view> -->
				<view class="uni-form-item">
					<view class="uni-form-label">
						报警推送人
					</view>
					<view class="uni-form-input" @click="open">
						<!--            <picker @change="bindPickerChange4" :value="bjIndex" :range="baoList" range-key="workerName">-->
						<view class="uni-input uni-select cl" v-if="!filterArr">
							请选择
							<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
						</view>
						<view class="uni-input uni-select" v-else>{{ filterArr }}
							<image class="icon-down" src="/static/icon-down-black.png" mode=""></image>
						</view>	
						<!--            </picker>-->
					</view>
				</view>
				<button form-type="submit" type="primary" class="btn submitBtn big">保存</button>
				<button class="btn deleteBtn big" v-show="!isAdd" @click="deleteFn">删除</button>
			</form>
		</view>
		<uni-popup ref="cityMore" type="bottom">
			<view class="checkList">
				<view class="header">
					<view class="title">选择报警推送人</view>
					<view class="ok" @click="$refs.cityMore.close()">确认</view>
				</view>
				<scroll-view scroll-y="true" class="scroll-Y">
					<checkbox-group @change="checkChange">
						<view class="checkItem" v-for="(item,index) in baoList" :key="index">
							<view class="name">{{ item.workerName }}</view>
							<view class="check">
								<checkbox :value="item"
									:checked="cityIdArr.map(item => item.workerId).includes(item.workerId)" />
							</view>
						</view>
					</checkbox-group>
				</scroll-view>
			</view>
		</uni-popup>

		<!--选择器搜索组件-->
		<!-- <pickerHospital v-model="isNation" :dataSource='driverNameList' :pickerValues="[5]" @recload='confirmHospital'>
		</pickerHospital> -->

	</view>
</template>

<script>
	import dayjs from 'dayjs';
	export default {
		data() {
			return {
				pageTitle: '新增车辆',
				selectIndex: null,
				colorList: ['蓝色', '绿色', '黄色', '白色', '黑色'],
				carTypeList: [],
				carTypeIndex: null,
				driverNameList: [],
				driverNameIndex: null,
				form: {
					carModuleType: 1,
					carColor: "",
					carNumber: "",
					carPhotosUrl: [],
					jsz: [],
					xsz: [],
					jqx: [],
					otherProve: [],
					carType: "",
					driverName: "",
					driverTelephone: "",
					driverWorkerName: "",
					outsideDriverIdCard: "",
					isBlack: 0,
					projectSn: '',
					entryAndExitPermit: 0
				},
				personList: [],
				projectDetail: {},
				isAdd: true,
				baoList: [],
				bjIndex: null,
				showTime: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				key: '',
				selectIndexQy: null,
				qyList: [],
				cityIdArr: [],
				isNation: false,
			}
		},
		computed: {
			filterArr() {
				let value = this.cityIdArr;
				try {
					if (value) {
						return value.map(item => item.workerName).join(',')
					}
				} catch (e) {
					return ""
				}
			},
			filterArrValue() {
				let value = this.cityIdArr;
				try {
					if (value) {
						return value.map(item => item.id).join(',')
					}
				} catch (e) {
					return ""
				}
			},

		},
		async onLoad(options) {
			this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'))


			await this.getCarTypeList()
			await this.getDriverNameList();
			await this.getProjectChilderSystemUserList();
			await this.enterpriseInfoList(() => {
				if (options.id) {
					this.isAdd = false
					this.pageTitle = '编辑车辆'
					this.getDetails(options.id)
				}
			});


		},

		methods: {
			// getHospital() {
			// 	//打开选择器
			// 	this.isNation = true
			// },
			// confirmHospital(data) {
			// 	console.log(data, '选择的数据')
			// },
			checkChange(e) {
				console.log(e.detail.value)
				this.cityIdArr = e.detail.value
			},
			open() {
				this.$refs.cityMore.open()
			},
			confirm(e) {
				console.log(e)
				let {
					year,
					month,
					day,
					hour,
					minute,
					second
				} = e;
				this.form[this.key] = `${year}-${month}-${day} ${hour}:${minute}:${second}`;
			},
			deleteFn() {
				var that = this
				uni.showModal({
					title: '提示',
					content: '确定删除该车辆吗？',
					success(res) {
						if (res.confirm) {
							that.sendRequest({
								url: 'xmgl/carInfo/delete',
								data: {
									id: that.form.id
								},
								method: "POST",
								success(res) {
									uni.showToast({
										title: '删除成功！'
									})

									uni.navigateBack({})


									setTimeout(() => {
										that.$router.go(0)
									}, 500)
								}
							})
						}
					}
				})
			},
			selectImg(type) {
				var that = this
				uni.chooseImage({
					count: 1,
					success(res) {
						const tempFilePaths = res.tempFilePaths;
						uni.uploadFile({
							url: that.url_config + 'upload/image', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'files',
							success: (uploadFileRes) => {
								console.log(uploadFileRes.data);
								if (type == 1) {
									that.form.carPhotosUrl.push({
										name: "",
										url: JSON.parse(uploadFileRes.data).data[0].imageUrl
									})
									// that.form.carPhotosUrl = JSON.parse(uploadFileRes.data).data[0]
									// 	.imageUrl
								} else if (type == 2) {
									that.form.jsz.push({
										name: "",
										url: JSON.parse(uploadFileRes.data).data[0].imageUrl
									})
								} else if (type == 3) {
									that.form.xsz.push({
										name: "",
										url: JSON.parse(uploadFileRes.data).data[0].imageUrl
									})
								} else if (type == 4) {
									that.form.jqx.push({
										name: "",
										url: JSON.parse(uploadFileRes.data).data[0].imageUrl
									})
								} else if (type == 5) {
									that.form.otherProve.push({
										name: "",
										url: JSON.parse(uploadFileRes.data).data[0].imageUrl
									})
								}
							}
						});
					}
				})
			},
			deleteImg(type, index) {
				if (type == 1) {
					this.form.carPhotosUrl.splice(index, 1)
					// this.form.carPhotosUrl = ''
				} else if (type == 2) {
					this.form.jsz.splice(index, 1)
				} else if (type == 3) {
					this.form.xsz.splice(index, 1)
				} else if (type == 4) {
					this.form.jqx.splice(index, 1)
				} else if (type == 5) {
					this.form.otherProve.splice(index, 1)
				}
			},
			radioChange(e) {
				this.form.isBlack = e.detail.value
			},
			radioCarModuleChange(e) {
				this.form.carModuleType = e.detail.value
			},
			radioEntryAndExitChange(e) {
				this.form.entryAndExitPermit = e.detail.value
			},
			//获取司机姓名
			getDriverNameList() {
				var that = this
				this.sendRequest({
					url: 'xmgl/workerInfo/selectWorkerInfoList',
					data: {
						projectSn: this.projectDetail.projectSn,
						inserviceType: 1,
						pageNo: 1,
						pageSize: -1
					},
					method: "POST",
					success(res) {
						console.log(res, '车辆数据')
						that.driverNameList = res.result.records
						if (!that.isAdd) {
							for (var i = 0; i < res.result.records.length; i++) {
								if (that.form.driverWorkerId == res.result.records[i].id) {
									that.driverNameIndex = i;
									break;
								}
							}
						}
					}
				})
			},
			//获取车种
			getCarTypeList() {
				var that = this
				this.sendRequest({
					url: 'xmgl/carType/list',
					data: {
						projectSn: this.projectDetail.projectSn
					},
					method: "POST",
					success(res) {
						that.carTypeList = res.result
						if (!that.isAdd) {
							for (var i = 0; i < res.result.length; i++) {
								if (that.form.carType == res.result[i].id) {
									that.carTypeIndex = i;
									console.log(that.carTypeIndex, 12346)
									break;
								}
							}
						}
					}
				})
			},
			async getDetails(id) {
				var that = this
				await this.sendRequest({
					url: 'xmgl/carInfo/queryById',
					data: {
						id: id
					},
					method: "POST",
					success: (res) => {
						that.form = res.result
						that.selectIndex = that.colorList.indexOf(that.form.carColor)
						let enterpriseId = that.qyList.map(item => item.enterpriseId).indexOf(that.form
							.enterpriseId)
						that.selectIndexQy = enterpriseId >= 0 ? enterpriseId : null;
						let carTypeIndex = that.carTypeList.map(item => item.id).indexOf(that.form
							.carType)
						that.carTypeIndex = carTypeIndex >= 0 ? carTypeIndex : null;
						// let bjIndex = that.baoList.map(item => item.workerId).indexOf(that.form
						//     .alarmPushWorkerId)
						// that.bjIndex = bjIndex >= 0 ? bjIndex : null;

						// alarmPushWorkerId
						if (this.form.alarmPushWorkerId) {
							let idArr = this.form.alarmPushWorkerId.split(',');
							console.log(idArr, "idArridArridArr")
							that.cityIdArr = that.baoList.filter(item => {
								return idArr.includes(item.id)
							});
						}
						let driverNameIndex = that.driverNameList.map(item => item.id).indexOf(that.form
							.driverWorkerId)
						that.driverNameIndex = driverNameIndex >= 0 ? driverNameIndex : null;

						if (that.form.carPhotosUrl) {
							var arr = JSON.parse(that.form.carPhotosUrl)
							if (arr.length > 0) {
								that.form.carPhotosUrl = arr
							} else {
								that.form.carPhotosUrl = []
							}
						} else {
							that.form.carPhotosUrl = []
						}
						if (that.form.jsz) {
							var arr = JSON.parse(that.form.jsz)
							if (arr.length > 0) {
								that.form.jsz = arr
							} else {
								that.form.jsz = []
							}
						} else {
							that.form.jsz = []
						}
						if (that.form.xsz) {
							var arr = JSON.parse(that.form.xsz)
							if (arr.length > 0) {
								that.form.xsz = arr
							} else {
								that.form.xsz = []
							}
						} else {
							that.form.xsz = []
						}
						if (that.form.jqx) {
							var arr = JSON.parse(that.form.jqx)
							if (arr.length > 0) {
								that.form.jqx = arr
							} else {
								that.form.jqx = []
							}
						} else {
							that.form.jqx = []
						}
						if (that.form.otherProve) {
							var arr = JSON.parse(that.form.otherProve)
							if (arr.length > 0) {
								that.form.otherProve = arr
							} else {
								that.form.otherProve = []
							}
						} else {
							that.form.otherProve = []
						}
					}
				})
			},
			getProjectChilderSystemUserList() {
				var that = this
				this.sendRequest({
					url: 'xmgl/systemUser/getProjectChilderSystemUserList',
					data: {
						projectSn: this.projectDetail.projectSn
					},
					method: "POST",
					success(res) {
						console.log(res, "报警")
						that.baoList = res.result.map(item => {
							item.name = item.workerName
							return item
						});
					}
				})
			},
			enterpriseInfoList(next) {
				var that = this
				this.sendRequest({
					url: 'xmgl/enterpriseInfo/list',
					data: {
						projectSn: this.projectDetail.projectSn
					},
					method: "POST",
					success(res) {
						that.qyList = res.result;
						next()
					}
				})
			},
			bindPickerChange: function(e) {
				this.selectIndex = e.detail.value
			},
			bindPickerChange2: function(e) {
				this.carTypeIndex = e.detail.value
			},
			bindPickerChange3: function(e) {
				this.driverNameIndex = e.detail.value
			},
			bindPickerChange4: function(e) {
				this.bjIndex = e.detail.value
			},
			bindPickerChange5: function(e) {
				this.selectIndexQy = e.detail.value
			},
			bindDateChange: function(e) {
				this.form.eduTime = e.detail.value
			},
			formSubmit(e) {
				var that = this
				console.log(e)
				var params = {
					...e.detail.value,
					num: this.form.num,
					inspectionDate: this.form.inspectionDate,
					insuranceTerminationDate: this.form.insuranceTerminationDate,
					xszBeginDate: this.form.xszBeginDate,
					xszEndDate: this.form.xszEndDate,
					enterFactoryEndDate: this.form.enterFactoryEndDate,
					projectSn: this.projectDetail.projectSn,
					entryAndExitPermit: this.form.entryAndExitPermit
				}
				
				if(params.xszBeginDate && params.xszEndDate && dayjs(params.xszBeginDate).isAfter(dayjs(params.xszEndDate))) {
					uni.showToast({
						title: '行驶证有效期开始不能大于结束时间',
						icon: 'none'
					})
					return false;
				}
				

				if (this.selectIndex == null) {
					uni.showToast({
						title: '请选择车辆颜色',
						icon: 'none'
					})
					return false;
				}
				if (this.carTypeIndex == null) {
					uni.showToast({
						title: '请选择车辆类型',
						icon: 'none'
					})
					return false;
				}
				// if ([1, 2].includes(this.form.carModuleType)) {
				// 	delete params.driverWorkerName;
				// 	if (this.driverNameIndex == null) {
				// 		uni.showToast({
				// 			title: '请选择司机姓名',
				// 			icon: 'none'
				// 		})
				// 		return false;
				// 	}
				// }
				// if ([3].includes(this.form.carModuleType)) {
				// 	if (params.driverWorkerName == '') {
				// 		uni.showToast({
				// 			title: '请输入司机姓名',
				// 			icon: 'none'
				// 		})
				// 		return false;
				// 	}
				// }
				// let idCardReg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i
				// if ([3].includes(this.form.carModuleType)) {
				// 	if (!idCardReg.test(params.outsideDriverIdCard)) {
				// 		uni.showToast({
				// 			title: '请输入正确的身份证格式',
				// 			icon: 'none'
				// 		})
				// 		return false;
				// 	}
				// } else {
				// 	delete params.outsideDriverIdCard;
				// }
				if (params.carNumber == '') {
					uni.showToast({
						title: '请输入车牌号',
						icon: 'none'
					})
					return false;
				}
				let reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
				// if (params.driverTelephone == '') {
				// 	uni.showToast({
				// 		title: '请输入司机电话',
				// 		icon: 'none'
				// 	})
				// 	return false;
				// } else 
				if (params.driverTelephone && !reg.test(params.driverTelephone)) {
					uni.showToast({
						title: '电话格式错误',
						icon: 'none'
					})
					return false;
				}
				if (params.isBlack === '') {
					uni.showToast({
						title: '请选择是否黑名单',
						icon: 'none'
					})
					return false;
				}
				if (this.form.carPhotosUrl) {
					params.carPhotosUrl = JSON.stringify(this.form.carPhotosUrl)
				}
				if (this.form.jsz) {
					params.jsz = JSON.stringify(this.form.jsz)
				}
				if (this.form.xsz) {
					params.xsz = JSON.stringify(this.form.xsz)
					// params.xsz = JSON.stringify([{
					// 	name: '',
					// 	url: this.form.xsz
					// }])
				}
				if (this.form.jqx) {
					params.jqx = JSON.stringify(this.form.jqx)
				}
				if (this.form.otherProve) {
					params.otherProve = JSON.stringify(this.form.otherProve)
				}
				params.carColor = this.colorList[this.selectIndex]
				if (this.driverNameList[this.driverNameIndex]) {
					params.driverWorkerId = this.driverNameList[this.driverNameIndex].id
				}
				if (this.filterArrValue) {
					params.alarmPushWorkerId = this.filterArrValue;
				}
				if (this.carTypeList[this.carTypeIndex]) {
					params.carType = this.carTypeList[this.carTypeIndex].id
				}
				params.carModuleType = this.form.carModuleType
				if (this.qyList[this.selectIndexQy]) {
					params.enterpriseId = this.qyList[this.selectIndexQy].enterpriseId
				}

				if ([2, 3].includes(this.form.carModuleType)) {
					// params.isBlack = '0';
					if (this.form.reserveStartTime) {
						params.reserveStartTime = this.form.reserveStartTime
					} else {
						uni.showToast({
							title: '请选择预约开始时间',
							icon: 'none'
						})
						return false;
					}
					if (this.form.reserveEndTime) {
						params.reserveEndTime = this.form.reserveEndTime
					} else {
						uni.showToast({
							title: '请选择预约结束时间',
							icon: 'none'
						})
						return false;
					}
				}
				var url = 'xmgl/carInfo/edit'
				if (this.isAdd) {
					url = 'xmgl/carInfo/add'
				} else {
					params.id = this.form.id
				}

				

				console.log(params, "params");
				this.sendRequest({
					url: url,
					data: params,
					method: "POST",
					success(res) {
						uni.showToast({
							title: '保存成功！'
						})
						// uni.navigateBack({

						// })
						uni.navigateTo({
							url: './index?listType=1'
						});

					}

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	:deep(.uni-radio-input) {
		width: 44rpx;
		height: 44rpx;
		svg {
			font-size: 36rpx;
			width: 36rpx;
			height: 36rpx;
		}
	}
	:deep(.uni-date__x-input) {
		height: initial;
		line-height: initial;
		font-size: 28rpx;
	}
	.addImgBox {
		border: 1px solid rgba(42, 43, 91, 0.1);
		background-color: #f6f5f8;
		width: 120rpx;
		height: 120rpx;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		border-radius: 20rpx;
		font-size: 24rpx;

		.icon-add {
			width: 36rpx;
			height: 36rpx;
		}
	}

	.uni-input {
		&.def {
			color: #ddd;
		}

		&.text {
			color: #372D66;
		}
	}

	.imgBox {
		width: 120rpx;
		height: 120rpx;
		display: inline-flex;
		position: relative;
		margin-right: 30rpx;
		margin-bottom: 15rpx;

		.img {
			width: 100%;
			height: 100%;
			border-radius: 20rpx;
		}

		.deleteImg {
			position: absolute;
			right: -20rpx;
			top: -20rpx;
		}
	}

	.checkList {
		background-color: #fff;


		.scroll-Y {
			height: 600rpx;
		}

		.header {
			display: flex;
			justify-content: space-between;
			border-bottom: 1rpx solid #ddd;
			padding: 20rpx;

			.title {
				font-weight: 500;
			}

			.ok {
				color: $uni-color-primary;
			}
		}


	}

	.checkItem {
		display: flex;
		padding: 20rpx;

		.name {
			flex: 1;
			margin-right: 20rpx;
		}

		.check {}
	}
</style>