<template>
	<view :class="{showHiddenWindowActive:showHiddenWindow}">
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">安全检查核实</block>
		</cu-custom>
		<view class="form">
			<view class="wui-form-list">
				<view class="cu-form-group">
					<view class="title">检查标题：</view>
					<view>{{form.INSPECTION_SUBJECT}}现场检查记录</view>
				</view>

				<view class="cu-form-group">
					<view class="title" style="height: auto;">
						<view>被检查单位：</view>
					</view>
					<view>{{ form.INSPECTED_DEPARTMENT_NAMES }}</view>
				</view>
				<view class="cu-form-group" v-if="form.INSPECTED_DEPARTMENT_NAME">
					<view class="title">被检查单位现场负责人：</view>
					<view> {{ form.INSPECTED_SITEUSER_NAME }} </view>
				</view>

				<view class="cu-form-group">
					<view class="title">检查场所：</view>
					<text> {{ form.INSPECTION_PLACE }} </text>
				</view>

				<view class="cu-form-group">
					<view class="title" style="height: auto;">
						<view>检查类型：</view>
					</view>
					<text> {{ form.INSPECTION_TYPE_NAME }} </text>
				</view>

				<view class="cu-form-group">
					<view class="title">检查开始时间：</view>
					<text>{{ form.INSPECTION_TIME_START }}</text>
				</view>

				<view class="cu-form-group">
					<view class="title">检查结束时间：</view>
					<text >{{form.INSPECTION_TIME_END}}</text>
				</view>

        <view class="cu-form-group">
          <view class="title">记录填写时间：</view>
          <view>{{form.CREATTIME}}</view>
        </view>
      </view>
    </view>
    <view class="form">
      <view class="wui-form-list">
				<view class="cu-form-group">
					<view class="title">检查情况：</view>
				</view>
				<view v-show="form.situationList && form.situationList.length > 0" class="ace-content">
					<view class="add_pard_item" v-for="(item,index) of form.situationList" :key="'SITUATION'+index">
						<view class="cu-form-textarea">
							<textarea disabled v-model="item.SITUATION"></textarea>
						</view>
					</view>
				</view>
      </view>
    </view>
    <view class="form">
      <view class="wui-form-list" style="padding-bottom: 10upx;">
				<view class="cu-form-group">
					<view class="title">检查人员：</view>
				</view>
				<view v-if="form.inspectorList && form.inspectorList.length > 0" v-for="(item, index) of form.inspectorList" :key="'INSPECTOR'+index" class="add_pard_item">
					<view class="cu-form-group">
						<view class="title" style="height: auto;">
							<view>{{ index + 1}}.检查人员单位：</view>
						</view>
						<text>{{ item.INSPECTION_DEPARTMENT_NAME }}</text>
					</view>
					<view class="cu-form-group">
						<view class="title">{{ index + 1}}.检查人员：</view>
						<text>
							{{ item.INSPECTION_USER_NAME }}
						</text>
					</view>
				</view>
      </view>
    </view>
    <view class="form">
      <view class="wui-form-list">
				<view class="cu-form-group">
					<view class="title">发现问题：</view>
				</view>

				<view style="padding: 20upx">
					<uni-table border stripe emptyText="暂无更多数据">
						<uni-tr>
							<uni-th align="center" style="font-weight: bold;width: 100upx">序号</uni-th>
							<uni-th align="center" style="font-weight: bold">隐患部位</uni-th>
							<uni-th align="center" style="font-weight: bold">隐患描述</uni-th>
							<uni-th align="center" style="font-weight: bold;width: 180upx">操作</uni-th>
						</uni-tr>
						<uni-tr v-for="(item, index) in form.hiddenList" :key="item.HIDDEN_ID">
							<uni-td>{{ index + 1 }}</uni-td>
							<uni-td>{{ item.HIDDENPART_NAME?item.HIDDENPART_NAME:item.HIDDENPART }}</uni-td>
							<uni-td>{{ item.HIDDENDESCR }}</uni-td>
							<uni-td style="text-align: center;">
								<icon type="info" size="26" @tap="showHidden(item, index)" />
							</uni-td>
						</uni-tr>
					</uni-table>
				</view>

      </view>
    </view>
    <view class="form">
      <view class="wui-form-list">
				<block v-for="(item, index) in form.inspectorVerifyList" :key="item.INSPECTION_INSPECTOR_ID">
					<view  class="cu-form-group">
						<view class="title">检查人员核实结果：</view>
						<view >同意</view>
					</view>
					<view class="cu-form-textarea">
						<view class="cu-form-title">检查人意见:</view>
						<textarea v-model="item.INSPECTION_USER_OPINION" disabled placeholder="请输入作业负责人意见"></textarea>
					</view>
					<view class="cu-form-group">
						<view class="title">检查人签字：</view>
						<view>
							<view>
								<image :src="baseImgPath + item.INSPECTION_USER_SIGN_IMG" style="width: 180upx;height: 100upx"></image>
							</view>
							<view style="text-align: center">{{item.INSPECTION_USER_SIGN_TIME}}</view>
						</view>
					</view>
				</block>
      </view>
    </view>
    <view class="form">
      <view class="wui-form-list">
				<view class="cu-form-group" v-if="!forbidEdit">
					<view class="title">核实结果：</view>
					<radio-group @change="changeRadioGroup($event)">
						<label class="radio"><radio value="1" />同意</label>
						<label class="radio"><radio value="-1" />不同意</label>
					</radio-group>
				</view>
				<view class="cu-form-textarea" v-if="!forbidEdit" >
					<view class="cu-form-title text-hui">核实意见</view>
					<textarea maxlength="-1" v-model="inspectorForm.INSPECTION_USER_OPINION" placeholder="检查人意见（有异议时必填）"></textarea>
				</view>
				<view class="cu-form-group" style="border: none;" v-if="!forbidEdit">
					<view class="title">签字</view>
					<button class="cu-btn bg-green shadow" @tap="modalShow = true" data-target="Modal">手写签字</button>
				</view>
				<view class="cu-bar bg-white" v-show="signImgList && signImgList.length > 0">
					<view class="action">
						签字照片
					</view>
				</view>
				<view class="cu-form-group" v-show="signImgList && signImgList.length > 0">
					<view class="grid col-4 grid-square flex-sub">
						<view style="width: 60%;" class="bg-img" v-for="(item,index) in signImgList" :key="index" @tap="ViewImage" data-type="0" :data-url="signImgList[index].filePath">
							<image :src="signImgList[index].filePath" mode="aspectFill"></image>
							<view class="cu-tag bg-red" @tap.stop="delImg" data-type="0" :data-index="index">
								<text class='cuIcon-close'></text>
							</view>
						</view>
					</view>
				</view>
				<view class="cu-modal" :class="{'show':modalShow}">
					<sign @confirm="subCanvas" @cancel="modalShow = false"></sign>
				</view>
			</view>
		</view>
		<view class="cu-bar btn-group" style="margin-top: 30upx;">
			<button v-if="!forbidEdit" class="cu-btn bg-blue margin-tb-sm lg" @click="$noMultipleClicks(goSubmit)">提交</button>
			<button v-if="forbidEdit" class="cu-btn bg-green margin-tb-sm lg" @click="$noMultipleClicks(goback)">返回</button>
		</view>
		<view class="padding flex flex-direction"></view>

		<uni-drawer ref="showHiddenWindow" mode="right" :mask-click="true" @change="change($event,'showHiddenWindow')">
			<scroll-view scroll-y="true" style="height: 90vh;">
				<view class="de-drawer">
					<view class="cu-bar bg-white">
						<view class="action">
							隐患照片
						</view>
						<view class="action">
							{{hiddenForm.hiddenImgs.length}}/4
						</view>
					</view>
					<view class="cu-form-group">
						<view class="grid col-4 grid-square flex-sub">
							<view class="bg-img" v-for="(item,index) in hiddenForm.hiddenImgs" :key="item.IMGFILES_ID" @tap="ViewImage"  data-type="0" :data-url="item.FILEPATH">
								<image  :src="baseImgPath + item.FILEPATH" mode="aspectFill"></image>
							</view>
						</view>
					</view>
          <view class="ai_btn ">
            <view class="ai_btn_con" @click="$noMultipleClicks(goIdentifyImg)">
              <image src="../../../../static/ai_img.png" style="width: 16px;height: 16px"/>
              <view class="text" style="margin-left: 5px;"> AI隐患识别与处置</view>
            </view>
          </view>
					<view class="cu-bar bg-white">
						<view class="action">
							隐患视频
						</view>
						<view class="action">
							{{hiddenForm.hiddenVideos.length}}/1
						</view>
					</view>
					<view class="cu-form-group">
						<view class="grid col-4 grid-square flex-sub">
							<view class="bg-img" v-for="(item,vindex) in hiddenForm.hiddenVideos" :key="item.IMGFILES_ID" @tap="ViewVideo" data-type="0" :data-url="item.FILEPATH" style="background-color: #000">
								<image src="/static/icon-apps/video.png" mode="aspectFill" @click="playVideo"
									   :data-src="baseImgPath + item.FILEPATH"></image>
							</view>
						</view>
					</view>
					<view class="cu-form-textarea">
						<view class="cu-form-title text-hui">隐患描述</view>
						<textarea maxlength="-1" :disabled="true" v-model="hiddenForm.HIDDENDESCR" placeholder="请对隐患进行详细描述(必填项)"></textarea>
					</view>
					<view class="cu-form-group">
						<view class="title">隐患部位</view>
						<text>{{ hiddenForm.HIDDENPART_NAME?hiddenForm.HIDDENPART_NAME:hiddenForm.HIDDENPART }}</text>
					</view>
<!--          <view class="cu-form-group">-->
<!--            <view class="title">隐患部位描述</view>-->
<!--            <text>{{ hiddenForm.POSITIONDESC }}</text>-->
<!--          </view>-->

					<view class="cu-form-group">
						<view class="title">隐患级别</view>
						<text>{{ hiddenForm.HIDDENLEVEL_NAME }}</text>
					</view>

					<view class="cu-form-group">
						<view class="title">隐患类型</view>
						<text>{{ hiddenForm.HIDDENTYPE_NAME || hiddenForm.HIDDENTYPE2_NAME }}</text>
					</view>
<!--          <view class="cu-form-group">-->
<!--            <view class="title">是否相关方</view>-->
<!--            <text>{{ hiddenForm.ISRELEVANT == '1'?'是':'否' }}</text>-->
<!--          </view>-->
					<view class="cu-form-group">
						<view class="title">隐患发现时间</view>
						<text>{{ hiddenForm.CREATTIME }}</text>
					</view>
<!--					<view class="cu-form-group">-->
<!--						<view class="title">隐患上报位置：</view>-->
<!--					</view>-->
<!--					<view class="cu-form-group"  v-if="hiddenForm.LONGITUDE && hiddenForm.LONGITUDE != 'undefined'">-->
<!--						<view class="sign-title">经度：</view>-->
<!--						<view class="wui-sign-cotent">{{hiddenForm.LONGITUDE}}</view>-->
<!--					</view>-->
<!--					<view class="cu-form-group"  v-if="hiddenForm.LATITUDE && hiddenForm.LATITUDE != 'undefined'">-->
<!--						<view class="sign-title">纬度：</view>-->
<!--						<view class="wui-sign-cotent">{{hiddenForm.LATITUDE}}</view>-->
<!--					</view>-->
					<view class="cu-form-group">
						<view class="title">隐患发现人</view>
						<text>
							{{ hiddenForm.CREATOR_NAME }}
						</text>
					</view>

					<view class="de-drawer-bottom">
						<view class="cz-btn">
							<text class="cu-btn" @click="cancelHidden">返回</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</uni-drawer>
		<view :class="['cu-modal',{'show':modalVideoShow}]" v-if="modalVideoShow">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">播放视频</view>
					<view class="action" @tap="modalVideoShow = false">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<video :src="videoSrc" :show-fullscreen-btn="false" :autoplay="true"></video>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-green text-green" @click="modalVideoShow = false">关闭</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		basePath,corpinfoId,deptId,loginUser,formatDate,loginSession,baseImgPath
	} from '@/common/tool.js';
	import tkiTree from "@/components/select-tree/select-tree.vue"
	import gcoord from '@/common/gcoord.js'
	import ruiDatePicker from '@/components/rattenking-dtpicker/rattenking-dtpicker.vue'
	import moreSelect from '@/components/more-select/more-select.vue';
	import uniPopup from '@/components/more-select/uni-popup/uni-popup.vue';
	import sign from '@/components/sign/sign.vue';

	export default {
		components: {
			tkiTree, ruiDatePicker, moreSelect, uniPopup, sign
		},
		data() {
			return {
				baseImgPath:baseImgPath,
				isUps:false,
				forbidEdit:false,// 是否禁止修改
				msg:'add',
				noClick:true,
				treeNode:[],//部门下拉数据
				inspectedSiteuserList: [], // 被检查单位现场负责人下拉数据
				inspectionTypeTreeList: [], // 检查类型下拉数据
				inspectorList: [], // 检查人员(二维数组)下拉数据
				form:{
					INSPECTION_ID: '', // 检查ID
					INSPECTION_SUBJECT: '', // 检查标题
					INSPECTION_SOURCE: '5', // 检查来源（4-监管端 5-企业端）
					INSPECTION_ORIGINATOR_ID: '', // 检查发起人
					INSPECTED_DEPARTMENT_ID: '', // 被检查单位
					INSPECTED_DEPARTMENT_NAME: '',
					INSPECTED_SITEUSER_ID: '', // 被检查单位现场负责人
					INSPECTED_SITEUSER_INDEX: '',
					INSPECTED_SITEUSER_NAME: '',
					INSPECTED_EXPLAIN: '', // 申辩内容
					INSPECTED_SITEUSER_SIGN_IMG: '', // 被检查单位现场负责人签字
					INSPECTED_SITEUSER_SIGN_TIME: '', // 被检查单位现场负责人签字时间
					INSPECTION_TYPE: '', // 检查类型
					INSPECTION_TYPE_NAME: '',
					INSPECTION_PLACE: '', // 检查场所
					INSPECTION_TIME_START: '', // 检查开始时间
					INSPECTION_TIME_END: '', // 检查结束时间
					INSPECTION_STATUS: '', // 状态(0.暂存 1.检查人待确认、2.被检查人待确认、3.归档 -1.检查人异议打回 -2被检查人申辩)
					inspectorList:
							[{
								INSPECTION_INSPECTOR_ID: '',	//检查人员主键
								INSPECTION_DEPARTMENT_ID: '',	//检查人员部门ID
								INSPECTION_DEPARTMENT_NAME: '',
								INSPECTION_USER_ID: '',		//检查人员ID
								INSPECTION_USER_INDEX: '',
								INSPECTION_USER_NAME: ''
							}], // 检查人员
					inspectorVerifyList: [],
					situationList:
							[{
								INSPECTION_SITUATION_ID: '',
								SITUATION: ''
							}], // 检查情况
					hiddenList: [{ ...this.hiddenForm }] // 隐患信息集合
				},// 数据
				hiddenIds: [], // 检查保存后返回的隐患ID集合
				delSituations: [], // 编辑时删除的原来检查情况
				delInspectors: [], // 编辑时删除的原来检查情况
				delHiddens: [], // 编辑时删除的原来发现问题
				delHiddenFiles: [], // 编辑时删除的原来发现问题附件
				rules:[
					{name:'INSPECTION_SUBJECT',message:'请输入检查标题'},
					{name:'INSPECTED_DEPARTMENT_ID',message:'请选择被检查单位'},
					{name:'INSPECTED_SITEUSER_ID',message:'请选择被检查单位现场负责人'},
					{name:'INSPECTION_TYPE',message:'请选择检查类型不能为空'},
					{name:'INSPECTION_PLACE',message:'请输入检查场所'},
					{name:'INSPECTION_TIME_START',message:'请选择检查开始时间'},
					{name:'INSPECTION_TIME_END',message:'请选择作业结束时间'}
				],
				showHiddenWindow: false,	// 隐患添加窗口显隐
				hiddenRegionTreeList: [], // 隐患部位下拉数据
				hiddenLevelTreeList: [], // 隐患级别下拉数据
				hiddenTypeTreeList: [], // 隐患类型下拉数据
				hiddenType2TreeList: [], // 隐患类型2下拉数据
				creatorList: [], // 隐患责任人下拉数据
				hiddenForm: {
					HIDDEN_ID: '', // 隐患ID
					HIDDENDESCR: '', // 隐患描述
					HIDDENPART: '', // 隐患部位
					HIDDENPART_NAME: '',
					HIDDENLEVEL: '', // 隐患级别
					HIDDENLEVEL_NAME: '',
					HIDDENTYPE: '', // 隐患类型1
					HIDDENTYPE_NAME: '',
					HIDDENTYPE2: '', // 隐患类型2
					HIDDENTYPE2_NAME: '',
					LONGITUDE: '', // 隐患位置经度
					LATITUDE: '', // 隐患位置纬度
          CREATTIME: '', // 隐患发现时间
					HIDDENFINDDEPT: '', // 隐患发现部门（隐患责任人部门）
					HIDDENFINDDEPT_NAME: '',
					CREATOR: '', // 发现人（隐患责任人）
					CREATOR_INDEX: '',
					CREATOR_NAME: '',
					SOURCE: '5', // 隐患描述
          POSITIONDESC: '',// 隐患位置描述
          ISRELEVANT: '', // 是否相关方
					hiddenImgs: [],
					hiddenVideos: []
				},
				modalShow: false,
				videoSrc: '',
				hiddenRules:[
					{name:'HIDDENDESCR',message:'请选择隐患描述'},
					{name:'HIDDENPART',message:'请选择隐患部位'},
					{name:'HIDDENLEVEL',message:'请选择隐患级别'},
					{name:'HIDDENTYPE',message:'请选择隐患类型'},
					/*{name:'HIDDENTYPE2',message:'请选择隐患类型2'},*/
					{name:'LONGITUDE',message:'请选择隐患位置'},
					{name:'LATITUDE',message:'请选择隐患位置'},
					{name:'CREATTIME',message:'请选择隐患发现时间'},
					// {name:'HIDDENFINDDEPT',message:'请选择隐患责任人部门'},
					{name:'CREATOR',message:'请选择隐患责任人'}
				],
				todayDate:'',
				cityIndex: 0,
				signImgList: [],
				inspectorForm: {
					INSPECTION_STATUS: '',
					INSPECTION_INSPECTOR_ID: '', // 安全检查人员主键ID
					INSPECTION_ID: '', // 安全检查ID
					INSPECTION_USER_ID: loginUser.USER_ID, // 检查人
					INSPECTION_USER_OPINION: '', // 检查人意见（有异议时必填）
					INSPECTION_USER_SIGN_IMG: '', // 检查人签字
					INSPECTION_USER_SIGN_TIME: ''// 检查人签字时间
				},
				inspectorRules: [
					{ name:'INSPECTION_STATUS', message: '核实结果不能为空' },
					{ name:'INSPECTION_ID', message: '安全检查ID不能为空' },
					{ name:'INSPECTION_USER_ID', message: '检查人不能为空' }
					// INSPECTION_USER_OPINION: [{ required: true, message: '检查人意见不能为空', trigger: 'blur' }],
					// INSPECTION_USER_SIGN_IMG: [{ required: true, message: '检查人签字不能为空', trigger: 'blur' }],
					// INSPECTION_USER_SIGN_TIME: [{ required: true, message: '请选择检查人签字时间', trigger: 'blur' }]
				],
				modalVideoShow:false
			}
		},
		onLoad(event){
			this.todayDate =  formatDate(new Date(), 'yyyy-MM-dd hh:mm');
			this.form.INSPECTION_ID = event.INSPECTION_ID;
			this.inspectorForm.INSPECTION_ID = event.INSPECTION_ID;
			this.inspectorForm.INSPECTION_INSPECTOR_ID = event.INSPECTION_INSPECTOR_ID
			this.msg="edit";
			this.getData();

			// 初始化现场作业负责人
			this.getDept()
			this.getDict()
			loginSession();

		},
		methods: {
			getData() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/safetyenvironmental/goEdit',
					method: 'POST',
 					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						INSPECTION_ID: _this.form.INSPECTION_ID,
					},
					success: (res) => {
						if ("success" == res.data.result) {
							uni.hideLoading();
							_this.form = res.data.pd; //参数map
              _this.form.hiddenForm = res.data.pd.hiddenList[0];
							for (let i = 0; i < _this.form.inspectorList.length; i++) {
								_this.inspectorList.push([])
								_this.getUserList('inspectorList', _this.form.inspectorList[i].INSPECTION_DEPARTMENT_ID, i)
							}
							for (let i = 0; i < _this.form.inspectorVerifyList.length; i++) {
								if (loginUser.USER_ID ===  _this.form.inspectorVerifyList[i].INSPECTION_USER_ID) {
									_this.forbidEdit = true;
								}
							}
						} else if ("exception" == data.result) {
							uni.showToast({
								title: '错误',
								duration: 2000
							});
						}
					}
				});
			},
			changeRadioGroup(e){
				this.inspectorForm.INSPECTION_STATUS = e.detail.value
			},
			subCanvas (e) {
				this.signImgList.splice(0, this.signImgList.length);
				this.signImgList.push(e);
        this.inspectorForm.INSPECTION_USER_SIGN_IMG = e.filePath;
				this.$set(this.inspectorForm, 'INSPECTION_USER_SIGN_TIME', formatDate(new Date(), 'yyyy-MM-dd hh:mm'))
				this.modalShow = false;
			},
			delImg (e) {
				var _this = this;
				let i = e.currentTarget.dataset.index
				uni.showModal({
					content: '确定要删除这张图片吗？',
					cancelColor: "#000000",
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							_this.imgList.splice(i, 1)
						}
					}
				})
			},
			goSubmit(){
				var _this = this;
				let required = true
				this.inspectorRules.map(({name,message})  => {
					if (!this.inspectorForm[name]) {
						uni.showToast({
							icon: 'none',
							title: message,
							duration: 1500
						});
						required = false
					}
				})
				if (!required) {
					return
				}
				if (this.inspectorForm.INSPECTION_STATUS === '-1' && this.inspectorForm.INSPECTION_USER_OPINION.length === 0) {
					uni.showToast({
						icon: 'none',
						title: '核实结果有异议时必填',
						duration: 1500
					});
					return;
				}
				if (this.signImgList.length === 0) {
					uni.showToast({
						icon: 'none',
						title: '请签字',
						duration: 1500
					});
					return;
				}
				uni.showLoading({
					title: '请稍候'
				})
				this.$set(this.inspectorForm, 'OPERATOR', loginUser.USER_ID)
				this.$set(this.inspectorForm, 'ACTION_USER', loginUser.NAME)
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.uploadFile({
					url: basePath + "/app/safetyenvironmentalinspector/verify",
					filePath: _this.signImgList[0].filePath,
					name: 'FFILE',
					formData: this.inspectorForm,
					success: (res) => {
						uni.showToast({
							icon: 'none',
							title: '保存成功',
							duration: 2000
						});
						_this.goback()
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showModal({
							content: err.errMsg,
							showCancel: false
						});
					}
				})
			},
			changeStartDate(e) {
				this.form.INSPECTION_TIME_START = e
				this.$forceUpdate();//强制刷新
			},
			changeEndDate(e) {
				this.form.INSPECTION_TIME_END = e
				this.$forceUpdate();//强制刷新
			},
			showZgTree(ref, index) {
				// console.info('ref > tkiTree2:'+(ref > 'tkiTree2'))
				if (index > 7) {
					this.$refs[ref][0]._show();
				} else {
					this.$refs[ref]._show();
				}
			},
			zgtreeCancel(e) {
				this.isUps = false;
			},
			zgtreeConfirm(e, list, i) {
				if (list === 'inspectedSiteuserList') { // 被检查单位现场负责人
					this.form.INSPECTED_DEPARTMENT_ID = e[0].id
					this.form.INSPECTED_DEPARTMENT_NAME = e[0].name
					this.form.INSPECTED_SITEUSER_INDEX = ''
					this.form.INSPECTED_SITEUSER_ID = ''
					this.form.INSPECTED_SITEUSER_NAME = ''
					this.getUserList(list, e[0].id)
				}
				if (list === 'inspectionTypeTreeList') { // 检查类型
					this.form.INSPECTION_TYPE = e[0].id
					this.form.INSPECTION_TYPE_NAME = e[0].name
				}
				if (list === 'inspectorList') { // 检查人员
					this.form.inspectorList[i].INSPECTION_DEPARTMENT_ID = e[0].id
					this.form.inspectorList[i].INSPECTION_DEPARTMENT_NAME= e[0].name
					this.form.inspectorList[i].INSPECTION_USER_INDEX = ''
					this.form.inspectorList[i].INSPECTION_USER_ID = ''
					this.form.inspectorList[i].INSPECTION_USER_NAME = ''
					this.getUserList(list, e[0].id, i);
				}
				if (list === 'hiddenRegionTreeList') { // 隐患部位
					this.hiddenForm.HIDDENPART = e[0].id
					this.hiddenForm.HIDDENPART_NAME = e[0].name
				}
				if (list === 'hiddenLevelTreeList') {
					this.hiddenForm.HIDDENLEVEL = e[0].id
					this.hiddenForm.HIDDENLEVEL_NAME = e[0].name
				}
				if (list === 'hiddenTypeTreeList') {
					this.hiddenForm.HIDDENTYPE = e[0].id
					this.hiddenForm.HIDDENTYPE_NAME = e[0].name
				}
				if (list === 'hiddenType2TreeList') {
					this.hiddenForm.HIDDENTYPE2 = e[0].id
					this.hiddenForm.HIDDENTYPE2_NAME = e[0].name
				}
				if (list === 'creatorList') {
					this.hiddenForm.HIDDENFINDDEPT = e[0].id
					this.hiddenForm.HIDDENFINDDEPT_NAME = e[0].name
					this.hiddenForm.CREATOR_INDEX = ''
					this.hiddenForm.CREATOR = ''
					this.hiddenForm.CREATOR_NAME = ''
					this.getUserList(list, e[0].id)
				}
			},
			inspectedSiteuserChange(e) {
				this.form.INSPECTED_SITEUSER_INDEX = e.detail.value;
				this.form.INSPECTED_SITEUSER_ID = this.inspectedSiteuserList[e.detail.value].USER_ID;
				this.form.INSPECTED_SITEUSER_NAME = this.inspectedSiteuserList[e.detail.value].NAME;
			},
			inspectorChange(e,index) {
				this.form.inspectorList[index].INSPECTION_USER_INDEX = e.detail.value;
				this.form.inspectorList[index].INSPECTION_USER_ID = this.inspectorList[index][e.detail.value].USER_ID;
				this.form.inspectorList[index].INSPECTION_USER_NAME = this.inspectorList[index][e.detail.value].NAME;
			},

			addSituation() {
				this.form.situationList.push(
					{
						INSPECTION_SITUATION_ID: '',
						SITUATION: ''
					}
				)
			},
			removeSituation (item, index) {
				var _this = this;
				uni.showModal({
					title: '提示',
					cancelText: '确认',
					confirmText: '取消',
					content: '确定删除检查情况吗？',
					success: function (res) {
						if (res.cancel) {
							_this.form.situationList.splice(index, 1)
							if (item.INSPECTION_SITUATION_ID) {
								_this.delSituations.push(item.INSPECTION_SITUATION_ID)
							}
						}
					}
				});
			},

			addInspector() {
				this.form.inspectorList.push(
					{
						INSPECTION_INSPECTOR_ID: '',	//检查人员主键
						INSPECTION_DEPARTMENT_ID: '',	//检查人员部门ID
						INSPECTION_DEPARTMENT_NAME: '',
						INSPECTION_USER_ID: '',		//检查人员ID
						INSPECTION_USER_INDEX: '',
						INSPECTION_USER_NAME: ''
					}
				)
			},
			removeInspector(item, index){
				var _this = this;
				uni.showModal({
					title: '提示',
					cancelText: '确认',
					confirmText: '取消',
					content: '确定移除检查人员吗？',
					success: function (res) {
						if (res.cancel) {
							this.form.inspectorList.splice(index,1);
							if (item.INSPECTION_INSPECTOR_ID) {
								_this.delInspectors.push(item.INSPECTION_INSPECTOR_ID)
							}
						}
					}
				});
			},

			// 打开隐患添加窗口
			showHidden(item) {
				this.resetHd()
				this.creatorList = []
				this.form.inspectorList.forEach(item => {
					this.creatorList.push({ USER_ID: item.INSPECTION_USER_ID, NAME: item.INSPECTION_USER_NAME })
				})
				this.hiddenForm = item
				this.$refs['showHiddenWindow'].open()
				this.showHiddenWindow = true
			},
			// 取消添加隐患
			cancelHidden() {
				this.$refs['showHiddenWindow'].close()
				this.showHiddenWindow = false
			},
			// 抽屉状态发生变化触发
			change(e, type) {
				this[type] = e
			},
			ViewImage(e) {
				if(e.currentTarget.dataset.type==0) {
					let files =[];
					for(var i=0;i<this.hiddenForm.hiddenImgs.length;i++){
						files.push(this.baseImgPath +  this.hiddenForm.hiddenImgs[i].FILEPATH)
					}
					console.info(files)
					uni.previewImage({
						urls: files,
						current: e.currentTarget.dataset.url
					});
				}else{
					let files =[];
					for(var i=0;i<this.imgList1.length;i++){
						files.push(this.imgList1[i].filePath)
					}
					uni.previewImage({
						urls: files,
						current: e.currentTarget.dataset.url
					});
				}
			},

			ViewVideo(e){

			},
			playVideo(e) {
				this.videoSrc = e.currentTarget.dataset.src
				this.modalVideoShow = true
			},
			changeDiscoverDate(e) {
				this.hiddenForm.CREATTIME = e
				this.$forceUpdate();//强制刷新
			},
			creatorChange(e) {
				this.hiddenForm.CREATOR_INDEX = e.detail.value;
				this.hiddenForm.CREATOR = this.creatorList[e.detail.value].USER_ID;
				this.hiddenForm.CREATOR_NAME = this.creatorList[e.detail.value].NAME;
			},

			/** 坐标定位 */
			showMapModal() {
				var _this = this
				uni.navigateTo({
					url: '/pages/map/map',
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						acceptDataFromOpenedPage: function (e) {
							_this.hiddenForm.LONGITUDE = e.data.longitue;
							_this.hiddenForm.LATITUDE = e.data.latitude;
						}
					},
				})
			},

			getDept() {
				var _this = this;
				uni.request({
					url: basePath + '/app/sys/listTree',//部门下拉接口
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						CORPINFO_ID : corpinfoId,
					},
					success: (res) => {
						if("success" == res.data.result){
							_this.treeNode=eval(res.data.zTreeNodes);
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				});
			},
			//获取人员列表
			getUserList(list,dept,i){
				//发送 post 请求
				var _this=this
				uni.request({
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type':'application/x-www-form-urlencoded'
					},
					url: basePath+'/app/sys/listUser',
					data: {DEPARTMENT_ID:dept, NOMAIN:'1', tm:new Date().getTime()},
					success: function(res){
						if("success" == res.data.result){
							if(i>-1) {
								_this[list][i] = [];
								_this[list][i] = res.data.userList;
								_this.$forceUpdate();//强制刷新
							}else{
								_this[list]=res.data.userList;
							}
						}else{
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				})
			},
      goIdentifyImg() {
        if (this.imgList.length === 0) {
          uni.showToast({
            icon: 'none',
            title: '请先上传图片',
            duration: 2000
          });
        } else if (this.imgList.length > 1) {
          uni.showToast({
            icon: 'none',
            title: '识别暂时只能上传一张图片',
            duration: 2000
          });
        } else {
          var _this = this;
          if(this.imgList[0].id != ""){
            uni.showToast({
              icon: 'none',
              title: '请删除图片重新上传图片后,再次进行图片识别',
              duration: 2000
            });
            return;
          }
          _this.buttonloading = true
          uni.showLoading({
            title: '识别中...'
          })
          uni.uploadFile({
            url: basePath + '/app/hidden/identifyImg',
            filePath: _this.imgList[0].filePath,
            name: 'FFILE',
            formData: {
              CORPINFO_ID: loginUser.CORPINFO_ID,
              USER_ID: loginUser.USER_ID,

            },
            success: (res) => {
              _this.buttonloading = false
              _this.aiFlag = true
              if ("success" == JSON.parse(res.data).result) {
                const aiHiddens = JSON.parse(res.data).aiHiddens;
                let hiddenDescr = ""
                let rectificationSuggestions = ""
                let legalBasis = ""
                aiHiddens.forEach((item) => {
                  hiddenDescr += JSON.parse(item).hiddenDescr + ";"
                  rectificationSuggestions += JSON.parse(item).rectificationSuggestions + ";"
                  legalBasis += JSON.parse(item).legalBasis + ";"
                })
                _this.pd.HIDDENDESCR = hiddenDescr
                _this.pd.LEGALBASIS = legalBasis
                _this.pd.RECTIFYDESCR = rectificationSuggestions
                _this.radioType(1)
              } else {
                uni.showToast({
                  icon: 'none',
                  title: "未识别图片中的隐患",
                  duration: 2000
                });
              }
              uni.hideLoading();
            },
            fail: (err) => {
              _this.buttonloading = false
              uni.hideLoading();
              uni.showModal({
                content: err.errMsg,
                showCancel: false
              });
            }
          })
        }
      },
			//获取数据字典数据
			getDict() {
				var _this = this;

				uni.request({
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					url: basePath + '/dictionaries/listSelectTreeByTkiTree?tm=' + new Date().getTime(),
					data: {DICTIONARIES_ID: '60e6481d96e44a5390ff5c347c4d1ffe'},
					success: function (res) {
						_this.inspectionTypeTreeList = eval(res.data.zTreeNodes);
					}
				});

				uni.request({
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type':'application/x-www-form-urlencoded'
					},
					url: basePath+'/app/hidden/getTreehiddenRegionListAll',
					data: {
						CORPINFO_ID: corpinfoId,
						tm:new Date().getTime()
					},
					success: function(res){
						if("success" == res.data.result){
							var json = res.data.zTreeNodes
							_this.hiddenRegionTreeList = JSON.parse(json) ;
						}else{
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				})

				uni.request({
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					url: basePath + '/dictionaries/listSelectTreeByTkiTree?tm=' + new Date().getTime(),
					data: {DICTIONARIES_ID: '5e7cf8620ba54ad89719d0be62133c7a'},
					success: function (res) {
						var data = res.data.zTreeNodes ;
						_this.hiddenLevelTreeList = JSON.parse(data) ;
					}
				})

				uni.request({
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					url: basePath + '/dictionaries/listSelectTreeByTkiTree?tm=' + new Date().getTime(),
					data: {DICTIONARIES_ID: '3babc15144444bdc8d763d0af2bdfff6'},
					success: function (res) {
						var jons = res.data.zTreeNodes ;
						_this.hiddenTypeTreeList = JSON.parse(jons) ;
					}
				})

				uni.request({
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					url: basePath + '/dictionaries/listSelectTreeByTkiTree?tm=' + new Date().getTime(),
					data: {DICTIONARIES_ID: '18c0a9aea6e54feab9f4ab3f46e0bc86'},
					success: function (res) {
						var jons = res.data.zTreeNodes ;
						_this.hiddenType2TreeList = JSON.parse(jons) ;
					}
				})
			},

			goback(){
				var pages = getCurrentPages();	// 获取当前页面栈
				var prePage = pages[pages.length - 2];	// 上二级页面
				prePage.$vm.initflag = true;    // A 页面 init方法 为true
				uni.navigateBack({delta: 1});
				uni.hideLoading();
			},

			resetHd() {
				this.hiddenForm = {
					HIDDEN_ID: '', // 隐患ID
					HIDDENDESCR: '', // 隐患描述
					HIDDENPART: '', // 隐患部位
					HIDDENPART_NAME: '',
					HIDDENLEVEL: '', // 隐患级别
					HIDDENLEVEL_NAME: '',
					HIDDENTYPE: '', // 隐患类型1
					HIDDENTYPE_NAME: '',
					HIDDENTYPE2: '', // 隐患类型2
					HIDDENTYPE2_NAME: '',
					LONGITUDE: '', // 隐患位置经度
					LATITUDE: '', // 隐患位置纬度
          CREATTIME: '', // 隐患发现时间
					HIDDENFINDDEPT: '', // 隐患发现部门（隐患责任人部门）
					HIDDENFINDDEPT_NAME: '',
					CREATOR: '', // 发现人（隐患责任人）
					CREATOR_INDEX: '',
					CREATOR_NAME: '',
					SOURCE: '5', // 隐患描述
					hiddenImgs: [],
					hiddenVideos: []
				}
			}
		}
	}
</script>

<style>
	.right_icon {
		position: relative;
		padding-right: 36upx;
		width: 200upx;
		text-align: right;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.right_icon ::after {
		font-family: cuIcon;
		display: block;
		content: "\e6a3";
		position: absolute;
		font-size: 17px;
		color: #8799a3;
		line-height: 50px;
		width: 30px;
		text-align: center;
		top: -28upx;
		bottom: 0;
		right: -22upx;
		margin: auto;
	}

	.modal_content {
		display: flex;
		text-align: left;
	}
	.modal_left {
		flex-basis: 50%;
		padding: 50upx 20upx;
		border-right: 1px solid #000000;
	}
	.modal_right {
		flex-basis: 50%;
		padding: 50upx;
	}
	.modal_left_title,.modal_right_title{
		font-size: 16px;
		color: #000000;
		font-weight: 700;
	}
	.checkbox-item{
		display: flex;
		align-items:center;
		padding: 0 30upx;
		min-height: 100upx;
		background-color: #ffffff;
		border-bottom: 1upx solid #ddd;
	}
	.checkbox-item:last-child{
		border-bottom: none;
	}
	.showHiddenWindowActive{
		overflow: hidden;
		height: 100vh;
	}
  .ai_btn {
       width: 100%;
       box-sizing: border-box;
       background: #FFFFFF;
       margin-bottom: 10px;
       padding: 10px;
     }

  .ai_btn .ai_btn_con {
    width: 45%;
    background: #dfeaff;
    border-radius: 20px;
    display: flex;
    align-items: center;
    height: 40px;
    padding: 0 10px;
  }
</style>
