<!-- 企业信息维护 -->
<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')}}2019-08-08 14:00:00</span>-->
            <span class="date-title-class">{{$t('enterpriseInfoManage.supplierInfoManage.lastUpdateTime')}}{{basicForm.lastRefreshTime | formatDate}}</span>
            <auth-button type="primary" size="medium" icon="iconfont iconshuaxin"
                         :label="$t('enterpriseInfoManage.supplierInfoManage.refresh')" @click="showRefresh"
                         :menuCode="menuId" perms="suRefresh" :openPerms="true"></auth-button>
            <auth-button type="primary" size="medium" icon="iconfont iconzancun"
                         :label="$t('common.saveBtn')" @click="save"
                         :menuCode="menuId" perms="suSave" :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.trim="basicForm.enterpriseName" maxlength="100" class="border-color 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.fincrmIndustryCommerceDto.fromTime" :disabled="true" :placeholder="$t('common.pleaseInput')"></el-input>-->
                <el-date-picker class="dymForm" type="date" v-model="basicForm.approvedTime" :disabled="true"></el-date-picker>
              </el-form-item>
            </el-col>
            <!--企业类型-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="enterpriseType" :label="$t('enterpriseInfoManage.supplierInfoManage.enterpriseType')">
                <!--<el-input v-model="basicForm.fincrmEnterpriseInfoDto.enterpriseType" :disabled="true" :placeholder="$t('common.pleaseInput')"></el-input>-->
                <select-dictionary v-model="basicForm.enterpriseType" :disabled="true" :dictTypeCode="'ZDC0113'"
                                   :placeholder="''">
                </select-dictionary>
              </el-form-item>
            </el-col>
            <!--企业性质-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="enterpriseNature" :class="{detail: basicForm.showEnterpriseNatureRedFlag}"  :label="$t('enterpriseInfoManage.supplierInfoManage.enterpriseProperty')">
                <select-dictionary v-model="basicForm.enterpriseNature" :dictTypeCode="'enterprise_nature'"
                                   :placeholder="$t('common.pleaseSelect')">
                </select-dictionary>
              </el-form-item>
            </el-col>
            <!--行业分类-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="industry" :class="{detail: basicForm.showIndustryRedFlag}"  :label="$t('enterpriseInfoManage.supplierInfoManage.industryClassify')">
                <!--<el-input v-model="basicForm.industryCategory" :disabled="false" :placeholder="$t('common.pleaseInput')"></el-input>-->
                <select-dictionary v-model="basicForm.industryCategory" :dictTypeCode="'ZD0007'" :filterable="true"
                                   :placeholder="$t('common.pleaseSelect')">
                </select-dictionary>
              </el-form-item>
            </el-col>
            <!--企业等级-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="internalRank" :label="$t('enterpriseInfoManage.supplierInfoManage.enterpriseLevel')">
                <!--<el-input v-model="basicForm.fincrmEnterpriseInfoDto.internalRank" :disabled="true" :placeholder="$t('common.pleaseInput')"></el-input>-->
                <select-dictionary v-model="basicForm.enterpriseGrade" :disabled="true" :dictTypeCode="'enterprise_grade'"
                                   :placeholder="''">
                </select-dictionary>
              </el-form-item>
            </el-col>
            <!--核心企业-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="coreEnterpriseName" :label="$t('enterpriseInfoManage.supplierInfoManage.coreEnterprise')">
                <el-input v-model="basicForm.coreEnterpriseName" class="dymForm" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <!-- 关联企业(下拉框)-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="affiliatedEnterpriseIds" :class="{detail: basicForm.showRedFlag}" :label="$t('enterpriseInfoManage.supplierInfoManage.affiliatedEnterprise')">
                <!--<el-input v-model="basicForm.affiliatedEnterprise" :disabled="true" :placeholder="$t('common.pleaseInput')"></el-input>-->
                <select-affiliated-enterprises v-model="basicForm.affiliatedEnterpriseIds" :multiple="true" @selectChanged="selectChanged" :placeholder="$t('common.pleaseSelect')"></select-affiliated-enterprises>
              </el-form-item>
            </el-col>
            <!-- 业务开展时间-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="busStartTime" :label="$t('enterpriseInfoManage.supplierInfoManage.busStartTime')">
                <el-date-picker  v-model="basicForm.bizStartTime" :disabled="true" class="pickerWidth dymForm"></el-date-picker>
              </el-form-item>
            </el-col>
            <!-- 提单总数-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="ladingAll" :label="$t('enterpriseInfoManage.supplierInfoManage.totalBill')">
                <el-input v-model="basicForm.ladingAll" class="dymForm" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <!-- 业务类型-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="bizStatus" :label="$t('enterpriseInfoManage.supplierInfoManage.businessType')">
                <el-input class="dymForm" v-model="basicForm.bizType" :disabled="true"
                                   :placeholder="''">
                </el-input>
              </el-form-item>
            </el-col>
            <!-- 提单数量-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="ladingAmount" :label="$t('enterpriseInfoManage.supplierInfoManage.billAmount')">
                <el-input class="dymForm" v-model="basicForm.ladingAmount" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <!-- 无提单天数-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="noBillDays" :label="$t('enterpriseInfoManage.supplierInfoManage.noBillDays')">
                <el-input class="dymForm" v-model="basicForm.noBillDays" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <!-- 保理资料模板-->
            <!--<el-col :md="24" :lg="8" :xl="8">-->
              <!--<el-form-item prop="absDataTemplate" :label="$t('enterpriseInfoManage.supplierInfoManage.absDataTemplate')">-->
                <!--<el-input v-model="basicForm.absDataTemplate" :disabled="true"></el-input>-->
              <!--</el-form-item>-->
            <!--</el-col>-->
            <!-- 操作难度等级-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="optDifficultyLevel" :label="$t('enterpriseInfoManage.supplierInfoManage.difficultLevel')">
                <select-dictionary v-model="basicForm.optDifficultyLevel" :disabled="true" :dictTypeCode="'opt_difficulty_level'" :store="$store"
                                   :placeholder="''">
                </select-dictionary>
              </el-form-item>
            </el-col>
            <!-- 盖章方式-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="sealWay" :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" v-if="basicForm.stampWay === '1'">
              <el-form-item prop="noElectronicReason" :label="$t('enterpriseInfoManage.supplierInfoManage.noApplyReason')">
                <el-input class="dymForm" v-model="basicForm.noElectronicReason" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <!-- 有效期至-->
            <el-col :md="24" :lg="8" :xl="8" v-else>
              <el-form-item prop="stampExpiryTime" :label="$t('enterpriseInfoManage.supplierInfoManage.termValidity')">
                <el-date-picker v-model="basicForm.stampExpiryTime" :disabled="true" class="pickerWidth dymForm"></el-date-picker>
              </el-form-item>
            </el-col>
            <!-- 账号有效个数-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="validAccounts" :label="$t('enterpriseInfoManage.supplierInfoManage.accountValNumber')">
                <el-input class="dymForm" v-model="basicForm.validAccounts" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <!--  联系人有效个数-->
            <el-col :md="24" :lg="8" :xl="8">
              <el-form-item prop="validContacts" :label="$t('enterpriseInfoManage.supplierInfoManage.contactValNumber')">
                <el-input class="dymForm" v-model="basicForm.validContacts" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-tabs type="card">
          <!-- 业务操作信息 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.businessOperateInfo')">
            <business-operate-info @saveSuccess="saveSuccess"></business-operate-info>
          </el-tab-pane>
          <!-- 企业收款账户信息 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.enterpriseAccountInfo')">
            <enterprise-account-info></enterprise-account-info>
          </el-tab-pane>
          <!-- 企业工商信息 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.businessInfo')">
            <business-info ref="businessInfo"></business-info>
          </el-tab-pane>
          <!-- 企业资质信息 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.qualificationInfo')">
            <qualification-info></qualification-info>
          </el-tab-pane>
          <!-- 企业开票信息 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.billInfo')">
            <enterprise-invoice-info></enterprise-invoice-info>
          </el-tab-pane>
          <!-- 回寄地址 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.returnAddress')">
            <return-address-info></return-address-info>
          </el-tab-pane>
          <!-- 资料特殊性 -->
          <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.dataParticularity')">
            <data-specificity-info></data-specificity-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 { timeAgo } from '@/filters/index.js'
import { upDownLayout, dymForm, authButton, SelectDictionary, validate } from 'newepoch-components'
import backButton from '@/components/element/enterpriseInfoManage/backButton.vue'
// 业务操作信息
import BusinessOperateInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/businessOperateInfo.vue'
// 企业账户收款信息
import EnterpriseAccountInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/enterpriseAccountInfo.vue'
// 企业工商信息
import BusinessInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/businessInfo.vue'
// 企业开票信息
import enterpriseInvoiceInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/enterpriseInvoiceInfo.vue'
// 回寄地址
import returnAddressInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/returnAddressInfo.vue'
// 刷新提示--企业信息变更
import RefreshHintEdit from '@/pages/enterpriseInfoManage/supplierInfoManage/refreshHintEdit.vue'
// 资料特殊性
import dataSpecificityInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/dataSpecificityInfo.vue'
// 企业资质信息
import qualificationInfo from '@/pages/enterpriseInfoManage/supplierInfoManage/qualificationInfo'
// 关联企业下拉框
import SelectAffiliatedEnterprises from '@/components/element/enterpriseInfoManage/SelectAffiliatedEnterprises.vue'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
import storage from '@/utils/storage'
export default {
  name: 'enterpriseMaintainEdit',
  components: {
    upDownLayout,
    dymForm,
    authButton,
    BusinessOperateInfo,
    RefreshHintEdit,
    EnterpriseAccountInfo,
    BusinessInfo,
    dataSpecificityInfo,
    enterpriseInvoiceInfo,
    returnAddressInfo,
    qualificationInfo,
    SelectDictionary,
    SelectAffiliatedEnterprises,
    backButton
  },
  data () {
    return {
      activeNames: ['1'],
      handleFlag: false,
      refreshFlag: false,
      refreshModel: '',
      item: {},
      // 保存数据
      formData: {
        fincrmEnterpriseDTO: {},
        fincrmEnterpriseInfoDTO: {},
        industryCommerceDTO: {},
        fincrmEnterpriseBusinessDTO: {}
      },
      queryParas: {
        // keyId: '1911181638423510001',
        keyId: storage.getLocal('params').enterpriseId,
        tagCode: '140'
      },
      basicForm: {
        enterpriseName: '',
        affiliatedEnterpriseIds: []
      },
      formRules: {
        enterpriseName: [{ required: true, message: this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.enterpriseName, trigger: 'blur' },
          { validator: validate.enterpriseNameValidate, trigger: 'blur' }]
      }
    }
  },
  activated () {
    // 初始调用
    this.queryParas.keyId = storage.getLocal('params').enterpriseId
    this.handleFilter()
  },
  mounted () {
    // 初始调用
    this.queryParas.keyId = storage.getLocal('params').enterpriseId
    this.handleFilter()
  },
  computed: {
    menuId () {
      return storage.getLocal('params').menuId
    }
  },
  methods: {
    // 新增联系人成功刷新页面
    saveSuccess () {
      this.queryParas.keyId = storage.getLocal('params').enterpriseId
      this.handleFilter()
    },
    // 关联企业处理
    selectChanged (val, name, data) {
      if (data) {
        let coreEnterpriseInfo = []
        data.forEach(it => {
          if (it) {
            let info = {}
            info.coreEnterpriseId = it.keyId
            info.coreEnterpriseName = it.enterpriseName
            coreEnterpriseInfo.push(info)
          }
        })
        this.formData.fincrmEnterpriseCoreRelDtoList = coreEnterpriseInfo
      }
    },
    // 保存
    save () {
      let $this = this
      $this.$refs['basicForm'].validate((valid) => {
        if (valid) {
          // 企业Id
          $this.formData.fincrmEnterpriseDTO.keyId = $this.queryParas.keyId
          $this.formData.fincrmEnterpriseInfoDTO.enterpriseId = $this.queryParas.keyId
          // 企业名称
          $this.formData.fincrmEnterpriseDTO.enterpriseName = $this.basicForm.enterpriseName
          // 企业性质
          $this.formData.fincrmEnterpriseInfoDTO.enterpriseNature = format.formatDictDefoult($this.basicForm.enterpriseNature)
          // 行业分类
          $this.formData.industryCommerceDTO.industry = $this.basicForm.industryCategory
          $this.formData.industryCommerceDTO.name = $this.basicForm.enterpriseName
          // 企业业务ID
          $this.formData.fincrmEnterpriseBusinessDTO.keyId = $this.basicForm.enterpriseBusId
          // 企业详情ID
          $this.formData.fincrmEnterpriseInfoDTO.keyId = $this.basicForm.enterpriseInfoId
          // 修改类型
          $this.formData.updateEnterpriseType = 1
          // 统一社会信用代码
          $this.formData.industryCommerceDTO.creditCode = storage.getLocal('params').creditCode
          // $this.formData.industryCommerceDTO = $this.basicForm.affiliatedEnterpriseIds
          supplierInfoManageApi.enterpriseUpdate.update($this.formData).then(res => {
            if (res && res.data) {
              $this.warning(this.$i18n.messages[this.$i18n.locale].common.saveSuccessInfo)
              this.handleFilter()
              this.$refs['businessInfo'].getNetWork()
            } 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 = 'E'
      this.item = {}
      this.refreshFlag = true
    },
    // 比较不同
    compareFun (data) {
      // this.saveSuccess().then(() => {})
      this.$refs['businessInfo'].getNetWork()
      if (data) {
        data.forEach(it => {
          // 行业分类
          if (it.modifyField === 'industry') {
            this.$set(this.basicForm, 'showIndustryRedFlag', true)
          }
          // 企业名称
          if (it.modifyField === 'name') {
            this.$set(this.basicForm, 'showEnterpriseNameRedFlag', true)
          }
          // 企业性质
          if (it.modifyField === 'enterpriseNature') {
            this.$set(this.basicForm, 'showEnterpriseNatureRedFlag', true)
          }
          // 关联企业
          // if (it.modifyField === 'enterpriseName') {
          //   this.$set(this.basicForm, 'showEnterpriseNameRedFlag', true)
          // }
        })
      }
    },
    // 查询
    handleFilter () {
      let $this = this
      supplierInfoManageApi.enterpriseModified.getEnterpriseModified(this.queryParas).then(res => {
        if (res && res.data) {
          $this.basicForm = res.data
          if ($this.basicForm.enterpriseType === '-1') $this.$set($this.basicForm, 'enterpriseType', '')
          if ($this.basicForm.enterpriseNature === '-1') $this.$set($this.basicForm, 'enterpriseNature', '')
          // 企业等级
          $this.basicForm.enterpriseGrade = format.formatDictDefoult($this.basicForm.enterpriseGrade)
          if ($this.basicForm.enterpriseGrade === '-1') $this.$set($this.basicForm, 'enterpriseGrade', '')
          // 企业类型
          // $this.basicForm.enterpriseType = format.formatDictDefoult($this.basicForm.enterpriseType)
          // 操作难度
          $this.basicForm.optDifficultyLevel = format.formatDict(res.data.optDifficultyLevel)
          // 业务开展时间
          $this.basicForm.bizStartTime = format.formatCheckDatetime(res.data.bizStartTime)
          // 核准日期
          $this.basicForm.approvedTime = format.formatDateNull(res.data.approvedTime)
          // this.$set(this.basicForm, 'lastLadingTime', res.data.lastLadingTime)
          // this.$set(this.basicForm, 'coreEnterpriseName', res.data.coreEnterpriseName)
          // 无提单天数计算
          let day = 0
          if (res.data.lastLadingTime && res.data.lastLadingTime !== -2209017600000) {
            let lastLadingTime = res.data.lastLadingTime
            day = format.timeAgo(lastLadingTime)
          }
          this.basicForm.noBillDays = day
          // 关联企业处理
          if (res.data.relEnterpriseList) {
            let affiliatedEnterpriseIds = []
            res.data.relEnterpriseList.forEach(it => {
              affiliatedEnterpriseIds.push(it.coreEnterpriseId)
            })
            this.$set($this.basicForm, 'affiliatedEnterpriseIds', affiliatedEnterpriseIds)
          }
        }
      })
    }
  }
}
</script>

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