<!-- 企业工商信息 -->
<template>
  <div>
    <el-row>
      <el-col :span="4" align="left" class="title-class">
        <span>{{$t('enterpriseInfoManage.supplierInfoManage.enterpriseBasicInfo')}}</span>
      </el-col>
      <el-col :span="20" align="right">
        <auth-button type="primary" size="small" icon="iconfont iconbaoliyewuxinxichaxun"
                     :label="$t('enterpriseInfoManage.supplierInfoManage.checkInnerEye')" @click="gotoEye"
                     :menuCode="menuId" perms="bussView" :openPerms="true"></auth-button>
      </el-col>
    </el-row>
    <div class="business-info">
      <el-divider></el-divider>
    </div>
    <el-form :model="businessForm" label-width="140px" label-position="right" ref="businessForm" :rules="formRule">
      <dym-form :componentList="componentList" :formValue="businessForm"></dym-form>
    </el-form>
    <el-collapse v-model="activeNames">
      <!-- 企业信息变更记录 -->
      <el-collapse-item :title="$t('enterpriseInfoManage.supplierInfoManage.enterpriseChangeInfo')" name="1">
        <enterprise-change-info :sourceData.sync="sourceData"></enterprise-change-info>
      </el-collapse-item>
    <!-- 企业股东信息   -->
      <el-collapse-item :title="$t('enterpriseInfoManage.supplierInfoManage.shareholderInfo')" name="2">
        <shareholder-info :holderForms.sync="holderForms"></shareholder-info>
      </el-collapse-item>
    <!-- 企业主要成员信息   -->
      <el-collapse-item :title="$t('enterpriseInfoManage.supplierInfoManage.enterpriseKeyMemberInfo')" name="3">
        <enterprise-key-member-info :memberList.sync="memberList"></enterprise-key-member-info>
      </el-collapse-item>
    <!-- 企业分支机构信息   -->
      <el-collapse-item :title="$t('enterpriseInfoManage.supplierInfoManage.enterpriseBranch')" name="4">
        <enterprise-branch :enterpriseBranchList.sync="enterpriseBranchList"></enterprise-branch>
      </el-collapse-item>
    </el-collapse>
<!--    <div class="dialog-footer">-->
<!--      <auth-button :xhr="$xhr" :store="$store" size="" type="primary"-->
<!--                   icon="iconfont iconbaocun" :label="$t('common.save')" @click="save"-->
<!--                   :menuCode="menuId" perms="bussSave" :openPerms="true"></auth-button>-->
<!--    </div>-->
  </div>
</template>

<script>
import * as format from '@/filters/index.js'
import { dymForm, DataTable, authButton, SelectDictionary, validate } from 'newepoch-components'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/companyApi'
import { TIANYANCHA } from '@/constant.js'
import storage from '@/utils/storage'
import enterpriseChangeInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/businessInfo/enterpriseChangeInfo'
import shareholderInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/businessInfo/shareholderInfo'
import enterpriseKeyMemberInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/businessInfo/enterpriseKeyMemberInfo'
import enterpriseBranch from '@/pages/enterpriseInfoManage/supplierInfoManage/businessInfo/enterpriseBranch'
import { regExp } from '@/validator/index'
export default {
  name: 'businessInfo',
  components: {
    dymForm,
    DataTable,
    authButton,
    SelectDictionary,
    enterpriseChangeInfo,
    shareholderInfo,
    enterpriseKeyMemberInfo,
    enterpriseBranch
  },
  data () {
    return {
      pa: '',
      activeNames: 0,
      businessForm: {},
      holderForms: [],
      memberList: [],
      sourceData: [],
      enterpriseBranchList: [],
      memberForm: {},
      enterpriseName: '',
      componentList: [
        // 注册号
        {
          value: 'regNumber',
          disabled: true,
          componentName: 'el-input',
          maxlength: 18,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.registerNumber,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'regNumber'
        },
        // 登记机关
        {
          value: 'regInstitute',
          disabled: true,
          componentName: 'el-input',
          maxlength: 100,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.registerOrgan,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'regInstitute'
        },
        // 法人
        {
          value: 'legalPersonName',
          disabled: true,
          componentName: 'el-input',
          maxlength: 100,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.legalPerson,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'legalPersonName'
        },
        // 企业状态
        {
          value: 'regStatus',
          disabled: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'ZDC0140',
          store: this.$store,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.enterpriseStatus,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'regStatus'
        },
        // 更新日期
        {
          value: 'modifyTime',
          disabled: true,
          componentName: 'el-date-picker',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.updateDate,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'modifyTime'
        },
        // 统一社会信用代码
        {
          value: 'creditCode',
          disabled: true,
          componentName: 'el-input',
          maxlength: 18,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.creditCode,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'creditCode'
        },
        // 注册资本
        {
          value: 'regCapital',
          disabled: true,
          componentName: 'el-input',
          maxlength: 15,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.registerAssets,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'regCapital'
        },
        // 注册资本币种
        {
          value: 'regCapitalCurrency',
          disabled: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'ZDC0141',
          store: this.$store,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.registerAssetsType,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'regCapitalCurrency'
        },
        // 企业类型
        {
          value: 'companyOrgType',
          disabled: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'ZDC0113',
          store: this.$store,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.enterpriseType,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'companyOrgType'
        },
        // 注册地址
        {
          value: 'regLocation',
          disabled: true,
          componentName: 'el-input',
          maxlength: 254,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.registerAddress,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'regLocation'
        },
        // 营业开始日期
        {
          value: 'fromTime',
          disabled: true,
          componentName: 'el-date-picker',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.openingDate,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'fromTime'
        },
        // 营业结束日期
        {
          value: 'toTime',
          disabled: true,
          componentName: 'el-date-picker',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.closingDate,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'toTime'
        },
        // 发照日期
        {
          value: 'checkDate',
          disabled: true,
          componentName: 'el-date-picker',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.issueDate,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'checkDate'
        },
        // 经营范围
        {
          value: 'businessScope',
          disabled: true,
          componentName: 'el-input',
          type: 'textarea',
          rows: 3,
          maxlength: 254,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.busScope,
          width: '50%',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'businessScope'
        }
        // // 经营性质
        // {
        //   value: 'economicAture',
        //   disabled: false,
        //   componentName: 'SelectDictionary',
        //   dictTypeCode: 'ZDC0134',
        //   store: this.$store,
        //   label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.busNature,
        //   width: '50%',
        //   placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
        //   cols: [24, 24, 24, 8],
        //   prop: 'economicAture'
        // }
      ],
      formRule: {
        // 统一社会信用代码
        creditCode: [{
          required: true,
          message: this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.creditCode,
          trigger: 'blur'
        }, { validator: validate.creditCodeValidate, trigger: 'blur' }],
        // 法人
        legalPersonName: [{ validator: validate.nameValidate, trigger: 'blur' }],
        regCapital: [{ validator: validate.yuanValidate, trigger: 'blur' }],
        // 营业开始日期
        fromTime: [{ validator: this.fromTimeCheck, trigger: 'blur' }],
        // 营业结束日期
        toTime: [{ validator: this.toTimeCheck, trigger: 'blur' }]
      }
    }
  },
  computed: {
    menuId () {
      let obj = this.$store.getters.menuObject
      return obj[this.$route.path]
    }
  },
  methods: {
    // 营业开始日期验证
    fromTimeCheck: function (rule, value, callback) {
      if (this.businessForm.toTime) {
        if (Date.parse(value) > Date.parse(this.businessForm.toTime)) {
          callback(new Error(this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.formTimeCheck))
        } else {
          callback()
        }
      } else {
        callback()
      }
    },
    // 营业结束日期验证
    toTimeCheck: function (rule, value, callback) {
      if (this.businessForm.fromTime) {
        if (Date.parse(value) > Date.parse(this.businessForm.fromTime)) {
          callback()
        } else {
          callback(new Error(this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.toTimeCheck))
        }
      } else {
        callback()
      }
    },
    // 注册资本校验
    regCapitalShowCheck: function (rule, value, callback) {
      if (!this.UtilJs.isEmpty(value)) {
        if (regExp.amountMoney.test(value)) {
          callback()
        } else {
          callback(new Error(this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.regCapitalShowCheckMessage))
        }
      } else {
        callback()
      }
    },
    creditCodeCheck: function (rule, value, callback) {
      if (!this.UtilJs.isEmpty(value)) {
        if (regExp.englishAndNumber.test(value)) {
          callback()
        } else {
          callback(new Error(this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.creditCodeCheck))
        }
      } else {
        callback(new Error(this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.creditCode))
      }
    },
    getNetWork () {
      let { enterpriseId, enterpriseName } = this.pa
      this.enterpriseName = enterpriseName
      this.loadCommerceInfo({ enterpriseId: enterpriseId })
      this.loagIndustryChangeRecordList({ enterpriseId: enterpriseId })
      this.loadIndustryPartnerList({ enterpriseId: enterpriseId })
      this.loadIndustryMemberList({ enterpriseId: enterpriseId })
      this.loadIndustryBranchList({ enterpriseId: enterpriseId })
    },
    // 跳转天眼查
    gotoEye () {
      let enterpriseName = this.enterpriseName
      window.open(TIANYANCHA + enterpriseName)
    },
    // 保存数据
    save () {
      // this.businessForm.regCapital = this.businessForm.regCapitalShow.replace(/,/g, '')
      this.businessForm.enterpriseId = storage.getLocal('params').enterpriseId
      this.saveIndustryBranchList(this.businessForm)
    },
    // 按企业获取企业工商信息
    loadCommerceInfo (parmas) {
      let that = this
      supplierInfoManageApi.refreshHintEditApi.getIndustryCommerceList(parmas).then(res => {
        // console.log('按企业获取企业工商信息', res)
        if (res.data && res.data.length !== 0) {
          // res.data[0].regCapitalShow = format.thousandFilter(res.data[0].regCapital)
          that.businessForm = res.data[0]
          that.businessForm.checkDate = format.formatDate(that.businessForm.checkDate)
          that.businessForm.fromTime = format.formatDate(that.businessForm.fromTime)
          that.businessForm.toTime = format.formatDate(that.businessForm.toTime)
          // that.businessForm.regCapital = format.thousandFilter(that.businessForm.regCapital)
        } else {
          that.businessForm = {}
        }
      })
    },
    // 按企业工商信息变更历史
    loagIndustryChangeRecordList (parmas) {
      let that = this
      supplierInfoManageApi.refreshHintEditApi.getIndustryChangeRecordList(parmas).then(res => {
        // console.log('按企业工商信息变更历史', res)
        if (res.data) {
          that.sourceData = res.data
        }
      })
    },
    // 获取企业工商信息股东表
    loadIndustryPartnerList (parmas) {
      let that = this
      supplierInfoManageApi.refreshHintEditApi.getIndustryPartnerList(parmas).then(res => {
        // console.log('获取企业工商信息股东表', res)
        that.holderForms.length = 0
        if (res.data) {
          // that.holderForm = res.data
          that.holderForms.push(...res.data)
        }
      })
    },
    // 获取企业主要成员表
    loadIndustryMemberList (parmas) {
      let that = this
      supplierInfoManageApi.refreshHintEditApi.getIndustryMemberList(parmas).then(res => {
        // console.log('获取企业主要成员表', res)
        if (res.data) {
          that.memberList = res.data
        }
      })
    },
    // 获取企业工商信息分支机构
    loadIndustryBranchList (parmas) {
      let that = this
      supplierInfoManageApi.refreshHintEditApi.getIndustryBranchList(parmas).then(res => {
        if (res.data) {
          // console.log('获取企业工商信息分支机构', res)
          that.enterpriseBranchList = res.data
        }
      })
    },
    // 保存工商信息
    saveIndustryBranchList (parmas) {
      let $this = this
      $this.$refs['businessForm'].validate((valid) => {
        if (valid) {
          supplierInfoManageApi.refreshHintEditApi.putIndustryCommerce(parmas).then(res => {
            if (res) {
              $this.success(this.$i18n.messages[this.$i18n.locale].common.saveBtnSuccessfully)
              let { enterpriseId } = storage.getLocal('params')
              this.loadCommerceInfo({ enterpriseId: enterpriseId })
              this.loagIndustryChangeRecordList({ enterpriseId: enterpriseId })
            }
          })
        } else {
          $this.warning(this.$i18n.messages[this.$i18n.locale].common.formrulesMessage)
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
  @import '@/styles/enterpriseInfoManage/supplierInfoManage/businessInfo.scss';
</style>
