<template>
	<!-- 新增问题 -->
	<view class="addIssue">
		<view class="fixedheader">
			<headers :showBack="true">
				<view class="headerName">
					{{pageTitle}}
				</view>
			</headers>
		</view>
		<view class="content" :style="{paddingTop: (mobileTopHeight + 50) * 1.5 + 'rpx'}">
			<view class="type flex">
				<view class="name"><text class="star">*</text>通行设备：</view>
				<picker @change="(e)=>bindPickerChange(e,1)" :value="passEquipIndex" class="picker"
					:range="devEquipList" range-key="devName">
					<view class="uni-input uni-select cl" v-if="passEquipIndex==null && !defaultDevEquip">
						请选择 <image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
					<view class="uni-input uni-select" v-else>
						{{defaultDevEquip || devEquipList[passEquipIndex].devName}}
						<image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
				</picker>
			</view>
			<view class="type flex">
				<view class="name"><text class="star">*</text>通行方向：</view>
				<picker @change="(e)=>bindPickerChange(e,2)" :value="passDirectionIndex" class="picker"
					:range="passDirectionList" range-key="name">
					<view class="uni-input uni-select cl" v-if="form.direction==null">
						请选择 <image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
					<view class="uni-input uni-select" v-else>
						{{form.direction==1?'进':form.direction==2?'出':''}}
						<image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
				</picker>
			</view>
			<view class="type flex">
				<view class="name"><text class="star">*</text>通行时间：</view>
				<dateTimePiccker :placeholder="'请选择'" :start="startTime" fields="second"
					:default-value="form.passTime" @change="bindPickerChange($event,'passTime')"
					class="dateTimePiccker">
					<!-- <view class="uni-input uni-select cl" v-if="form.inspectTime===''">
						请选择 <image class="icon-right" src="/static/icon-right.png"></image>
					</view>
					<view class="uni-input uni-select" v-else>{{form.inspectTime}}
						<image class="icon-right" src="/static/icon-right.png"></image>
					</view> -->
				</dateTimePiccker>
				<!-- <picker @change="(e)=>bindPickerChange(e,4)" mode="date" :value="form.inspectTime" class="picker">
					<view class="uni-input uni-select cl" v-if="form.inspectTime===''">
						请选择 <image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
					<view class="uni-input uni-select" v-else>{{form.inspectTime}}
						<image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
				</picker> -->
			</view>
			<view class="type flex">
				<view class="name"><text class="star">*</text>通行方式：</view>
				<picker @change="(e)=>bindPickerChange(e,3)" :value="passTypeIndex" class="picker"
					:range="passTypeList" range-key="name">
					<view class="uni-input uni-select cl" v-if="form.passType==null">
						请选择 <image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
					<view class="uni-input uni-select" v-else>
						{{form.passType==1?'IC卡':form.passType==2?'人脸识别':form.passType==3?'指纹识别':form.passType==5?'二维码':form.passType==6?'蓝牙':''}}
						<image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
				</picker>
			</view>
			<!-- <view class="type flex3">
				<view class="name">补充说明：</view>
				<textarea class="textarea" maxlength="-1" placeholder-class="cl" name="inspectContent"
					@input='supplementTextarea' :value="form.dangerDesc" placeholder="请输入"></textarea>
			</view> -->
			<view class="addSaveBtn" @click="addSaveBtn">新增保存</view>
		</view>
	</view>
</template>

<script>
	import dateTimePiccker from '@/components/dateTimePicker/index.vue'
	import {
		dateformat
	} from "@/utils/tool.js"
	export default {
		components: {
			dateTimePiccker
		},
		data() {
			return {
				passTypeList: [{
						name: 'IC卡',
						value: 1
					},
					{
						name: '人脸识别',
						value: 2
					},
					{
						name: '指纹识别',
						value: 3
					},
					{
						name: '二维码',
						value: 5
					},
					{
						name: '蓝牙',
						value: 6
					}
				],
				passTypeIndex: null,
				passDirectionList: [{
						name: '进',
						value: 1
					},
					{
						name: '出',
						value: 2
					}
				],
				passDirectionIndex: null,
				defaultDevEquip: "",
				devEquipList: [],
				passEquipIndex: null,
				mobileTopHeight: 0,
				startTime: this.getDate({
					format: true,
				}),
				form: {
					passTime: "",
					passType: null,
					direction: null,
					devCode: ""
				},
				workerInfo: {}
			}
		},
		onLoad(option) {
			this.pageTitle = option.type == 'add' ? '添加补卡' : '添加补卡';
			this.projectSn = JSON.parse(uni.getStorageSync('projectDetail')).projectSn;
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
			this.workerInfo = JSON.parse(decodeURIComponent(option.item));
			this.getPassEquipList();
		},
		mounted() {
			var that = this
			uni.getSystemInfo({
				success(res) {
					that.mobileTopHeight = res.statusBarHeight ? res.statusBarHeight : 0;
					uni.setStorageSync('systemInfo', res)
					console.log(res)
				}
			})
			console.log('this.mobileTopHeight', this.mobileTopHeight)
		},
		methods: {
			//获取通行设备
			getPassEquipList() {
				this.sendRequest({
					url: 'xmgl/ufaceDev/list',
					method: 'post',
					data: {
						projectSn: this.projectSn
					},
					success: res => {
						console.log(res.result, '通行设备')
						if (res.result.length > 0) {
							this.devEquipList = res.result;
						} else {
							this.devEquipList = [];
						}
					}
				})
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year;
				} else if (type === 'end') {
					// year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			//下拉选择回显
			bindPickerChange(e, type) {
				console.log(e)
				if (type == 1) {
					this.passEquipIndex = e.detail.value;
					this.form.devCode = this.devEquipList[e.detail.value].devSn;
				} else if (type == 2) {
					this.passDirectionIndex = e.detail.value;
					this.form.direction = this.passDirectionList[e.detail.value].value;
				} else if (type == 3) {
					this.passTypeIndex = e.detail.value;
					this.form.passType = this.passTypeList[e.detail.value].value
				} else if (type == 'passTime') {
					this.form.passTime = e.f3;
				}
			},
			//新增保存
			async addSaveBtn() {
				console.log(this.workerInfo,777888)
				console.log(this.form,888999)
				let data = JSON.parse(JSON.stringify(this.form));
				if (!data.devCode) {
					uni.showToast({
						title: '请选择通行设备',
						icon: 'none'
					})
					return
				}
				if (!data.direction) {
					uni.showToast({
						title: '请选择通行方向',
						icon: 'none'
					})
					return
				}
				if (!data.passTime) {
					uni.showToast({
						title: '请选择通行时间',
						icon: 'none'
					})
					return
				}
				if (!data.passType) {
					uni.showToast({
						title: '请选择通行方式',
						icon: 'none'
					})
					return
				}
				let requestData = {
					...data,
					faceUrl: this.workerInfo.fieldAcquisitionUrl,
					idCard: this.workerInfo.idCard,
					projectCode: this.projectSn
				}
				this.sendRequest({
					url: 'xmgl/itbgp/api/passRecord',
					method: 'post',
					data: requestData,
					success: (res) => {
						console.log(res)
						if (res.status == 1) {
							uni.showToast({
								title: '保存成功'
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1200)
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.fixedheader {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 2;

		.headerName {
			z-index: 1;
		}
	}

	.tab {
		width: 100%;
		height: 90rpx;
		text-align: center;
		box-shadow: 0 0 20rpx rgba(194, 194, 194, 0.5);
	}

	.tabType {
		width: 50%;
		line-height: 43px;
		border-bottom: 1px solid rgba(194, 194, 194, 0.2);

	}

	.noCheckTab {
		padding-bottom: 4rpx;
	}

	.lagCss {
		width: 180px;
		height: 61px;
		background: #fff;
		text-align: center;
		line-height: 29px;
		border-radius: 20rpx;
	}

	.add2 {
		width: 240rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		color: #fff;
		background: #4181fe;
		border-radius: 50rpx;
		font-size: 28rpx;
		margin: 0px 24rpx;
	}

	.point {
		height: 40rpx;
		width: 40rpx;
		position: absolute;
	}

	.flex {
		display: flex;
		align-items: center;
	}

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

	.flex3 {
		display: flex;
	}

	.content {
		width: 100%;
		box-sizing: border-box;
		padding: 40rpx 30rpx;
	}

	.type {
		font-size: 30rpx;
		line-height: 80rpx;
		margin-bottom: 16rpx;
		/* border-bottom: 1px solid rgba(194, 194, 194, 0.2); */
	}

	.type .name {
		margin-right: 6px;
		width: 176rpx;
		text-align: right;
	}

	.radio-wrap {
		display: flex;
		align-items: center;

		.radio {
			margin-right: 40rpx;
		}
	}

	.accessory {
		width: 100%;
		height: 70px;
		padding: 0 20rpx;
		box-sizing: border-box;
	}

	.accessoryImg {
		width: 110rpx;
		height: 120rpx;
		margin-right: 16rpx;
	}

	.picker {
		width: 70%;
		border: 1px solid rgba(42, 43, 91, 0.3);
		padding: 0px 30rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
	}

	.uni-input {
		line-height: 64rpx;
	}

	.textarea {
		width: calc(79% - 64rpx);
		border-radius: 10rpx;
		border: 1px solid rgba(42, 43, 91, 0.3);
		padding: 8px 30rpx;
		box-sizing: border-box;
		height: 100rpx;
	}

	.inpuStyle {
		width: calc(80% - 70rpx);
		border-radius: 40rpx;
		border: 1px solid rgba(42, 43, 91, 0.3);
		padding: 8px 30rpx;
		box-sizing: border-box;
		height: 70rpx;
		color: #000;
	}

	.cl {
		font-size: 30rpx;
		border-radius: 10rpx;
	}


	.imgBox_wrap {
		display: flex;
		flex-wrap: wrap;
		margin-top: 20rpx;
		width: 75%;
	}

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

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

	}

	.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;
		}
	}

	.unitDialog {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 111;
		background-color: rgba(0, 0, 0, 0.5);
	}

	.unitContent {
		width: 85%;
		height: 70%;
		margin: 25% auto 0;
		background-color: #fff;
		box-sizing: border-box;
		padding: 40rpx 30rpx;
		border-radius: 10rpx;
		box-shadow: 0 0 20rpx rgba(255, 255, 255, 0.6);
	}

	.tabs {
		border-bottom: 1px solid rgba(153, 153, 153, 0.5);
	}

	.tabs_name {
		width: 40%;
		text-align: center;
		padding: 10rpx 10rpx;
		box-sizing: border-box;
		font-size: 30rpx;
	}

	.checkName {
		border-bottom: 4rpx solid #4181FE;
		color: #4181FE;
	}

	.noCheckName {
		padding-top: 4px;
	}

	.unitList {
		margin: 20rpx 0;
		font-size: 30rpx;

		.title {
			margin-bottom: 20rpx;
		}

		.list_val {
			padding: 8px 20rpx;
		}
	}

	.bg_999 {
		background-color: rgba(153, 153, 153, 0.1);
	}

	.ellipsis {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.status {
		color: #007AFF;
	}

	.addSaveBtn {
		margin: 60rpx auto;
		width: 60%;
		padding: 20rpx 0;
		text-align: center;
		background-color: #4181FE;
		color: #fff;
		font-size: 34rpx;
		border-radius: 60rpx;
		letter-spacing: 4rpx;
		box-shadow: 0 3px 20rpx rgba(65, 129, 254, 0.8);
	}

	.addSaveBtn:active {
		background-color: rgba(65, 129, 254, 0.8);
	}

	.radio-box {
		display: flex;
	}

	.radio-item {
		display: flex;
		margin-right: 20rpx;
		align-items: center;
		font-size: 28rpx;

		:deep( .uni-radio-input ){
			width: 32rpx;
			height: 32rpx;
		}
	}

	.radio-text {
		height: 72rpx;
	}

	.butA {
		display: flex;
		// position: absolute;
		top: 60%;

		width: 70%;
	}

	.icon-right {
		margin-left: 16rpx;
		width: 16rpx;
		height: 32rpx;
	}

	.dateTimePiccker {
		border: 1px solid #ccc;
		border-radius: 10rpx;
		width: 67%;
		padding-left: 20rpx;
	}
</style>