<!-- 核心企业信息维护 -->
<template>
  <div>
    <up-down-layout :handleFlag.sync="handleFlag">
      <template slot="table">
        <el-row>
          <el-col :span="1" align="left">
            <back-button size="medium" @back="back"></back-button>
          </el-col>
          <el-col :span="23" align="right">
            <span class="date-title-class">{{$t('enterpriseInfoManage.supplierInfoManage.lastUpdateTime')}}{{basicForm.lastRefreshTime | formatDate}}</span>
            <auth-button type="primary" icon="iconfont iconshuaxin" :label="$t('enterpriseInfoManage.supplierInfoManage.refresh')"
                         size="medium"
                         @click="showRefresh" :menuCode="menuId" perms="croRefresh" :openPerms="true"></auth-button>
            <auth-button type="primary" icon="iconfont iconbaocun" :label="$t('common.saveBtn')" @click="save"
                         size="medium"
                         :menuCode="menuId" perms="croSave" :openPerms="true"></auth-button>
          </el-col>
        </el-row>
<!--        <div class="enterprise-info">-->
<!--          <el-divider></el-divider>-->
<!--        </div>-->
        <el-collapse v-model="activeNames" class="marginTopBottom">
          <el-collapse-item title="" name="1">
            <el-form :model="basicForm" label-width="130px" ref="basicForm">
          <el-row>
            <!--企业名称-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="enterpriseName" :class="{detail: basicForm.showEnterpriseNameRedFlag}" :label="$t('enterpriseInfoManage.supplierInfoManage.enterpriseName')"
                            :rules="formRules.enterpriseName">
                <el-input v-model="basicForm.enterpriseName" class="dymForm" maxlength="100" :placeholder="$t('common.pleaseInput')"></el-input>
              </el-form-item>
            </el-col>
            <!--核心企业简称-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="shortName" :class="{detail: basicForm.showRedFlag}"  :label="$t('enterpriseInfoManage.coreEnterpriseInfoManage.coreEnterpriseShortName')"
                            :rules="formRules.shortName">
                <el-input v-model="basicForm.shortName" maxlength="20" :disabled="false" class="dymForm" :placeholder="$t('common.pleaseInput')"></el-input>
              </el-form-item>
            </el-col>
            <!--核心企业简码-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="enterpriseCode" :label="$t('enterpriseInfoManage.coreEnterpriseInfoManage.enterpriseCode')">
                <el-input v-model="basicForm.enterpriseCode" maxlength="20" :disabled="false" class="dymForm" :placeholder="$t('common.pleaseInput')"></el-input>
              </el-form-item>
            </el-col>
            <!--曾用名-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="historyNames" :label="$t('enterpriseInfoManage.supplierInfoManage.usedName')">
                <el-input v-model="basicForm.historyNames" :disabled="true" class="dymForm"></el-input>
              </el-form-item>
            </el-col>
            <!--营业执照核准日期-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="approvedTime" :label="$t('enterpriseInfoManage.supplierInfoManage.yyzzApprovedDate')">
                <el-input v-model="basicForm.approvedTime" :disabled="true" class="dymForm"></el-input>
              </el-form-item>
            </el-col>
            <!--企业性质-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="enterpriseNature" :label="$t('enterpriseInfoManage.supplierInfoManage.enterpriseProperty')">
                <!--<select-dictionary v-model="basicForm.fincrmEnterpriseInfoDto.enterpriseNature" :disabled="true" :dictTypeCode="''" :store="$store"-->
                                   <!--:placeholder="''">-->
                <!--</select-dictionary>-->
                <select-dictionary v-model="basicForm.enterpriseNature" :disabled="true" :dictTypeCode="'enterprise_nature'" :store="$store"
                                   :placeholder="''">
                </select-dictionary>
                <!--<el-input v-model="basicForm.enterpriseNature" :disabled="true"-->
                          <!--:placeholder="''"></el-input>-->
              </el-form-item>
            </el-col>
            <!-- 盖章方式-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="stampWay" :label="$t('enterpriseInfoManage.supplierInfoManage.sealWay')">
                <select-dictionary v-model="basicForm.stampWay" :disabled="true" :dictTypeCode="'sealing_method'" :store="$store"
                                   :placeholder="''">
                </select-dictionary>
              </el-form-item>
            </el-col>
            <!-- 未申请电子章原因-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="noElectronicReason" :label="$t('enterpriseInfoManage.supplierInfoManage.noApplyReason')">
                <el-input v-model="basicForm.noElectronicReason" :disabled="true" class="dymForm"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
          </el-collapse-item>
        </el-collapse>
        <!--<el-form :model="basicForm" label-width="130px" ref="basicForm">-->
          <!--<dym-form :componentList="componentList" :formValue.sync="basicForm"></dym-form>-->
        <!--</el-form>-->
        <el-tabs type="card">
          <!-- 业务操作信息 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.businessOperateInfo')">
            <core-enterbusiness-operate-info></core-enterbusiness-operate-info>
          </el-tab-pane>
          <!-- 企业工商信息 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.businessInfo')">
            <business-info></business-info>
          </el-tab-pane>
        </el-tabs>
      </template>
    </up-down-layout>
    <refresh-hint-edit :visible.sync="refreshFlag" :menuId="menuId" @compareFun="compareFun"  :form="item" :editModel="refreshModel"></refresh-hint-edit>
  </div>
</template>

<script>
import * as format from '@/filters/index.js'
import { upDownLayout, dymForm, authButton, SelectDictionary, validate } from 'newepoch-components'
// 业务操作信息
import coreEnterbusinessOperateInfo from '@/pages/enterpriseInfoManage/coreEnterpriseInfoManage/coreEnterbusinessOperateInfo.vue'
// 企业工商信息
import BusinessInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/businessInfo.vue'
import backButton from '@/components/element/enterpriseInfoManage/backButton.vue'
import storage from '@/utils/storage'
// 刷新提示--企业信息变更
import RefreshHintEdit from '@/pages/enterpriseInfoManage/supplierInfoManage/refreshHintEdit.vue'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
export default {
  name: 'coreEnterpriseInfoManageEdit',
  components: {
    upDownLayout,
    dymForm,
    authButton,
    BusinessInfo,
    coreEnterbusinessOperateInfo,
    RefreshHintEdit,
    SelectDictionary,
    backButton
  },
  data () {
    return {
      activeNames: ['1'],
      handleFlag: false,
      refreshFlag: false,
      refreshModel: '',
      item: {},
      queryParas: {
        keyId: storage.getLocal('params').enterpriseId,
        tagCode: '60'
      },
      basicForm: {},
      formRules: {
        enterpriseName: [{ required: true, message: this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.enterpriseName, trigger: 'blur' },
          { validator: validate.enterpriseNameValidate, trigger: 'blur' }],
        shortName: [{ required: true, message: this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.coreEnterpriseShortName, trigger: 'blur' },
          { validator: validate.enterpriseNameValidate, trigger: 'blur' }]
      }
    }
  },
  computed: {
    menuId () {
      return storage.getLocal('params').menuId
    }
  },
  activated () {
    this.queryParas.keyId = storage.getLocal('params').enterpriseId
    // 初始调用
    this.handleFilter()
  },
  mounted () {
    // 初始调用
    this.queryParas.keyId = storage.getLocal('params').enterpriseId
    this.handleFilter()
  },
  methods: {
    // 刷新比较
    compareFun (data) {
      if (data) {
        data.forEach(it => {
          // 企业名称
          if (it.modifyField === 'name') {
            this.$set(this.basicForm, 'showEnterpriseNameRedFlag', true)
          }
          // 核心企业简称
          // if (it.modifyField === 'enterpriseName') {
          //   this.$set(this.basicForm, 'showEnterpriseNameRedFlag', true)
          // }
        })
      }
    },
    // 保存
    save () {
      let $this = this
      $this.$refs['basicForm'].validate((valid) => {
        if (valid) {
          let data = {
            fincrmEnterpriseDTO: {},
            fincrmEnterpriseInfoDTO: {},
            fincrmEnterpriseBusinessDTO: {},
            industryCommerceDTO: {}
          }
          // 企业Id
          data.fincrmEnterpriseDTO.keyId = $this.queryParas.keyId
          data.fincrmEnterpriseInfoDTO.enterpriseId = $this.queryParas.keyId
          // 企业名称
          data.fincrmEnterpriseDTO.enterpriseName = $this.basicForm.enterpriseName
          // 核心企业简称
          data.fincrmEnterpriseDTO.shortName = $this.basicForm.shortName
          // 核心企业简码
          data.fincrmEnterpriseDTO.enterpriseCode = $this.basicForm.enterpriseCode
          // 企业业务ID
          data.fincrmEnterpriseBusinessDTO.keyId = $this.basicForm.enterpriseBusId
          // 企业详情ID
          data.fincrmEnterpriseInfoDTO.keyId = $this.basicForm.enterpriseInfoId
          // 企业名称
          data.industryCommerceDTO.name = $this.basicForm.enterpriseName
          // 修改类型
          data.updateEnterpriseType = 3
          // 统一社会信用代码
          data.industryCommerceDTO.creditCode = storage.getLocal('params').creditCode
          supplierInfoManageApi.enterpriseUpdate.update(data).then(res => {
            if (res && res.data) {
              $this.warning(this.$i18n.messages[this.$i18n.locale].common.saveSuccessInfo)
              this.handleFilter()
            } else {
              $this.error(this.$i18n.messages[this.$i18n.locale].common.saveError)
            }
          })
        } else {
          $this.warning(this.$i18n.messages[this.$i18n.locale].common.formrulesMessage)
        }
      })
    },
    // 返回
    back () {
      this.$router.go(-1)
      // this.$router.push({
      //   name: 'supplierInfoManageList'
      // })
    },
    // 刷新
    showRefresh () {
      this.refreshModel = 'V'
      this.item = {}
      this.refreshFlag = true
    },
    // 查询
    handleFilter () {
      let $this = this
      supplierInfoManageApi.enterpriseModified.getEnterpriseModified(this.queryParas).then(res => {
        if (res && res.data) {
          $this.basicForm = res.data
          $this.basicForm.approvedTime = format.formatDateNull($this.basicForm.approvedTime)
          $this.basicForm.enterpriseNature = format.formatDictDefoultNew($this.basicForm.enterpriseNature)
        }
      })
    }
  }
}
</script>

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