<template>
  <view>
    <cu-custom bgColor="bg-gradual-blueness" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">隐患整改</block>
    </cu-custom>
    <view>
      <hiddenView :hidden_id="this.id"/>
    </view>
    <view>
      <view class="wui-form-list">
        <view class="wui-sub-title">
          <text>隐患整改</text>
        </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 v-if="IS_NORMAL=='1'">
          <view class="cu-form-textarea">
            <view class="cu-form-title">
              隐患整改描述
            </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="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>
            <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-bar bg-white" v-if="HAVEPLAN=='1'">
              <view class="action" style="font-size: 28upx; font-weight: bold; color: #000;">
                整改计划照片
              </view>
              <view class="action">
                {{ imgList_plan.length }}/4
              </view>
            </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>
        </view>
        <view v-if="IS_NORMAL=='2'">
          <view class="cu-form-textarea">
            <view class="cu-form-title">无法整改原因</view>
            <textarea maxlength="-1" v-model="pd.REPULSE_CAUSE" placeholder="请输入无法整改原因"></textarea>
          </view>
          <view v-if="!CONFIRM_DEPT_HSA">
            <view class="cu-form-group margin-top">
              <view class="title">隐患确认人部门</view>
              <view class="picker-tree-box">
                <view class="picker-tree" @tap="showZgTree">
                  {{ pd.CONFIRM_DEPT_NAME ? pd.CONFIRM_DEPT_NAME : '请选择' }}
                </view>
              </view>
              <tki-tree ref="tkiTree"
                        :selectParent=true
                        :range="treeNode"
                        rangeKey="name"
                        @confirm="fnHiddenConfirmDept"
              ></tki-tree>
            </view>
            <view class="cu-form-group margin-top">
              <view class="title">隐患确认人</view>
              <view style="position: relative">
                <view class="search-input">
                  <input
                      type="text"
                      style="text-align: right"
                      v-model="searchConfirmUser"
                      placeholder="请输入确认人"
                      @input="filterConfirmUser"
                      @click="toggleConfirmDropdown"
                  >
                  <view class="search-icon" @click="toggleConfirmDropdown">
                    <text class="cuIcon-right"></text>
                  </view>
                </view>
                <view v-show="showAnalyzeDropdown" class="showbg" style="position: absolute; left: 0; top: 36px;">
                  <view
                      v-for="(user, index) in filteredConfirmUsers"
                      :key="index"
                      @click="selectConfirmUser(user)"
                  >
                    {{ user.NAME }}
                  </view>
                </view>
              </view>
            </view>
          </view>
        </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>
    <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 hiddenView from '@/components/hidden_view/index.vue';

import LibrarySelect from "@/components/library-select/index.vue";
import ykAuthpup from "@/components/yk-authpup/yk-authpup"

export default {
  components: {
    LibrarySelect,
    tkiTree,
    lFile,
    hiddenView,
    ykAuthpup
  },
  data() {
    return {
      searchConfirmUser: '',
      filteredConfirmUsers: [],
      permissionID: '',
      noClick: true,
      showAnalyzeDropdown: false,
      CONFIRM_DEPT_HSA: false,
      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: [],
      confirmUserList: [],
      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;
    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: {
    selectConfirmUser(user) {
      this.searchConfirmUser = user.NAME;
      this.pd.CONFIRM_USER = user.USER_ID;
      this.pd.CONFIRM_USER_NAME = user.NAME;
      this.showAnalyzeDropdown = false;
    },
    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'
            }
            if (_this.pd.CONFIRM_DEPT) {
              _this.CONFIRM_DEPT_HSA = true
            }
            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
            });
          }
        }
      });
    },
    filterConfirmUser() {
      console.log('filterConfirmUser')
      const query = this.searchConfirmUser.trim().toLowerCase();
      if (!query) {
        this.filteredConfirmUsers = this.confirmUserList;
        this.pd.CONFIRM_USER = '';
        this.pd.CONFIRM_USER_NAME = '';
      } else {
        this.filteredConfirmUsers = this.confirmUserList.filter(user =>
            user.NAME.toLowerCase().includes(query)
        );
      }
    },
    toggleConfirmDropdown() {
      if (!this.pd.CONFIRM_DEPT) {
        uni.showToast({
          icon: 'none',
          title: '请选择确认人部门',
          duration: 1500
        });
        return;
      }
      if (!this.confirmUserList.length) {
        uni.showToast({
          icon: 'none',
          title: '部门下无确认人',
          duration: 1500
        });
        return;
      }
      this.showAnalyzeDropdown = !this.showAnalyzeDropdown;
      if (this.showAnalyzeDropdown) this.filterConfirmUser();
    },

    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;
          }
        }
        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.REPULSE_CAUSE) {
          uni.showToast({
            icon: 'none',
            title: '请输入无法整改原因',
            duration: 1500
          });
          return;
        }
        if (!_this.pd.CONFIRM_DEPT) {
          uni.showToast({
            icon: 'none',
            title: '请选择确认部门',
            duration: 1500
          });
          return;
        }
        if (!_this.pd.CONFIRM_USER) {
          uni.showToast({
            icon: 'none',
            title: '请选择确认人',
            duration: 1500
          });
          return;
        }
        uni.request({
          url: basePath + "/app/hidden/editRecV2", //提交接口
          method: 'POST',
          dataType: 'json',
          header: {
            'Content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            CONFIRM_DEPT: _this.pd.CONFIRM_DEPT,
            CONFIRM_USER: _this.pd.CONFIRM_USER,
            REPULSE_CAUSE: _this.pd.REPULSE_CAUSE,
            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,
            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();
    },
    fnHiddenConfirmDept(e) {
      this.isUps = false;
      this.pd.CONFIRM_DEPT = e[0].id;
      this.pd.CONFIRM_DEPT_NAME = e[0].name;
      this.uindex = -1;
      this.pd.CONFIRM_USER = '';
      this.pd.CONFIRM_USER_NAME = '';
      this.pd.searchConfirmUser = '';
      this.$forceUpdate();//强制刷新
      this.getConfirmUserList();
    },
    getConfirmUserList() {
      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: _this.pd.CONFIRM_DEPT,
          tm: new Date().getTime(),
          CORPINFO_ID: loginUser.CORPINFO_ID,
          USER_ID: loginUser.USER_ID,
          ISCONFIRM: 1,
        },
        success: function (res) {
          if ("success" == res.data.result) {
            _this.confirmUserList = res.data.userList;
          } else {
            uni.showToast({
              title: res.data.message,
              duration: 2000
            });
          }
        }
      })
    },

    // 确定回调事件
    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;
}

.showbg {
  position: absolute;
  top: 45px;
  left: 0;
  background: #ffffff;
  line-height: 2.6;
  width: 100%;
  padding: 5px;
  border: 1px solid #eeeeee;
  border-radius: 4px;
  z-index: 999;
}

.search-input {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 4px;
  padding: 0 10px;
  height: 40px;
}

.search-icon {
  position: absolute;
  right: 10px;
  font-size: 18px;
  color: #666;
}

.cuIcon-right {
  position: absolute;
  right: -12px;
  top: -10px;
}
</style>
