<template>
	<!-- 新增问题 -->
	<view class="addIssue">
		<view class="fixedheader">
			<headers :showBack="true" :themeType="true">
				<view class="headerName">
					选中移交人
				</view>
			</headers>
		</view>
		<view class="content" :style="{paddingTop: mobileTopHeight + 60 + 'px'}">
			<view class="type flex">
				<view class="name"><text class="star">*</text>移交给：</view>
				<!-- <picker @change="(e)=>bindPickerChange(e,6)" :value="changePeopleIndex" class="picker"
					:range="personUpdateList" range-key="realName" v-if="isShowPicker">
					<view class="uni-input uni-select cl" v-if="changePeopleIndex==null">
						请选择 <image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
					<view class="uni-input uni-select" v-else>{{personUpdateList[changePeopleIndex].realName}}
						<image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
				</picker> -->
				<picker @click="$refs.verifyManIdTree._show()" :disabled="true" class="picker">
					<view class="uni-input uni-select cl" v-if="!handOverPersonName">
						请选择 <image class="icon-down" src="/static/icon-down-black.png"></image>
					</view>
					<view class="uni-input uni-select flex2" v-else>
						<view style="width: 98%;" class="ellipsis">{{handOverPersonName}}</view>
					</view>
				</picker>
			</view>
		</view>
		<view class="confrim-btn">
			<view @click="onNavigateBack">取消</view>
			<view @click="addSaveBtn">确定</view>
		</view>
		<search-tree ref="verifyManIdTree" :roleFlag="false" :defaultList='handOverPersonId' :multiple="personnelType == 1 ? false : true"
			@confirm="(val)=>bindPickerChange(val,6)" idKey='userId' :range="personUpdateList" rangeKey="realName"
			confirmColor="#4e8af7" :selectParent="true" />
	</view>
</template>

<script>
	import tkiTree from "@/components/tki-tree/tki-tree.vue"
	import searchTree from "@/components/search-tree/search-tree.vue"
	import canversCom from "@/pages/videoManage/component/canversCom.vue"
	import dateTimePiccker from '@/components/dateTimePicker/index.vue'
	import {
		dateformat
	} from "@/utils/tool.js"
	export default {
		components: {
			tkiTree,
			canversCom,
			dateTimePiccker,
			searchTree,
		},
		data() {
			return {
				isShowPicker: true,
				mobileTopHeight: 0,
				projectSn: '',
				form: {
				},
				personUpdateList: [], // 人员列表-整改人
				changePeopleIndex: null, //整改人
				id: "",
				recordType: '',
				dangerReviewInfo: {},
				personnelType: 1,
				handOverPersonName: "",
				handOverPersonId: [],
			}
		},
		onLoad(option) {
			this.id = option.id;
			this.personnelType = option.personnelType; // 人员类型
			this.projectSn = JSON.parse(uni.getStorageSync('projectDetail')).projectSn;
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
			this.getXzSecurityDangerReviewVerifyList();
			this.getBasicInfo();
		},
		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: {
			getXzSecurityDangerReviewVerifyList() {
				this.sendRequest({
					url: 'xmgl/xzSecurityDangerReviewVerify/getEffectiveConfig',
					method: 'post',
					data: {
						sn: this.projectSn,
						companyProjectType: 2,
					},
					success: res => {
						if (res.code == 200) {
							const data = res.result;
							this.dangerReviewInfo = {
								...data
							};
						}
					}
				})
			},
			//获取基本信息
			getBasicInfo() {
				let that = this;
				this.sendRequest({
					url: 'xmgl/xzSecurityQualityInspectionRecord/selectQualityInspectionRecordById',
					method: 'post',
					data: {
						id: that.id
					},
					success: res => {
						that.recordType = res.result.recordType;
						that.form = {
							...res.result,
						};
						// if(this.personnelType == 1) {
						// 	this.handOverPersonName = this.form.changeName;
						// 	this.handOverPersonId = this.form.changeId ? this.form.changeId.split(',') : [];
						// } else if (this.personnelType == 2) {
						// 	this.handOverPersonName = this.form.reviewNames;
						// 	this.handOverPersonId = this.form.reviewIds ? this.form.reviewIds.split(',') : [];
						// } else if (this.personnelType == 3) {
						// 	this.handOverPersonName = this.form.verifyManNames;
						// 	this.handOverPersonId = this.form.verifyManIds ? this.form.verifyManIds.split(',') : [];
						// }
						this.getPersonUpdateList();
					}
				})
			},
			// 取消
			onNavigateBack() {
				uni.navigateBack({
					delta: 1
				})
			},


			//下拉选择回显
			bindPickerChange(e, type) {
				console.log(e)
				if (type == 6) {
					if (e.length == 0) return;
					// this.changePeopleIndex = e.detail.value;
					this.handOverPersonId = e.map(item => item.userId);
					this.handOverPersonName = e.map(item => item.realName).join(',');
				}
			},


			//获取人员列表--- 整改人
			getPersonUpdateList() {
				let data = {
					projectSn: this.projectSn,
					enterpriseId: this.form.enterpriseIds,
					safeQualityRegionIdForDuty: this.form.regionIds,
				};
				if (this.dangerReviewInfo.enableVerify == 1 && this.form.status == 4) {
					data.roleName = this.dangerReviewInfo.verifyRoleName;
				}
				if (this.dangerReviewInfo.enableReview == 1 && this.form.status == 3) {
					data.roleName = this.dangerReviewInfo.reviewRoleName;
				}
				this.sendRequest({
					url: 'xmgl/systemUser/getProjectChilderSystemUserList',
					method: 'post',
					data: {
						...data,
					},
					success: res => {
						console.log(res.result)
						if (res.result.length > 0) {
							console.log('检查人员列表', this.personList);
							this.personUpdateList = res.result;
						} else {
							this.personUpdateList = [];
						}
					}
				})
			},
			//新增保存
			async addSaveBtn() {
				let data = {
					...this.form,
				};
				if (!this.handOverPersonId) {
					uni.showToast({
						title: "请选择移交人",
						icon: 'none'
					})
					return false
				}
				const ids = this.handOverPersonId ? this.handOverPersonId.join(',') : "";
				if(this.personnelType == 1) {
					data.changeId = ids;
					data.changeName = this.handOverPersonName;
				} else if (this.personnelType == 2) {
					data.reviewIds = ids;
					data.reviewNames = this.handOverPersonName;
				} else if (this.personnelType == 3) {
					data.verifyManIds = ids;
					data.verifyManNames = this.handOverPersonName;
				}
				console.log(data);
				const objUrl = {
					1: 'xmgl/xzSecurityQualityInspectionRecord/updateChangeId',
					2: 'xmgl/xzSecurityQualityInspectionRecord/updateReviewIds',
					3: 'xmgl/xzSecurityQualityInspectionRecord/updateVerifyManIds',
				}
				// 安全问题
				this.sendRequest({
					url: objUrl[this.personnelType],
					method: 'post',
					data: data,
					success: (res) => {
						console.log(res)
						if (res.code == 200) {
							uni.showToast({
								title: '保存成功'
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1200)
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						}
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.confrim-btn {
		padding: 18rpx 26rpx;
		background-color: #FFFFFF;
		box-shadow: 0rpx -8rpx 8rpx 0rpx rgba(0, 0, 0, 0.05);
		display: flex;
		width: 100%;
		position: fixed;
		bottom: 0;

		>view {
			width: 50%;
			height: 76rpx;
			font-weight: 500;
			font-size: 28rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		>view:first-child {
			background-color: rgba(81, 129, 246, 0.1);
			border-radius: 6rpx 0rpx 0rpx 6rpx;
			color: #5181F6;
		}

		>view:last-child {
			background-color: #5181F6;
			border-radius: 0rpx 6rpx 6rpx 0rpx;
			color: #FFFFFF;
		}
	}

	.fixedheader {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 2;

		.headerName {
			z-index: 1;
		}
	}

	.tab {
		width: 100%;
		height: 45px;
		text-align: center;
		box-shadow: 0 0 10px rgba(194, 194, 194, 0.5);
	}

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

	}

	.checkedTab {
		color: #498CEC;
		border-bottom: 4rpx solid #498CEC;

	}

	.noCheckTab {
		padding-bottom: 2px;
	}

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

	.add2 {
		width: 120px;
		height: 30px;
		line-height: 30px;
		text-align: center;
		color: #fff;
		background: #4181fe;
		border-radius: 25px;
		font-size: 14px;
		margin: 0px 22px;
	}

	.point {
		height: 20px;
		width: 20px;
		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: 20px 30rpx 120rpx;
	}

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

	.type .name {
		margin-right: 6px;
		width: 162rpx;
		text-align: right;
		font-size: 28rpx;
		color: #808080;
	}

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

		.radio {
			margin-right: 20px;
		}
	}

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

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

	.picker {
		// width: 70%;
		border: 2rpx solid rgba(42, 43, 91, 0.3);
		padding: 0px 30rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
		width: calc(100% - 204rpx);
		height: 68rpx;
	}

	.pickerone {
		// width: 70%;
		border: 2rpx solid rgba(42, 43, 91, 0.3);
		box-sizing: border-box;
		border-radius: 10rpx;
		width: calc(100% - 204rpx);




		.issueserch {
			width: 80rpx;
			// background: skyblue;
			display: flex;
			align-items: center;
			justify-content: center;

			.icon-down {
				width: 40rpx !important;
				height: 40rpx !important;
			}
		}
	}

	/deep/ .uni-easyinput__placeholder-class {
		font-size: 28rpx;
		color: #A2A4AF;
	}

	.uni-input {
		line-height: 32px;
	}

	.textarea {
		// width: calc(79% - 32px);
		width: calc(100% - 204rpx);
		border-radius: 10rpx;
		border: 2rpx solid rgba(42, 43, 91, 0.3);
		padding: 16rpx 28rpx;
		box-sizing: border-box;
		height: 68rpx;
		font-size: 28rpx;
	}

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

	.uni-input {
		font-size: 28rpx;
	}

	.cl {
		border-radius: 5px;
		font-size: 28rpx;
		color: #A2A4AF;
	}


	.imgBox_wrap {
		display: flex;
		flex-wrap: wrap;
		margin-top: 10px;
		width: 75%;
	}

	.imgBox {
		width: 112rpx;
		height: 120rpx;
		display: inline-flex;
		position: relative;
		flex-wrap: wrap;
		border-radius: 8rpx;
		margin-right: 20rpx;

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

		.deleteImg {
			position: absolute;
			right: -20rpx;
			top: -20rpx;
			color: #fff;
			width: 20rpx;
			height: 20rpx;
			background-image: url('@/static/workTicketManage/index-icon9.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;

		}

	}

	.addImgBox {
		width: 118rpx;
		height: 120rpx;
		background: #FFFFFF;
		border-radius: 8rpx;
		border: 2rpx solid #D8DBE8;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		font-size: 24rpx;

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

	.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: 20px 30rpx;
		border-radius: 5px;
		box-shadow: 0 0 10px 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: 5px 10rpx;
		box-sizing: border-box;
		font-size: 30rpx;
	}

	.checkName {
		border-bottom: 2px solid #4181FE;
		color: #4181FE;
	}

	.noCheckName {
		padding-top: 4px;
	}

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

		.title {
			margin-bottom: 10px;
		}

		.list_val {
			padding: 8px 10px;
		}
	}

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

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

	.status {
		color: #007AFF;
	}

	.addSaveBtn {
		margin: 30px auto;
		width: 60%;
		padding: 10px 0;
		text-align: center;
		background-color: #4181FE;
		color: #fff;
		font-size: 34rpx;
		border-radius: 30px;
		letter-spacing: 2px;
		box-shadow: 0 3px 10px 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: 2rpx solid #ccc;
		border-radius: 10rpx;
		// width: 67%;
		padding-left: 20rpx;
		width: calc(100% - 204rpx);
		font-size: 28rpx;
		height: 68rpx;
		line-height: 68rpx;
	}
</style>