<!--
  @description:基本信息
  @Modifier:qk
  @routerPath:supplierDeclaration/supplier/essentialInformation
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <el-form
      ref="form"
      :model="formData"
      :rules="rules"
      :inline-message="true"
    >
      <div class="page-title">
        1. 基本信息
        <el-button
          size="mini"
          style="color: red;font-size:18px;"
          type="text"
        >
          （必填）
        </el-button>
      </div>
      <table class="from_table">
        <tr>
          <!-- 单位注册地 -->
          <td><el-form-item ref="area" :label="language.Placeofregistration" prop="area" /></td>
          <td>
            <!--父级-->
            <el-select
              v-model="formData.incorporation"
              :placeholder="language.Pleasechoose"
              style="width: calc(47% - 4px);"
            >
              <el-option
                v-for="(item,index) in incorporationGroup"
                :key="index"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
            <!--子级-->
            <el-select
              v-model="formData.area"
              :placeholder="language.Pleasechoose"
              :disabled="formData.incorporation === '00'"
              filterable
              style="width: calc(50% - 4px)"
            >
              <el-option
                v-for="(child,childIndex) in incorporationList"
                :key="childIndex"
                :label="child.typename"
                :value="child.typecode"
              />
            </el-select>
          </td>
          <!-- 机构类型 -->
          <td><el-form-item ref="unittype" :label="language.Typeoforganization" prop="unittype" /></td>
          <td>
            <el-select v-model="formData.unittype" :placeholder="language.Pleasechoose" style="width: 100%">
              <el-option
                v-for="item in documentMethodList"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
        </tr>
        <tr class="singleRow">
          <!-- 供应商名称 -->
          <td><el-form-item ref="departName" :label="language.Suppliernames" prop="departName" /></td>
          <td colspan="3">
            <gx-input
              v-model.trim="formData.departName"
              gx-maxlength="varchar500"
              type="text"
              placeholder="请输入供应商名称"
              style="width: 96%"
            />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item
              ref="businesslicence"
              :label="businesslicenceTitle"
              prop="businesslicence"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.businesslicence"
              gx-maxlength="varchar20"
              type="text"
              placeholder="请输入合法资质编码/统一社会信用"
              style="width: 90%"
              :disabled="disableFlag"
              @change="()=>{businesslicenceCheck()}"
            />
          </td>
          <!--          </template>-->
          <!--供应商分类-->
          <td>
            <el-form-item
              ref="supplierType"
              :label="language.Supplierclassification"
              prop="supplierType"
            />
          </td>
          <td>
            <el-checkbox-group v-model="formData.supplierType">
              <el-checkbox
                v-for="(item) in supplierTypeCodeGroup"
                :key="item.typecode"
                :label="item.typecode"
              >
                {{ item.typename }}
              </el-checkbox>
            </el-checkbox-group>
          </td>
        </tr>
        <tr>
          <!--企业性质-->
          <td>
            <el-form-item
              ref="entPrpt"
              :label="language.Natureofenterprise"
              prop="entPrpt"
            />
          </td>
          <td>
            <el-select v-model="formData.entPrpt" :placeholder="language.Pleasechoose" style="width: 100%">
              <el-option
                v-for="item in supplierEntPrptGroup"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
          <!--单位成立日期-->
          <td>
            <el-form-item
              ref="foundingTime"
              :label="language.Dateofestablishment"
              prop="foundingTime"
            />
          </td>
          <td>
            <el-date-picker
              v-model="formData.foundingTime"
              :clearable="false"
              :value-format="elValueSaveFormat"
              type="date"
              style="width: 90%"
              placeholder="选择日期"
            />
          </td>
        </tr>
        <tr>
          <!--法人/负责人-->
          <td>
            <el-form-item
              ref="corporation"
              :label="language.Legalpersonpersonincharge"
              prop="corporation"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.corporation"
              gx-maxlength="varchar20"
              type="text"
              placeholder="请输入法人/负责人"
              :disabled="disableFlag"
              style="width: 90%"
            />
          </td>

          <!--法人/负责人身份证号或护照号-->
          <td>
            <el-form-item
              ref="corporateid"
              :label="language.PassportNo"
              prop="corporateid"
              style="width:220px"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.corporateid"
              gx-maxlength="varchar20"
              type="text"
              placeholder="请输入法人/负责人身份证号或护照号"
              style="width: 90%"
            />
          </td>
        </tr>
        <tr class="singleRow">
          <!--单位地址-->
          <td><el-form-item ref="areaValue" :label="language.Unitaddress" prop="areaValue" /></td>
          <td>
            <!--地区组件-->
            <cascader :region-text="formData.areaValue" @regionData="regionData" />
          </td>
          <td><el-form-item ref="address" label="详细地址" prop="address" /></td>
          <td>
            <gx-input
              v-model.trim="formData.address"
              gx-maxlength="varchar100"
              type="text"
              placeholder="请输入"
              style="width:90%"
            />
          </td>
        </tr>
        <tr class="singleRow">
          <!--供货范围-->
          <td>
            <el-form-item
              ref="supplyScope"
              :label="language.Scopeofsupply"
              prop="supplyScope"
            />
          </td>
          <td colspan="3">
            <el-input
              v-model="formData.supplyScope"
              :placeholder="language.Pleasechoose"
              disabled
              style="width: calc(96% - 135px );"
            />
            <!-- 请选择 -->
            <el-button type="primary" @click="dialogData.dialog=true">
              选择
            </el-button>
            <el-button @click="categoryTreeInfo('clear')">
              <!-- 清空 -->
              {{ language.empty }}
            </el-button>
          </td>
        </tr>
        <tr class="singleRow">
          <!--公司简介-->
          <td>
            <el-form-item
              ref="descr"
              :label="language.Companyprofile"
              prop="descr"
            />
          </td>
          <td colspan="3">
            <gx-input
              v-model.trim="formData.descr"
              gx-maxlength="varchar4000"
              :autosize="{ minRows: 8, maxRows: 8 }"
              type="textarea"
              placeholder="请输入"
              style="width:96%"
            />
          </td>
        </tr>
        <tr>
          <!-- 营业执照扫描件 -->
          <td>
            <el-form-item
              ref="businessLicenseType"
              :label="language.Scanningcopyofbusinesslicense"
              prop="businessLicenseType"
            />
          </td>
          <td>
            <upload
              :on-change="businessLicenseFile"
              :data="businessLicenseData"
              :auto-delete="true"
              :auto-upload="true"
              :limit="1"
              title=""
              but-text="图片上传"
              file-ref="fileRef"
              accept="image/jpg,image/jpeg,image/png"
              tip-text="上传格式 (.jpg .png)"
            />
          </td>
          <!--
                营业执照有效期
               与后面的复选框"长期"不可同时选中
               -->
          <td>
            <el-form-item
              ref="effectiveStartDate"
              :label="language.Validityofbusinesslicense"
              prop="effectiveStartDate"
            />
          </td>
          <td width="600px">
            <el-date-picker
              v-model="businessLicensTime[0]"
              :clearable="false"
              :format="elValueFormatDate"
              :default-time="defaultTimeDateTime"
              :disabled="formData.longTerm==='01'"
              :value-format="elValueSaveFormat"
              type="datetime"
              style="width:calc((97% - 100px)/2)"
              placeholder="开始日期"
            />至
            <el-date-picker
              v-model="businessLicensTime[1]"
              :clearable="false"
              :picker-options="disabledPickerOptions"
              :disabled="formData.longTerm==='01'"
              :format="elValueFormatDate"
              :default-time="defaultTimeDateTime"
              :value-format="elValueSaveFormat"
              type="datetime"
              style="width:calc((97% - 80px)/2)"
              placeholder="结束日期"
            />
            <el-checkbox
              v-model="formData.longTerm"
              true-label="01"
              false-label="00"
              style="padding: 0"
            >
              长期
            </el-checkbox>
          </td>
        </tr>
        <tr class="singleRow">
          <!-- 负责人身份证或护照扫描件 -->
          <td>
            <el-form-item
              ref="bprincipalType"
              :label="language.PassportNo"
              prop="bprincipalType"
              style="width:220px"
            />
          </td>
          <td colspan="3">
            <upload
              :on-change="principalFile"
              :data="principalData"
              :auto-delete="true"
              :auto-upload="true"
              :limit="1"
              file-ref="fileRefs"
              but-text="图片上传"
              title=""
              accept="image/jpg,image/jpeg,image/png"
              tip-text="上传格式 (.jpg .png)"
            />
          </td>
        </tr>
      </table>
      <div class="page-title">
        2.基本户信息
      </div>
      <table class="from_table">
        <tr>
          <!--开户银行-->
          <td>
            <el-form-item
              ref="finance.bankname"
              :label="language.Bankofdeposit"
              prop="finance.bankname"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.finance.bankname"
              gx-maxlength="varchar500"
              type="text"
              placeholder="请输入开户银行"
              style="width:96%"
            />
          </td>
          <!--账户-->
          <td>
            <el-form-item
              ref="finance.bankaccount"
              :label="language.account"
              prop="finance.bankaccount"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.finance.bankaccount"
              gx-maxlength="varchar50"
              type="text"
              placeholder="请输入账户"
              style="width:96%"
            />
          </td>
        </tr>
        <tr>
          <!--开户行号-->
          <td>
            <el-form-item
              ref="finance.accountNum"
              label="开户行号"
              prop="finance.accountNum"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.finance.accountNum"
              gx-maxlength="varchar20"
              type="text"
              placeholder="请输入开户行号"
              style="width:96%"
            />
          </td>
          <!--联行号-->
          <td>
            <el-form-item
              ref="finance.correspondentNum"
              label="联行号"
              prop="finance.correspondentNum"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.finance.correspondentNum"
              gx-maxlength="varchar20"
              type="text"
              placeholder="请输入联行号"
              style="width:96%"
            />
          </td>
        </tr>
        <tr>
          <!--开户行省份-->
          <td>
            <el-form-item
              ref="finance.accountCity"
              label="开户行地址"
              prop="finance.accountCity"
            />
          </td>
          <td>
            <!--地区组件-->
            <cascader
              :region-text="formData.finance.accountCity"
              style="width:240px"
              @regionData="bankAdderssData"
            />
            <gx-input
              v-model.trim="formData.finance.accountAddress"
              gx-maxlength="varchar1000"
              type="text"
              placeholder="请输入"
              style="width:calc(97% - 246px)"
            />
          </td>
          <!--电话-->
          <td>
            <el-form-item
              ref="finance.accountPhone"
              label="电话"
              prop="finance.accountPhone"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.finance.accountPhone"
              gx-maxlength="varchar20"
              type="text"
              placeholder="请输入"
              style="width:96%"
            />
          </td>
        </tr>
        <tr>
          <!--注册资本(万元)-->
          <td>
            <el-form-item
              ref="finance.regcapital"
              :label="language.Registeredcapital"
              prop="finance.regcapital"
            />
          </td>
          <td>
            <money :thousands="true" :unit-fixed="6" :money-value="formData.finance" width="96%" name="regcapital" />
          </td>
          <!--币种-->
          <td>
            <el-form-item
              ref="finance.currencies"
              label="币种"
              prop="finance.currencies"
            />
          </td>
          <td>
            <el-select v-model="formData.finance.currencies" :placeholder="language.Pleasechoose" style="width: 107%">
              <el-option
                v-for="item in currencies"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
        </tr>
        <tr>
          <!--实缴资本-->
          <td>
            <el-form-item
              ref="finance.actualCapital"
              label="实缴资本(万元)"
              prop="finance.actualCapital"
            />
          </td>
          <td>
            <money :thousands="true" :unit-fixed="6" :money-value="formData.finance" width="96%" name="actualCapital" />
          </td>
          <!--开户许可证-->
          <td>
            <el-form-item
              ref="finance.accountLicence"
              label="开户许可证"
              prop="finance.accountLicence"
            />
          </td>
          <td>
            <upload
              ref="upload"
              :data="accountLicenceData"
              :auto-delete="true"
              :auto-upload="true"
              :limit="1"
              file-ref="fileRefs"
              but-text="图片上传"
              title=""
              accept="image/jpg,image/jpeg,image/png"
              tip-text="上传格式 (.jpg .png)"
              @on-change="accountLicenceFile"
            />
          </td>
        </tr>
      </table>
    </el-form>
    <!-- 审核意见 -->
    <inforaMtionAudit />

    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <!-- 编辑申报材料 -->
          <template v-if="pageType==='declarationFirst'">
            <!-- 保存 -->
            <el-button :loading="confirmLoading" @click="butSaveData('form')">
              保存
            </el-button>
            <!-- 下一步 -->
            <el-button :loading="confirmLoading" type="primary" @click="nextStep('form')">
              {{ language.approvalNext }}
            </el-button>
          </template>
          <!-- 申报材料变更 -->
          <template v-if="pageType==='declarationChange'">
            <el-button :loading="confirmLoading" @click="butSaveData('form')">
              保存
            </el-button>
            <el-button :loading="confirmLoading" type="primary" @click="submitData('form')">
              提交
            </el-button>
          </template>
        </div>
      </div>
    </div>
    <!-- 供货范围 -->
    <category-tree-dialog :dialog-data="dialogData" @categoryTreeInfo="categoryTreeInfo" />
  </div>
</template>

<script>
/* 接口*/
import { saveDepartInfo, getUpdateDepartInfo } from
'@/api/supplier/supplierBaseInfo'// 暂存 ，获取
import { changeDepartInfo } from '@/api/supplier/supplierUser'
import { checkDepartInfo } from '@/api/common/user.js'
import { getOrgBaseInfoByDepartName } from '@/api/supplier/supplierUser.js'// 获取基本信息（天眼查）
import { submitDepartChangeInfo } from '@/api/supplier/supplierChange.js'// 基本信息变更提交
/* 公用方法*/
import { bankCardNumber, characters1_auto, validateInput, creditCode, linkerName, passportOrMakeId, checkLinktel } from '@/assets/js/validate'// 校验输入内容
import { validFn, randomData } from '@assets/js/utils'// 常用方法
/* 混合开发*/
import { declareHegSupperGroupMixin } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperGroupMixin'// 供应商-字典
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins'// 供应商-公用方法参数
/* 组件*/
import inforaMtionAudit from '../inforaMtionAudit/inforaMtionAudit-detail'// 审核信息
import categoryTreeDialog from '@/views/common/tools/categoryTree-dialog'// 供货范围-弹框
import cascader from '@comp/common/cascader'// 地区三级联动
import upload from '@comp/common/updownload/upload'// 文件上传组件
import money from '@comp/common/money/money'// 金额
// vuex
import { mapGetters } from 'vuex'
export default {
  name: 'EssentialInformationAdd',
  components: {
    'category-tree-dialog': categoryTreeDialog, // 供货范围选择弹框
    cascader, // 地区三级联动
    upload, // 文件上传
    money, // 附件
    inforaMtionAudit // 审核意见组件
  },
  mixins: [declareHegSupperGroupMixin, declareHegSupperMixins],
  props: {
    judgePageData: {
      type: Object,
      default: function() {
        return {
          departId: '', // 供应商id
          declarationId: '', // 申报审核携带参数
          isViewPage: '', // 判斷是否是供应商本人登录 空代表是
          departInfoId: '', // 变更提交携带参数
          changeRecord: false // 该节点是否有变更记录
        }
      }
    }
  },
  data() {
    return {
      disableFlag: false, // 禁止编辑 合法资质编码、法人
      confirmLoading: false,
      pageType: this.$route.meta.type, // 当前页面所处状态 declarationFirst 编辑申报材料查看 declarationChange 申报材料变更时
      // 获取数据所需参数
      // judgePageData: {
      //   departId: '', // 供应商id
      //   declarationId: '', // 申报id
      //   isViewPage: '' // 非变更查看页面传01 否则传空
      // },
      // 弹窗-展示/隐藏状态 true 展示/false 隐藏
      dialogData: {
        title: '供货范围',
        dialog: false, // 供货范围
        selectCodes: [] // 当前选中的供货范围Code
      },
      businessLicensTime: [], // 营业执照有效期 与后面的复选框"长期"不可同时选中
      // formData: {
      //   /* 图片上传-不传给后端主要是为了校验是否上传了文件*/
      //   businessLicenseType: '', // 营业执照扫描件
      //   departInfoId: '',
      //   bprincipalType: '', // 法人/负责人身份证号或护照号
      //   accountLicence: '' // 开户许可证
      // },
      // 校验输入内容
      rules: {
        area: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 单位注册地国家
        unittype: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 机构类型
        departName: [{ required: true, validator: validateInput, trigger: 'blur' }], // 供应商名称
        supplierType: [{ required: false, validator: characters1_auto, trigger: 'change' }], // 供应商分类
        businesslicence: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 合法资质编码
        entPrpt: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 企业性质
        foundingTime: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 单位成立日期
        corporation: [{ required: true, validator: linkerName, trigger: 'blur' }], // 法人/负责人
        corporateid: [{ required: true, validator: passportOrMakeId, trigger: 'blur' }], // 法人/负责人身份证号或护照号
        areaValue: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 单位地址
        supplyScope: [{ required: false, trigger: 'change' }], // 供货范围
        descr: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 公司简介
        effectiveStartDate: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 营业执照有效期
        address: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 单位地址
        /* 开户信息部分*/
        'finance.bankname': [{ required: true, validator: validateInput, trigger: 'blur' }], // 开户银行
        'finance.bankaccount': [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 账户
        'finance.currencies': [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 币种
        'finance.regcapital': [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 注册资本(万元)
        'finance.accountNum': [{ required: true, validator: bankCardNumber, trigger: 'blur' }], // 开户行行号
        // 'finance.correspondentNum': [{ required: true, validator: bankCardNumber, trigger: 'blur' }], // 联行号
        'finance.accountProvince': [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 开户行省份
        'finance.accountCity': [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 开户行城市
        'finance.actualCapital': [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 实缴资本
        'finance.accountAddress': [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 地址
        'finance.accountPhone': [{ required: true, validator: checkLinktel, trigger: 'blur' }], // 电话
        /* 图片上传-不传给后端主要是为了校验是否上传了文件*/
        accountLicence: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 开户许可证
        businessLicenseType: [{ required: true, message: '请上传', trigger: 'change' }], // 营业执照扫描件
        bprincipalType: [{ required: true, message: '请上传', trigger: 'change' }]// 法人/负责人身份证号或护照号
      }
    }
  },
  computed: {
    /* language 国际化*/
    ...mapGetters(['language'])
  },
  watch: {
    // 营业执照有效期
    businessLicensTime() {
      this.businessLicenseChange()// 营业执照有效期
    },
    // 供货范围-弹框选中回显
    'formData.supplyScopeId'() {
      if (this.formData.supplyScopeId) {
        this.dialogData.selectCodes = this.formData.supplyScopeId.split(',')
      } else {
        this.dialogData.selectCodes = []
      }
    },
    // 机构类型
    'formData.unittype'(val) {
      this.formData.orgType = val// 机构类型
    },
    // 营业执照有效期-复选框
    'formData.longTerm'() {
      this.businessLicenseCheckChange()// 营业执照有效期-复选框
    },
    // 单位注册地
    'formData.incorporation'(val) {
      // 00 境内
      if (val === '00') {
        this.rules.businesslicence = [{ required: true, validator: creditCode, trigger: 'blur' }]
      } else {
        this.rules.businesslicence = [{ required: true, validator: characters1_auto, trigger: 'blur' }]
      }
    }
  },
  created() {
    this.judgePageData.isViewPage = this.pageType === 'declarationChange' ? '' : '01'
    this.initKey() // 获取供应字典
    this.getDepartInfo() // 获取基本信息
  },
  methods: {
    // 合法资质编码/统一社会信用代码 重复校验
    async businesslicenceCheck() {
      if (!this.formData.businesslicence) return
      let isCheck = true // false 未重复 true 重复
      const data = {
        businesslicence: this.formData.businesslicence,
        departInfoId: this.formData.departInfoId
      }
      await checkDepartInfo(data).then(res => {
        isCheck = false
      })
      return isCheck
    },
    // 负责人身份证号或护照号
    principalFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'bprincipalType', 'true')// 上传了
      } else {
        this.$set(this.formData, 'bprincipalType', '')// 未上传
      }
    },
    // 营业执照扫描件
    businessLicenseFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'businessLicenseType', 'true')// 上传了
      } else {
        this.$set(this.formData, 'businessLicenseType', '')// 未上传
      }
    },
    // 开户许可证
    accountLicenceFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'accountLicence', 'true')// 上传了
      } else {
        this.$set(this.formData, 'accountLicence', '')// 未上传
      }
    },
    // 供应商基本信息变更时，点击修改触发保存的方法
    getDepartInfo() {
      // 变更
      if (this.pageType === 'declarationChange') {
        const params = {
          departId: this.judgePageData.departId
        }
        changeDepartInfo(params).then((response) => {
          this.initData('', '01')// 获取基本信息
        })
      } else {
        this.initData()// 获取基本信息
      }
    },
    // 获取基本信息
    initData(val, isUpdateButton) {
      if (this.pageType === 'declarationChange' && val) {
        this.judgePageData.isViewPage = val === 'change' ? '' : '01'
      }
      const params = {
        departId: this.judgePageData.departId,
        declarationId: this.judgePageData.declarationId, // 申报id
        isViewPage: this.judgePageData.isViewPage, // 判断是否为变更数据
        isUpdateButton: isUpdateButton || '00'
      }
      getUpdateDepartInfo(params).then((response) => {
        const { info, expand, finance } = response.data
        if (info || expand) {
          this.formData = { ...info, ...expand, finance: finance || this.formData.finance }// 基本信息部分
        }
        if (this.formData.effectiveStartDate) {
          this.businessLicensTime = [this.formData.effectiveStartDate, this.formData.effectiveEndDate]
        }
        if (this.pageType === 'declarationChange') {
          this.formData.departInfoId = response.data.info.id
        }
        /* 初始化默认值 */
        // 供应商分类
        if (this.formData.supplierType && typeof this.formData.supplierType === 'string') { // 非空时
          this.formData.supplierType = this.formData.supplierType.split(',')
        } else { // 为空时
          this.formData.supplierType = ['00'] // 供应商分类 00 设备制造商
        }
        // 判断是否有Id
        if (!this.formData.id) {
          this.formData.id = randomData()// 随机生成Id
          // 用户信息-第一次编辑-初始化用户信息
          const { currentDepart } = this.$store.getters.info
          this.formData.departName = currentDepart.departname// 供应商名称
          // 天眼查接口初始化基本信息
          this.getOrgBaseInfoByDepartName()
          // 禁止编辑
          // this.disableFlag = false
        }
        // 附件主键Id
        this.businessLicenseData.bizId = this.formData.id // 营业执照扫描件
        this.principalData.bizId = this.formData.id // 法人/负责人身份证号或护照号
        this.accountLicenceData.bizId = this.formData.id // 开户许可证
        this.formData.finance.id = this.formData.id // fianceId
      })
    },
    // 通过机构名称获取第三方的机构信息
    getOrgBaseInfoByDepartName() {
      const param = {
        departId: this.$store.getters.info.currentDepart.id, // 供应商id
        departName: this.$store.getters.info.currentDepart.departname // 供应商名称
      }
      getOrgBaseInfoByDepartName(param).then((res) => {
        const {
          businesslicence,
          busyScope,
          corporation,
          detailedAddress,
          regcapital
        } = res.data
        this.formData.businesslicence = businesslicence // 合法资质编码
        this.formData.descr = busyScope // 公司简介
        this.formData.corporation = corporation.trim() // 法人
        this.formData.address = detailedAddress // 地址
        this.formData.finance.regcapital = regcapital // 注册资本
      })
    },
    // 单位地址 所在区域三级联动组件使用
    regionData(regionName, location) {
      this.formData.areaValue = regionName
      // 将数组转成字符串
      this.formData.orgCountry = location.join(',')
    },
    // 开户行地址
    bankAdderssData(regionName, location) {
      this.formData.finance.accountCity = regionName
      // 将数组转成字符串
      this.formData.orgCountry = location.join(',')
    },
    // 范围选择/清空
    categoryTreeInfo(data) {
      if (data === 'clear') { // 清空
        this.formData.supplyScope = ''// 名称
        this.formData.supplyScopeId = ''// 代码
      } else { // 选择
        this.formData.supplyScope = data.labels// 名称
        this.formData.supplyScopeId = data.keys// 代码
      }
    },
    // 营业执照有效期
    businessLicenseChange() {
      if (this.businessLicensTime[0] && this.businessLicensTime[1]) { // 有时间时
        this.formData.effectiveStartDate = this.businessLicensTime[0]
        this.formData.effectiveEndDate = this.businessLicensTime[1]
      } else { // 没有时间时
        this.formData.effectiveStartDate = ''
        this.formData.effectiveEndDate = ''
      }
    },
    // 营业执照有效期-复选框
    businessLicenseCheckChange() {
      /* 与后面的复选框"长期"不可同时选中*/
      if (this.formData.longTerm === '01') { // 选择时
        // 取消校验空
        delete this.rules.effectiveStartDate// 营业执照有效期
      } else {
        // 打开校验
        this.rules.effectiveStartDate = [{ required: true, message: '请选择', trigger: 'change' }]// 营业执照有效期
      }
    },
    // 保存组装数据
    assemblyData() {
      const data = {
        ...this.formData
      }
      // 营业执照有效期
      if (data.effectiveStartDate) {
        data.effectiveStartDate = this.$Moment(data.effectiveStartDate).format(this.momentSaveFormat)
        data.effectiveEndDate = this.$Moment(data.effectiveEndDate).format(this.momentSaveFormat)
      }
      // 供应商分类
      if (data.supplierType) data.supplierType = data.supplierType.join(',')
      // 删掉不传给后端的参数
      delete data.businessLicenseType// 营业执照扫描件
      delete data.bprincipalType // 法人/负责人身份证号或护照号
      return data
    },
    // 保存数据接口下一步
    saveData(type) {
      // 统一社会信用代码/是否校验通过 false 未通过
      const check = this.businesslicenceCheck()
      check.then(() => { // 未重复
        this.confirmLoading = true// btnLoding
        const data = this.assemblyData()// 组装数据
        data.status = '00'
        saveDepartInfo(data).then(res => {
          this.formData.id = res.data.id// Id
          this.formData.departId = res.data.departId
          this.formData.finance.id = res.data.financeId
          // route携带参数
          this.confirmLoading = false// btnLoding
          const pathData = {
            id: this.formData.id,
            departId: this.formData.departId
          }
          if (type === 'next') { // 下一步
            this.$emit('stepPage', 'next', pathData)// 步骤条切换方法 next 下一步
          } else if (type === 'save') { // 保存
            this.confirmLoading = false// btnLoding
            // this.initData()
            // 申报材料变更-保存提示
            this.$message({
              message: '保存成功',
              type: 'success'
            })
          }
        }).catch(() => {
          this.confirmLoading = false// btnLoding
        })
      })
    },
    // 申报材料变更-保存
    butSaveData(formName) {
      this.saveData('save')
      // 校验输入内容
      // this.$refs[formName].validate((valid, field) => {
      //   if (valid) { // 校验通过
      //     this.saveData('save')//
      //   } else {
      //     validFn(field, this)// 校验
      //   }
      // })
    },
    // 申报材料变更-提交
    submitData(formName) {
      // 校验输入内容
      this.$refs[formName].validate((valid, field) => {
        if (valid) { // 校验通过
          this.$confirm('确认提交审核吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.formData.supplierType = this.formData.supplierType.join()
            this.formData.status = '01'
            submitDepartChangeInfo(this.formData).then((response) => {
              if (response.header.ret === '0') {
                this.$message({
                  type: 'success',
                  message: '提交成功'
                })
                if (this.pageType === 'declarationChange' && this.judgePageData.changeRecord === false) {
                  this.$nextTick(function() {
                    this.$emit('showStatuschage')// 传给父集组件参数-审核状态-审核图片展示
                    const data = 'change'
                    this.initData(data)
                  })
                } else {
                  this.$router.push({
                    path: 'supplier'
                  })
                }
              } else {
                this.$message({
                  type: 'warning',
                  message: '提交失败'
                })
              }
            })
          }).catch(() => {
          })
          // this.saveData('save')//
        } else {
          validFn(field, this)// 校验
        }
      })
    },
    // 暂存，进行下一步
    nextStep(formName) {
      // 校验输入内容
      this.$refs[formName].validate((valid, field) => {
        if (valid) { // 校验通过
          this.saveData('next')// 下一步
        } else {
          validFn(field, this)// 校验
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
