<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      width="1400px"
      height="500px"
      @close="close"
      append-to-body
      @keyup.enter.native=""
      :visible.sync="visible">
    <el-row>
      <el-form size="middle" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="status === 'audit' || status === 'taskFormDetail'"
               label-width="135px" @submit.native.prevent>

        <el-divider content-position="left"><i class="el-icon-document"></i> 项目信息</el-divider>
        <el-row  :gutter="0">
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName"
                          :rules="[
                              {required: true, message:'项目名称不能为空', trigger:'blur'},
                              {required: true, message:'项目名称不能为空', trigger:'change'}
                   ]">
              <!--                <el-input v-model="inputForm.projectName" placeholder="请填写项目名称" clearable></el-input>-->
              <el-input size="medium" :readonly="true" @focus="openContractForm()" v-model="inputForm.projectName" placeholder="请选择项目名称">
                <el-button slot="append" icon="el-icon-search" @click="openContractForm()"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目编号" prop="projectNumber"
                          :rules="[
                   ]">
              <el-input :disabled="true" v-model="inputForm.projectNumber" placeholder="请填写项目编号" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目经理1" prop="projectMasterName"
                          :rules="[
                   ]">
              <el-input :disabled="true" v-model="inputForm.projectMasterName" placeholder="请填写项目经理1" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目经理2" prop="realHeaderName"
                          :rules="[
                   ]">
              <el-input :disabled="true" v-model="inputForm.realHeaderName" placeholder="请填写项目经理2" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left"><i class="el-icon-document"></i> 基础信息</el-divider>
        <el-row  :gutter="0">
          <el-col :span="12">
            <el-form-item label="单据编号" prop="documentNo"
                          :rules="[

                   ]">
              <el-input :disabled="true" v-model="inputForm.documentNo" placeholder="自动生成" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报告所属部门" prop="officeId"
                          :rules="[
                   ]">
              <SelectTree
                ref="officeTree"
                :props="{
                  value: 'id',             // ID字段名
                  label: 'name',         // 显示名称
                  children: 'children'    // 子级字段名
                }"

                :url="`/sys/office/treeData?type=2`"
                :value="inputForm.officeId"
                size="medium"
                :accordion="true"
                @getValue="(value) => {inputForm.officeId=value}"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="盖章类型" prop="signatureType"
                          :rules="[
                   ]">
              <!--                <el-input v-model="inputForm.signatureType" placeholder="请填写盖章类型" clearable></el-input>-->
              <el-select v-model="inputForm.signatureType" placeholder="请选择盖章类型" clearable style="width: 100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_signature_type')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col v-if="inputForm.signatureType === '1' || inputForm.signatureType === '3' || commonJS.isEmpty(inputForm.signatureType)" :span="12">
            <el-form-item label="签字注师1" prop="signatureAnnotator1"
                          :rules="[
                            {required: true, message:'签字注师1不能为空', trigger:'change'}
                   ]">
              <!--                <el-input v-model="inputForm.signatureAnnotator1" placeholder="请填写签字注师1" clearable></el-input>-->
              <UserSelect size="medium" ref="userSelect1" :disabled="status === 'audit' || status === 'taskFormDetail'" :readonly="true" :limit='1' :value="inputForm.signatureAnnotator1" @getValue='(value) => {changeSignatory1(value)}'></UserSelect>
            </el-form-item>
          </el-col>

          <el-col v-if="inputForm.signatureType === '1' || inputForm.signatureType === '3' || commonJS.isEmpty(inputForm.signatureType)" :span="12">
            <el-form-item label="签字注师2" prop="signatureAnnotator2"
                          :rules="[
                            {required: true, message:'签字注师2不能为空', trigger:'change'}
                   ]">
              <!--                <el-input v-model="inputForm.signatureAnnotator2" placeholder="请填写签字注师2" clearable></el-input>-->
              <UserSelect size="medium" ref="userSelect2" :disabled="status === 'audit' || status === 'taskFormDetail'" :readonly="true" :limit='1' :value="inputForm.signatureAnnotator2" @getValue='(value) => {changeSignatory2(value)}'></UserSelect>
            </el-form-item>
          </el-col>

          <el-col v-if="inputForm.signatureType === '2' " :span="12">
            <el-form-item label="签字注师1" prop="signatureAnnotator1"
                          :rules="[
                              {required: true, message:'签字注师1不能为空', trigger:'blur'}
                   ]">
              <!--                <el-input v-model="inputForm.signatureAnnotator1" placeholder="请填写签字注师1" clearable></el-input>-->
              <UserSelect size="medium" ref="userSelect1" :disabled="status === 'audit' || status === 'taskFormDetail'" :readonly="true" :limit='1' :value="inputForm.signatureAnnotator1" @getValue='(value) => {changeSignatory1(value)}'></UserSelect>
            </el-form-item>
          </el-col>

          <el-col v-if="inputForm.signatureType === '2' " :span="12">
            <el-form-item label="签字注师2" prop="signatureAnnotator2"
                          :rules="[
                              {required: true, message:'签字注师2不能为空', trigger:'blur'}
                   ]">
              <!--                <el-input v-model="inputForm.signatureAnnotator2" placeholder="请填写签字注师2" clearable></el-input>-->
              <UserSelect size="medium" ref="userSelect2" :disabled="status === 'audit' || status === 'taskFormDetail'" :readonly="true" :limit='1' :value="inputForm.signatureAnnotator2" @getValue='(value) => {changeSignatory2(value)}'></UserSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审计意见类型" prop="opinionType"
                          :rules="[
                     ]">
              <el-select v-model="inputForm.opinionType" placeholder="请选择审计意见类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_opinion_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="auditFees"
                          :rules="[
                   ]">
              <el-input v-model="inputForm.auditFees" placeholder="请填写审计收费(税前、元)" clearable
                        @keyup.native="inputForm.auditFees = twoDecimalPlaces(inputForm.auditFees)"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="报告实际制作人" prop="realCreate"
                          :rules="[
                          {required: true, message:'报告实际制作人不能为空', trigger:'blur'},
                          {required: true, message:'报告实际制作人不能为空', trigger:'change'}
                   ]">
              <UserSelectAll size="medium" :readonly="true" :disabled="status === 'audit' || status === 'taskFormDetail'" :limit='1' :value="inputForm.realCreate" @getValue='(value) => {inputForm.realCreate = value}'></UserSelectAll>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建时间" prop="createDate"
                          :rules="[
                   ]">
              <el-input :disabled="true" v-model="inputForm.createDate" placeholder="请填写创建时间" clearable></el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-divider content-position="left"><i class="el-icon-document"></i> 报告信息</el-divider>
        <el-row  :gutter="0">
          <el-col :span="12">
            <el-form-item label="被服务单位" prop="servedUnitName"
                          :rules="[
                            {required: true, message:'被服务单位不能为空', trigger:'blur'},
                            {required: true, message:'被服务单位不能为空', trigger:'change'}
                   ]">
              <el-input :readonly="true" @focus="openWorkClient()" v-model="inputForm.servedUnitName" placeholder="请填写被服务单位" clearable>
                <el-button slot="append" icon="el-icon-search" @click="openWorkClient()"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报告类型" prop="reportType"
                          :rules="[
                            {required: true, message:'报告类型不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.reportType" placeholder="请选择报告类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_report_title_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="industry"
                          :rules="[
                            {required: true, message:'所属行业不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.industry" placeholder="请选择所属行业" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_industry')"
                  :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="businessObjects"
                          :rules="[
                            {required: true, message:'业务对象不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.businessObjects" placeholder="请选择业务对象" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_business_objects')"
                  :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="businessType"
                          :rules="[
                            {required: true, message:'业务类型不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.businessType" @change="changeBusinessType" placeholder="请选择业务类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_business_type')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="inputForm.businessType === '1'">
            <el-form-item label="审计业务类型" prop="auditBusinessType"
                          :rules="[
                            {required: true, message:'审计业务类型不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.auditBusinessType" placeholder="请选择审计业务类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_audit_business_type1')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="inputForm.businessType === '2'">
            <el-form-item label="审计业务类型" prop="auditBusinessType"
                          :rules="[
                            {required: true, message:'审计业务类型不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.auditBusinessType" placeholder="请选择审计业务类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_audit_business_type2')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="inputForm.businessType === '3'">
            <el-form-item label="审计业务类型" prop="auditBusinessType"
                          :rules="[
                            {required: true, message:'审计业务类型不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.auditBusinessType" placeholder="请选择审计业务类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_audit_business_type3')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="inputForm.businessType === '4'">
            <el-form-item label="审计业务类型" prop="auditBusinessType"
                          :rules="[
                            {required: true, message:'审计业务类型不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.auditBusinessType" placeholder="请选择审计业务类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_audit_business_type4')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="inputForm.businessType === '5'">
            <el-form-item label="审计业务类型" prop="auditBusinessType"
                          :rules="[
                            {required: true, message:'审计业务类型不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.auditBusinessType" placeholder="请选择审计业务类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_audit_business_type5')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="inputForm.businessType === '6'">
            <el-form-item label="审计业务类型" prop="auditBusinessType"
                          :rules="[
                            {required: true, message:'审计业务类型不能为空', trigger:'change'}
                   ]">
              <el-select v-model="inputForm.auditBusinessType" placeholder="请选择审计业务类型" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_audit_business_type6')"
                  :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="reportNumber"
                          :rules="[
                   ]">
              <el-input :disabled="true" v-model="inputForm.reportNumber" placeholder="自动生成" clearable></el-input>
            </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-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报告日期" prop="reportDate"
                          :rules="[
                   ]">
              <el-date-picker
                placement="bottom-start"
                value-format="yyyy-MM-dd"
                v-model="inputForm.reportDate"
                style="width: 100%"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!--<el-form size="middle" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="status !== 'audit' && status !== 'taskFormDetail'"
                   label-width="135px" @submit.native.prevent>
            <el-col :span="12">
              <el-form-item label="意见类型" prop="opinionType"
                            :rules="[
                              {required: true, message:'意见类型不能为空', trigger:'blur'}
                     ]">
                <el-select v-model="inputForm.opinionType" placeholder="请选择意见类型" style="width:100%;">
                  <el-option
                    v-for="item in $dictUtils.getDictList('cw_opinion_type')"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-form>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="盖章状态" prop="sealType"-->
<!--                          :rules="[-->
<!--                   ]">-->
<!--              <el-input :disabled="true" v-model="inputForm.sealType" placeholder="请填写盖章状态" clearable></el-input>-->
<!--            </el-form-item>-->
<!--          </el-col>-->

        </el-row>
        <el-divider content-position="left"><i class="el-icon-document"></i> 其他信息</el-divider>
        <el-row  :gutter="0">
          <el-col :span="12">
            <el-form-item label="公司注册地址" prop="registerAddress"
                          :rules="[
                   ]">
              <el-input v-model="inputForm.registerAddress" placeholder="请填写公司注册地址" clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务所在地" prop="businessLocation"
                          :rules="[
                   ]">
              <el-input v-model="inputForm.businessLocation" placeholder="请填写业务所在地" clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否数据证券业务" prop="securityBusiness"
                          :rules="[
                   ]">
              <el-select v-model="inputForm.securityBusiness" placeholder="请选择报告类别" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('cw_report_negotiable')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left"><i class="el-icon-document"></i> 报告审核信息</el-divider>
        <el-row  :gutter="15">
<!--          <el-col :span="12">-->
<!--            <el-form-item label="报告类别" prop="reportTitleType"-->
<!--                          :rules="[-->
<!--                   ]">-->
<!--              <el-select v-model="inputForm.reportTitleType" placeholder="请选择报告类别" style="width:100%;">-->
<!--                <el-option-->
<!--                  v-for="item in $dictUtils.getDictList('cw_report_title_type')"-->
<!--                  :key="item.value"-->
<!--                  :label="item.label"-->
<!--                  :value="item.value">-->
<!--                </el-option>-->
<!--              </el-select>-->
<!--              &lt;!&ndash;                <el-input size="medium" v-model="inputForm.reportTitleType" placeholder="请填写报告类型及标题"></el-input>&ndash;&gt;-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <!--<el-col :span="12">
            <el-form-item label="报告编号" prop="reportReviewNo"
                          :rules="[
                   ]">
              <el-input size="medium" :disabled="true" v-model="inputForm.reportReviewNo" placeholder="自动生成">
                &lt;!&ndash;                  <el-button slot="append" icon="el-icon-search" @click="openContractForm()"></el-button>&ndash;&gt;
              </el-input>
            </el-form-item>
          </el-col>-->
          <el-col :span="12">
            <el-form-item label="共印份数（大写）" prop="allPrintNum"
                          :rules="[
                   ]">
              <el-input size="medium" v-model="inputForm.allPrintNum" placeholder="请输入本报告共印份数">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发出份数（大写）" prop="issueNum"
                          :rules="[
                   ]">
              <el-input size="medium" v-model="inputForm.issueNum" placeholder="请输入发出份数">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="存档份数（大写）" prop="placeOnFileNum"
                          :rules="[
                   ]">
              <el-input size="medium" v-model="inputForm.placeOnFileNum" placeholder="请输入发出份数">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="打印人签名" prop="printedBy"
                          :rules="[
                   ]">
              <el-input size="medium" v-model="inputForm.printedBy" placeholder="请输入打印人签名">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="校对人签名" prop="checkAutograph"
                          :rules="[
                   ]">
              <el-input size="medium" v-model="inputForm.checkAutograph" placeholder="请输入校对人签名">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计算机文号" prop="computerNo"
                          :rules="[
                   ]">
              <el-input size="medium" v-model="inputForm.computerNo" placeholder="请输入校对人签名">
              </el-input>
            </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="archiveFile">-->
<!--          &lt;!&ndash;        签章文件&ndash;&gt;-->
<!--          <UpLoadComponent ref="archiveFile"></UpLoadComponent>-->
<!--        </el-tab-pane>-->
        <el-tab-pane label="附件" name="enclosure">
          <!--        附件-->
          <UpLoadComponent ref="enclosure"></UpLoadComponent>
        </el-tab-pane>
      </el-tabs>
    </el-row>
      <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="close()" icon="el-icon-circle-close">关闭</el-button>
      <el-button size="small" v-if="method !== 'view'" type="primary" icon="el-icon-circle-check" @click="doSubmit('save')">确定</el-button>
      </span>
    <ProjectRecoredChooseCom  ref="projectRecoredChooseCom" @getProject="getContract"></ProjectRecoredChooseCom>
    <ReportServiceUnitForm ref="reportServiceUnitForm" @getWorkClientChoose="getWorkClientChoose"></ReportServiceUnitForm>
    </el-dialog>
  </div>
</template>

<script>
  import ReportReviewService from '@/api/cw/reportManagement/ReportReviewService'
  // import UpLoadComponent from '@/views/common/UpLoadComponentV2.1'
  import UpLoadComponent from '@/views/common/UpLoadComponent'
  import SelectUserTree from '@/views/modules/utils/treeUserSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import UserSelect from '../workClientInfo/clientUserSelect'
  import UserSelectAll from '@/components/userSelect'
  import ProjectRecordsService from '@/api/cw/projectRecords/ProjectRecordsService'
  import ProjectReportService from '@/api/cw/reportManagement/ProjectReportService'
  import EnterpriseSearchService from '@/api/cw/common/EnterpriseSearchService'
  import ReportServiceUnitForm from './ReportServiceUnitForm'
  import ProjectRecoredChooseCom from '../projectRecords/ProjectRecordsChooseCom'
  export default {
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      },
      status: {
        type: String,
        default: ''
      }
    },
    data () {
      return {
        title: '',
        method: '',
        loading: false,
        inputForm: {
          reportReviewNo: '',
          allPrintNum: '',
          issueNum: '',
          placeOnFileNum: '',
          printedBy: '',
          checkAutograph: '',
          computerNo: '',
          opinionType: '',
          reportNo: '',
          reportNumber: '',
          reportType: '',
          businessType: '',
          auditBusinessType: '',
          reportDate: '',
          servedUnitName: '', // 被服务单位
          registerAddress: '',
          securityBusiness: '',
          businessLocation: '',
          auditFees: '',
          projectId: '',
          id: '',
          createDate: '',
          createBy: {
            id: '',
            name: JSON.parse(localStorage.getItem('user')).name
          },
          remarks: '',
          documentNo: '',
          projectName: '',
          projectNumber: '',
          officeId: '',
          signatureAnnotator1: '',
          signatureAnnotator2: '',
          signatureType: '',
          projectMasterId1: '',
          projectMasterId2: '',
          projectMasterName: '',
          cwProjectInfoList: [],
          cwFileInfoList: [],
          cwFileInfoList2: [],
          servedUnitId: '',
          status: '',
          realCreate: '',
          realHeaderName: '',
          industry: '',
          businessObjects: ''
        },
        keyWatch: '',
        activeName: 'enclosure',
        tableKey: '',
        tableKeyClient: '1',
        visible: false
      }
    },
    ReportReviewService: null,
    projectRecordsService: null,
    ProjectReportService: null,
    enterpriseSearchService: null,
    created () {
      this.reportReviewService = new ReportReviewService()
      this.enterpriseSearchService = new EnterpriseSearchService()
      this.projectRecordsService = new ProjectRecordsService()
      this.projectReportService = new ProjectReportService()
    },
    computed: {
      bus: {
        get () {
          this.$refs.enclosure.setDividerName('附件', false)
          // this.$refs.archiveFile.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: {
      SelectUserTree,
      UpLoadComponent,
      SelectTree,
      UserSelect,
      ReportServiceUnitForm,
      ProjectRecoredChooseCom,
      UserSelectAll
    },
    methods: {
      getKeyWatch (keyWatch) {
        this.keyWatch = keyWatch
      },
      changeSignatory1 (value) {
        if (this.inputForm.signatureAnnotator2 === value && this.commonJS.isNotEmpty(value)) {
          this.$message.warning('首次发行签字注师1和首次发行签字注师2不可以相同')
          this.$nextTick(() => {
            this.inputForm.signatureAnnotator1 = ''
            this.$refs.userSelect1.changeNameValue('')
            this.$refs.userSelect1.clearSelectData()
            this.$forceUpdate()
          })
        } else if (this.commonJS.isNotEmpty(this.inputForm.signatureAnnotator2) &&
          this.inputForm.projectMasterId1 !== this.inputForm.signatureAnnotator2 &&
          this.inputForm.projectMasterId2 !== this.inputForm.signatureAnnotator2 &&
          this.inputForm.projectMasterId1 !== value &&
          this.inputForm.projectMasterId2 !== value &&
          this.commonJS.isNotEmpty(value)) {
          console.log('项目经理1', this.inputForm.projectMasterId1)
          console.log('项目经理2', this.inputForm.projectMasterId2)
          console.log('签字注师2', this.inputForm.signatureAnnotator2)
          console.log('签字注师1', value)
          this.$message.warning('签字注师1和签字注师2至少有一个与项目经理相同')
          this.$nextTick(() => {
            this.inputForm.signatureAnnotator1 = ''
            this.$refs.userSelect1.changeNameValue('')
            this.$refs.userSelect1.clearSelectData()
            this.$forceUpdate()
          })
        } else {
          this.inputForm.signatureAnnotator1 = value
        }
      },
      changeSignatory2 (value) {
        if (this.inputForm.signatureAnnotator1 === value && this.commonJS.isNotEmpty(value)) {
          this.$message.warning('首次发行签字注师1和首次发行签字注师2不可以相同')
          this.$nextTick(() => {
            this.inputForm.signatureAnnotator2 = ''
            this.$refs.userSelect2.changeNameValue('')
            this.$refs.userSelect2.clearSelectData()
            this.$forceUpdate()
          })
        } else if (this.commonJS.isNotEmpty(this.inputForm.signatureAnnotator1) &&
          this.inputForm.projectMasterId1 !== this.inputForm.signatureAnnotator1 &&
          this.inputForm.projectMasterId2 !== this.inputForm.signatureAnnotator1 &&
          this.inputForm.projectMasterId1 !== value && this.commonJS.isNotEmpty(value) &&
          this.inputForm.projectMasterId2 !== value) {
          console.log('项目经理1', this.inputForm.projectMasterId1)
          console.log('项目经理2', this.inputForm.projectMasterId2)
          console.log('签字注师1', this.inputForm.signatureAnnotator1)
          console.log('签字注师2', value)
          this.$message.warning('签字注师1和签字注师2至少有一个与项目经理相同')
          this.$nextTick(() => {
            this.inputForm.signatureAnnotator2 = ''
            this.$refs.userSelect2.changeNameValue('')
            this.$refs.userSelect2.clearSelectData()
            this.$forceUpdate()
          })
        } else {
          this.inputForm.signatureAnnotator2 = value
        }
      },
      init (method, id) {
        this.visible = true
        this.activeName = 'enclosure'
        // this.activeName = 'archiveFile'
        this.reportReviewService = new ReportReviewService()
        this.projectRecordsService = new ProjectRecordsService()
        this.projectReportService = new ProjectReportService()
        this.method = method
        if (method === 'add') {
          this.title = '报告信息添加'
          this.method = method
        }
        this.inputForm = {
          reportReviewNo: '',
          allPrintNum: '',
          issueNum: '',
          placeOnFileNum: '',
          printedBy: '',
          checkAutograph: '',
          computerNo: '',
          servedUnitId: '',  // 被服务单位id
          opinionType: '',
          reportNo: '',
          reportNumber: '',
          reportType: '',
          businessType: '',
          auditBusinessType: '',
          reportDate: '',
          servedUnitName: '', // 被服务单位
          registerAddress: '',
          securityBusiness: '2',
          businessLocation: '',
          auditFees: '',
          projectId: '',
          id: '',
          createDate: '',
          createBy: {
            id: '',
            name: JSON.parse(localStorage.getItem('user')).name
          },
          remarks: '',
          documentNo: '',
          projectName: '',
          officeId: '',
          projectNumber: '',
          signatureAnnotator1: '',
          signatureAnnotator2: '',
          signatureType: '',
          projectMasterName: '',
          projectMasterId1: '',
          projectMasterId2: '',
          cwProjectInfoList: [],
          realCreate: '',
          realHeaderName: '',
          industry: '',
          businessObjects: ''
        }
        this.inputForm.id = id
        this.loading = false
        this.$nextTick(() => {
          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.officeId)) {
            this.inputForm.officeId = JSON.parse(localStorage.getItem('user')).officeDTO.id
          }
          if (this.commonJS.isEmpty(this.inputForm.realCreate)) {
            this.inputForm.realCreate = JSON.parse(localStorage.getItem('user')).id
          }
          if (this.commonJS.isEmpty(this.inputForm.signatureType) && this.method !== 'view') {
            this.inputForm.signatureType = '1'
          }
          this.$refs.enclosure.clearUpload()
          this.$refs.enclosure.newUpload(this.method, [], 'cwProjectReport', null, null, null, null, false)
          // this.$refs.archiveFile.clearUpload()
          // this.$refs.archiveFile.newUpload(this.method, [], 'cwProjectReport', null, null, null, null, false)
          // this.$refs.inputForm.resetFields()
          // this.loading = true
          /* this.projectReportService.queryById(this.inputForm.id).then(({data}) => {
            this.inputForm.status = data.status
            console.log('this.inputForm.servedUnitName', data)
            this.inputForm = this.recover(this.inputForm, data)
            this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
            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.officeId)) {
              this.inputForm.officeId = JSON.parse(localStorage.getItem('user')).officeDTO.id
            }
            if (this.commonJS.isEmpty(this.inputForm.realCreate)) {
              this.inputForm.realCreate = JSON.parse(localStorage.getItem('user')).id
            }
            if (this.status === 'audit' || this.status === 'taskFormDetail') {
              this.method = 'view'
            }
            this.$refs.archiveFile.newUpload(this.method, data.cwFileInfoList, 'cwWorkContract', null, null, null, null, false)
            this.loading = false
          }) */
        })
      },
      openContractForm () {
        if (!this.commonJS.isEmpty(this.inputForm.contractId)) {
          // this.$refs.projectInfoForm.init(this.inputForm.contractId)
          this.$refs.projectRecoredChooseCom.init(this.inputForm.contractId)
        } else {
          this.$refs.projectRecoredChooseCom.init()
          // this.$refs.projectInfoForm.init()
        }
      },
      getContract (row) {
        console.log('row', row)
        this.inputForm.projectName = row.projectName // 项目名称
        this.inputForm.projectId = row.id // 项目id
        this.inputForm.projectNumber = row.projectNumber // 项目编号
        this.inputForm.projectMasterName = row.projectMasterName // 项目经理
        this.inputForm.projectMasterId1 = row.projectMasterId // 项目经理1id
        this.inputForm.projectMasterId2 = row.realHeader // 项目经理2id
        this.inputForm.realHeaderName = row.realHeaderName // 项目经理2名称
        this.inputForm.signatureAnnotator1 = row.projectMasterId // 签字注师1id = 项目经理1id
        this.inputForm.signatureAnnotator2 = row.realHeader // 签字注师2id = 项目经理2id
        this.clearClientList()
        this.$forceUpdate()
        this.inputForm.cwProjectInfoList = []
      },
      clearClientList () {
        // 项目直接对接联系人列表清除
        this.inputForm.clientList = []
        this.$forceUpdate()
      },
      /* saveForm (callback) {
        this.doSubmit('save', callback)
      },
      startForm (callback) {
        this.doSubmit('start', callback)
      }, */
      /* reapplyForm (callback) {
        this.projectReportService.queryById(this.inputForm.id).then(({data}) => {
          if (data.status !== '4') { // 审核状态不是“驳回”，就弹出提示
            this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
            throw new Error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
          } else {
            this.doSubmit('reapply', callback)
          }
        })
      }, */
      /* async agreeForm (callback) {
        await this.projectReportService.queryById(this.inputForm.id).then(({data}) => {
          // console.log('进来了看看data', data)
          if (data.status !== '2') { // 审核状态不是“待审核”，就弹出提示
            this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
            throw new Error()
          } else {
            this.doSubmit('agree', callback)
          }
        })
      }, */
      // 表单提交
      async doSubmit (status, callback) {
        if (this.$refs.enclosure.checkProgress()) {
          this.loading = false
          throw new Error()
        } else {
          if (status === 'save') {
            console.log('save111111')
            // 暂存
            this.inputForm.status = '5'
            this.loading = true
            this.$refs['inputForm'].validate((valid) => {
              if (valid) {
                this.loading = true
                let _this = this
                let _num = 0
                const wait = function () {
                  return new Promise((resolve, reject) => {
                    if (_this.commonJS.isNotEmpty(_this.inputForm.signatureAnnotator1) &&
                      _this.commonJS.isEmpty(_this.inputForm.signatureAnnotator2) &&
                      _this.inputForm.signatureAnnotator1 !== _this.inputForm.projectMasterId1 &&
                      _this.inputForm.signatureAnnotator1 !== _this.inputForm.projectMasterId2) {
                      _this.$message.error('签字注师1和签字注师2至少有一个与项目经理相同')
                      _num = 1
                      _this.loading = false
                    }
                    if (_this.commonJS.isNotEmpty(_this.inputForm.signatureAnnotator2) &&
                      _this.commonJS.isEmpty(_this.inputForm.signatureAnnotator1) &&
                      _this.inputForm.signatureAnnotator2 !== _this.inputForm.projectMasterId1 &&
                      _this.inputForm.signatureAnnotator2 !== _this.inputForm.projectMasterId2) {
                      _this.$message.error('签字注师1和签字注师2至少有一个与项目经理相同')
                      _num = 1
                      _this.loading = false
                    }
                    _this.inputForm.cwFileInfoList2 = _this.$refs.enclosure.getDataList()
                    // _this.$refs.archiveFile.getDataList().then((data) => {
                    //   _this.inputForm.cwFileInfoList = data
                    //   if (_this.commonJS.isNotEmpty(_this.inputForm.cwFileInfoList)) {
                    //     _this.inputForm.cwFileInfoList.forEach((item, index) => {
                    //       if (_this.commonJS.isEmpty(item.fileType)) {
                    //         _this.$message.error('签章文件中，第' + (index + 1) + '条数据的“文件类型”未填写')
                    //         _num = 1
                    //         _this.loading = false
                    //         throw new Error('签章文件中，第' + (index + 1) + '条数据的“文件类型”未填写')
                    //       } else if (_this.commonJS.isEmpty(item.sealType)) {
                    //         _this.$message.error('签章文件中，第' + (index + 1) + '条数据的“盖章类型”未填写')
                    //         _num = 1
                    //         _this.loading = false
                    //         throw new Error('签章文件中，第' + (index + 1) + '条数据的“盖章类型”未填写')
                    //       }
                    //     })
                    //   } else {
                    //     _this.$message.error('最少有一条签章文件数据！')
                    //     _num = 1
                    //     _this.loading = false
                    //   }
                    // })
                    resolve()
                  })
                }
                wait().then(() => {
                  if (_num !== 1) {
                    if (this.commonJS.isEmpty(this.inputForm.createDate)) {
                      this.inputForm.createDate = this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
                    }
                    this.projectReportService.saveForm(this.inputForm).then(({data}) => {
                      this.$emit('refreshList')
                      callback(data.businessTable, data.businessId, this.inputForm)
                      this.close()
                      this.loading = false
                    }).catch(() => {
                      this.close()
                      this.loading = false
                    })
                  }
                })
              } else {
                this.loading = false
              }
            })
            return
          } else if (status === 'start') {
            // 送审  待审核
            this.inputForm.status = '2'
          } else if (status === 'agree') {
            // 审核同意
            this.inputForm.agreeDate = this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
            this.inputForm.agreeUserId = this.$store.state.user.id
            this.inputForm.status = '5'
          } else if (status === 'reapply') {
            this.inputForm.status = '2'
          }
          this.$refs['inputForm'].validate((valid) => {
            if (valid) {
              this.loading = true
              // eslint-disable-next-line no-unused-vars
              let _this = this
              let _num = 0
              const wait = function () {
                return new Promise((resolve, reject) => {
                  // _this.$refs.archiveFile.getDataList().then((data) => {
                  //   _this.inputForm.cwFileInfoList = data
                  //   if (_this.commonJS.isNotEmpty(_this.inputForm.cwFileInfoList)) {
                  //     _this.inputForm.cwFileInfoList.forEach((item, index) => {
                  //       if (_this.commonJS.isEmpty(item.fileType)) {
                  //         _this.$message.error('签章文件中，第' + (index + 1) + '条数据的“文件类型”未填写')
                  //         _num = 1
                  //         _this.loading = false
                  //         throw new Error('签章文件中，第' + (index + 1) + '条数据的“文件类型”未填写')
                  //       } else if (_this.commonJS.isEmpty(item.sealType)) {
                  //         _this.$message.error('签章文件中，第' + (index + 1) + '条数据的“盖章类型”未填写')
                  //         _num = 1
                  //         _this.loading = false
                  //         throw new Error('签章文件中，第' + (index + 1) + '条数据的“盖章类型”未填写')
                  //       }
                  //     })
                  //   } else {
                  //     _this.$message.error('最少有一条签章文件数据！')
                  //     _num = 1
                  //     _this.loading = false
                  //   }
                  // })
                  resolve()
                })
              }
              wait().then(() => {
                if (_num !== 1) {
                  if (this.commonJS.isEmpty(this.inputForm.createDate)) {
                    this.inputForm.createDate = this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
                  }
                  this.projectReportService.saveForm(this.inputForm).then(({data}) => {
                    callback(data.businessTable, data.businessId, this.inputForm)
                    this.$emit('refreshList')
                    this.loading = false
                  }).catch(() => {
                    this.loading = false
                  })
                }
              })
            }
          })
        }
      },
      /* async updateStatusById (type, callback) {
        if (await this.$refs.archiveFile.checkProgress()) {
          this.loading = false
          throw new Error()
        } else {
          if (type === 'reject' || type === 'reback') {
            await this.projectReportService.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.projectReportService.updateStatusById(param).then(() => {
                    callback()
                  })
                  // this.projectRecordsService.updateStatusById(param)
                }
                if (type === 'reback') {
                  // 撤回
                  let param = {status: '3', id: this.inputForm.id}
                  // this.projectRecordsService.updateStatusById(param)
                  this.projectReportService.updateStatusById(param)
                }
              }
            })
          } else if (type === 'hold') {
            this.projectReportService.queryById(this.inputForm.id).then(({data}) => {
              if (data.status !== '4') { // status的值不等于“驳回”就弹出提示
                this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
                throw new Error()
              } else {
                // 终止
                let param = {status: '1', id: this.inputForm.id}
                this.projectReportService.updateStatusById(param).then(() => {
                  callback()
                })
              }
            })
          }
        }
      }, */
      close () {
        this.inputForm = {
          reportReviewNo: '',
          allPrintNum: '',
          issueNum: '',
          placeOnFileNum: '',
          printedBy: '',
          checkAutograph: '',
          computerNo: '',
          opinionType: '',
          reportNo: '',
          reportNumber: '',
          reportType: '',
          businessType: '',
          auditBusinessType: '',
          reportDate: '',
          servedUnitName: '', // 被服务单位
          registerAddress: '',
          securityBusiness: '',
          businessLocation: '',
          auditFees: '',
          projectId: '',
          id: '',
          createDate: '',
          createBy: {
            id: '',
            name: JSON.parse(localStorage.getItem('user')).name
          },
          remarks: '',
          documentNo: '',
          projectName: '',
          projectNumber: '',
          officeId: '',
          signatureAnnotator1: '',
          signatureAnnotator2: '',
          signatureType: '',
          projectMasterId1: '',
          projectMasterId2: '',
          projectMasterName: '',
          cwProjectInfoList: [],
          cwFileInfoList: [],
          cwFileInfoList2: [],
          servedUnitId: '',
          status: '',
          realCreate: '',
          realHeaderName: '',
          industry: '',
          businessObjects: ''
        }
        this.$refs.enclosure.clearUpload()
        // this.$refs.archiveFile.clearUpload()
        this.$refs.inputForm.resetFields()
        this.visible = false
      },
      tabHandleClick (event) {
        // console.log(event)
      },
      // 删除
      removeEvent (row, rowIndex, type) {
        if (type === 'client') {
          // this.$refs.clientTable.remove(row)
          // this.inputForm.cwProjectInfoList.splice(rowIndex, 1)
        }
      },
      openWorkClient () {
        this.$refs.reportServiceUnitForm.init(this.inputForm.projectId)
      },
      getWorkClientChoose (row) {
        this.inputForm.servedUnitName = row.name
        this.inputForm.servedUnitId = row.id
        this.inputForm.sealType = '未盖章'
        // this.tableKeyClient = Math.random()
      },
      // 两位小数数字验证
      twoDecimalPlaces (num) {
        let str = num.toString()
        var len1 = str.substr(0, 1)
        var len2 = str.substr(1, 1)
        // eslint-disable-next-line eqeqeq
        if (str.length > 1 && len1 == 0 && len2 != '.') {
          str = str.substr(1, 1)
        }
        // eslint-disable-next-line eqeqeq
        if (len1 == '.') {
          str = ''
        }
        // eslint-disable-next-line eqeqeq
        if (str.indexOf('.') != -1) {
          var str_ = str.substr(str.indexOf('.') + 1)
          // eslint-disable-next-line eqeqeq
          if (str_.indexOf('.') != -1) {
            str = str.substr(0, str.indexOf('.') + str_.indexOf('.') + 1)
          }
          if (str_.length > 2) {
            this.$message.warning(`金额小数点后只能输入两位，请正确输入！`)
            return (str = '')
          }
        }
        // eslint-disable-next-line no-useless-escape
        str = str.replace(/[^\d^\.]+/g, '') // 保留数字和小数点
        return str
      },
      changeBusinessType () {
        // 切换业务类型的时候，审计业务类型清空
        this.inputForm.auditBusinessType = ''
      }
    }
  }
</script>
<style scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }
</style>
