<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div>
    <el-dialog :title="title" :close-on-click-modal="false" draggable width="1200px" height="500px" @close="close"
      v-model="visible">
      <el-row>
        <el-col :span="24">
          <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method === 'view' ? 'readonly' : ''"
            label-width="110px" @submit.native.prevent>
            <!-- :disabled="status === 'audit' || status === 'taskFormDetail'" -->
            <el-row :gutter="15">
              <!--                <el-col :span="12">-->
              <!--                  <el-form-item label="档案名称" prop="name"-->
              <!--                                :rules="[-->
              <!--                                {required: true, message:'档案名称不能为空', trigger:'blur'}-->
              <!--                   ]">-->
              <!--                    <el-input v-model="inputForm.name" placeholder="请填写档案名称" clearable></el-input>-->
              <!--                  </el-form-item>-->
              <!--                </el-col>-->
              <el-divider content-position="left"><i class="el-icon-document"></i> 归档信息</el-divider>

              <el-col :span="12">
                <el-form-item label="档案号" prop="fileNumber" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.fileNumber" placeholder="请填写档案号" clearable></el-input>
                </el-form-item>
              </el-col>


              <el-col :span="12" v-if="status === 'audit'">
                <el-form-item label="审计收费(元)" prop="auditMoney" :rules="[
                  { required: true, message: '请输入审计收费(元)', trigger: 'blur' }
                ]">
                  <el-input v-on:input="inputForm.auditMoney = inputForm.auditMoney.replace(/[^\d.]/g, '')
                    .replace(/^\./g, '')
                    .replace(/\.{2,}/g, '.')
                    .replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
                    .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^0+/, '0')" v-model="inputForm.auditMoney"
                    controls-position="right" :controls="false" style="width:100%;" placeholder="请输入审计收费(元)"
                    :disabled="this.inputForm.auditMoney == this.accountTotal && this.accountTotal != 0 ? true : false"
                    clearable @keyup="inputMoney">
                    <template #suffix>
                      <el-button style="background-color: white;color: #1b1e25;border-color: white;" type="primary"
                        @click="openInvoice(this.inputForm.id)" icon="el-icon-search"></el-button>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12" v-else>
                <el-form-item label="审计收费(元)" prop="auditMoney" :rules="[
                  { required: true, message: '请输入审计收费(元)', trigger: 'blur' }
                ]">
                  <el-input v-on:input="inputForm.auditMoney = inputForm.auditMoney.replace(/[^\d.]/g, '')
                    .replace(/^\./g, '')
                    .replace(/\.{2,}/g, '.')
                    .replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
                    .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^0+/, '0')" v-model="inputForm.auditMoney"
                    controls-position="right" :controls="false" style="width:100%;" placeholder="请输入审计收费(元)"
                    :disabled="true" clearable @keyup="inputMoney">
                    <template #suffix>
                      <el-button :disabled="true" style="background-color: white;color: #1b1e25;border-color: white;"
                        type="primary" @click="openInvoice(this.inputForm.id)" icon="el-icon-search"></el-button>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="档案年度" prop="year" :rules="[
                  { required: true, message: '档案年度不能为空', trigger: 'blur' }
                ]">
                  <el-date-picker :disabled="true" v-model="inputForm.year" type="year" value-format="YYYY"
                    placeholder="选择档案年度" style="width:100%" placement="bottom-start" :clearable="false">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-divider content-position="left"><i class="el-icon-document"></i> 项目报告信息</el-divider>


              <el-col :span="12">
                <el-form-item label="委托项目类型" prop="entrustType" :rules="[
                ]">
                  <el-select :disabled="status === 'taskFormDetail'" @change="handleEntrustTypeChange"
                    v-model="inputForm.entrustType" placeholder="请选择委托项目类型" style="width:100%;">
                    <el-option v-for="item in $dictUtils.getDictList('cw_entrust_type')" :key="item.value"
                      :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="项目现场负责人" prop="projectManager">
                  <SelectUserTree :disabled="true" ref="companyTree" size="large" :props="{
                    value: 'id',             // ID字段名
                    label: 'name',         // 显示名称
                    children: 'children'    // 子级字段名
                  }" :url="`/system-server/sys/user/treeUserDataAllOffice?type=2`" :value="inputForm.projectManager"
                    :clearable="true" :accordion="true" @getValue="(value) => { inputForm.projectManager = value }" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="报告文号" prop="reportNo" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.reportNo" placeholder="请填写报告文号" clearable>
                    <!--                    <el-button slot="append" :disabled="status === 'audit' || status === 'taskFormDetail'" @click="openReportChoose" icon="el-icon-search"></el-button>-->
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="被审计单位" prop="auditedUnitsName" :rules="[
                  { required: true, message: '被审计单位不能为空', trigger: 'blur' },
                  { required: true, message: '被审计单位不能为空', trigger: 'change' }
                ]">
                  <el-input :disabled="true" v-model="inputForm.auditedUnitsName" @click="openChooseClient"
                    placeholder="请填写被审计单位" clearable>
                    <el-button slot="append" @click="openChooseClient" icon="el-icon-search"></el-button>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="项目名称" prop="cwProjectRecordsDTO.projectName" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.cwProjectRecordsDTO.projectName" placeholder="请填写项目名称"
                    clearable>
                    <!--                      <el-button slot="append" :disabled="status === 'audit' || status === 'taskFormDetail'" @click="openChooseProject" icon="el-icon-search"></el-button>-->
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="报告日期" prop="reportDate" :rules="[
                ]">
                  <!-- <el-input :disabled="status === 'taskFormDetail'" v-model="inputForm.reportDate" placeholder="请填写报告日期"
                  clearable></el-input> -->
                  <el-date-picker style="width:100%" placement="bottom-start" value-format="YYYY-MM-DD HH:mm:ss"
                    format="YYYY-MM-DD" type="date" :disabled="true" v-model="inputForm.reportDate"
                    placeholder="选择报告日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="二级复核" prop="secondAuditName" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.secondAuditName" placeholder="" clearable>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="归档时间" prop="auditDate" :rules="[
                ]">
                  <!-- <el-input :disabled="status === 'taskFormDetail'" v-model="inputForm.auditDate" placeholder="请填写归档时间"
                  clearable></el-input> -->
                  <el-date-picker :disabled="status === 'taskFormDetail'" v-model="inputForm.auditDate" type="datetime"
                    value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss" placeholder="选择归档时间"
                    style="width:100%" placement="bottom-start" :clearable="false">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="签字注师1" prop="signatureAnnotator1Name" :rules="[
                  { validator: validateSignatures, trigger: 'blur' },
                ]">
                  <el-input :disabled="status === 'taskFormDetail'" clearable
                    v-model="inputForm.signatureAnnotator1Name" @clear.native="clearSignatureAnnotator1Name"
                    @click="openUserDia1" placeholder="请填写签字注师1">
                    <template #suffix>
                      <el-button :disabled="status === 'taskFormDetail'"
                        style="background-color: white;color: #1b1e25;border-color: white;" type="primary" slot="append"
                        icon="el-icon-search" @click="openUserDia1">
                      </el-button>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="签字注师2" prop="signatureAnnotator2Name" :rules="[
                  { validator: validateSignatures, trigger: 'blur' },
                ]">
                  <el-input :disabled="status === 'taskFormDetail'" clearable
                    v-model="inputForm.signatureAnnotator2Name" @clear.native="clearSignatureAnnotator2Name"
                    @click="openUserDia2" placeholder="请填写签字注师2">
                    <template #suffix>
                      <el-button :disabled="status === 'taskFormDetail'"
                        style="background-color: white;color: #1b1e25;border-color: white;" type="primary" slot="append"
                        icon="el-icon-search" @click="openUserDia2">
                      </el-button>
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="报告册数" prop="reportNum" :rules="[
                  { required: true, message: '报告册数不能为空', trigger: 'blur' }
                ]">
                  <el-input-number :disabled="status === 'taskFormDetail'" v-model="inputForm.reportNum"
                    controls-position="right" style="width:100%" :precision="0" :max="9999999999" :step="1" :min="0"
                    placeholder="请填写报告册数" :controls="false" clearable>
                  </el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="底稿册数" prop="papersNum" :rules="[
                  { required: true, message: '底稿册数不能为空', trigger: 'blur' }
                ]">
                  <el-input-number :disabled="status === 'taskFormDetail'" v-model="inputForm.papersNum"
                    controls-position="right" style="width:100%" :precision="0" :max="9999999999" :step="1" :min="0"
                    placeholder="请填写底稿册数" :controls="false" clearable>
                  </el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="合同" prop="contract" :rules="[
                ]">
                  <el-input :disabled="status === 'taskFormDetail'" v-model="inputForm.contract"
                    placeholder="参考兴光流转表中合同列填写。如：有、2018-A5等" clearable>
                  </el-input>
                </el-form-item>
              </el-col>


              <el-col v-if="status !== 'audit'" :span="12">
                <el-form-item label="盒号" prop="number" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.number" placeholder="请填写盒号" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col v-if="status !== 'audit'" :span="12">
                <el-form-item label="确认盒号" prop="isNumber" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.isNumber" placeholder="请填写确认盒号" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12" v-if="status !== 'audit'">
                <el-form-item class="star-require" label="审定金额(不含税/元)" prop="approvedNoIncludingTax" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.approvedNoIncludingTax"
                    :placeholder="`报告中审定金额（不含税/元）为：${this.inputForm.approvedNoIncludingTaxBak}元。与所填写不同，如需归档，请进行同步，保证金额相同`"
                    v-on:input="inputForm.approvedNoIncludingTax = inputForm.approvedNoIncludingTax.replace(/[^\d.]/g, '')
                      .replace(/^\./g, '')
                      .replace(/\.{2,}/g, '.')
                      .replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
                      .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^0+/, '0')" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12" v-if="status !== 'audit'">
                <el-form-item class="star-require" label="审定金额(含税/元)" prop="approvedIncludingTax" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.approvedIncludingTax"
                    :placeholder="`报告中审定金额（含税/元）为：${this.inputForm.approvedIncludingTaxBak}元。与所填写不同，如需归档，请进行同步，保证金额相同`"
                    v-on:input="inputForm.approvedIncludingTax = inputForm.approvedIncludingTax.replace(/[^\d.]/g, '')
                      .replace(/^\./g, '')
                      .replace(/\.{2,}/g, '.')
                      .replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
                      .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^0+/, '0')" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col v-if="status !== 'audit'" :span="24">
                <el-form-item label="备注" prop="remarks" :rules="[
                ]">
                  <el-input type="textarea" :disabled="true" v-model="inputForm.remarks" placeholder="请填写备注"
                    clearable></el-input>
                </el-form-item>
              </el-col>
              <!-- <el-form v-if="status === 'audit'" style="width: 100%" :model="inputForm" ref="inputForm"
              v-loading="loading" :class="method === 'view' ? 'readonly' : ''" label-width="110px"
              @submit.native.prevent> -->
              <el-col :span="12" v-if="status === 'audit'">
                <el-form-item label="盒号" prop="number" :rules="[
                  { required: true, message: '盒号不能为空', trigger: 'blur' }
                ]">
                  <el-input style="width: 100%" :disabled="false" v-model="inputForm.number" placeholder="请填写盒号"
                    clearable></el-input>
                  <span style="color: #E6A23C; font-weight: bold;">{{ boxNumberTips }}</span>

                </el-form-item>
              </el-col>
              <el-col :span="12" v-if="status === 'audit'">
                <el-form-item label="确认盒号" prop="isNumber" :rules="[
                  { required: true, message: '确认盒号不能为空', trigger: 'blur' }
                ]">
                  <el-input :disabled="false" style="width: 100%" v-model="inputForm.isNumber" placeholder="请填写确认盒号"
                    clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12" v-if="status === 'audit'">
                <el-form-item class="star-require" label="审定金额(不含税/元)" prop="approvedNoIncludingTax" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.approvedNoIncludingTax"
                    :placeholder="`报告中审定金额（不含税/元）为：${this.inputForm.approvedNoIncludingTaxBak}元。与所填写不同，如需归档，请进行同步，保证金额相同`"
                    v-on:input="inputForm.approvedNoIncludingTax = inputForm.approvedNoIncludingTax.replace(/[^\d.]/g, '')
                      .replace(/^\./g, '')
                      .replace(/\.{2,}/g, '.')
                      .replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
                      .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^0+/, '0')" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12" v-if="status === 'audit'">
                <el-form-item class="star-require" label="审定金额(含税/元)" prop="approvedIncludingTax" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.approvedIncludingTax"
                    :placeholder="`报告中审定金额（含税/元）为：${this.inputForm.approvedIncludingTaxBak}元。与所填写不同，如需归档，请进行同步，保证金额相同`"
                    v-on:input="inputForm.approvedIncludingTax = inputForm.approvedIncludingTax.replace(/[^\d.]/g, '')
                      .replace(/^\./g, '')
                      .replace(/\.{2,}/g, '.')
                      .replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
                      .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^0+/, '0')" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24" v-if="status === 'audit'">
                <el-form-item label="备注" prop="remarks" :rules="[
                ]">
                  <el-input type="textarea" :disabled="false" style="width: 100%" v-model="inputForm.remarks"
                    placeholder="请填写备注" clearable></el-input>
                </el-form-item>
              </el-col>
              <!-- </el-form> -->

              <!--            <el-row :gutter="15" v-if="inputForm.contractNo">

              <el-col :span="12">
                <el-form-item label="案卷号" prop="filedNo" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.filedNo" placeholder="请填写案卷号" clearable></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="合同编号" prop="contractNo" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.contractNo" placeholder="请填写合同编号" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="合同名称" prop="contractName" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.contractName" placeholder="请填写合同名称"
                    clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="委托方" prop="clientContacts" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.clientContacts" placeholder="请填写委托方"
                    clearable></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="合同金额" prop="contractAmount" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.contractAmount" placeholder="请填写合同金额"
                    clearable></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="合同创建人" prop="contractCreateName" :rules="[
                ]">
                  <el-input :disabled="true" v-model="inputForm.contractCreateName" placeholder="请填写合同创建人"
                    clearable></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-col :span="12" v-else>
              <el-form-item label="">
                <el-text size="large" type="danger">无合同</el-text>
              </el-form-item>

            </el-col>-->
            </el-row>
          </el-form>

          <el-tabs v-model="activeName" type="border-card" @tab-click="tabHandleClick">
            <el-tab-pane label="附件" name="files">
              <!--        附件-->
              <UpLoadComponent ref="uploadComponent"></UpLoadComponent>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
          <el-button v-if="method === 'edit'" type="primary" icon="el-icon-circle-check"
            @click="doSubmit('save')">确定</el-button>
        </span>
      </template>
      <ProjectRecordsChooseCom ref="projectRecordsChooseCom" @getProject="getProject"></ProjectRecordsChooseCom>
      <WorkClientChooseByProjectCom ref="workClientChooseByProjectCom" @getClient="getClient">
      </WorkClientChooseByProjectCom>
      <ReportChooseByProjectCom ref="reportChooseByProjectCom" @getReport="getReport"></ReportChooseByProjectCom>
    </el-dialog>

  </div>
</template>

<script>
import UpLoadComponent from '@/views/common/UpLoadComponentV3.1'
import ProjectReportArchiveService from '@/api/cw/projectRecords/ProjectReportArchiveService'
import ProjectRecordsChooseCom from '@/views/cw/projectRecords/ProjectRecordsChooseCom'
import WorkClientChooseByProjectCom from '@/views/cw/projectReportArchive/WorkClientChooseByProjectCom'
import ReportChooseByProjectCom from '@/views/cw/projectReportArchive/ReportChooseByProjectCom'
import SelectUserTree from '@/views/utils/treeUserSelect'
export default {
  props: {
    businessId: {
      type: String,
      default: ''
    },
    formReadOnly: {
      type: Boolean,
      default: false
    },
    status: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      title: '',
      method: '',
      loading: false,
      dialogVisible: false,
      inputForm: {
        id: '',
        createDate: '',
        createBy: {
          id: '',
          name: ''
        },
        remarks: '',
        projectId: '',
        name: '',
        auditedUnits: '',
        reportNum: '',
        papersNum: '',
        auditMoney: '',
        connectReport: '',
        year: '',
        number: '',
        isNumber: '',
        auditDate: '',
        procInsId: '',
        processDefinitionId: '',
        status: '',
        workAttachmentDtoList: [],
        cwProjectReportArchiveReportDTOList: [],
        cwProjectRecordsDTO: {
          remarks: '',
          projectNumber: '',
          projectName: '',
          officeId: '',
          projectMoney: '',
          auditYear: '',
          planStartDate: '',
          planEndDate: '',
          projectMasterId: '',
          projectLeaderId: '',
          procInsId: '',
          processDefinitionId: '',
          status: '',
          contractId: ''
        },
        auditedUnitsName: '',
        fileNumber: '',
        reportDate: '',
        reportNo: '',
        signatureAnnotator1: '',
        signatureAnnotator1Name: '',
        signatureAnnotator2: '',
        signatureAnnotator2Name: '',
        reportCreateName: '',
        reportId: '',
        reportRemarks: ''
      },
      keyWatch: '',
      activeName: 'files',
      tableKeyReport: '',
      isShow: false,
      visible: false
    }
  },
  projectReportArchiveService: null,
  created() {
    this.projectReportArchiveService = new ProjectReportArchiveService()
  },
  computed: {
    bus: {
      get() {
        this.$refs.uploadComponent.setDividerName('附件', false)
        return this.businessId
      },
      set(val) {
        this.businessId = val
      }
    }
  },
  watch: {
    'keyWatch': {
      handler(newVal) {
        if (this.commonJS.isNotEmpty(this.bus)) {
          this.init('', this.bus)
        } else {
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
          })
        }
      }
    }
  },
  components: {
    UpLoadComponent,
    ProjectRecordsChooseCom,
    WorkClientChooseByProjectCom,
    ReportChooseByProjectCom,
    SelectUserTree
  },
  methods: {
    getKeyWatch(keyWatch) {
      this.keyWatch = keyWatch
    },
    init(method, id) {
      this.visible = true
      if (method === 'edit') {
        this.title = '项目报告归档修改'
        this.method = method
      } else {
        this.title = '项目报告归档详情'
        this.method = 'view'
      }
      this.activeName = 'files'
      this.projectReportArchiveService = new ProjectReportArchiveService()
      this.inputForm = {
        id: '',
        createDate: '',
        createBy: {
          id: '',
          name: this.$store.state.user.name
        },
        remarks: '',
        projectId: '',
        name: '',
        auditedUnits: '',
        reportNum: '',
        papersNum: '',
        auditMoney: '',
        year: '',
        number: '',
        isNumber: '',
        contract: '',
        approvedNoIncludingTax: "",
        approvedIncludingTax: "",
        approvedNoIncludingTaxBak: "",
        approvedIncludingTaxBak: "",
        businessType: "",
        projectManager: '',
        filedNo: '',
        contractNo: "",
        contractName: "",
        clientContacts: "",
        contractAmount: "",
        contractCreateName: "",
        entrustType: "",
        auditDate: '',
        procInsId: '',
        processDefinitionId: '',
        status: '',
        workAttachmentDtoList: [],
        cwProjectReportArchiveReportDTOList: [],
        cwProjectRecordsDTO: {
          remarks: '',
          projectNumber: '',
          projectName: '',
          officeId: '',
          projectMoney: '',
          auditYear: '',
          planStartDate: '',
          planEndDate: '',
          projectMasterId: '',
          projectLeaderId: '',
          procInsId: '',
          processDefinitionId: '',
          status: '',
          contractId: ''
        },
        auditedUnitsName: '',
        connectReport: '',
        fileNumber: '',
        reportDate: '',
        reportNo: '',
        signatureAnnotator1: '',
        signatureAnnotator1Name: '',
        signatureAnnotator2: '',
        signatureAnnotator2Name: '',
        reportCreateName: '',
        reportId: '',
        reportRemarks: '',
        procDefId: '',
        procDefKey: '',
        formTitle: '',
        title: '',
        secondAuditName: ''
      }
      this.inputForm.id = id
      this.loading = false
      this.$nextTick(async () => {
        this.$refs.inputForm.resetFields()
        this.loading = true
        const data = await this.projectReportArchiveService.queryById(this.inputForm.id)
        this.$refs.uploadComponent.clearUpload()
        this.inputForm = this.recover(this.inputForm, data)
        this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
        if (this.$route.query.procInsId) {
          let userInfo = this.$TOOL.data.get("USER_INFO");
          if (this.inputForm.createBy.id === userInfo.id) {
            this.isAuditUser = false
          } else {
            this.isAuditUser = true
          }
        }
        if (this.commonJS.isEmpty(this.inputForm.workAttachmentDtoList)) {
          this.inputForm.workAttachmentDtoList = []
        }
        if (this.commonJS.isEmpty(this.inputForm.createDate)) {
          this.inputForm.createDate = this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
        }
        if (this.commonJS.isEmpty(this.inputForm.createBy.name)) {
          this.inputForm.createBy.name = this.$store.state.user.name
        }
        if (this.commonJS.isEmpty(this.inputForm.officeId)) {
          this.inputForm.officeId = this.$store.state.user.office.id
        }
        if (this.commonJS.isEmpty(this.inputForm.papersNum)) {
          this.inputForm.papersNum = 0
        }
        if (this.commonJS.isEmpty(this.inputForm.reportNum)) {
          this.inputForm.reportNum = 0
        }
        if (this.status === 'audit' || this.status === 'taskFormDetail') {
          this.method = 'view'
        }
        if (this.inputForm.auditMoney === '0') {
          this.isShow = true
          console.log('connectReport', this.inputForm.connectReport)
        }

        if (!this.commonJS.isEmpty(data.status) && data.status == 2) {
          this.handleBoxNumber(data.entrustType)
          //将原有审核时间进行处理并同步
          //通过reportId获取上一次审核通过时间
          const hiData = await this.projectReportArchiveService.getLastAuditDateByReportId(this.inputForm.reportId);
          if (!this.commonJS.isEmpty(hiData.auditDate)) {
            try {
              await this.$confirm('该报告之前已经归档并作废，是否沿用原有归档审核时间？上次归档时间为：' + hiData.auditDate, '确认信息', {
                distinguishCancelAndClose: true,
                confirmButtonText: '是',
                cancelButtonText: '否'
              });
              this.inputForm.auditDate = hiData.auditDate;
            } catch (action) {
              //将当前时间进行放入
              this.inputForm.auditDate = this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
            }
            this.inputForm.number = hiData.number
            this.inputForm.isNumber = hiData.isNumber
          } else {
            this.inputForm.auditDate = this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
          }
        }
        this.$refs.uploadComponent.newUpload(this.method, this.inputForm.workAttachmentDtoList, 'cw_project_archive', null, null, null, null, false)
        this.loading = false

      })
    },
    saveForm(callback) {
      this.doSubmit('save', callback)
    },
    startForm(callback) {
      this.doSubmit('start', callback)
    },
    async agreeForm(callback) {
      await this.projectReportArchiveService.queryById(this.inputForm.id).then((data) => {
        if (data.status !== '2') { // 审核状态不是“待审核”，就弹出提示
          this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
          throw new Error()
        } else {
          this.doSubmit('agree', callback)
        }
      })
    },
    // 表单提交
    async doSubmit(status, callback) {
      if (status === 'save') {
        // 暂存
        // this.inputForm.status = '1'
        this.loading = true
        if (this.$refs.uploadComponent.checkProgress()) {
          this.loading = false
          return
        }
        await this.$refs.uploadComponent.getDataList().then((list) => {
          console.log('list', list)
          // list为返回数据
          this.inputForm.workAttachmentDtoList = list
        })
        if (this.inputForm.isNumber !== this.inputForm.number) {
          this.$message.error('“案卷号”与“确认案卷号”不一致，请重新填写')
          this.loading = false
          throw new Error('“案卷号”与“确认案卷号”不一致，请重新填写')
        }
        console.log('this.inputForm.workAttachmentDtoList', this.inputForm.workAttachmentDtoList)
        // this.inputForm.createDate = this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
        this.projectReportArchiveService.saveForm(this.inputForm).then((data) => {
          // callback(data.businessTable, data.businessId, this.inputForm)
          this.close()
          this.$emit('refreshList')
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
        return
      } else if (status === 'start') {
        // 送审  待审核
        this.inputForm.status = '2'
      }
      this.$refs['inputForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          if (this.$refs.uploadComponent.checkProgress()) {
            this.loading = false
            throw new Error()
          } else {
            let _this = this
            const wait = function () {
              return new Promise((resolve, reject) => {
                if (status === 'agree') {
                  // 审核同意
                  _this.inputForm.auditDate = _this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
                  // this.inputForm.agreeUserId = this.$store.state.user.id
                  _this.inputForm.status = '5'
                  if (_this.inputForm.isNumber !== _this.inputForm.number) {
                    _this.$message.error('“案卷号”与“确认案卷号”不一致，请重新填写')
                    _this.loading = false
                    throw new Error('“案卷号”与“确认案卷号”不一致，请重新填写')
                  }
                }
                _this.$refs.uploadComponent.getDataList().then((list) => {
                  // list为返回数据
                  _this.inputForm.workAttachmentDtoList = list
                  list.forEach(item => {
                    if (_this.commonJS.isEmpty(item.fileType)) {
                      _this.$message.error('附件中的文件类型不可以为空')
                      throw new Error()
                    }
                  })
                })
                if (_this.commonJS.isEmpty(_this.inputForm.createDate)) {
                  _this.inputForm.createDate = _this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
                }
                resolve()
              })
            }
            wait().then(() => {
              this.projectReportArchiveService.saveForm(this.inputForm).then((data) => {
                callback(data.businessTable, data.businessId, this.inputForm)
                this.loading = false
              }).catch(() => {
                this.loading = false
              })
            })
          }
        }
      })
    },
    async updateStatusById(type) {
      if (type === 'reject' || type === 'reback') {
        if (await this.$refs.uploadComponent.checkProgress()) {
          this.loading = false
          throw new Error()
        }
        await this.projectReportArchiveService.queryById(this.inputForm.id).then((data) => {
          if (data.status !== '2') { // status的值不等于“审核中”就弹出提示
            this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
            throw new Error()
          } else {
            if (type === 'reject') {
              // 驳回
              this.inputForm.status = '4'
              let param = { status: '4', id: this.inputForm.id }
              this.projectReportArchiveService.updateStatusById(param)
            }
            if (type === 'reback') {
              // 撤回
              let param = { status: '3', id: this.inputForm.id }
              this.projectReportArchiveService.updateStatusById(param)
            }
          }
        })
      }
    },
    close() {
      this.inputForm = {
        id: '',
        createDate: '',
        createBy: {
          id: '',
          name: ''
        },
        remarks: '',
        projectId: '',
        name: '',
        auditedUnits: '',
        reportNum: '',
        papersNum: '',
        auditMoney: '',
        connectReport: '',
        year: '',
        number: '',
        isNumber: '',
        auditDate: '',
        procInsId: '',
        processDefinitionId: '',
        status: '',
        workAttachmentDtoList: [],
        cwProjectReportArchiveReportDTOList: [],
        cwProjectRecordsDTO: {
          remarks: '',
          projectNumber: '',
          projectName: '',
          officeId: '',
          projectMoney: '',
          auditYear: '',
          planStartDate: '',
          planEndDate: '',
          projectMasterId: '',
          projectLeaderId: '',
          procInsId: '',
          processDefinitionId: '',
          status: '',
          contractId: ''
        },
        auditedUnitsName: '',
        fileNumber: '',
        reportDate: '',
        reportNo: '',
        signatureAnnotator1: '',
        signatureAnnotator1Name: '',
        signatureAnnotator2: '',
        signatureAnnotator2Name: '',
        reportCreateName: '',
        reportId: '',
        reportRemarks: ''
      }
      this.$refs.uploadComponent.clearUpload()
      this.$refs.inputForm.resetFields()
      this.inputForm.reportId = ''
      this.inputForm.projectId = ''
      this.visible = false
    },
    tabHandleClick(event) {
      // console.log(event)
    },
    // 新增
    // eslint-disable-next-line no-dupe-keys
    insertEvent(type) {
    },
    // 删除
    removeEvent(row, rowIndex, type) {
      if (type === 'report') {
        this.$refs.reportTable.remove(row)
        this.inputForm.cwProjectReportArchiveReportDTOList.splice(rowIndex, 1)
      }
    },
    // 打开项目选择组件
    openChooseProject(event) {
      if (this.commonJS.isNotEmpty(this.inputForm.auditedUnitsName) || this.commonJS.isNotEmpty(this.inputForm.auditedUnits) || this.commonJS.isNotEmpty(this.inputForm.cwProjectReportArchiveReportDTOList)) {
        this.$confirm(`重新选择项目会清空"被审计单位"以及"审计报告"的数据，是否继续？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$refs.projectRecordsChooseCom.init()
        }).catch(() => {
        })
      } else {
        this.$refs.projectRecordsChooseCom.init()
      }
    },
    // 项目选择结果获取
    getProject(row) {
      this.inputForm.projectId = row.id
      this.inputForm.cwProjectRecordsDTO.projectName = row.projectName
      this.inputForm.cwProjectRecordsDTO.projectNumber = row.projectNumber
      this.inputForm.cwProjectRecordsDTO.projectMasterId = row.projectMasterId
      this.inputForm.auditedUnitsName = ''
      this.inputForm.auditedUnits = ''
      this.inputForm.cwProjectReportArchiveReportDTOList = []
    },
    // 打开被审计单位选择组件
    openChooseClient() {
      this.$refs.workClientChooseByProjectCom.init(this.inputForm.projectId)
    },
    // 被审计单位选择结果获取
    getClient(row) {
      this.inputForm.auditedUnitsName = row.name
      this.inputForm.auditedUnits = row.id
    },
    // 打开审计报告选择组件
    openReportChoose() {
      this.$refs.reportChooseByProjectCom.init(this.inputForm.projectId, this.inputForm.id)
    },
    // 审计报告选择结果获取
    getReport(row) {
      if (this.commonJS.isNotEmpty(row)) {
        if (this.commonJS.isNotEmpty(row.reportId)) {
          this.projectReportArchiveService.findReportUse(row.reportId).then((data) => {
            if (data === false) {
              this.inputForm.reportDate = row.reportDate
              this.inputForm.reportNo = row.reportNo
              this.inputForm.signatureAnnotator1 = row.signatureAnnotator1
              this.inputForm.signatureAnnotator1Name = row.signatureAnnotator1Name
              this.inputForm.signatureAnnotator2 = row.signatureAnnotator2
              this.inputForm.signatureAnnotator2Name = row.signatureAnnotator2Name
              this.inputForm.reportCreateName = row.createName
              this.inputForm.reportId = row.reportId
            } else {
              this.$message.error('此报告正在归档中或已归档，请重新选择')
            }
          })
        }
      }
    },
    //打开开票列表页面
    openInvoice() {
      this.dialogVisible = true
    },

  }
}
</script>
<style scoped>
/deep/ .el-input-number .el-input__inner {
  text-align: left;
}
</style>
