<template>
	<view>
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">隐患整改</block>
		</cu-custom>
		<scroll-view scroll-y>
			<view class="wui-form-list">
        <view class="cu-form-group">
          <view class="title">
            <text>隐患描述</text>
          </view>
          <view>
            <text>{{pd.HIDDENDESCR}}</text>
          </view>
        </view>
				<view class="cu-form-group">
					<view class="title">
						<text>隐患来源</text>
					</view>
					<view>
            <text v-if="pd.SOURCE=='1'">隐患快报</text>
            <text v-if="pd.SOURCE=='2'">风险管控清单检查</text>
            <text v-if="pd.SOURCE=='3'">风险管控清单检查</text>
            <text v-if="pd.SOURCE=='4'">安全检查</text>
            <text v-if="pd.SOURCE=='5'">安全检查</text>
            <text v-if="pd.SOURCE=='6'">消防管理检查(app端)</text>
					</view>
				</view>
				<view class="cu-form-group" v-if="pd.SOURCE==2">
					<view class="title">
						<text>风险点（单元）</text>
					</view>
					<view>
						<text>{{pd.RISK_UNIT}}</text>
					</view>
				</view>
				<view class="cu-form-group bb-default" v-if="pd.SOURCE==2">
					<view class="title">
						<text>辨识部位</text>
					</view>
					<view style="flex: 1;padding: 20upx 0;">
						<text>{{pd.IDENTIFICATION}}</text>
					</view>
				</view>
				<view class="cu-form-textarea" v-if="pd.SOURCE==2">
					<view class="title">
						<text>存在风险</text>
					</view>
					<view class="cu-form-p">
						<text>{{pd.RISK_DESCR}}</text>
					</view>
				</view>
				<view class="cu-form-group bb-default" v-if="pd.SOURCE==2">
					<view class="title">
						<text>风险分级</text>
					</view>
					<view>
						<text>{{pd.LEVEL}}</text>
					</view>
				</view>
				<view class="cu-form-textarea" v-if="pd.SOURCE==2">
					<view class="title">
						<text>检查内容</text>
					</view>
					<view class="cu-form-p">
						<text>{{pd.CHECK_CONTENT}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>隐患部位</text>
					</view>
					<view>
						<text>{{pd.HIDDENPART}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>发现人</text>
					</view>
					<view>
						<text>{{pd.CREATORNAME}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>发现时间</text>
					</view>
					<view>
						<text>{{pd.CREATTIME}}</text>
					</view>
				</view>

				<view class="cu-form-group">
					<view class="title">
						<text>隐患级别</text>
					</view>
					<view>
						<text>{{pd.HIDDENLEVELNAME}}</text>
					</view>
				</view>
        <view v-if="pd.HIDDEN_CATEGORY && pd.HIDDEN_CATEGORY !== ''" class="cu-form-group">
          <view class="title">
            <text>隐患类别</text>
          </view>
          <view>
            <text>{{pd.HIDDEN_CATEGORY_NAME}}</text>
          </view>
        </view>
				<view class="cu-form-group">
					<view class="title">
						<text>隐患类型</text>
					</view>
					<view>
						<text>{{pd.HIDDENTYPE_NAME}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>整改类型</text>
					</view>
					<view>
						<text v-if="pd.RECTIFICATIONTYPE=='1'">立即整改</text>
						<text v-else-if="pd.RECTIFICATIONTYPE=='2'">限期整改</text>
					</view>
				</view>
				<view v-if="pd.RECTIFICATIONTYPE=='2'" class="cu-form-group bb-default">
					<view class="title">
						<text>整改期限</text>
					</view>
					<view>
						<text>{{pd.RECTIFICATIONDEADLINE}}</text>
					</view>
				</view>
				<view class="cu-form-textarea">
					<view class="title">
						<text>隐患照片</text>
					</view>
					<view class="cu-form-p">
						<scroll-view scroll-x class="bg-white nav" scroll-with-animation>
							<view class="cu-item" v-for="(item,index) in files" v-bind:key="index">
								<view class="imgs">
									<image :src="baseImgPath+item.FILEPATH" :data-index="index" @click="ViewShowImage"
										mode=""></image>
								</view>
							</view>
						</scroll-view>
					</view>
				</view>
        <view class="de-item-sp" v-if="videoList.length>0">
          <view class="de-sub-title">
            <text class="text-grey">隐患视频</text>
          </view>
          <view class="de-sub-content" style="background-color: #000;width: 120upx;">
            <image src="/static/icon-apps/video.png" mode="aspectFill" @click="playVideo"
                   :data-src="baseImgPath + videoList[0].FILEPATH"
                   style="width: 120upx;height: 120upx;"></image>
          </view>
        </view>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">是否正常整改</view>
				<radio-group class="selected">
					<view class="group mr20">
						<radio class='radio' value="1" :checked="IS_NORMAL=='1'" @click="radioNormal('1')"></radio>
						<text>是</text>
					</view>
					<view class="group">
						<radio class='radio' value="0" :checked="IS_NORMAL=='2'" @click="radioNormal('2')"></radio>
						<text>否</text>
					</view>
				</radio-group>
			</view>
			<view class="cu-form-group margin-top" v-if="IS_NORMAL=='2'">
				<view class="title">整改部门</view>
				<view class="picker-tree-box">
					<view class="picker-tree" @tap="showZgTree">
						{{pd.RECTIFICATIONDEPTNAME?pd.RECTIFICATIONDEPTNAME:'请选择'}}</view>
				</view>
				<tki-tree ref="tkiTree" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm">
				</tki-tree>
			</view>
			<view class="cu-form-group margin-top" v-if="IS_NORMAL=='2'">
				<view class="title">整改责任人</view>
				<picker @change="PickerZgr" :value="uindex" :range="rectificationUserList" range-key="NAME">
					<view class="picker">
						{{pd.RECTIFICATIONORNAME?pd.RECTIFICATIONORNAME:'请选择'}}
					</view>
				</picker>
			</view>

			<view class="wui-form-list" v-if="IS_NORMAL=='1'">
				<view class="wui-sub-title">
					<text>隐患整改</text>
				</view>
				<view class="cu-form-textarea">
					<view class="cu-form-title">
            隐患整改描述
<!--            <button class="cu-btn bg-green sm reg-btn" @click="library = true">选择其它</button>-->
          </view>
					<textarea :value="RECTIFYDESCR" maxlength="-1" @input="textareaAInput" placeholder="请对隐患整改进行详细描述(必填项)"></textarea>
				</view>
				<view class="cu-form-group bb-default">
					<view class="title">整改日期</view>
					<picker mode="date" :value="RECTIFICATIONTIME" start="2015-09-01" @change="changeDate">
						<view class="picker">
							{{RECTIFICATIONTIME==''?'请选择':RECTIFICATIONTIME}}
						</view>
					</picker>
				</view>
				<view class="cu-bar bg-white">
					<view class="action" style="font-size: 28upx; font-weight: bold; color: #000;">
						整改后照片
					</view>
					<view class="action">
						{{imgList.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 imgList" :key="index" @tap="ViewImage"
							:data-url="imgList[index]">
							<image :src="imgList[index]" mode="aspectFill"></image>
							<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
								<text class='cuIcon-close'></text>
							</view>
						</view>
						<view class="solids" @tap.stop="openAuth('CAMERA')" v-if="imgList.length<4">
							<text class='cuIcon-cameraadd'></text>
						</view>
					</view>
				</view>
				<view class="add_pard_box" v-if="pd.HIDDENLEVEL=='hiddenLevel0001'">
					<view class="add_pard_btns">
						<view class="add_pard_b">
							<button class="cu-btn round bg-blue" @click="addOther">添加</button>
						</view>
					</view>
					<view class="add_pard_item" v-for="(item,index) of other">
						<view class="add_pard_del" v-if="index>0" @click="removeOther(index)">
							<text class="cuIcon-roundclosefill text-red f40"></text>
						</view>
						<view class="cu-form-group">
							<view class="title">验收部门</view>
							<view class="picker-tree-box">
								<view class="picker-tree" @tap="showYsTree(index)">
									{{other[index].DEPARTMENT_NAME || '请选择'}}
                </view>
							</view>
							<tki-tree :ref="'tkiTree'+index" :selectParent=true :range="treeNode" rangeKey="name"
								@confirm="ystreeConfirm($event,index)"></tki-tree>
						</view>
						<view class="cu-form-group">
							<view class="title">验收部门负责人</view>
							<picker @change="PickerYsr($event,index)" :value="other[index].index"
								@click="haveUser(otherUserList[index])"
								:disabled="otherUserList[index] ==null || otherUserList[index].length==0"
								:range="otherUserList[index]" range-key="NAME">
								<view class="picker">
                  {{other[index].USER_NAME || '请选择'}}
                </view>
							</picker>
						</view>
					</view>
				</view>
				<view class="add_pard_box" v-if="pd.HIDDENLEVEL=='hiddenLevel0002'">
					<view class="add_pard_item">
						<view class="cu-form-group">
							<view class="title">验收部门</view>
							<view class="picker">
								{{deppd.NAME}}
							</view>
						</view>
						<view class="cu-form-group">
							<view class="title">验收部门负责人</view>
							<view class="picker">
								{{userpd.USERNAME}}
							</view>
						</view>
					</view>
				</view>
        <view class="cu-form-group">
          <view class="title">是否有整改方案</view>
          <radio-group class="selected">
            <view class="group mr20">
              <radio class='radio' value="1" :checked="HAVESCHEME==='1'" @click="radio('1')"></radio>
              <text>是</text>
            </view>
            <view class="group">
              <radio class='radio' value="0" :checked="HAVESCHEME==='0'" @click="radio('0')"></radio>
              <text>否</text>
            </view>
          </radio-group>
        </view>
				<view class="cu-form-group" v-if="HAVESCHEME=='1'">
					<view class="title">
						<text>排查日期</text>
					</view>
					<view>
						<text>{{pd.CREATTIME}}</text>
					</view>
				</view>
				<view class="cu-form-group bb-default" v-if="HAVESCHEME=='1'">
					<view class="title">
						<text>隐患清单</text>
					</view>
					<view>
						<text>{{pd.LIST_NAME}}</text>
					</view>
				</view>

				<view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
					<view class="cu-form-title">治理标准</view>
					<textarea maxlength="-1" v-model="pd.GOVERNSTANDARDS" placeholder="请输入治理标准"></textarea>
				</view>
				<view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
					<view class="cu-form-title">治理方法</view>
					<textarea maxlength="-1" v-model="pd.GOVERNMETHOD" placeholder="请输入治理方法"></textarea>
				</view>
				<view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
					<view class="cu-form-title">经费落实</view>
					<textarea maxlength="-1" v-model="pd.EXPENDITURE" placeholder="请输入经费落实"></textarea>
				</view>
				<view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
					<view class="cu-form-title">负责人员</view>
					<textarea maxlength="-1" v-model="pd.PRINCIPAL" placeholder="请输入负责人员"></textarea>
				</view>
				<view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
					<view class="cu-form-title">工时安排</view>
					<textarea maxlength="-1" v-model="pd.PROGRAMMING" placeholder="请输入工时安排"></textarea>
				</view>
				<view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
					<view class="cu-form-title">时限要求</view>
					<textarea maxlength="-1" v-model="pd.TIMELIMITFOR" placeholder="请输入时限要求"></textarea>
				</view>
				<view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
					<view class="cu-form-title">工作要求</view>
					<textarea maxlength="-1" v-model="pd.JOBREQUIREMENT" placeholder="请输入工作要求"></textarea>
				</view>
				<view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
					<view class="cu-form-title">其他事项</view>
					<textarea maxlength="-1" v-model="pd.OTHERBUSINESS" placeholder="请输入其他事项"></textarea>
				</view>
				<view class="cu-bar bg-white" v-if="HAVESCHEME=='1'">
					<view class="action" style="font-size: 28upx; font-weight: bold; color: #000;">
						方案照片
					</view>
					<view class="action">
						{{imgList_fa.length}}/4
					</view>
				</view>
				<view class="cu-form-group" v-if="HAVESCHEME=='1'">
					<view class="grid col-4 grid-square flex-sub">
						<view class="bg-img" v-for="(item,index) in imgList_fa" :key="index" @tap="ViewImage_fa"
							:data-url="imgList_fa[index]">
							<image :src="imgList_fa[index]" mode="aspectFill"></image>
							<view class="cu-tag bg-red" @tap.stop="DelImg_fa" :data-index="index">
								<text class='cuIcon-close'></text>
							</view>
						</view>
						<view class="solids" @tap.stop="openAuthFa('CAMERA')" v-if="imgList_fa.length<4">
							<text class='cuIcon-cameraadd'></text>
						</view>
					</view>
				</view>

				<view class="cu-form-group">
					<view class="title">是否有整改计划</view>
					<radio-group class="selected">
						<view class="group mr20">
							<radio class='radio' value="1" :checked="HAVEPLAN==='1'" @click="planRadio('1')"></radio>
							<text>是</text>
						</view>
						<view class="group">
							<radio class='radio' value="0" :checked="HAVEPLAN==='0'" @click="planRadio('0')"></radio>
							<text>否</text>
						</view>
					</radio-group>
				</view>
				<view class="cu-form-group" v-if="HAVEPLAN=='1'">
					<view class="grid col-4 grid-square flex-sub">
						<view class="bg-img" v-for="(item,index) in imgList_plan" :key="index" @tap="ViewImage_plan"
							  :data-url="imgList_plan[index]">
							<image :src="imgList_plan[index]" mode="aspectFill"></image>
							<view class="cu-tag bg-red" @tap.stop="DelImg_plan" :data-index="index">
								<text class='cuIcon-close'></text>
							</view>
						</view>
						<view class="solids" @tap.stop="openAuthPlan('CAMERA')" v-if="imgList_plan.length<4">
							<text class='cuIcon-cameraadd'></text>
						</view>
					</view>
				</view>

				<!--				<view class="cu-form-textarea">-->
				<!--					<l-file ref="lFile" @up-success="onSuccess"></l-file>-->
				<!--					<view class="cu-form-title">隐患描述1</view>-->
				<!--					<button @tap="onUpload">上传</button>-->
				<!--				</view>-->
			</view>

			<view class="padding flex flex-direction bf">
				<button :loading="buttonloading" class="cu-btn bg-green margin-tb-sm lg" @click="$noMultipleClicks(goSubmit)">提 交</button>
			</view>
			<view class="cu-tabbar-height"></view>
		</scroll-view>
    <view :class="['cu-modal',{'show':modalShow}]" v-if="modalShow">
      <view class="cu-dialog">
        <view class="cu-bar bg-white justify-end">
          <view class="content">播放视频</view>
          <view class="action" @tap="modalShow = false">
            <text class="cuIcon-close text-red"></text>
          </view>
        </view>
        <video :src="videoSrc" :show-fullscreen-btn="false" :autoplay="true" @fullscreenchange="fullScreenHandler"></video>
        <view class="cu-bar bg-white justify-end">
          <view class="action">
            <button class="cu-btn line-green text-green" @click="modalShow = false">关闭</button>
          </view>
        </view>
      </view>
    </view>
    <library-select :visible.sync="library" :value="pd.HIDDENPART" :name="pd.RISK_UNIT" @confirm="confirm" />

    <yk-authpup ref="authpup" type="top" @changeAuth="ChooseImage" :permissionID="permissionID"></yk-authpup>
    <yk-authpup ref="authpup_fa" type="top" @changeAuth="ChooseImage_fa" :permissionID="permissionID"></yk-authpup>
    <yk-authpup ref="authpup_plan" type="top" @changeAuth="ChooseImage_plan" :permissionID="permissionID"></yk-authpup>
	</view>
</template>

<script>
	import {
		basePath,
		corpinfoId,
		loginSession,
		loginUser,
		baseImgPath
	} from '@/common/tool.js';
	import lFile from '@/components/l-file/l-file.vue'
	import tkiTree from "@/components/select-tree/select-tree.vue"
  import LibrarySelect from "@/components/library-select/index.vue";
  import ykAuthpup from "@/components/yk-authpup/yk-authpup"
	export default {
		components: {
      LibrarySelect,
			tkiTree,
			lFile,
      ykAuthpup
		},
		data() {
			return {
        permissionID:'',
				noClick: true,
				date: '',
				RECTIFICATIONTIME: '',
				buttonloading: false,
				imgList: [],
				imgList_plan: [],
				imgList_fa: [],
				id: '',
				pd: [],
				files: [],
				RECTIFYDESCR: '',
				basePath: basePath,
				baseImgPath: baseImgPath,
				HAVESCHEME: '0',
				HAVEPLAN:'0',
				HIDDENSCHEME_ID: '',
				treeNode: [], //部门下拉数据
				uindex: -1,
				IS_NORMAL: 1,
				rectificationUserList: [],
				other: [{
					"DEPARTMENT_ID": '',
					"USER_ID": '',
					"DEPARTMENT_NAME": '',
					"USER_NAME": '',
					index: -1
				}], //其他验收部门负责人员
				otherUserList: [],
				userpd: [],
				deppd: [],
				videoList: [],
				modalShow: false,
				videoSrc: '',
				library: false,
			}
		},
		onLoad(e) {
			this.id = e.id;
			// let now = new Date();
			// this.date = formatDate(now, 'yyyy-MM-dd');

			this.getData();
			this.getDept();

			loginSession();



		},
		// filters: {
		// 	formatDate(time) {
		// 		time = time * 1
		// 		let date = new Date(time)
		// 		return formatDate(date, 'yyyy-MM-dd hh:mm')
		// 	}
		// },
		methods: {
      fullScreenHandler(e) {
        if (uni.getSystemInfoSync().platform == "ios") { return }
      },
			getData() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/hidden/goEdit',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						HIDDEN_ID: _this.id,
            CORPINFO_ID:loginUser.CORPINFO_ID,
            USER_ID:loginUser.USER_ID,
					},
					success: (res) => {
						if ("success" == res.data.result) {
							uni.hideLoading();
							_this.pd = res.data.pd; //参数map
              console.log(_this.pd);
              if (_this.pd.HIDDENLEVEL == 'hiddenLevel0002') {
								_this.getqyData();
							}
							if (_this.pd.ISCONFIRM == '1') {
								_this.HAVESCHEME = '1'
							}
              for (let i = 0; i < res.data.hImgs.length; i++) {
                // if(res.data.hImgs[i].FILEPATH.substring(res.data.hImgs[i].FILEPATH.lastIndexOf(".") + 1, res.data.hImgs[i].FILEPATH.length) === 'mp4'){
                //   _this.videoList.push(res.data.hImgs[i])
                // }else {
                  _this.files.push(res.data.hImgs[i])
                // }
              }
              _this.videoList =res.data.hiddenVideo
							// _this.files = res.data.hImgs;
							_this.other[0].DEPARTMENT_ID=_this.pd.HIDDENFINDDEPT;
							_this.other[0].DEPARTMENT_NAME=_this.pd.HIDDENFINDDEPTNAME;
							_this.other[0].USER_ID=_this.pd.CREATOR;
							_this.other[0].USER_NAME=_this.pd.CREATORNAME;
							this.getUserList(this.other[0].DEPARTMENT_ID,0);
							this.$forceUpdate();//强制刷新
						} else if ("exception" == data.result) {
							uni.showToast({
								title: '错误',
								duration: 2000
							});
						}
					}
				});
			},
			getqyData() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/corpinfo/goqyzzh',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
            CORPINFO_ID:loginUser.CORPINFO_ID,
            USER_ID:loginUser.USER_ID,
					},
					success: (res) => {
						if ("success" == res.data.result) {
							uni.hideLoading();
							_this.userpd = res.data.userpd; //参数map
							_this.deppd = res.data.deppd; //参数map
							console.log(_this.pd.HIDDENLEVEL)
							if (_this.pd.HIDDENLEVEL == 'hiddenLevel0002') {
								_this.other[0].DEPARTMENT_ID = res.data.deppd.DEPARTMENT_ID;
								_this.other[0].DEPARTMENT_NAME = res.data.deppd.NAME;
								_this.other[0].USER_ID = res.data.userpd.USER_ID;
								_this.other[0].USER_NAME = res.data.userpd.USERNAME;


								console.log(_this.other)
							}
						} else if ("exception" == data.result) {
							uni.showToast({
								title: '错误',
								duration: 2000
							});
						}
					}
				});
			},

      openAuth(permissionID){
        this.permissionID = permissionID;
        setTimeout(()=>{
          this.$refs['authpup'].open();
        },200)
      },

      openAuthFa(permissionID){
        this.permissionID = permissionID;
        setTimeout(()=>{
          this.$refs['authpup_fa'].open();
        },200)
      },

      openAuthPlan(permissionID){
        this.permissionID = permissionID;
        setTimeout(()=>{
          this.$refs['authpup_plan'].open();
        },200)
      },

			//图片上传
      ChooseImage() {
        var _this = this;
        uni.chooseImage({
          count: 4, //默认9
          sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
          sourceType: ['camera', 'album'], //从相册选择
          success: (res) => {
            if (this.imgList.length != 0) {
              this.imgList = this.imgList.concat(res.tempFilePaths)
            } else {
              this.imgList = res.tempFilePaths
            }
          }
        });
      },
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				uni.showModal({
					title: '新泰安全',
					content: '确定要删除这张图片吗？',
					cancelColor: "#000000",
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			//图片上传
      ChooseImage_fa() {
        var _this = this;
        uni.chooseImage({
          count: 4, //默认9
          sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
          sourceType: ['camera', 'album'], //从相册选择
          success: (res) => {
            if (this.imgList_fa.length != 0) {
              this.imgList_fa = this.imgList_fa.concat(res.tempFilePaths)
            } else {
              this.imgList_fa = res.tempFilePaths
            }
          }
        });
      },
			ViewImage_fa(e) {
				uni.previewImage({
					urls: this.imgList_fa,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg_fa(e) {
				uni.showModal({
					title: '新泰安全',
					content: '确定要删除这张图片吗？',
					cancelColor: "#000000",
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList_fa.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},

			//整改计划图片上传
			ChooseImage_plan() {
				var _this = this;
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera', 'album'], //从相册选择
					success: (res) => {
						if (this.imgList_plan.length != 0) {
							this.imgList_plan = this.imgList_plan.concat(res.tempFilePaths)
						} else {
							this.imgList_plan = res.tempFilePaths
						}
					}
				});
			},
			ViewImage_plan(e) {
				uni.previewImage({
					urls: this.imgList_plan,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg_plan(e) {
				uni.showModal({
					title: '新泰安全',
					content: '确定要删除这张图片吗？',
					cancelColor: "#000000",
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList_plan.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},

			textareaAInput(e) {
				this.RECTIFYDESCR = e.detail.value
			},
			async goSubmit() {
				var _this = this;
				if (_this.IS_NORMAL == 1) {
					if (!_this.RECTIFYDESCR) {
						uni.showToast({
							icon: 'none',
							title: '请填整改描述',
							duration: 1500
						});
						return;
					}
					if (!_this.RECTIFICATIONTIME) {
						uni.showToast({
							icon: 'none',
							title: '请选择整改时间',
							duration: 1500
						});
						return;
					}
					if (_this.imgList.length <= 0) {
						uni.showToast({
							icon: 'none',
							title: '请上传整改后照片',
							duration: 1500
						});
						return;
					}

					if (this.HAVESCHEME == 1) {
						if (this.pd.GOVERNSTANDARDS == '' || this.pd.GOVERNSTANDARDS == undefined) {
							uni.showToast({
								icon: 'none',
								title: '请输入治理标准要求',
								duration: 1500
							});
							return;
						}
						if (this.pd.GOVERNMETHOD == '' || this.pd.GOVERNMETHOD == undefined) {
							uni.showToast({
								icon: 'none',
								title: '请输入治理方法',
								duration: 1500
							});
							return;
						}
						if (this.pd.EXPENDITURE == '' || this.pd.EXPENDITURE == undefined) {
							uni.showToast({
								icon: 'none',
								title: '请输入经费和物资的落实',
								duration: 1500
							});
							return;
						}
						if (this.pd.PRINCIPAL == '' || this.pd.PRINCIPAL == undefined) {
							uni.showToast({
								icon: 'none',
								title: '请输入负责治理人员',
								duration: 1500
							});
							return;
						}
						if (this.pd.PROGRAMMING == '' || this.pd.PROGRAMMING == undefined) {
							uni.showToast({
								icon: 'none',
								title: '请输入工时安排',
								duration: 1500
							});
							return;
						}
						if (this.pd.TIMELIMITFOR == '' || this.pd.TIMELIMITFOR == undefined) {
							uni.showToast({
								icon: 'none',
								title: '请输入时限要求',
								duration: 1500
							});
							return;
						}
						if (this.pd.JOBREQUIREMENT == '' || this.pd.JOBREQUIREMENT == undefined) {
							uni.showToast({
								icon: 'none',
								title: '请输入工作要求',
								duration: 1500
							});
							return;
						}
						if (this.pd.OTHERBUSINESS == '' || this.pd.OTHERBUSINESS == undefined) {
							uni.showToast({
								icon: 'none',
								title: '请输入其他事项',
								duration: 1500
							});
							return;
						}
						if (_this.imgList_fa.length <= 0) {
							uni.showToast({
								icon: 'none',
								title: '请上传方案照片',
								duration: 1500
							});
							return;
						}
					}
					if(_this.HAVEPLAN == 1){
						if (_this.imgList_plan.length <= 0) {
							uni.showToast({
								icon: 'none',
								title: '请上传计划照片',
								duration: 1500
							});
							return;
						}
					}
					if (!_this.other[0].USER_ID) {
						uni.showToast({
							icon: 'none',
							title: '请添加验收部门负责人',
							duration: 1500
						});
						return;
					}


					new Promise((resolve, reject) => {
						_this.submit().then(() => {
							resolve();
						})
					}).then(() => {
						var fileList = [];
						for (var i = 0; i < _this.imgList.length; i++) {
							var file = {};
							file.type = 4;
							file.filePath = _this.imgList[i];
							file.FOREIGN_KEY = _this.id;
							fileList.push(file);
						}
						if (_this.HAVESCHEME == 1) {
							for (var i = 0; i < _this.imgList_fa.length; i++) {
								var file = {};
								file.type = 8;
								file.filePath = _this.imgList_fa[i];
								file.FOREIGN_KEY = _this.HIDDENSCHEME_ID;
								fileList.push(file);
							}
						}

						if (_this.HAVEPLAN == 1) {
							for (var i = 0; i < _this.imgList_plan.length; i++) {
								var file = {};
								file.type = 22;
								file.filePath = _this.imgList_plan[i];
								file.FOREIGN_KEY = _this.id;
								fileList.push(file);
							}
						}
						var m = 0;
						_this.uploadImg(fileList, m).then(() => {
							resolve();
						})
					}).then(() => {
						uni.showToast({
							icon: 'none',
							title: '提交成功',
							duration: 1500
						});
						setTimeout(function() {
							var pages = getCurrentPages(); // 获取当前页面栈
							var prePage = pages[pages.length - 2]; // 上一个页面
							prePage.$vm.initflag = true; // A 页面 init方法 为true
							uni.navigateBack({});
							uni.hideLoading();
						}, 1500);
					})

				} else {
					if (!_this.pd.RECTIFICATIONDEPT) {
						uni.showToast({
							icon: 'none',
							title: '请选择整改部门',
							duration: 1500
						});
						return;
					}
					if (!_this.pd.RECTIFICATIONOR) {
						uni.showToast({
							icon: 'none',
							title: '请选择整改人',
							duration: 1500
						});
						return;
					}
					uni.request({
						url: basePath + "/app/hidden/editRec", //提交接口
						method: 'POST',
						dataType: 'json',
						header: {
							'Content-type': 'application/x-www-form-urlencoded'
						},
						data: {
							RECTIFICATIONDEPT: _this.pd.RECTIFICATIONDEPT,
							RECTIFICATIONOR: _this.pd.RECTIFICATIONOR,
							HIDDEN_ID: _this.id,
							  CORPINFO_ID:loginUser.CORPINFO_ID,
							  USER_ID:loginUser.USER_ID,
						},
						success: (res) => {
							uni.hideLoading();
							if ("success" == res.data.result) {
								uni.showToast({
									icon: 'none',
									title: '提交成功',
									duration: 1500
								});
								setTimeout(function() {
									var pages = getCurrentPages(); // 获取当前页面栈
									var prePage = pages[pages.length - 2]; // 上一个页面
									prePage.$vm.initflag = true; // A 页面 init方法 为true
									uni.navigateBack({});
									uni.hideLoading();
								}, 1500);
							} else {
								uni.showToast({
									title: '错误',
									duration: 2000
								});
							}
						}
					});
				}
			},
			uploadImg(tempFilePaths, i) {
				return new Promise((resolve, reject) => {
					var _this = this;
					if (tempFilePaths.length == 0) {
						resolve();
					}
					uni.showLoading({
						title: '上传中'
					})
					uni.uploadFile({
						url: basePath + '/app/imgfiles/add',
						filePath: tempFilePaths[i].filePath,
						name: 'FFILE',

						formData: {
							'FOREIGN_KEY': tempFilePaths[i].FOREIGN_KEY,
							'TYPE': tempFilePaths[i].type,
              CORPINFO_ID: loginUser.CORPINFO_ID,
              USER_ID: loginUser.USER_ID,
						},
						success: (res) => {
							i++;
							if (tempFilePaths.length > i) {
								_this.uploadImg(tempFilePaths, i);
							} else {
								console.info("提交成功")
								uni.hideLoading();
								console.info("提交成功123")
								resolve();
							}
						},
						fail: (err) => {
							uni.hideLoading();
							uni.showModal({
								content: err.errMsg,
								showCancel: false
							});
						}
					})
				})
			},

			uploadImg_fa(tempFilePaths, i) {
				var _this = this;
				uni.showLoading({
					title: '上传中'
				})
				uni.uploadFile({
					url: basePath + '/app/imgfiles/add',
					filePath: tempFilePaths[i],
					name: 'FFILE',

					formData: {
						'FOREIGN_KEY': _this.HIDDENSCHEME_ID,
						'TYPE': '8',
            CORPINFO_ID: loginUser.CORPINFO_ID,
            USER_ID: loginUser.USER_ID,
					},
					success: (res) => {
						i++;
						if (tempFilePaths.length > i) {
							_this.uploadImg(tempFilePaths, i);
						} else {
							if (_this.HAVESCHEME == '1') {
								_this.onUpload()
							} else {
								uni.showToast({
									icon: 'none',
									title: '提交成功',
									duration: 1500
								});
								setTimeout(function() {
									var pages = getCurrentPages(); // 获取当前页面栈
									var prePage = pages[pages.length - 2]; // 上一个页面
									prePage.$vm.initflag = true; // A 页面 init方法 为true
									uni.navigateBack({});
									uni.hideLoading();
								}, 1500);
							}


						}
					},
					fail: (err) => {
						uni.hideLoading();
						console.log('uploadImage fail', err);
						uni.showModal({
							content: err.errMsg,
							showCancel: false
						});
					}
				})
			},
			submit() {
				return new Promise((resolve, reject) => {
					var _this = this;
					this.buttonloading = true
					uni.request({
						url: basePath + "/app/hidden/rectify", //提交接口
						method: 'POST',
						dataType: 'json',
						header: {
							'Content-type': 'application/x-www-form-urlencoded'
						},
						data: {
							RECTIFICATIONTIME: _this.RECTIFICATIONTIME,
							RECTIFYDESCR: _this.RECTIFYDESCR,
							HAVESCHEME: _this.HAVESCHEME,
							HAVEPLAN: _this.HAVEPLAN,
							// RECTIFICATIONDEPT:_this.pd.RECTIFICATIONDEPT,
							// RECTIFICATIONOR:_this.pd.RECTIFICATIONOR,
							HIDDEN_ID: _this.id,

							SCREENINGDATE: _this.pd.CREATTIME ? _this.pd.CREATTIME : '',
							LISTNAME: _this.pd.LIST_NAME ? _this.pd.LIST_NAME : '',
							GOVERNSTANDARDS: _this.pd.GOVERNSTANDARDS ? _this.pd.GOVERNSTANDARDS : '',
							GOVERNMETHOD: _this.pd.GOVERNMETHOD ? _this.pd.GOVERNMETHOD : '',
							EXPENDITURE: _this.pd.EXPENDITURE ? _this.pd.EXPENDITURE : '',
							PRINCIPAL: _this.pd.PRINCIPAL ? _this.pd.PRINCIPAL : '',
							PROGRAMMING: _this.pd.PROGRAMMING ? _this.pd.PROGRAMMING : '',
							TIMELIMITFOR: _this.pd.TIMELIMITFOR ? _this.pd.TIMELIMITFOR : '',
							JOBREQUIREMENT: _this.pd.JOBREQUIREMENT ? _this.pd.JOBREQUIREMENT : '',
							OTHERBUSINESS: _this.pd.OTHERBUSINESS ? _this.pd.OTHERBUSINESS : '',
							OTHER: JSON.stringify(_this.other),
							  CORPINFO_ID:loginUser.CORPINFO_ID,
							  USER_ID:loginUser.USER_ID,
						},
						success: (res) => {
							uni.hideLoading();
							this.buttonloading = false
							if ("success" == res.data.result) {
								_this.HIDDENSCHEME_ID = res.data.HIDDENSCHEME_ID
								resolve();
							} else {
								uni.showToast({
									title: '错误',
									duration: 2000
								});
								reject();
							}

						}
					});
				})
			},
			haveUser(e) {
				if (e == null || e.length == 0) {
					uni.showToast({
						icon: "none",
						title: '请先选择有人员的部门',
						duration: 2000
					});
				}
				console.info(1)
			},
			onUpload() {
				return new Promise((resolve, reject) => {
					this.$refs.lFile.upload({
						// #ifdef APP-PLUS
						// nvue页面使用时请查阅nvue获取当前webview的api，当前示例为vue窗口
						currentWebview: this.$mp.page.$getAppWebview(),
						// #endif
						//非真实地址，记得更换,调试时ios有跨域，需要后端开启跨域并且接口地址不要使用http://localhost/
						url: basePath + "/app/hidden/rectify1?HIDDENSCHEME_ID=" + this.HIDDENSCHEME_ID,
						//默认file,上传文件的key
						name: 'file',
						// header:{
						// 	'Content-type':'application/x-www-form-urlencoded'
						// },
						//...其他参数
					});
					resolve();
				})
			},
			onSuccess(res) {
				return new Promise((resolve, reject) => {
					resolve();
				})


			},
			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:loginUser.CORPINFO_ID,
						USER_ID:loginUser.USER_ID,
					},
					success: (res) => {
						if ("success" == res.data.result) {
							_this.treeNode = eval(res.data.zTreeNodes);
							// _this.other[0].DEPARTMENT_ID = loginUser.DEPARTMENT_ID;
							// _this.other[0].DEPARTMENT_NAME = loginUser.DEPARTMENT_NAME;
							// _this.other[0].USER_ID = loginUser.USER_ID;
							// _this.other[0].USER_NAME = loginUser.NAME;
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				});
			},
			// 确定回调事件
			zgtreeConfirm(e) {
				this.pd.RECTIFICATIONDEPT = e[0].id;
				this.pd.RECTIFICATIONDEPTNAME = e[0].name;
				this.uindex = -1;
				this.pd.RECTIFICATIONOR = '';
				this.pd.RECTIFICATIONORNAME = '';
				this.$forceUpdate(); //强制刷新
				this.getUserList(this.pd.RECTIFICATIONDEPT);
			},
			// 显示树形选择器
			showZgTree() {
				this.$refs.tkiTree._show();
			},

			// 确定回调事件
			ystreeConfirm(e, index) {
        console.log(e,index)
				this.other[index].DEPARTMENT_ID = e[0].id;
				this.other[index].DEPARTMENT_NAME = e[0].name;
				this.other[index].USER_ID = '';
				this.other[index].USER_NAME = '';
				this.other[index].index = -1;
				this.getUserList(this.other[index].DEPARTMENT_ID, index);
				this.$forceUpdate(); //强制刷新
			},
			// 显示树形选择器
			showYsTree(index) {
				let ref = 'tkiTree' + index;
				this.$refs['tkiTree' + index][0]._show();
			},
			//根据主键ID获取数据
			addOther: function() {
				var _this = this;
				let o = {
					"DEPARTMENT_ID": '',
					"USER_ID": '',
					"DEPARTMENT_NAME": '',
					"USER_NAME": '',
					index: -1
				};
				_this.other.push(o);
				let index = _this.other.length - 1;
				_this.otherUserList[index] = [];
			},
			removeOther: function(index) {
				this.other.splice(index, 1);
				this.otherUserList.splice(index, 1);
			},
			//获取人员列表
			getUserList(DEPARTMENT_ID, 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: DEPARTMENT_ID,
						LOGINUSERID: loginUser.USER_ID,
						NOSELF: '1',
						tm: new Date().getTime(),
						CORPINFO_ID:loginUser.CORPINFO_ID,
						USER_ID:loginUser.USER_ID,
					},
					success: function(res) {
						if ("success" == res.data.result) {
							if (i > -1) {
								_this.otherUserList[i] = [];
								_this.otherUserList[i] = res.data.userList;
								_this.$forceUpdate(); //强制刷新
							} else {
								_this.rectificationUserList = res.data.userList;
							}
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				})
			},
			PickerZgr(e) {
				this.uindex = e.detail.value;
				this.pd.RECTIFICATIONOR = this.rectificationUserList[this.uindex].USER_ID;
				this.pd.RECTIFICATIONORNAME = this.rectificationUserList[this.uindex].NAME;
				this.$forceUpdate(); //强制刷新
			},
			PickerYsr(e, index) {
				this.other[index].index = e.detail.value;
				this.other[index].USER_ID = this.otherUserList[index][e.detail.value] ? this.otherUserList[index][e.detail.value].USER_ID : '';
				this.other[index].USER_NAME = this.otherUserList[index][e.detail.value] ? this.otherUserList[index][e.detail.value].NAME : '';

        for (let i = 0; i < this.other.length; i++) {
          if (i !== index && this.other[i].USER_ID === this.otherUserList[index][e.detail.value].USER_ID) {
            uni.showToast({
              title: '不能选择重复的验收部门负责人',
              icon: 'none',
              duration: 2000
            })
            this.other[index].index = ''
            this.other[index].USER_ID = ''
            this.other[index].USER_NAME = ''
            break
          }
        }
				this.$forceUpdate(); //强制刷新
			},
			radio(e) {
				this.HAVESCHEME = e
			},
			planRadio(e) {
				this.HAVEPLAN = e
			},
			radioNormal(e) {
				this.IS_NORMAL = e
			},

			changeDate(e) {
				this.RECTIFICATIONTIME = e.detail.value
			},
			ViewShowImage(e) {
				let files = [];
				for (var i = 0; i < this.files.length; i++) {
					files.push(baseImgPath + this.files[i].FILEPATH)
				}
				uni.previewImage({
					urls: files,
					current: e.currentTarget.dataset.index
				});
			},
      playVideo(e) {
        this.videoSrc = e.currentTarget.dataset.src
        this.modalShow = true
      },
      confirm({RECTIFYDESCR}){
        this.RECTIFYDESCR = RECTIFYDESCR
      }
		}
	}
</script>

<style>


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

	.selected .radio {
		transform: scale(0.75);
		margin-right: 10upx;
	}

	.bf .cu-btn {
		border-radius: 0;
		width: 100%;
		height: 84upx;
		font-weight: bold;
	}

	.group {
		display: flex;
		align-items: center;
	}
</style>
