<template>
  <div class="app-container">
    <div>
      <el-table v-if="false" border :data="dueList" class="tableWrapper">
        <!-- <el-table-column  type="selection" width="55" align="center" /> -->
        <el-table-column label="尽调名称" align="center" prop="investigateName">
          <template slot-scope="scope">
            <div :title="scope.row.investigateName">
              {{ scope.row.investigateName }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          label="尽调人员"
          align="center"
          prop="investigatePerson"
        >
          <template slot-scope="scope">
            <div :title="scope.row.investigatePerson">
              {{ scope.row.investigatePerson }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="尽调费用(元)"
          align="center"
          prop="investigateCost"
        >
          <template slot-scope="scope">
            <div :title="scope.row.investigateCost">
              {{ scope.row.investigateCost }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="描述" align="center" prop="describe">
          <template slot-scope="scope">
            <div :title="scope.row.describe">
              {{ scope.row.describe }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark">
          <template slot-scope="scope">
            <div :title="scope.row.remark">
              {{ scope.row.remark }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <div :title="scope.row.createTime">
              {{ scope.row.createTime }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="360"
        >
          <template slot-scope="scope">
            <!--
              v-show="scope.row.investigatePersonId.indexOf(user.userId) > -1" -->
            <!-- <el-button
              class="custom-blue-color"
              size="mini"
              type="text"
              icon="el-icon-search"
              @click="handleLook(scope.row)"
              >查看报告</el-button
            > -->
            <el-button
              v-show="scope.row.investigatePersonId.indexOf(user.userId) > -1"
              size="mini"
              type="text"
              icon="el-icon-upload2"
              @click="handleShowApplyPop(scope.row)"
              >上传报告</el-button
            >
            <!-- status 0=进行中  1=完成 -->
            <!-- <el-button
              v-if="scope.row.status === '0'"
              size="mini"
              type="text"
              icon="el-icon-circle-check"
              @click="handleDuePlan(scope.row)"
              >完成尽调</el-button
            > -->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              >修改</el-button
            >
            <el-button
              class="custom-red-color"
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 添加或修改尽调申请 -->
    <el-dialog
      :title="dueDiligenceTit"
      :visible.sync="dueDiligenceOpen"
      width="1100px"
      append-to-body
    >
      <el-form
        ref="dueForm"
        class="special-el-form"
        :model="dueForm"
        :rules="dueRules"
        label-width="170px"
      >
       <el-form-item
          label="项目名称"
          prop="projectName"
          class="special-el-form-item public-input-height-2"
          :rules="[
            { required: true, trigger: 'blur', message: '请选择' },
          ]"
        >
          <div
            class="el-input__inner inputSimulation"
            @click="handleProjectItem"
            :class="{ show_disabled: pageType === '1' }"
            :title="dueForm.projectName"
          >
            {{ dueForm.projectName ? dueForm.projectName : "请选择 " }}
          </div>
          <projectItem
            ref="projectItem"
            @getProjectInfo="getProjectInfo"
          ></projectItem>
        </el-form-item>
        <el-form-item
          label="尽调名称"
          prop="investigateName"
          class="special-el-form-item"
        >
          <el-input
            maxlength="100"
            v-model="dueForm.investigateName"
            placeholder="请输入尽调名称"
          />
        </el-form-item>
        <el-form-item
          label="尽调地点"
          prop="investigatePlace"
          class="special-el-form-item"
        >
          <el-input
            maxlength="100"
            v-model="dueForm.investigatePlace"
            placeholder="请输入尽调地点"
          />
        </el-form-item>

        <el-form-item label="期望尽调开始时间" prop="startTime">
          <el-date-picker
            clearable
            v-model="dueForm.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择期望尽调开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="期望尽调结束时间" prop="endTime">
          <el-date-picker
            clearable
            v-model="dueForm.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择期望尽调结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="尽调资料是否齐全" prop="readiness">
          <el-radio-group v-model="dueForm.readiness">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否有第三方投资机构" prop="thirdParty">
          <el-radio-group v-model="dueForm.thirdParty">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="尽调费用(元)" prop="investigateCost">
          <el-input
            maxlength="20"
            v-model="dueForm.investigateCost"
            placeholder="请输入尽调费用"
            @input="
              (value) =>
                (dueForm.investigateCost = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
                  .replace(/-/g, ''))
            "
          />
        </el-form-item>
        <el-form-item label="尽调财务数据截止日期" prop="deadDate">
          <el-date-picker
            clearable
            v-model="dueForm.deadDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择尽调财务数据截止日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="尽调人员"
          prop="investigatePerson"
          class="special-el-form-item public-input-height-2"
        >
          <div
            class="el-input__inner inputSimulation"
            @click="handleSelectPeople"
          >
            {{
              dueForm.investigatePerson
                ? dueForm.investigatePerson
                : "请选择尽调人员"
            }}
          </div>
        </el-form-item>
        <el-form-item
          label="尽调背调资料"
          prop="file"
          class="special-el-form-item"
        >
          <fileItem
            ref="fileItems"
            :id="dueForm.id"
            @getFileList="getFileList"
          ></fileItem>
        </el-form-item>
        <el-form-item label="描述" prop="describe" class="special-el-form-item">
          <el-input
            rows="4"
            maxlength="200"
            v-model="dueForm.describe"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remark" class="special-el-form-item">
          <el-input
            rows="4"
            maxlength="200"
            type="textarea"
            v-model="dueForm.remark"
            placeholder="请输入备注"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDueForm">取 消</el-button>
        <el-button type="warning" @click="submitDueForm(false)" v-preventReClick>暂 存</el-button>
        <el-button type="primary" @click="submitDueForm(true)" v-preventReClick>提 交</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改尽调报告 -->
    <el-dialog
      :title="dueDiligenceTit1"
      :visible.sync="dueDiligenceOpen1"
      width="1100px"
      append-to-body
    >
      <h3>尽调申请详情</h3>
      <el-divider></el-divider>
      <el-form
        ref="duePeportForm"
        class="special-el-form"
        :model="duePeportForm"
        :rules="dueRules1"
        label-width="170px"
      >
        <el-form-item label="项目名称" class="special-el-form-item">
          <el-input
            type="textarea"
            rows="2"
            disabled
            v-model="dueForm.projectName"
          />
        </el-form-item>
        <el-form-item label="尽调名称" class="special-el-form-item">
          <el-input
            disabled
            v-model="dueForm.investigateName"
            placeholder="请输入尽调名称"
          />
        </el-form-item>
        <el-form-item
          label="尽调地点"
          prop="investigatePlace"
          class="special-el-form-item"
        >
          <el-input
            disabled
            maxlength="100"
            v-model="dueForm.investigatePlace"
          />
        </el-form-item>
        <el-form-item label="期望尽调开始时间" prop="startTime">
          <el-date-picker
            disabled
            clearable
            v-model="dueForm.startTime"
            type="date"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="期望尽调结束时间" prop="endTime">
          <el-date-picker
            disabled
            clearable
            v-model="dueForm.endTime"
            type="date"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="尽调资料是否齐全" prop="readiness">
          <el-radio-group v-model="dueForm.readiness" disabled>
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否有第三方投资机构" prop="thirdParty">
          <el-radio-group v-model="dueForm.thirdParty" disabled>
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="尽调费用(元)">
          <el-input disabled v-model="dueForm.investigateCost" />
        </el-form-item>

        <el-form-item label="尽调财务数据截止日期" prop="deadDate">
          <el-date-picker
            disabled
            clearable
            v-model="dueForm.deadDate"
            type="date"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="尽调人员" class="special-el-form-item">
          <el-input
            type="textarea"
            rows="2"
            disabled
            v-model="dueForm.investigatePerson"
          />
        </el-form-item>
        <el-form-item label="尽调资料" class="special-el-form-item">
          <fileItem
            ref="fileItems1"
            :id="dueForm.id"
            @getFileList="getFileList"
          ></fileItem>
        </el-form-item>
        <el-form-item label="描述" class="special-el-form-item">
          <el-input
            disabled
            rows="4"
            v-model="dueForm.describe"
            type="textarea"
          />
        </el-form-item>
        <el-form-item label="备注" class="special-el-form-item">
          <el-input
            disabled
            rows="4"
            type="textarea"
            v-model="dueForm.remark"
          />
        </el-form-item>
        <h3>尽调报告</h3>
        <el-divider></el-divider>
        <el-form-item label="报告" prop="listFile" class="special-el-form-item">
          <fileItem
            ref="reportFileItems"
            :id="duePeportForm.id"
            @getFileList="getreportFileList"
          ></fileItem>
        </el-form-item>
        <el-form-item label="备注" prop="remark" class="special-el-form-item">
          <el-input
            rows="4"
            type="textarea"
            v-model="duePeportForm.remark"
            placeholder="请输入备注"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitduePeportForm" v-preventReClick
          >确 定</el-button
        >
        <el-button @click="cancelduePeportForm">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 查看该申请下的所有尽调报告 -->
    <!-- <el-dialog
      v-if="false"
      title="尽调报告"
      :visible.sync="dueDiligenceOpen2"
      width="1100px"
      append-to-body
      class="examineDialog"
    >
      <div v-if="dueAllPeportList.length > 0">
        <el-form
          v-for="(item, index) in dueAllPeportList"
          :key="index"
          class="special-el-form"
          :model="item"
          label-width="100px"
        >
          <el-form-item label="尽调人员" class="special-el-form-item">
            <el-input disabled v-model="item.investigatePerson" />
          </el-form-item>
          <el-form-item label="报告" class="special-el-form-item">
            <fileItem
              ref="dueAllreportFileItems"
              :id="item.id"
              @getFileList="getreportFileList"
            ></fileItem>
          </el-form-item>
          <el-form-item label="备注" class="special-el-form-item">
            <el-input
              disabled
              rows="4"
              type="textarea"
              v-model="item.remark"
              placeholder="请输入备注"
            />
          </el-form-item>
          <el-divider></el-divider>
        </el-form>
      </div>
      <div
        v-else
        class="public-flex-center public-padded-t-20"
        style="color: #909399"
      >
        暂无数据
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dueDiligenceOpen2 = false"
          >确 定</el-button
        >
        <el-button @click="dueDiligenceOpen2 = false">取 消</el-button>
      </div>
    </el-dialog> -->
    <!-- 尽调申请及下面报告 -->
    <el-tabs type="border-card" v-if="showDetail" style="border: 1px solid #DCDFE6;">
      <el-tab-pane label="尽职背调申请表">
        <el-form
          v-if="dueForm.id"
          ref="dueForm"
          class="special-el-form public-padded-t-20"
          :model="dueForm"
          label-width="170px"
        >
          <el-form-item label="尽调名称" class="special-el-form-item">
            <el-input
              disabled
              v-model="dueForm.investigateName"
              placeholder="请输入尽调名称"
            />
          </el-form-item>
          <el-form-item
            label="尽调地点"
            prop="investigatePlace"
            class="special-el-form-item"
          >
            <el-input
              disabled
              maxlength="100"
              v-model="dueForm.investigatePlace"
            />
          </el-form-item>
          <el-form-item label="期望尽调开始时间" prop="startTime">
            <el-date-picker
              disabled
              clearable
              v-model="dueForm.startTime"
              type="date"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="期望尽调结束时间" prop="endTime">
            <el-date-picker
              disabled
              clearable
              v-model="dueForm.endTime"
              type="date"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="尽调资料是否齐全" prop="readiness">
            <el-radio-group v-model="dueForm.readiness" disabled>
              <el-radio label="1">是</el-radio>
              <el-radio label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否有第三方投资机构" prop="thirdParty">
            <el-radio-group v-model="dueForm.thirdParty" disabled>
              <el-radio label="1">是</el-radio>
              <el-radio label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="尽调费用(元)">
            <el-input disabled v-model="dueForm.investigateCost" />
          </el-form-item>

          <el-form-item label="尽调财务数据截止日期" prop="deadDate">
            <el-date-picker
              disabled
              clearable
              v-model="dueForm.deadDate"
              type="date"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="尽调人员" class="special-el-form-item">
            <el-input
              type="textarea"
              rows="2"
              disabled
              v-model="dueForm.investigatePerson"
            />
          </el-form-item>
          <el-form-item label="尽调资料" class="special-el-form-item">
            <fileItem
              ref="fileItems1"
              :id="dueForm.id"
              @getFileList="getFileList"
            ></fileItem>
          </el-form-item>
          <el-form-item label="描述" class="special-el-form-item">
            <el-input
              disabled
              rows="4"
              v-model="dueForm.describe"
              type="textarea"
            />
          </el-form-item>
          <el-form-item label="备注" class="special-el-form-item">
            <el-input
              disabled
              rows="4"
              type="textarea"
              v-model="dueForm.remark"
            />
          </el-form-item>
          <el-form-item label="财务评估报告" class="special-el-form-item">
            <fileItem ref="financeFileItem" :id="dueForm.id" :is-detail="true"></fileItem>
          </el-form-item>
          <el-form-item label="法务评估报告"  class="special-el-form-item">
            <fileItem ref="legalFileItem" :id="dueForm.id" :is-detail="true"></fileItem>
          </el-form-item>
          <el-form-item label="其他" class="special-el-form-item">
            <fileItem ref="otherFileItem" :id="dueForm.id" :is-detail="true"></fileItem>
          </el-form-item>
        </el-form>
        <div
          v-else
          class="public-flex-center public-padded-20"
          style="color: #909399"
        >
          暂无数据
        </div>
      </el-tab-pane>
<!--      <el-tab-pane label="尽职背调报告汇总表">
        <div v-if="dueAllPeportList.length > 0">
          <el-form
            v-for="(item, index) in dueAllPeportList"
            :key="index"
            class="special-el-form public-padded-t-20"
            :model="item"
            label-width="100px"
          >
            <el-form-item label="尽调人员" class="special-el-form-item">
              <el-input disabled v-model="item.investigatePerson" />
            </el-form-item>
            <el-form-item label="报告" class="special-el-form-item">
              <fileItem
                ref="dueAllreportFileItems"
                :id="item.id"
                @getFileList="getreportFileList"
              ></fileItem>
            </el-form-item>
            <el-form-item label="备注" class="special-el-form-item">
              <el-input
                disabled
                rows="4"
                type="textarea"
                v-model="item.remark"
                placeholder="请输入备注"
              />
            </el-form-item>
            <el-divider></el-divider>
          </el-form>
        </div>
        <div
          v-else
          class="public-flex-center public-padded-20"
          style="color: #909399"
        >
          暂无数据
        </div>
      </el-tab-pane>-->
    </el-tabs>
    <section v-if="showDetail">
      <flowBase :procInstId="dueForm.procInstId" :id="dueForm.projectPoolId" v-if="dueForm.procInstId"></flowBase>
    </section>
    <!--选择人员-->
    <selecUser
      ref="flowUser"
      :checkType="checkType"
      :selectValues="selectValues"
      :selectNameValues="selectNameValues"
      @handleUserSelect="handleUserSelect"
    ></selecUser>
  </div>
</template>
<script>
import {
  getInvestigateById,
  delInvestigate,
  updateInvestigate,
  updateStatus,
  addInvestigate,
  addInvestigatePerson,
  investigateListProjectPoolIdNew,
  getProjectInvestigateId,
  getDueAllPeportList,
} from "@/api/invest/pool";
import {investigateStart} from "@/api/project/investigate/pool";
import projectItem from "./projectItem";
import fileItem from "../../invest/components/fileItem";
import selecDept from "../../invest/components/selecDept";
import selecUser from "../../invest/components/selecUser";
import flowBase from "../flowBase.vue";
import { mapGetters } from "vuex";

export default {
  props: {
    projectId: {
      type: String,
    },
    projectName: {
      type: String,
      default: null,
      required: false,
    },
  },
  dicts: ["up_way", "project_stage"],
  components: { projectItem, fileItem, selecDept, selecUser,flowBase },
  data() {
    const validateLogo = (rule, value, callback) => {
      if (this.reportFileList.length <= 0) {
        callback(new Error("请上传文件"));
      } else {
        callback();
      }
    };
    return {
      pageType: null,
      // 人员选择器
      checkType: "multiple",
      // 数据回显
      selectValues: null,
      selectNameValues: null,
      userVisible: false,
      dueList: [],
      total: null,
      dueDiligenceTit: "",
      dueDiligenceOpen: false,
      dueDiligenceTit1: "",
      dueDiligenceOpen1: false,
      dueDiligenceOpen2: false,
      duePeportForm: {
        createBy: null,
        createTime: null,
        deptId: null,
        deptName: null,
        id: null,
        investigatePerson: null,
        investigatePersonId: null,
        listFile: null,
        projectInvestigateId: null,
        remark: null,
        updateBy: null,
        updateTime: null,
      },
      dueForm: {
        id: null,
        investigateName: null,
        investigateCode: null,
        projectPoolId: null,
        investigatePerson: null,
        investigatePersonId: null,
        investigateCost: null,
        //
        startTime: null,
        endTime: null,
        investigatePlace: null,
        readiness: null,
        thirdParty: null,
        deadDate: null,
        //
        describe: null,
        remark: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        projectName: null,
        flag:null,
      },
      dueAllPeportList: [],
      dueRules1: {
        listFile: [{ required: true, validator: validateLogo }],
        remark: [{ required: true, trigger: "blur", message: "请输入" }],
      },
      dueRules: {
        investigateName: [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        projectName: [{ required: true, trigger: "blur", message: "请输入" }],
        investigatePerson: [
          { required: true, trigger: "blur", message: "请选择" },
        ],
        investigateCost: [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        describe: [{ required: true, trigger: "blur", message: "请输入" }],

        startTime: { required: true, trigger: "blur", message: "请选择" },
        endTime: { required: true, trigger: "blur", message: "请选择" },
        investigatePlace: [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        readiness: [{ required: true, trigger: "change", message: "请选择" }],
        thirdParty: [{ required: true, trigger: "change", message: "请选择" }],
        deadDate: { required: true, trigger: "blur", message: "请选择" },
      },
      fileList: [],
      showProjectItem: false,
      reportFileList: [],
      dueDiligenceType: "0",
      showDetail: false,
      isWatch:false,
    };
  },
  computed: {
    ...mapGetters(["user"]),
  },
  watch: {
    dueDiligenceOpen: function (newValue, oldValue) {
      if (newValue === false) {
        this.selectValues = null;
        this.selectNameValues = null;
      }
    },
  },
  mounted() {
    // this.getList();
  },
  methods: {
     //展示人员
    handleProjectItem() {
      this.$refs.projectItem.showProjectItem = true;
      // 2. 调用子组件的刷新方法，重新加载项目列表
      // 确保子组件已加载且存在刷新方法
      if (this.$refs.projectItem && typeof this.$refs.projectItem.refreshProjectList === 'function') {
        this.$refs.projectItem.refreshProjectList(this.isWatch);
      }
    },
    // 获取公司信息
    getProjectInfo(info) {
      if (info.length > 0) {
        this.dueForm.projectPoolId = info[0].id;
        this.dueForm.projectName = info[0].projectName;
      }
    },
    // 展示最新的尽调申请及下面的尽调报告
    handleShowDetail(id) {
      this.showDetail = true;
      this.getInvestigateListProjectPoolIdNew(id);
    },
    handleSelectPeople() {
      this.$refs.flowUser.handleUserVisible(true);
    },
    // 根据尽调申请id查下面所有的报告
    handleLook(row) {
      let that = this;
      getDueAllPeportList(row.id).then((response) => {
        let rows = response.rows;
        this.dueAllPeportList = rows;
        this.dueDiligenceOpen2 = true;
        if (rows && rows.length > 0) {
          setTimeout(() => {
            for (let i in rows) {
              this.$refs.dueAllreportFileItems[i].handleButton();
              this.$refs.dueAllreportFileItems[i].getListFileBusinessId(
                rows[i].id
              );
            }
          }, 300);
        }
      });
    },
    // 根据项目ID获取最新尽调申请
    getInvestigateListProjectPoolIdNew(id) {
      let that = this;
      investigateListProjectPoolIdNew(id).then((response) => {
        if (response.data) {
          this.dueForm = response.data;
          setTimeout(() => {
            this.$refs.fileItems1.handleButton();
            this.$refs.fileItems1.listFile = [];
            this.$refs.fileItems1.getListFileBusinessId(that.dueForm.id,"11");
            //项目行研报告
            this.$refs.financeFileItem.handleButton();
            this.$refs.financeFileItem.fileList = [];
            this.$refs.financeFileItem.getListFileBusinessId(that.dueForm.id, "14");
            //项目技术报告
            this.$refs.legalFileItem.handleButton();
            this.$refs.legalFileItem.fileList = [];
            this.$refs.legalFileItem.getListFileBusinessId(that.dueForm.id, "15");
            //其他
            this.$refs.otherFileItem.handleButton();
            this.$refs.otherFileItem.fileList = [];
            this.$refs.otherFileItem.getListFileBusinessId(that.dueForm.id, "0");
          }, 300);
          this.handleLook(response.data);
        }
      });
    },

    // 修改尽调申请
    handleUpdate(row) {
      let that = this;
      this.resetDueForm();
      const id = row.id;
      getInvestigateById(id).then((response) => {
        if (response.data) {
          this.dueForm = response.data;
          // this.dueForm.projectName = this.projectName;
          this.selectValues = response.data.investigatePersonId;
          this.selectNameValues = response.data.investigatePerson;
          this.dueDiligenceTit = "修改尽调申请";
          this.dueDiligenceOpen = true;
          setTimeout(() => {
            that.$refs.fileItems.fileList = [];
            that.$refs.fileItems.getListFileBusinessId(this.dueForm.id);
          }, 300);
        }
      });
    },
    /*用户选中赋值*/
    checkUserComplete() {
      this.userVisible = false;
      //   this.checkType = "";
    },
    // 获取fileList
    getFileList(fileList) {
      if (fileList && fileList.length > 0) {
        this.fileList = fileList;
      } else {
        this.fileList = [];
      }
    },
    getreportFileList(fileList) {
      if (fileList && fileList.length > 0) {
        this.reportFileList = fileList;
      } else {
        this.reportFileList = [];
      }
    },
    // 用户选中数据
    handleUserSelect(selection) {
      const that = this;
      if (selection) {
        if (selection instanceof Array) {
          const userIds = selection.map((item) => item.userId);
          const nickName = selection.map((item) => item.nickName);
          this.dueForm.investigatePerson = nickName.join(",");
          this.dueForm.investigatePersonId = userIds.join(",");
          this.selectNameValues = nickName.join(",");
          this.selectValues = userIds.join(",");
        } else {
          this.dueForm.investigatePerson = selection.nickName;
          this.dueForm.investigatePersonId = selection.userId;
          this.selectNameValues = selection.nickName;
          this.selectValues = selection.userId;
        }
        this.$refs.dueForm.clearValidate(["investigatePerson"]);
      }
    },
    // 发起尽调申请
    handleShowApplyPop(row) {
      let that = this;
      this.fileList = [];
      this.resetDueForm();
      setTimeout(() => {
        that.$refs.fileItems.fileList = [];
      }, 300);
      this.dueDiligenceTit = "发起尽调申请";
      this.dueDiligenceOpen = true;
      // this.dueForm.projectName = row.projectName;
      // this.dueForm.projectPoolId = row.id;
      if(row==1){
        this.isWatch=true;
      }
    },
    // 上传尽调报告-按钮
    handleShowReportPop(row) {
      //console.log("row=", row);
      let that = this;
      this.dueForm = row.tProjectInvestigate;
      this.dueForm.projectName = row.projectName;
      this.duePeportForm.projectInvestigateId = this.dueForm.id;
      setTimeout(() => {
        that.$refs.fileItems1.handleButton();
        that.$refs.fileItems1.listFile = [];
        that.$refs.fileItems1.getListFileBusinessId(this.dueForm.id);
      }, 300);
      this.dueDiligenceTit1 = "上传尽调报告";
      this.dueDiligenceOpen1 = true;
    },
    // 尽调报告-上传
    submitduePeportForm() {
      this.$refs["duePeportForm"].validate((valid) => {
        if (valid) {
          this.duePeportForm.projectPoolId = this.dueForm.projectPoolId;
          this.duePeportForm.listFile = this.reportFileList;
          addInvestigatePerson(this.duePeportForm).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.$store.dispatch("getInvestigateNumber"); //初始化尽职背调代办数量
            this.dueDiligenceOpen1 = false;
            this.$emit("getList");
          });
        }
      });
    },
    cancelduePeportForm() {
      this.dueDiligenceOpen1 = false;
      this.resetduePeportForm();
    },
    resetduePeportForm() {
      this.duePeportForm = {
        createBy: null,
        createTime: null,
        deptId: null,
        deptName: null,
        id: null,
        investigatePerson: null,
        investigatePersonId: null,
        listFile: null,
        remark: null,
        updateBy: null,
        updateTime: null,
        projectInvestigateId: this.dueForm.id,
      };
    },
    // 尽调申请-提交
    submitDueForm(flag) {
      this.$refs["dueForm"].validate((valid) => {
        if (valid) {
          this.dueForm.flag = flag;
          this.dueForm.listFile = this.fileList;
          this.dueForm.investigateCost = this.dueForm.investigateCost
            .replace(/[^0-9.]/g, "")
            .replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")
            .replace(/-/g, "");
          if (
            new Date(this.dueForm.endTime).getTime() <
            new Date(this.dueForm.startTime).getTime()
          ) {
            this.$confirm(
              "期望尽调结束时间不能小于期望尽调开始时间,请重新选择!",
              "提示",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              }
            )
              .then(() => {})
              .catch(() => {});
            return false;
          }
          /*if (this.dueForm.id != null) {
            updateInvestigate(this.dueForm).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.dueDiligenceOpen = false;
              this.$emit("getList");
            });
          } else {
            addInvestigate(this.dueForm).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.dueDiligenceOpen = false;
              // this.$emit("changeShowDueApply", "0");
              this.$emit("getList");
            });
          }*/
          try {
            investigateStart(this.dueForm).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.dueDiligenceOpen = false;
              this.$emit("getList");
              this.$store.dispatch("getMyTaskInvestigateNumber"); //更新代办数量
            });
          } catch (err) {
            // 捕获重复提交错误
            this.$message.error(err.message);
          }
          //this.getList();
        }
      });
    },
    cancelDueForm() {
      this.dueDiligenceOpen = false;
      this.resetDueForm();
    },
    // 表单重置
    resetDueForm() {
      this.dueForm = {
        id: null,
        investigateName: null,
        investigateCode: null,
        investigatePerson: null,
        investigatePersonId: null,
        investigateCost: null,
        //
        startTime: null,
        endTime: null,
        investigatePlace: null,
        readiness: null,
        thirdParty: null,
        deadDate: null,
        //
        describe: null,
        remark: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        projectPoolId: null,
        projectName: null,
      };
      this.resetForm("dueForm");
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const investigateName = row.investigateName
        ? row.investigateName
        : "此项";
      this.$modal
        .confirm('是否确认删除"' + investigateName + '"？')
        .then(function () {
          return delInvestigate(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss">
.examineDialog {
  .el-input.is-disabled .el-input__inner,
  .el-textarea.is-disabled .el-textarea__inner {
    background-color: #fff;
    color: #333;
  }
}
</style>
