<!--
 * @Author: zhangtq 2452618307@qq.com
 * @Date: 2024-12-05 13:22:34
 * @LastEditors: zhangtq 2452618307@qq.com
 * @LastEditTime: 2025-01-21 09:41:32
 * @FilePath: src/views/snapshot/components/transferHiddenDangerDialog.vue
 * @Description: 这是默认设置,可以在设置》工具》File Description中进行配置
 -->
<template>
  <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="90%" style="height: 99%">
    <div class="app-container" style="overflow-y: scroll;height: 82vh;">
      <div class="top-btn">
        <el-button size="small" @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" size="small" @click="handleAdd">下发</el-button>
      </div>
      <!-- 基础信息 -->
      <el-card class="box-card">
        <div slot="header" class="card-header">
          <span>基础信息</span>
        </div>
        <el-form
          :model="baseInfoForm"
          ref="baseInfoForm"
          label-width="99px"
          :rules="rules1"
          size="small"
          :disabled="userType != '00'"
        >
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="隐患问题编号" prop="pitfallCode">
                <el-input
                  v-model="baseInfoForm.pitfallCode"
                  placeholder="请输入隐患问题编号"
                  disabled v-no-whitespace
                  class="cont-width"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="检查记录编号" prop="recordCode">
                <el-input
                  v-model="baseInfoForm.recordCode"
                  placeholder="请输入检查记录编号"
                  disabled v-no-whitespace
                  class="cont-width"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="对应检查级别" prop="inspectLevelName">
                <el-input
                  v-model="baseInfoForm.inspectLevelName"
                  placeholder="请输入对应检查级别"
                  disabled v-no-whitespace
                  class="cont-width"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="排查类型" prop="checkType">
                <el-select
                  v-model="baseInfoForm.checkType"
                  placeholder="请选择排查类型"
                  class="cont-width"
                  :disabled="isDisabled"
                >
                  <el-option
                    v-for="item in checkTypeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="创建人" prop="createUserName">
                <el-input v-model="baseInfoForm.createUserName" placeholder="请输入创建人" class="cont-width" disabled  v-no-whitespace/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="创建时间">
                <el-input v-model="baseInfoForm.createTime" placeholder="请输入创建时间" class="cont-width" disabled  v-no-whitespace/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="整改接收时间" prop="rectificationReceiveTime">
                <el-input
                  v-model="baseInfoForm.rectificationReceiveTime"
                  placeholder="请输入整改接收时间"
                  disabled v-no-whitespace
                  class="cont-width"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="整改反馈时间" prop="rectificationFeedbackTime">
                <el-input
                  v-model="baseInfoForm.rectificationFeedbackTime"
                  placeholder="请输入整改反馈时间"
                  disabled v-no-whitespace
                  class="cont-width"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="整改状态" prop="rectificationStatus">
                <el-input
                  v-model="baseInfoForm.rectificationStatus"
                  placeholder="请输入整改状态"
                  disabled v-no-whitespace
                  class="cont-width"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <!-- 检查方填写 -->
      <el-card class="box-card">
        <div slot="header" class="card-header">
          <span>检查方填写</span>
        </div>
        <el-form
          :model="inspectForm"
          ref="inspectForm"
          label-width="120px"
          size="small"
          :disabled="userType != '00'"
          :rules="rules2"
        >
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="检查人" prop="checkUserId">
                <el-select
                  v-model="inspectForm.checkUserId"
                  placeholder="请选择检查人"
                  filterable
                  class="cont-width"
                  @change="changeCheckUserId"
                >
                  <el-option
                    v-for="item in inspectNameOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="发现日期" prop="findTime">
                <el-date-picker
                  v-model="inspectForm.findTime"
                  type="date"
                  placeholder="选择发现日期"
                  value-format="yyyy-MM-dd"
                  clearable
                  class="cont-width"
                  :picker-options="{
                  disabledDate(time) {
                    return time.getTime() > Date.now()
                  },
                }"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="隐患工程" prop="proId">
                <el-select
                  v-model="inspectForm.proId"
                  placeholder="请选择隐患工程"
                  disabled
                  filterable
                  class="cont-width"
                  @change="changeProId"
                >
                  <el-option
                    v-for="item in hazardProOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="整改责任承包商" prop="subValue">
                <el-select
                  v-model="inspectForm.subValue"
                  placeholder="请选择整改责任承包商"
                  class="cont-width"
                  :disabled="!inspectForm.proId"
                  filterable
                  @change="changeSubValue"
                >
                  <el-option
                    v-for="item in rectificationContractorOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="隐患问题类别" prop="pitfallTypeId">
                <el-select
                  v-model="inspectForm.pitfallTypeId"
                  placeholder="请选择隐患问题类别"
                  filterable
                  class="cont-width"
                  @change="changePitfallTypeId"
                >
                  <el-option
                    v-for="item in hazardIssueTypeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="隐患问题级别" prop="pitfallLevelId">
                <el-select
                  v-model="inspectForm.pitfallLevelId"
                  placeholder="请选择隐患问题级别"
                  filterable
                  class="cont-width"
                  @change="changePitfallLevelId"
                >
                  <el-option
                    v-for="item in hazardIssueLevelOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="期限整改时间" prop="correctionTime">
                <el-date-picker
                  v-model="inspectForm.correctionTime"
                  type="date"
                  placeholder="选择期限整改时间"
                  value-format="yyyy-MM-dd"
                  clearable
                  class="cont-width"
                  :picker-options="{
                  disabledDate(time) {
                    return time.getTime() < Date.now() - 86400000
                  },
                }"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="承包商责任人" prop="subPersonName">
                <el-input
                  v-model="inspectForm.subPersonName"
                  placeholder="请选择承包商责任人"
                  class="cont-width"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="上传图片" prop="imgList">
                <el-upload
                  action="#"
                  accept="image/*"
                  :auto-upload="false"
                  list-type="picture-card"
                  :on-change="handleUpImg"
                  :on-remove="handleRemoveImg"
                  :on-exceed="handleExceedImg"
                  :file-list="inspectForm.imgList"
                  :limit="9"
                  :multiple="true"
                >
                  <i class="el-icon-plus"></i>
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="隐患问题描述" prop="pitfallDescription">
                <el-input
                  class="cont-width-textarea"
                  type="textarea"
                  v-model="inspectForm.pitfallDescription"
                  placeholder="请输入隐患问题描述"
                  clearable
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  maxlength="300"
                  show-word-limit
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="整改措施建议" prop="suggestion">
                <el-input
                  class="cont-width-textarea"
                  type="textarea"
                  v-model="inspectForm.suggestion"
                  placeholder="请输入整改措施建议"
                  clearable v-no-whitespace
                  :autosize="{ minRows: 4, maxRows: 6 }"
                  maxlength="300"
                  show-word-limit
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <!-- 整改方填写 -->
      <el-card class="box-card">
        <div slot="header" class="card-header">
          <span>整改方填写</span>
        </div>
        <el-form
          :model="rectificationForm"
          ref="rectificationForm"
          label-width="120px"
          size="small"
          :disabled="userType != '02'"
        >
          <el-form-item label="责任人" prop="rectificationName">
            <el-input v-model="rectificationForm.rectificationName" placeholder="请选择整改人" class="cont-width" v-no-whitespace />
          </el-form-item>
          <el-form-item label="产生原因描述" prop="causeDesc">
            <el-input v-model="rectificationForm.causeDesc" placeholder="请输入产生原因描述" class="cont-width" v-no-whitespace />
          </el-form-item>
          <el-form-item label="整改情况" prop="rectificationDesc">
            <el-input v-model="rectificationForm.rectificationDesc" placeholder="请输入整改情况" class="cont-width" v-no-whitespace />
          </el-form-item>
          <el-form-item label="上传图片" prop="imgList">
            <el-upload
              action="#"
              accept="image/*"
              :auto-upload="false"
              list-type="picture-card"
              :file-list="rectificationForm.imgList"
              :limit="9"
              :multiple="true"
            >
              <i class="el-icon-plus"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="上传文件" prop="fileList">
            <el-upload
              action="#"
              :auto-upload="false"
              :file-list="rectificationForm.fileList"
              :limit="9"
              :multiple="true"
            >
              <el-button size="small" type="primary">选择上传文件</el-button>
            </el-upload>
          </el-form-item>
        </el-form>
      </el-card>

      <!-- 验收方填写 -->
      <el-card class="box-card">
        <div slot="header" class="card-header">
          <span>验收方填写</span>
        </div>
        <el-form :model="acceptForm" ref="acceptForm" size="small" :disabled="userType != '00'" :rules="rules3">
          <el-row :gutter="10">
            <el-col :span="7" :offset="0">
              <el-form-item label="整改验收部门" prop="deptId" label-width="110px">
                <treeselect
                  v-model="acceptForm.deptId"
                  :options="deptOptions"
                  :show-count="true"
                  placeholder="请选择归属部门"
                  :noResultsText="'未找到相关部门！'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="0">
              <el-form-item label="整改验收人" prop="userId">
                <el-select
                  v-model="acceptForm.userId"
                  placeholder="请选择整改验收人"
                  class="cont-width"
                  @change="changeUserId"
                >
                  <el-option
                    v-for="item in acceptNameOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="0">
              <el-form-item label="是否进行流程审批" prop="isProcess">
                <el-select v-model="acceptForm.isProcess" placeholder="请选择是否进行流程审批" class="cont-width">
                  <el-option label="是" value="1" />
                  <el-option label="否" value="0" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="整改意见" prop="opinion" label-width="110px">
            <el-input
              class="cont-width-textarea"
              type="textarea"
              v-model="acceptForm.opinion"
              placeholder="请输入整改意见"
              clearable v-no-whitespace
              :autosize="{ minRows: 4, maxRows: 6 }"
              maxlength="300"
              show-word-limit
              disabled
            />
          </el-form-item>
          <el-form-item label="备注" prop="remarks" label-width="110px">
            <el-input
              class="cont-width-textarea"
              type="textarea"
              v-model="acceptForm.remarks"
              placeholder="请输入备注"
              clearable v-no-whitespace
              :autosize="{ minRows: 4, maxRows: 6 }"
              maxlength="300"
              show-word-limit
              disabled
            />
          </el-form-item>
        </el-form>
      </el-card>

      <!-- 延期信息 -->
      <el-card class="box-card">
        <div slot="header" class="card-header">
          <span>延期信息</span>
        </div>
        <el-form :model="delayInfoForm" ref="delayInfoForm" size="small" label-width="110px" :disabled="userType != '02'">
          <el-form-item label="延期整改时间" prop="delayRectificationTime">
            <el-date-picker
              v-model="delayInfoForm.delayRectificationTime"
              type="date"
              placeholder="选择延期整改时间"
              value-format="yyyy-MM-dd"
              clearable
              class="cont-width"
            />
          </el-form-item>
          <el-form-item label="延期原因" prop="delayReason">
            <el-input
              class="cont-width-textarea"
              type="textarea"
              v-model="delayInfoForm.delayReason"
              placeholder="请输入延期原因"
              clearable v-no-whitespace
              :autosize="{ minRows: 4, maxRows: 6 }"
              maxlength="300"
              show-word-limit
            />
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </el-dialog>
</template>
<script>
 import Treeselect from '@riophae/vue-treeselect'
 import '@riophae/vue-treeselect/dist/vue-treeselect.css'
 import { dictTableOption } from '@/api/tool/select'
 import {
   addHiddenDanger,
   getConsByProIdSelect, getDeptUserSelect,
   getOwnerSelect,
   getProSelect,
   getTypeOfViolationSelect
 } from '@/api/hiddenDangerManagement'
 import { deptTreeSelect } from '@/api/system/user'
 import { transferHiddenDanger } from '@/api/snapshot/snapshot'
 import { lookFaceFile, lookMioIoFile } from '@/utils/bonus'

 export default {
   name: 'TransferHiddenDangerDialog',
   components: { Treeselect },
   data() {
     return {
       dialogTitle: '',
       dialogVisible: false,
       userType: this.$store.state.user.userType, // 用户类型
       row: {}, // 行数据
       isDisabled: false, // 是否禁用
       isFrom: '1', // 采集来源1日常检查2安全大检查;3随手拍
       // 基础信息
       baseInfoForm: {
         pitfallCode: '', // 隐患问题编号
         recordCode: '', // 检查记录编号
         inspectLevel: '', // 对应检查级别
         inspectLevelName: '', // 对应检查级别
         checkType: '', // 排查类型
         checkTypeName: '', // 排查类型
         createUserId: '', // 创建人id
         createUserName: '', // 创建人
         createTime: '', // 创建时间
         rectificationReceiveTime: '', // 整改接收时间
         rectificationFeedbackTime: '', // 整改反馈时间
         rectificationStatus: '', // 整改状态
       },
       // 检查方填写
       inspectForm: {
         checkUserId: '', // 检查人id
         checkUserName: '', // 检查人
         findTime: '', // 发现日期
         proId: '', // 隐患工程id
         proName: '', // 隐患工程
         subValue: '', // 整改责任承包商
         subId: '', // 整改责任承包商id --> valueUuid
         subName: '', // 整改责任承包商 --> label
         pitfallTypeId: '', // 隐患问题类别
         pitfallTypeName: '', // 隐患问题类别
         pitfallLevelId: '', // 隐患问题级别
         pitfallLevelName: '', // 隐患问题级别
         correctionTime: '', // 期限整改时间
         subPersonId: '', // 承包商责任人id --> userId
         subPersonName: '', // 承包商责任人 --> name
         supUuid: '', // 监理uuid
         imgList: [], // 图片列表
         pitfallDescription: '', // 隐患问题描述
         suggestion: '', // 整改措施建议
       },
       // 整改方填写
       rectificationForm: {
         rectificationName: '', // 责任人
         causeDesc: '', // 产生原因
         rectificationDesc: '', // 整改情况
         imgList: [], // 图片列表
         fileList: [], // 文件列表
       },
       // 验收方填写
       acceptForm: {
         deptId: undefined, // 验收部门id
         deptName: '', // 验收部门
         userId: '', // 验收人id
         userName: '', // 验收人
         isProcess: '', // 是否进行流程审批
         opinion: '', // 验收描述
         remarks: '', // 备注
       },
       // 延期信息
       delayInfoForm: {
         delayRectificationTime: '', // 延期整改时间
         delayReason: '', // 延期原因
       },
       // 排查类型-下拉框
       checkTypeOptions: [],
       // 检查人-下拉框
       inspectNameOptions: [],
       // 隐患工程-下拉框
       hazardProOptions: [],
       // 整改责任承包商-下拉框
       rectificationContractorOptions: [],
       // 隐患问题类别-下拉框
       hazardIssueTypeOptions: [],
       // 隐患问题级别-下拉框
       hazardIssueLevelOptions: [],
       // 整改验收部门-树形下拉
       deptOptions: [],
       acceptNameOptions: [],
       rules1: {
         checkType: [{ required: true, message: '请选择排查类型', trigger: 'change' }],
       },
       rules2: {
         checkUserId: [{ required: true, message: '请选择检查人', trigger: 'change' }],
         findTime: [{ required: true, message: '请选择发现日期', trigger: 'change' }],
         proId: [{ required: true, message: '请选择隐患工程', trigger: 'change' }],
         subValue: [{ required: true, message: '请选择整改责任承包商', trigger: 'change' }],
         pitfallTypeId: [{ required: true, message: '请选择隐患问题类别', trigger: 'change' }],
         pitfallLevelId: [{ required: true, message: '请选择隐患问题级别', trigger: 'change' }],
         correctionTime: [{ required: true, message: '请选择期限整改时间', trigger: 'change' }],
         subPersonName: [{ required: true, message: '请选择承包商责任人', trigger: 'change' }],
         pitfallDescription: [{ required: true, message: '请输入隐患问题描述', trigger: 'blur' }],
       },
       rules3: {
         deptId: [{ required: true, message: '请选择整改验收部门', trigger: 'blur' }],
         userId: [{ required: true, message: '请选择整改验收人', trigger: 'change' }],
         isProcess: [{ required: true, message: '请选择是否进行流程审批', trigger: 'change' }],
         // opinion: [{ required: true, message: '请输入整改意见', trigger: 'blur' }],
       },
       loading: null,
       delIds: [],
       lookFaceFile: lookFaceFile(),
     }
   },
   created() {
     this.getOwnerSelect()
     this.getCheckType()
     this.getProSelect()
     this.getTroubleType()
     this.getTroubleLevel()
     this.getDeptTreeSelect()
   },
   watch: {
     // 监听整改验收部门 acceptForm.deptId
     'acceptForm.deptId': {
       handler: function (val) {
         // this.deptOptions 是树形下拉的数据, 通过deptId 递归循环 找到对应的部门名称
         this.acceptForm.deptName = this.findDeptName(val, this.deptOptions)
         if (val) {
           this.getDeptUserSelect(val)
         } else {
           this.acceptForm.userId = ''
           this.acceptForm.userName = ''
           this.acceptNameOptions = []
         }
       },
       immediate: true,
     },
     'baseInfoForm.inspectLevelName': {
       handler: function (val) {
         console.log('对应检查级别', val)
         this.inspectForm.inspectLevel = this.hazardIssueLevelOptions.find(item => item.label === val).value
       },
       immediate: true,
     },
     'baseInfoForm.checkType': {
       handler: function (val) {
         console.log('对应检查级别', val)
         this.baseInfoForm.checkTypeName = this.checkTypeOptions.find(item => item.value === val).label
       },
       immediate: true,
     },
   },
   methods: {
     openDialog(row) {
       console.log('row', row)
       this.row = row.data
       this.dialogTitle = row.dialogTitle
       this.dialogVisible = true
       this.baseInfoForm = {
         pitfallCode: '', // 隐患问题编号
         recordCode: '', // 检查记录编号
         inspectLevel: '', // 对应检查级别
         inspectLevelName: '', // 对应检查级别
         checkType: '', // 排查类型
         checkTypeName: '', // 排查类型
         createUserId: this.$store.state.user.id, // 创建人id
         createUserName: this.$store.state.user.userData.nickName, // 创建人
         createTime: '', // 创建时间
         rectificationReceiveTime: '', // 整改接收时间
         rectificationFeedbackTime: '', // 整改反馈时间
         rectificationStatus: '', // 整改状态
       }
       this.$nextTick(() => {
         this.$refs.baseInfoForm.clearValidate()
       })
       setTimeout(() => {
         this.$refs.inspectForm.resetFields()
         this.inspectForm.proId = row.data.proId
         this.inspectForm.proName = row.data.proName
         // this.inspectForm.imgList = row.data.photoList
         this.inspectForm.imgList = row.data.photoList.map(item => ({
           url: this.lookFaceFile + item.filePath,
           name: item.fileName,
           fileId: item.fileId
         }))
         this.inspectForm.pitfallDescription = row.data.description
         this.getConsByProIdSelect( row.data.proId)
       }, 500)
     },
     // 获取排查类型-下拉
     async getCheckType() {
       try {
         const params = {
           dictType: 'yh_check_type',
           dictValue: '',
         }
         const res = await dictTableOption(params)
         this.checkTypeOptions = res.data
       } catch (error) {
         console.log('获取排查类型-下拉失败', error)
       }
     },
     // 检查人-下拉
     async getOwnerSelect() {
       try {
         const res = await getOwnerSelect()
         this.inspectNameOptions = res.data
       } catch (error) {
         console.log('获取检查人-下拉失败', error)
       }
     },
     // 隐患工程-下拉
     async getProSelect() {
       try {
         const res = await getProSelect()
         this.hazardProOptions = res.data
       } catch (error) {
         console.log('获取隐患工程-下拉失败', error)
       }
     },
     // 隐患问题类别-下拉
     async getTroubleType() {
       try {
         const res = await getTypeOfViolationSelect({ type: '1' })
         this.hazardIssueTypeOptions = res.data
       } catch (error) {
         console.log('获取隐患问题类别-下拉失败', error)
       }
     },
     // 隐患问题级别-yn_trouble_level
     async getTroubleLevel() {
       try {
         const params = {
           dictType: 'yn_trouble_level',
           dictValue: '',
         }
         const res = await dictTableOption(params)
         this.hazardIssueLevelOptions = res.data
       } catch (error) {
         console.log('获取隐患问题级别-下拉失败', error)
       }
     },
     // 整改验收部门-树形下拉
     async getDeptTreeSelect() {
       try {
         const res = await deptTreeSelect()
         this.deptOptions = res.data
       } catch (error) {
         console.log('获取整改验收部门-树形下拉失败', error)
       }
     },
     // 检查人
     changeCheckUserId(val) {
       console.log('检查人', val)
       this.inspectForm.checkUserName = this.inspectNameOptions.find(item => item.value === val).label
     },
     // 隐患工程
     changeProId(val) {
       console.log('隐患工程', val)
       this.inspectForm.proName = this.hazardProOptions.find(item => item.value === val).label
       this.inspectForm.subValue = ''
       this.inspectForm.subId = ''
       this.inspectForm.subName = ''
       this.rectificationContractorOptions = []
       this.inspectForm.subPersonId = ''
       this.inspectForm.subPersonName = ''
       this.inspectForm.supUuid = ''
       this.getConsByProIdSelect(val)
     },
     // 获取整改责任承包商-下拉
     async getConsByProIdSelect(val) {
       try {
         const params = {
           proId: val,
         }
         const res = await getConsByProIdSelect(params)
         this.rectificationContractorOptions = res.data
       } catch (error) {
         console.log('获取整改责任承包商-下拉失败', error)
       }
     },
     // 整改责任承包商+负责人
     changeSubValue(val) {
       console.log('整改责任承包商', val, this.rectificationContractorOptions)
       this.inspectForm.subId = this.rectificationContractorOptions.find(item => item.value === val).valueUuid
       this.inspectForm.subName = this.rectificationContractorOptions.find(item => item.value === val).label
       this.inspectForm.subPersonId = this.rectificationContractorOptions.find(item => item.value === val).userId
       this.inspectForm.subPersonName = this.rectificationContractorOptions.find(item => item.value === val).name
       this.inspectForm.supUuid = this.rectificationContractorOptions.find(item => item.value === val).supUuid
     },
     // 隐患问题类别
     changePitfallTypeId(val) {
       console.log('隐患问题类别', val)
       this.inspectForm.pitfallTypeName = this.hazardIssueTypeOptions.find(item => item.value === val).label
     },
     // 隐患问题级别
     changePitfallLevelId(val) {
       console.log('隐患问题级别', val)
       this.inspectForm.pitfallLevelName = this.hazardIssueLevelOptions.find(item => item.value === val).label
     },
     // 递归-根据id找到对应的部门名称
     findDeptName(id, data) {
       for (let i = 0; i < data.length; i++) {
         if (data[i].id === id) {
           return data[i].label
         }
         if (data[i].children) {
           const res = this.findDeptName(id, data[i].children)
           if (res) {
             return res
           }
         }
       }
     },
     // 整改接收人-下拉
     async getDeptUserSelect(val) {
       try {
         this.acceptForm.userId = ''
         this.acceptForm.userName = ''
         this.acceptNameOptions = []
         const params = {
           deptId: val,
         }
         const res = await getDeptUserSelect(params)
         this.acceptNameOptions = res.data
       } catch (error) {
         console.log('获取整改接收人-下拉失败', error)
       }
     },
     // 整改接收人
     changeUserId(val) {
       console.log('整改接收人', val)
       this.acceptForm.userName = this.acceptNameOptions.find(item => item.value === val).label
     },
     // 上传图片
     handleUpImg(file, fileList) {
       console.log('上传图片', file, fileList)
       // 超过9张图片 提示
       if (fileList.length > 9) {
         return
       }
       this.inspectForm.imgList = fileList
     },
     // 移除图片
     handleRemoveImg(file, fileList) {
       console.log('移除图片', file, fileList)
       if (file.fileId) {
         this.delIds.push(file.fileId)
       }
       this.inspectForm.imgList = fileList
     },
     // 超过9张图片 提示
     handleExceedImg() {
       this.$message.error('最多上传9张图片')
     },
     // 下发
     handleAdd() {
       try {
         const formData = new FormData()
         if (this.inspectForm.imgList.length > 0) {
           this.inspectForm.imgList.forEach(item => {
             if (item.raw) {
               formData.append('checkPhotoList', item.raw)
             } else {
               formData.append('checkPhotoList', new Blob())
             }
           })
         } else {
           formData.append('checkPhotoList', new Blob())
         }
         const params = {
           ...this.baseInfoForm,
           ...this.inspectForm,
           ...this.acceptForm,
           isFrom: '3',
           checkLevel: this.baseInfoForm.inspectLevel,
           checkLevelName: this.baseInfoForm.inspectLevelName,
           delIds: this.delIds.join(','),
           snapshotId: this.row.snapshotId
         }
         delete params.imgList
         console.log('params', params)
         formData.append('params', JSON.stringify(params))
         // 打印 formData
         for (let [key, value] of formData.entries()) {
           console.log('🚀 ~ 参数-->', key, value)
         }
         // 下发
         this.submitForm(formData)
       } catch (error) {
         console.log('下发失败', error)
       }
     },
     // submitForm
     async submitForm(farmData) {
       let isPass = true
       this.$refs.inspectForm.validate(valid => {
         if (valid) {
           isPass = true
         } else {
           isPass = false
         }
       })
       this.$refs.acceptForm.validate(valid => {
         if (valid) {
           isPass = true
         } else {
           isPass = false
         }
       })
       console.log('isPass', isPass)
       if (!isPass) return false
       // loading
       const loading = this.$loading({
         lock: true,
         text: '下发中...',
         spinner: 'el-icon-loading',
         background: 'rgba(0, 0, 0, 0.7)',
       })
       try {
         const res = await transferHiddenDanger(farmData)
         console.log('提交成功', res)
         // 提示
         this.$message.success('下发成功')
         // 关闭页面
         loading.close()
         this.dialogVisible = false
         this.$emit('getList')

       } catch (error) {
         console.log('提交失败', error)
         // 关闭loading
         loading.close()
       }
     },
   },
 }
</script>
<style scoped lang="scss">
.top-btn {
  z-index: 9999;
  position: absolute;
  top: 90%;
  left: 90%;
  display: flex;
  flex-direction: row;
}
.box-card {
  margin: 20px 0;
}
.card-header {
  font-size: 16px;
  font-weight: 700;
}
.cont-width {
  width: 210px;
}
.cont-width-textarea {
  width: 450px;
}
</style>
