<!-- 开始检查 -->
<template>
    <view id="startChecking">
		<scroll-view scroll-y @scrolltolower="scrollGet" class="info-max-box">
			<!-- 综合检查 -->
			<viwe class="list" v-if="form.checkCategory==1">
				<view class="title">不符合项</view>
				<view class="check-for-big-box" v-for="(item,index) in form.checkHazardDtoList" :key="index">
					<view class="grade">
						<view class="grade_l">隐患等级：</view>
						<picker @change="gradeChange(item,$event)" :value="gradeIndex" :range="gradeArray" class="scope_r">
							<view class="grade_r">
								<view>{{item.hazardLevel==2?'一般隐患':(item.hazardLevel==1?'重大隐患':(item.hazardLevel==3?'管理问题':''))}}</view>
								<img src="@/pages_safetyExamine/images/icon_06.png">
							</view>
						</picker>
					</view>
					<view class="project" v-if="checkOptionList.length>0">
						<view class="project_l">检查项目：</view>
						<uni-data-picker :ellipsis="false" :localdata="checkOptionList[0]" :map="{text:'name',value:'id'}"
						popup-title="请选择所属目录" @change="(e)=>onchange('',e,index)" @nodeclick="onnodeclick()"
						ref="uniDataPicker" :addType="true" :addIndex="index">
							<view  class="project_r">{{item.hazardCheckName?item.hazardCheckName:'请选择检查项'}}</view>
						</uni-data-picker>
					</view>
					<view class="dangerCount" v-if="item.hazardCheckCount>0" style="margin-top: 20rpx;">此检查项在当前实验室累计出现<text>{{item.hazardCheckCount}}</text>次隐患</view>
					<view class="point">
						<view class="point_l">检查要点：</view>
						<textarea class="point_r" type="text" maxlength="999"  v-model="item.hazardCheckPoint"  placeholder="未查到此项检查要点，可在此输入添加" placeholder-style="font-size:28rpx;color:#999;"></textarea>
					</view>
					<view class="check-for-input-max-box">
						<view class="left-title-p">隐患描述：</view>
						<textarea type="text" v-model="item.hazardDescribe" maxlength="50" placeholder="请输入隐患描述" placeholder-style="font-size:28rpx;color:#999;"></textarea>
					</view>
					<view class="check-for-img-max-box">
						<view class="left-title-p">隐患照片（最多上传5张）：</view>
						<view class="right-img-box">
							<view class="img-box" v-for="(imgItem,imgIndex) in item.uploadDtoList" :key="imgIndex">
								<img class="img-data" :src="configURL+imgItem.fileUrl">
								<img class="position-img" src="@/images/basicsModules/icon_ssp_closure.png" @click="delImg('',index,imgIndex)">
							</view>
							<img class="add-button" src="@/images/basicsModules/icon_07.png" @click="selectImage(item)" v-if="item.uploadDtoList.length<5">
						</view>
					</view>
				   <view class="voice">
					   <view class="voice_t">
						   <view class="voice_t_l">语音备注：</view>
						   <img class="voice_t_r" src="@/pages_safetyExamine/images/icon_ksjc_yysr.png" @longpress.stop="recordButton(item,$event)" @touchmove.stop="cancelButton"  @touchend.stop="sendButton(item,$event)">
					   </view>
					   <view class="voice_b" v-for="(voiceItem,voiceIndex) in item.voiceRemark" :key="voiceIndex">
						   <view class="voice_b_l" @tap="voicePlay(voiceItem.url)"><img class="add-button" src="@/images/basicsModules/icon_yyt.png"/>{{voiceItem.times}}″</view>
						   <img class="voice_b_r" src="@/pages_safetyExamine/images/icon_fjgk_sc.png" @tap="voiceDele('',index,voiceIndex)"/>
					   </view>
				   </view>
					<view class="check-for-big-box-position-img-box" v-if="form.checkHazardDtoList.length>1" @click="delDetailsList(index,'',1)">
						<img src="@/images/basicsModules/icon_ssp_closure.png">
					</view>
				</view>
				<view class="add-for-item-p" @click="addDanger('')">+ 新增隐患项</view>
			</viwe>
			<!-- 专项检查 -->
			<viwe class="list" v-if="form.checkCategory==2" v-for="(itemAll,indexAll) in form.checkHazardInfoVoList" :key="indexAll">
				<view class="inconformity_tow" >
					<text>{{itemAll.hazardName}}</text>
					<img v-if="!form.isCustom" class="itemDelete" @click="delDetailsList(indexAll,'',2)" src="@/pages_safetyExamine/images/icon_fjgk_sc.png">
					<view class="unfold" @click="inconformityFun2(itemAll)" >
						<img v-if="itemAll.switch" src="@/pages_safetyExamine/images/icon_bfhx_xq.png"/>
						<img v-if="!itemAll.switch" src="@/pages_safetyExamine/images/icon_bfhx_sq.png"/>
					</view>
				</view>
				<view class="check-for-big-box danger_border" v-if="itemAll.switch">
					<view class="ident">检查项目:</view>
					<view class="special_danger" v-for="(item,index) in itemAll.checkHazardDtoList" :key="index">
						<view class="grade_title" :style="item.switch?'border-bottom: 1rpx solid #D8D8D8;':'border:none;'">
							<view class="sort">{{index+1}}</view>
							<text>第{{index+1}}项隐患</text>
							<view class="Flag" @click="switchChange(item)">
								<img class="checkFlag" v-if="item.checkFlag==0" src="@/pages_safetyExamine/images/icon_kzjc_bfh.png">
								<img class="checkFlag" v-if="item.checkFlag==1" src="@/pages_safetyExamine/images/icon_kzjc_fh.png">
							</view>
							<img v-if="!form.isCustom" class="itemDelete" @click="delDetailsList(index,indexAll,3)" src="@/pages_safetyExamine/images/icon_fjgk_sc.png">
						</view>
						<view class="special_project" v-if="checkOptionList.length>0">
							<uni-data-picker :ellipsis="false" :localdata="checkOptionList[0]" :map="{text:'name',value:'id'}"
							popup-title="请选择所属目录" @change="(e)=>onchange(indexAll,e,index)" @nodeclick="onnodeclick()"
							ref="uniDataPicker" :addType="true" :addIndex="index">
								<view  class="special_project_n">{{item.hazardCheckCode?item.hazardCheckCode:''}}{{item.hazardCheckName?item.hazardCheckName:'请选择检查项'}}</view>
							</uni-data-picker>
						</view>
						<view class="dangerCount" v-if="item.hazardCheckCount>0 && item.checkFlag==0">此检查项在当前实验室累计出现<text>{{item.hazardCheckCount}}</text>次隐患</view>
						<view class="grade" v-if="item.checkFlag==0">
							<view class="grade_l">隐患等级：</view>
							<picker @change="gradeChange(item,$event)" :value="gradeIndex" :range="gradeArray" class="scope_r">
								<view class="grade_r">
									<view>{{item.hazardLevel==2?'一般隐患':(item.hazardLevel==1?'重大隐患':(item.hazardLevel==3?'管理问题':''))}}</view>
									<img src="@/pages_safetyExamine/images/icon_06.png">
								</view>
							</picker>
						</view>
						<view class="check-for-input-max-box" v-if="item.checkFlag==0">
							<view class="left-title-p">隐患描述：</view>
							<textarea type="text" v-model="item.hazardDescribe" maxlength="50" placeholder="请输入隐患描述" placeholder-style="font-size:28rpx;color:#999;"></textarea>
						</view>
						<view class="check-for-img-max-box" v-if="item.checkFlag==0">
							<view class="left-title-p">隐患照片（最多上传5张）：</view>
							<view class="right-img-box">
								<view class="img-box" v-for="(imgItem,imgIndex) in item.uploadDtoList" :key="imgIndex">
									<img class="img-data" :src="configURL+imgItem.fileUrl">
									<img class="position-img" src="@/images/basicsModules/icon_ssp_closure.png" @click="delImg(item,index,imgIndex)">
								</view>
								<img class="add-button" src="@/images/basicsModules/icon_07.png" @click="selectImage(item)" v-if="item.uploadDtoList.length<5">
							</view>
						</view>
						<view class="voice" v-if="item.checkFlag==0">
						   <view class="voice_t">
							   <view class="voice_t_l">语音备注：</view>
							   <img class="voice_t_r" src="@/pages_safetyExamine/images/icon_ksjc_yysr.png" @longpress.stop="recordButton(item,$event)" @touchmove.stop="cancelButton"  @touchend.stop="sendButton(item,$event)">
						   </view>
						   <view class="voice_b" v-for="(voiceItem,voiceIndex) in item.voiceRemark" :key="voiceIndex">
							   <view class="voice_b_l" @tap="voicePlay(voiceItem.url)"><img class="add-button" src="@/images/basicsModules/icon_yyt.png"/>{{voiceItem.times}}″</view>
							   <img class="voice_b_r" src="@/pages_safetyExamine/images/icon_fjgk_sc.png" @tap="voiceDele(item,index,voiceIndex)"/>
						   </view>
						</view>
						<!-- <view class="check-for-big-box-position-img-box" v-if="form.checkHazardDtoList.length>1" @click="delDetailsList(index,'')">
							<img src="@/pages_manage/images/icon_ssp_closure.png">
						</view> -->
					</view>
					<view v-if="!form.isCustom" style="width: 630rpx;" class="add-for-item-p" @click="addDanger(itemAll)">+ 新增隐患项</view>
				</view>
			</viwe>
			<view v-if="!form.isCustom && form.checkCategory==2" class="add_content" @click="addDeviceDanger()">+ 新增检查内容</view>
		</scroll-view>
		<view class="bottom_btn">
			<view class="bottom_btn_li"  @click="goMinButton(index)" v-for="(item,index) in  bottomBtnList" :key="index">{{item}}</view>
		</view>
	</view>
</template>

<script>
	const myaudio  = uni.createInnerAudioContext();
    import { config } from '@/api/request/config.js'
    import {checkOptionListNew,treeDepselect,checkManageUpdate,checkManageAdd,getHazardInfoByJoinIds,countHazardNum} from '@/api/apiDemo/index.js'
    export default {
        name: "startChecking",
        data() {
            return {

				configURL:config.base_url,
				id:"",
                //页面子状态
                minPageType:1,
				//临时存储隐患信息ID
				hiddenDangerIdList:[],
				//数据
				form:{
					id:'',
					checkPlanId:'',
					manageStatus:'',//保存1  提交2
					subIds:'',//实验室
					subjectName:'',
					title:'',//计划标题
					deptId:'',//学院
					collegeName:'',
					buildId:'',//楼栋
					buildName:'',
					checkType:'',// 检查组织(1校院巡查 2实验室自查)
					checkResult:'1',// 检查结果 0不符合 1符合
					rectifyDeadline:'',//整改期限
					rectifyNotice:'1',//整改通知(1整改告知书 2整改通知书)
					roomNumber:'',//房间号
					checkCategory:'2',  //检查类别 1综合检查 2专项检查
					checkHazardDtoList:[
						{
							voiceRemark:[],//语音备忘存储
							hazardLevel:2,//隐患等级
							hazardCheckCode:'', //检查项目code序号
							hazardCheckName:'', //检查项目名称
							hazardCheckPro:'', //最后一级的id
							hazardCheckPoint:'',// 检查要点
							hazardDescribe:'', //隐患描述
							uploadDtoList:[],//隐患照片
						}
					],
					checkHazardInfoVoList:[

					]
				},
                inspectionUnit:"",
                inspectionUnitArray:[],
				inspectionUnitArrayData:[],
                //搜索回调列表
                searchList:[],
				searchNullType:true,
				//检查项
				checkOptionList:[],
				//新增检查项
				openIndex:"",
				open:false,
				jcxSstkMs:[],
				jcxSstkNum:'',
				//临时数据组
				temporaryIdList:[],
				//添加项 目录
				uniPicker:"请选择所属目录",
				//滑动记录
				startPoint:{},
				liveType:false,
				sendLock: true, //发送锁，当为true时上锁，false时解锁发送
				recorderManager : wx.getRecorderManager(),
				temporaryData:[],
				gradeIndex :0,
				gradeArray:['一般隐患','重大隐患','管理问题'],
				bottomBtnList:['上一步','保存','提交'],
				currentDate:'',//当前时间
				inconformityStatus2:false,

            }
        },
        onLoad(option) {

			//获取当前日期
			this.currentDate=this.getNowFormatDate()
			if(option.form){
				this.form=JSON.parse(decodeURIComponent(option.form));
			}
			if(option.joinHazardIds){
				this.getHazardInfoByJoinIds(this.form.subIds,option.joinHazardIds)
				this.form.joinHazardIds=option.joinHazardIds
			}
			console.log(this.form.isCustom)
        },
        onShow() {
			this.getCheckOptionList();
        },
		mounted() {

		},
        methods: {
			//根据设备id生成检查项
			async getHazardInfoByJoinIds(id,joinHazardIds) {
				let _this=this;
				const {data} = await getHazardInfoByJoinIds({joinHazardIds:joinHazardIds});
				if(data.code == 200){

					if(data.data[0]){
						let dataList=JSON.parse(JSON.stringify(data.data))
					    for(let i=0;i<dataList.length;i++){
							dataList[i].switch=true;
							for(let b=0;b<dataList[i].checkHazardDtoList.length;b++){
								//把最外层的code填充到内层
								//dataList[i].checkHazardDtoList[b].hazardCheckCode=dataList[i].code
								//语音备注类型转换
								if(dataList[i].checkHazardDtoList[b].voiceRemark){
									dataList[i].checkHazardDtoList[b].voiceRemark=JSON.parse(dataList[i].checkHazardDtoList[b].voiceRemark)
								}else{
									dataList[i].checkHazardDtoList[b].voiceRemark=[];
								}
							}
							//判断新旧数据是否相等,如果相等旧数据填充新数据
							for(let k=0;k<_this.form.checkHazardInfoVoList.length;k++){
								if(dataList[i].joinHazardId==_this.form.checkHazardInfoVoList[k].joinHazardId){
									 dataList[i]=_this.form.checkHazardInfoVoList[k]
								}
							}

						}
						this.form.checkHazardInfoVoList=dataList

					}


				}
			},
			switchChange(item){
				if(item.checkFlag==0){
					item.checkFlag=1
				}else{
					item.checkFlag=0
				}
			},
			//专项隐患项收起展开
			inconformityFun2(itemAll){
				itemAll.switch=!itemAll.switch;
			},
			//获取当前日期函数
			getNowFormatDate() {
			  let date = new Date(),
			    year = date.getFullYear(), //获取完整的年份(4位)
			    month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
			    strDate = date.getDate() // 获取当前日(1-31)
			  if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
			  if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0

			  return `${year}-${month}-${strDate}`
			},
			//隐患等级
			gradeChange(item,e){
				if(e.target.value==0){
					item.hazardLevel=2
				}else if(e.target.value==1){
					item.hazardLevel=1
				}else if(e.target.value==2){
					item.hazardLevel=3
				}

			},
			//语音备忘播放
			async voicePlay(item){
				 myaudio.src = config.base_url+item;
				 myaudio.play();
			},
			//语音备忘删除
			async voiceDele(item,index,voiceIndex){
				let self = this;
				uni.showModal({
				  title: '',
				  cancelColor:'#999999',
				  confirmColor:'#FF6E6E',
				  content: '确定删除此语音吗?',
				  success (res) {
				    if (res.confirm) {
				      console.log('用户点击确定')
					  if(self.form.checkCategory==1){//综合检查
						  self.form.checkHazardDtoList[index].voiceRemark.splice(voiceIndex,1);
					  }else if(self.form.checkCategory==2){//专项检查
						 item.voiceRemark.splice(voiceIndex,1);
					  }

					  self.$forceUpdate();
				    } else if (res.cancel) {
				      console.log('用户点击取消')

				    }
				  }
				})

			},
			//录制
			recordButton(item,e){
				console.log("按下")
				let self = this;
				if(item.voiceRemark.length>=5){
					uni.showToast({
						title: '语音备忘最多只能上传5条',
						icon:"none",
						mask:true,
						duration: 2000
					});
					return
				}
				this.liveType=true;
				console.log('录制',e)
				this.startPoint = e.touches[0];//记录长按时开始点信息，后面用于计算上划取消时手指滑动的距离。
				const options = {
					duration: 60000,
					sampleRate: 16000,
					numberOfChannels: 1,
					encodeBitRate: 48000,
					format: 'mp3',
					frameSize: 50
				}
				this.recorderManager.start(options);//开始录音
				this.recorderManager.onStart(() => {
					console.log('recorder start')
				})
				this.recorderManager.onError((res) => {
					console.log(res);
				})
				wx.showToast({
					title: "正在录音，上划取消发送",
					icon: "none",
					duration: 60000//先定义个60秒，后面可以手动调用wx.hideToast()隐藏
				});
				this.sendLock = false;//长按时是不上锁的。
			},
			//取消
			cancelButton(e){
				console.log("移动")
				let self = this;

			    this.liveType=false;
				console.log('取消',e)
				let moveLenght = e.touches[e.touches.length - 1].clientY - this.startPoint.clientY; //移动距离
				if (Math.abs(moveLenght) > 50) {
					wx.showToast({
						title: "松开手指,取消发送",
						icon: "none",
						duration: 60000
					});
					this.sendLock = true;//触发了上滑取消发送，上锁
				} else {
					wx.showToast({
						title: "正在录音，上划取消发送",
						icon: "none",
						duration: 60000
					});
					this.sendLock = false;//上划距离不足，依然可以发送，不上锁
				}
			},
			//发送
			sendButton(item,e){
				console.log("松开")
				let self = this;

			    this.liveType=false;
				console.log('发送',e)
				wx.hideToast();//结束录音、隐藏Toast提示框
				this.recorderManager.stop();//结束录音
				this.recorderManager.onStop((res) => {

					if(!this.sendLock){

						this.uploadVoice(item,res.duration,res.tempFilePath);
					}
					console.log('停止录音', res.tempFilePath)
					console.log("sendLock",this.sendLock);
				})
			},
			//上传MP3
			async uploadVoice(item,times,tempFilePaths){
				console.log(item)
				console.log(times)
				console.log(tempFilePaths)

			    var self = this;
			    uni.uploadFile({
			        url: config.base_url+'/base/file/upload', //仅为示例，非真实的接口地址
			        header:{'Authorization':uni.getStorageSync('token')},
			        filePath: tempFilePaths,
			        name: 'file',
			        formData: {
			            'user': 'test'
			        },
			        success: (uploadFileRes) => {
			            let res = JSON.parse(uploadFileRes.data);
						if(res.code == 200){
							console.log("上传成功",res)
							console.log(item)
							let seconds = Math.round((parseInt(times) % (1000 * 60)) / 1000);
							item.voiceRemark.push({'times':seconds,'url':res.data.url})
							console.log(JSON.stringify(self.voice))
							//self.textParseUrlIps(res.data.url);
							// self.newData.imgList.push(res.data.url);
						}else{
							uni.showToast({
								title: res.msg,
								icon:"none",
								mask:true,
								duration: 2000
							});
						}
			        },
			        fail: err => {
						uni.hideLoading()
					},
			        complete: () => {
			        }
			    });
			},


            /**************************检查项***************************/

			//获取检查项
			async getCheckOptionList() {
				const {data} = await checkOptionListNew();
				if(data.code == 200){
					let list = this.getTreeData(data.data);
					console.log(list)
					this.checkOptionList.push(JSON.parse(JSON.stringify(list)));

				}
			},
			getTreeData(data){
			  for(var i=0;i<data.length>0;i++){
				if(data[i].children == null||data[i].children.length<=0){
				  // children若为空数组，则将children设为undefined
				  data[i].children = undefined;
				}else {
					if(this.form.checkCategory==1 && data[i].level==3){
						if(data[i].children[0]){
						  let mainPoint=[]
						  for(let b=0;b<data[i].children.length;b++){
							mainPoint.push(data[i].children[b].name)
							data[i].mainPoint=mainPoint.join(',')
						  }
						}else{
						  data[i].mainPoint='';
						}
					   data[i].children=[];
					}
				  // children若不为空数组，则继续 递归调用 本方法
				  this.getTreeData(data[i].children);
				}
			  }
			  return data;
			},
			/**************************搜索项***************************/
			//搜索特定检查项
			async searchClick(text,index){
				console.log("搜索text",text);
				console.log("搜索index",index);
				const {data} = await checkOptionListNew({'searchValue':text});
				if(data.code == 200){
					if(data.data[0]){
						// let list = JSON.parse(JSON.stringify(this.checkOptionList));
						// list[index] = this.getTreeData(data.data);
						// this.$set(this,'checkOptionList',JSON.parse(JSON.stringify(list)))


						let list = [];
						list[0]=this.getTreeData(data.data)
						this.$set(this,'checkOptionList',JSON.parse(JSON.stringify(list)))

						console.log(this.checkOptionList)

						this.$refs.uniDataPicker[index].show();
					}else{
						uni.showToast({
							title: '未找到相关检查项',
							icon:"none",
							mask:true,
							duration: 2000
						});
					}
				}
			},
			//重置检查项
			async resetClick(index){
				console.log("重置index",index);
				const {data} = await checkOptionListNew();
				if(data.code == 200){
					let list = [];
					list[0] = this.getTreeData(data.data);
					this.$set(this,'checkOptionList',JSON.parse(JSON.stringify(list)))
					this.$refs.uniDataPicker[index].show();
				}
			},

			//选中固有检查项(新)
			onchange(indexAll,e,index) {
				let self = this;
				//hazardCheckCode:'', //检查项目code序号
				//hazardCheckName:'', //检查项目名称
				//hazardCheckPro:'', //最后一级的id
				if(this.form.checkCategory==1){//综合检查
					if(this.getTreeName(this.checkOptionList[0],e.detail.value[e.detail.value.length-1].value).level==3){
						let jcxSstkNum=this.getTreeName(this.checkOptionList[0],e.detail.value[e.detail.value.length-1].value).code
						this.$set(this.form.checkHazardDtoList[index],'hazardCheckPro',e.detail.value[e.detail.value.length-1].value);
						this.$set(this.form.checkHazardDtoList[index],'hazardCheckCode',jcxSstkNum);
						this.$set(this.form.checkHazardDtoList[index],'hazardCheckName',e.detail.value[e.detail.value.length-1].text);
						this.$set(this.form.checkHazardDtoList[index],'hazardCheckPoint',this.getTreeName(this.checkOptionList[0],e.detail.value[e.detail.value.length-1].value).mainPoint);

					}else{
						uni.showToast({
							title: '暂无数据',
							icon:"none",
							mask:true,
							duration: 2000
						});
					}
				}else if(this.form.checkCategory==2){//专项检查


					if(this.getTreeName(this.checkOptionList[0],e.detail.value[e.detail.value.length-1].value).level==4){
						let jcxSstkNum=this.getTreeName(this.checkOptionList[0],e.detail.value[e.detail.value.length-1].value).code
						console.log(jcxSstkNum)
						this.$set(this.form.checkHazardInfoVoList[indexAll].checkHazardDtoList[index],'hazardCheckCode',jcxSstkNum);
						this.$set(this.form.checkHazardInfoVoList[indexAll].checkHazardDtoList[index],'hazardCheckName',e.detail.value[e.detail.value.length-1].text);
						this.$set(this.form.checkHazardInfoVoList[indexAll].checkHazardDtoList[index],'hazardCheckPro',e.detail.value[e.detail.value.length-1].value);

					}else{
						uni.showToast({
							title: '暂无数据',
							icon:"none",
							mask:true,
							duration: 2000
						});
					}
				}
				this.countHazardNum(indexAll,index,e.detail.value[e.detail.value.length-1].value)
			},
			//此检查项在当前实验室累计出现次数
			async countHazardNum(indexAll,index,hazardCheckPro){
				const {data} = await countHazardNum({subId:this.form.subIds, hazardCheckPro:hazardCheckPro});
				if(data.code == 200){
					if(this.form.checkCategory==1){//综合检查
					     this.$set(this.form.checkHazardDtoList[index],'hazardCheckCount',data.data);
					}else if(this.form.checkCategory==2){//专项检查
						 this.$set(this.form.checkHazardInfoVoList[indexAll].checkHazardDtoList[index],'hazardCheckCount',data.data);
					}

				}
			},

			  //根据id查找元素
			getTreeName(list,id){
			   let _this=this
			  for (let i = 0; i < list.length; i++) {
				let a=list[i]
				if(a.id===id){
				  return a
				}else{
				  if(a.children && a.children.length>0){
					let res=_this.getTreeName(a.children,id)
					if(res){
					  return res
					}
				  }
				}
			  }
			},
			onnodeclick(node) {

			},
            // 图片上传
            selectImage(item) {
                let self = this;
                if(item.uploadDtoList.length>4){
                    uni.showToast({
                        title: '最多上传5张图片',
                        icon:"none",
                        mask:true,
                        duration: 2000
                    });
                    return
                }
                wx.chooseImage({
                    count: 1,
                    sizeType: ["original", "compressed"],
                    sourceType: ["album", "camera"],
                    success: function(res) {
                        let tempFilePaths = res.tempFilePaths[0];
                        self.uploadImg(tempFilePaths,item);
                    }
                });
            },
            async uploadImg(tempFilePaths,item){
                var self = this;
                uni.showLoading({
                    title: '上传中',
                    mask: true
                });
                uni.uploadFile({
                    url: config.base_url+'/base/file/upload', //仅为示例，非真实的接口地址
                    header:{'Authorization':uni.getStorageSync('token')},
                    filePath: tempFilePaths,
                    name: 'file',
                    formData: {
                        'user': 'test'
                    },
                    success: (uploadFileRes) => {
                        let res = JSON.parse(uploadFileRes.data);
						if(res.code == 200){
							item.uploadDtoList.push({'fileUrl':res.data.url,'fileName':res.data.name});
						}else{
							uni.showToast({
								title: res.msg,
								icon:"none",
								mask:true,
								duration: 2000
							});
						}
                    },
                    fail: err => {},
                    complete: () => {
                        uni.hideLoading()
                    }
                });
            },
            //删除图片
            delImg(item,index,minIndex){
				if(this.form.checkCategory==1){//综合检查
				 this.form.checkHazardDtoList[index].uploadDtoList.splice(minIndex,1);
				}else if(this.form.checkCategory==2){//专项检查
					item.uploadDtoList.splice(minIndex,1);
				}

				this.$forceUpdate();
			},
            //添加隐患
            addDanger(item){

				if(this.form.checkCategory==1){//综合检查
					if(this.form.checkHazardDtoList.length>19){
						uni.showToast({
							title: '最多添加20个隐患',
							icon:"none",
							mask:true,
							duration: 2000
						});
						return
					}
					let obj = {
						voiceRemark:[],//语音备忘存储
						hazardLevel:2,//隐患等级
						hazardCheckCode:'', //检查项目code序号
						hazardCheckName:'', //检查项目名称
						hazardCheckPro:'', //最后一级的id
						hazardCheckPoint:'',// 检查要点
						hazardDescribe:'', //隐患描述
						uploadDtoList:[],//隐患照片
					}
					this.form.checkHazardDtoList.push(obj);
				}else if(this.form.checkCategory==2){//专项检查
					let obj = {
						checkFlag:0,
						voiceRemark:[],//语音备忘存储
						hazardLevel:2,//隐患等级
						hazardCheckCode:'', //检查项目code序号
						hazardCheckName:'', //检查项目名称
						hazardCheckPro:'', //最后一级的id
						hazardDescribe:'', //隐患描述
						uploadDtoList:[],//隐患照片
					}
					item.checkHazardDtoList.push(obj);
				}

				this.getCheckOptionList();
				this.$forceUpdate();
            },
			//新增检查内容
			addDeviceDanger(){
				uni.navigateTo({
					url: '/pages_safetyExamine/examineManage/examineAddContent?form='+encodeURIComponent(JSON.stringify(this.form))
				});
			},
			//删除隐患
			delDetailsList(index,index2,type){//type 1综合检查 2专项检查设备项 3专项检查检查项
				 if(this.form.checkCategory==1){//综合检查
					 this.hiddenDangerIdList.push(this.form.checkHazardDtoList[index].id)
					 this.form.checkHazardDtoList.splice(index,1);
				 }else if(this.form.checkCategory==2){//专项检查
					if(type==2){//检查设备
					 this.form.checkHazardInfoVoList.splice(index,1);
					 }else if(type==3){//检查项
					  this.form.checkHazardInfoVoList[index2].checkHazardDtoList.splice(index,1);
					}
				 }
				 this.$forceUpdate();

			},
            //子页面切换
            goMinButton(index){
				let self = this;
				if(index == 0){

					if(this.form.checkCategory==1){//综合检查
						uni.redirectTo({
						    url: '/pages_safetyExamine/examineManage/examineAdd?form='+encodeURIComponent(JSON.stringify(this.form))
						});
					}else if(this.form.checkCategory==2){//专项检查
						if(!this.form.isCustom){
							this.form.checkHazardInfoVoList=[];
						}
						uni.redirectTo({
						    url: '/pages_safetyExamine/examineManage/examineAdd?form='+encodeURIComponent(JSON.stringify(this.form))
						});
					}
				}else if(index == 1 || index == 2){
					this.form.manageStatus=index;//1保存 2提交
					if(this.form.checkCategory==1){//综合检查
						console.log(self.form.checkHazardDtoList)
						if(self.form.checkHazardDtoList[0]){
							for(let i=0;i<self.form.checkHazardDtoList.length;i++){
								let num = i+1;
								if(!self.form.checkHazardDtoList[i].hazardCheckName){
									uni.showToast({
										title: '第'+num+'未选择隐患项',
										icon:"none",
										mask:true,
										duration: 2000
									});
									return
								}else if(!self.form.checkHazardDtoList[i].hazardDescribe && self.form.checkHazardDtoList[i].voiceRemark.length<=0){
									uni.showToast({
										title: '请输入第'+num+'项隐患描述!',
										icon:"none",
										mask:true,
										duration: 2000
									});
									return
								}else if(self.form.checkHazardDtoList[i].uploadDtoList.length<=0){
									uni.showToast({
										title: '请输入第'+num+'项隐患图片!',
										icon:"none",
										mask:true,
										duration: 2000
									});
									return
								}
							}
						}else{
							uni.showToast({
								title: '请添加隐患项',
								icon:"none",
								mask:true,
								duration: 2000
							});
							return
						}

					}else if(this.form.checkCategory==2){//专项检查

						for(let k=0;k<self.form.checkHazardInfoVoList.length;k++){
							for(let i=0;i<self.form.checkHazardInfoVoList[k].checkHazardDtoList.length;i++){
								let num = i+1;
								if(self.form.checkHazardInfoVoList[k].checkHazardDtoList[i].checkFlag==1){//符合
									if(!self.form.checkHazardInfoVoList[k].checkHazardDtoList[i].hazardCheckName){
										uni.showToast({
											title: '第'+num+'未选择隐患项',
											icon:"none",
											mask:true,
											duration: 2000
										});
										return
									}
								}else{
									if(!self.form.checkHazardInfoVoList[k].checkHazardDtoList[i].hazardCheckName){
										uni.showToast({
											title: '第'+num+'未选择隐患项',
											icon:"none",
											mask:true,
											duration: 2000
										});
										return
									}else if(!self.form.checkHazardInfoVoList[k].checkHazardDtoList[i].hazardDescribe && self.form.checkHazardInfoVoList[k].checkHazardDtoList[i].voiceRemark.length<=0){
										uni.showToast({
											title: '请输入第'+num+'项隐患描述!',
											icon:"none",
											mask:true,
											duration: 2000
										});
										return
									}else if(self.form.checkHazardInfoVoList[k].checkHazardDtoList[i].uploadDtoList.length<=0){
										uni.showToast({
											title: '请输入第'+num+'项隐患图片!',
											icon:"none",
											mask:true,
											duration: 2000
										});
										return
									}
								}

							}
						}

					}


					this.submitForm();
				}
            },
			//提交
			async submitForm(){
				let self = this;
				let obj=JSON.parse(JSON.stringify(self.form));

				if(this.form.checkCategory==1){//综合检查
					//语音备注JSON对象转字符串
					for(let i=0;i<obj.checkHazardDtoList.length;i++){
						if(obj.checkHazardDtoList[i].voiceRemark){
							obj.checkHazardDtoList[i].voiceRemark=JSON.stringify(obj.checkHazardDtoList[i].voiceRemark)
						}
					}
					for(let i=0;i<obj.checkHazardDtoList.length;i++){
						obj.checkHazardDtoList[i].checkCategory=this.form.checkCategory;
					}
				}else if(this.form.checkCategory==2){//专项检查
					let list=[]
					let checkFlagList=[];
					let hazardIds=[];
					let joinHazardIds=[];
					for(let i=0;i<this.form.checkHazardInfoVoList.length;i++){
					  hazardIds.push(this.form.checkHazardInfoVoList[i].hazardId)
					  joinHazardIds.push(this.form.checkHazardInfoVoList[i].joinHazardId)
					  for(let b=0;b<this.form.checkHazardInfoVoList[i].checkHazardDtoList.length;b++){
						checkFlagList.push(this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].checkFlag)
						//语音备注JSON对象转字符串
						if(this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].voiceRemark){
							this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].voiceRemark=JSON.stringify(this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].voiceRemark)
						}
						let obj2={
						  checkFlag:this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].checkFlag,
						  checkCategory:this.form.checkCategory,
						  hazardCheckCode:this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].hazardCheckCode,
						  hazardCheckName:this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].hazardCheckName,
						  hazardCheckPro:this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].hazardCheckPro,
						  hazardDescribe:this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].hazardDescribe,
						  hazardLevel:this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].hazardLevel,
						  uploadDtoList:this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].uploadDtoList,
						  voiceRemark:this.form.checkHazardInfoVoList[i].checkHazardDtoList[b].voiceRemark,
						  code:this.form.checkHazardInfoVoList[i].code,
						  hazardId:this.form.checkHazardInfoVoList[i].hazardId,
						  hazardName:this.form.checkHazardInfoVoList[i].hazardName,
						  hazardTypeMode:this.form.checkHazardInfoVoList[i].hazardTypeMode,
						  hazardTypeModeName:this.form.checkHazardInfoVoList[i].hazardTypeModeName,
						  joinHazardId:this.form.checkHazardInfoVoList[i].joinHazardId,
						}
						list.push(obj2)
					  }
					}
					if(hazardIds[0]){
						obj.hazardIds=hazardIds.join(',')
						obj.joinHazardIds=joinHazardIds.join(',')
					}
					if(checkFlagList.every(item=>{return item==1})){//符合
					  obj.checkResult=1;
					}else{//不符合
					  obj.checkResult=0;
					}
					obj.checkHazardDtoList=list;
				}
				if(self.form.id){
					const {data} = await checkManageUpdate(obj);
					if(data.code == 200){
						uni.showToast({
							title: '提交成功',
							icon:"none",
							mask:true,
							duration: 2000
						});
						uni.redirectTo({
						    url: '/pages_safetyExamine/examineManage/examineList?pageType='+this.form.checkType
						});
					}
				}else{
					const {data} = await checkManageAdd(obj);
					if(data.code == 200){
						uni.showToast({
							title: '提交成功',
							icon:"none",
							mask:true,
							duration: 2000
						});
						uni.redirectTo({
						    url: '/pages_safetyExamine/examineManage/examineList?pageType='+this.form.checkType
						});
					}
				}
			  },


        }

	}
</script>

<style lang="stylus" scoped>
    #startChecking{
		height:100%;
		.info-max-box{
			flex: 1;
			overflow: scroll;
			padding: 20rpx 0rpx 128rpx;
			box-sizing: border-box;
		}
		.list{
			.title{
				width: 690rpx;
				height: 100rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				margin: 20rpx 30rpx;
				font-size: 30rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 100rpx;
				padding-left: 24rpx;
				box-sizing: border-box;
			}
			.check-for-big-box{
				width 690rpx;
				//padding-top:30rpx;
				margin:0 30rpx 20rpx;
				background #fff
				border-radius:20rpx;
				overflow hidden
				position relative;
				padding:30rpx;
				box-sizing border-box;
				/* 隐患等级 */
				.grade{
					display: flex;
					justify-content: flex-start;
					.grade_l{
						width: 158rpx;
						text-align: left;
						font-size: 30rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 80rpx;
					}
					.grade_r{
						width: 480rpx;
						height: 80rpx;
						border-radius: 10rpx;
						border: 1rpx solid #E0E0E0;
						display: flex;
						justify-content: flex-start;
						align-items: center;
						padding-left: 20rpx;
						box-sizing: border-box;
						>view{
							flex:1;
							line-height:80rpx;
							font-size: 30rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 400;
							color: #333333;
							line-height: 80rpx;
						}
						>img{
							width: 14rpx;
							height: 8rpx;
							margin-right: 30rpx;
						}
					}
				}
				/* 检查项目 */
				.project{
					.project_l{
						width: 158rpx;
						text-align: left;
						font-size: 30rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 80rpx;
						margin-top: 24rpx;
					}
					.project_r{
						width: 630rpx;
						min-height: 80rpx;
						border-radius: 10rpx;
						border: 1rpx solid #E0E0E0;
						display: flex;
						justify-content: flex-start;
						align-items: center;
						padding-left: 20rpx;
						box-sizing: border-box;
					}
				}
				/* 检查要点 */
				.point{
					.point_l{
						width: 158rpx;
						text-align: left;
						font-size: 30rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 80rpx;
					}
					.point_r{
						width: 630rpx;
						height: 158rpx;
						border-radius: 20rpx 20rpx 20rpx 20rpx;
						opacity: 1;
						border: 1rpx solid #E0E0E0;
						padding: 20rpx 14rpx;
						box-sizing: border-box;
						font-size: 30rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 34rpx;
					}
				}
				/* 隐患描述 */
				.check-for-input-max-box{
					.left-title-p{
						width:150rpx;
						line-height:80rpx;
						text-align right
						font-size:30rpx;
					}
					textarea{
						width: 630rpx;
						height: 158rpx;
						border-radius: 20rpx 20rpx 20rpx 20rpx;
						border: 1rpx solid #E0E0E0;
						padding: 20rpx 14rpx;
						box-sizing: border-box;
						font-size: 30rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 34rpx;
					}
				}
				/* 隐患照片 */
				.check-for-img-max-box{
					.left-title-p{
						width: 100%;
						text-align: left;
						font-size: 30rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 80rpx;
					}
					.right-img-box{
						.img-box{
							display inline-block;
							height:180rpx;
							width:180rpx;
							position relative
							margin:0 14rpx 20rpx 0;
							border-radius 10rpx;
							overflow hidden;
							.img-data{
								height:180rpx;
								width:180rpx;
							}
							.position-img{
								position absolute
								right:0;
								top:0;
								width:36rpx;
								height:36rpx;
							}
						}
						.img-box:nth-of-type(3n+3){
							margin-right: 0rpx;
						}
						.add-button{
							 margin:0 20rpx 20rpx 0;
							border-radius 10rpx;
							overflow hidden;
							display inline-block
							height:180rpx;
							width:180rpx;
						}
					}
				}

				/* 语音备注 */
				.voice{
					.voice_t{
						height: 80rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;
						.voice_t_l{
							font-size: 30rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 400;
							color: #333333;
							line-height: 80rpx;
						}
						.voice_t_r{
							width: 170rpx;
							height: 50rpx;
						}
					}
					.voice_b{
						display flex;
						justify-content flex-start;
						align-items center;
						margin-bottom :30rpx;
						.voice_b_l{
							width: 400rpx;
							height: 40rpx;
							background:rgba(88,175,255,0.3);
							border-radius: 10rpx;
							display flex;
							justify-content flex-start;
							align-items center;
							>img{
								width: 18rpx;
								height: 24rpx;
								margin-left:16rpx;
								margin-right :20rpx;
							}
						}
						.voice_b_r{
							width: 28rpx;
							height: 28rpx;
							margin-left:20rpx;
						}
					}
				}
				.check-for-button-max-box{
					display flex
					margin-top:30rpx;
					margin-bottom:20rpx;
					.left-title-p{
						width:150rpx;
						line-height:88rpx;
						text-align right
						font-size:30rpx;
					}
					.button-text-p{
						border:1rpx solid #E0E0E0;
						width:440rpx;
						height:80rpx;
						border-radius:10rpx;
						line-height :80rpx;
						color: #A2A2A2
						padding:0 20rpx;
						font-size:28rpx;
						display:block;
						overflow:hidden;
						text-overflow:ellipsis;
						white-space:nowrap;
					}
				}
				.check-for-big-box-position-img-box{
					position absolute
					top:0;
					right:0;
					width:60rpx;
					height:60rpx;
					img{
						width:36rpx;
						height:36rpx;
						margin:12rpx;
					}
				}
			}
			/* 添加隐患项 */
			.add-for-item-p{
				width:690rpx;
				height:100rpx;
				border:4rpx dashed #0183FA;
				font-size: 30rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #0183FA;
				line-height: 100rpx;
				text-align center;
				border-radius:20rpx;
				margin:40rpx auto 100rpx;
		    }
		}
		/* 专项检查 */
		.inconformity_tow{
			width: 690rpx;
			height: 100rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin: 20rpx 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 30rpx;
			box-sizing: border-box;
			>text{
				flex: 1;
				font-size: 30rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 100rpx;
				text-align: left;
			}
			.unfold{
				>img{
					width: 30rpx;
					height: 26rpx;
					margin-left: 20rpx;
				}
			}
			>img{
				width: 30rpx;
				height: 26rpx;
				margin-left: 20rpx;
			}

		}
		.danger_border{
			border-radius: 20rpx;
			width: 690rpx;
			background: #FFFFFF;
			margin: 0rpx 30rpx 20rpx;
			overflow: hidden;
		}
		.special_danger{
			width:auto;
			background: #FFFFFF;
			padding: 0;
			box-sizing: border-box;
			border-radius: 0;
			.grade_title{
				height: 80rpx;
				display: flex;
				justify-content: space-between;
				border-bottom: 1rpx solid #D8D8D8;
				position: relative;
				background: #F5F5F5;
				border-radius: 20rpx 20rpx 0rpx 0rpx;
				.sort{
					width: 40rpx;
					height: 40rpx;
					background: #0183FA;
					border-radius: 20rpx 0rpx 10rpx 0rpx;
					font-size: 30rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 40rpx;
					text-align: center;
					position: absolute;
					left: 0;
					top: 0;
				}
				>text:nth-of-type(1){
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 400;
					color: #666666;
					line-height: 80rpx;
					width: 140rpx;
					margin-left: 66rpx;
				}
				.Flag{
					flex: 1;
					>img{
						width: 120rpx;
						height: 40rpx;
						margin-top: 20rpx;
					}
				}
				.isConform{
					width: 100rpx;
					height: 40rpx;
					font-size: 24rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 400;
					color: #0183FA;
					line-height: 36rpx;
					background: #C4DEF6;
					text-align: center;
					border-radius:20rpx;
					margin-left: 12rpx;
					margin-top: 20rpx;
				}
				.itemDelete{
					width: 30rpx;
					height: 30rpx;
					margin-right: 62rpx;
					margin-top: 24rpx;
					margin-left: 188rpx;
				}
				.noConform{
					width: 100rpx;
					height: 40rpx;
					font-size: 24rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 400;
					color: #FF0000;
					line-height: 36rpx;
					background: #F7C4C4;
					text-align: center;
					border-radius:20rpx;
					margin-left: 12rpx;
					margin-top: 20rpx;
				}

			}
			.special_project{
				min-height: 158rpx;
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 40rpx;
				padding: 20rpx 14rpx;
				box-sizing: border-box;
				border-radius: 0rpx 0rpx 20rpx 20rpx;
				opacity: 1;
				border: 1rpx solid #E0E0E0;
				border-top:none;
				margin-bottom: 20rpx;
				.special_project_n{

				}
			}
		}
		.ident{
			font-size: 30rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 400;
			color: #666666;
			line-height: 42rpx;
			margin-bottom: 34rpx;
		}
		.add_content{
			width:690rpx;
			height:100rpx;
			border:4rpx dashed #0183FA;
			font-size: 30rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 400;
			color: #0183FA;
			line-height: 100rpx;
			text-align center;
			border-radius:20rpx;
			margin:40rpx auto 100rpx;
		}
		.bottom_btn{
			width: 690rpx;
			height: 90rpx;
			background: #0183FA;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			display: flex;
			justify-content: flex-start;
			position: fixed;
			left: 30rpx;
			bottom: 20rpx;
			.bottom_btn_li{
				flex: 1;
				font-size: 30rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 90rpx;
				text-align: center;
				position: relative;
			}
			.bottom_btn_li::after{
				content:'';
				position: absolute;
				top: 20rpx;
				right:0rpx;
				width: 1rpx;
				height: 60rpx;
				background: #D8D8D8;
			}
			.bottom_btn_li:nth-of-type(3)::after{
				display: none;
			}
		}
		.dangerCount{
			font-size: 26rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 26rpx;
			text-align: right;
			margin-bottom: 20rpx;
			>text{
				color: #FF0000;
			}
		}
	}

</style>
