<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :editModel="editModel" :form="form"
                 :appendToBody="appendToBody" width="1480px" :autoSave="false"
                 title="项目公司查看" labelWidth="80px" @onSave="save"
                 :api="api">
      <el-row>
        <el-col :span="23" align="right">
          <span class="date-title-class">{{$t('enterpriseInfoManage.supplierInfoManage.lastUpdateTime')}}{{basicForm.lastRefreshTime | formatDate}}</span>
        </el-col>
      </el-row>
      <div class="enterprise-info">
        <el-divider></el-divider>
      </div>
      <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 :disabled="true" v-model="basicForm.enterpriseName" 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="historyNames" :label="$t('enterpriseInfoManage.supplierInfoManage.usedName')">
              <el-input v-model="basicForm.historyNames" :disabled="true"></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.yyzzApprovedDate" :disabled="true" :placeholder="$t('common.pleaseInput')"></el-input>-->
              <el-date-picker 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="enterpriseNature" :class="{detail: basicForm.showEnterpriseNatureRedFlag}"   :label="$t('enterpriseInfoManage.supplierInfoManage.enterpriseProperty')">
              <select-dictionary :disabled="true" v-model="basicForm.enterpriseNature" :dictTypeCode="'enterprise_nature'" :store="$store"
                                 :placeholder="$t('common.pleaseSelect')">
              </select-dictionary>
            </el-form-item>
          </el-col>
          <!--企业等级-->
          <el-col :md="24" :lg="8" :xl="8">
            <el-form-item prop="internalRank" :class="{detail: basicForm.showEnterpriseGradeRedFlag}"  :label="$t('enterpriseInfoManage.supplierInfoManage.enterpriseLevel')">
              <!--<el-input v-model="basicForm.enterpriseLevel" :disabled="false" :placeholder="$t('common.pleaseInput')"></el-input>-->
              <select-dictionary v-model="basicForm.enterpriseGrade" :disabled="true" :dictTypeCode="'enterprise_grade'" :store="$store"
                                 :placeholder="''">
              </select-dictionary>
            </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="coreEnterpriseName" :label="$t('enterpriseInfoManage.supplierInfoManage.coreEnterprise')">
              <el-input v-model="basicForm.coreEnterpriseName" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <!-- 业务开展时间-->
          <el-col :md="24" :lg="8" :xl="8">
            <el-form-item prop="bizStartTime" :label="$t('enterpriseInfoManage.supplierInfoManage.busStartTime')">
              <el-date-picker v-model="basicForm.bizStartTime" :disabled="true" class="pickerWidth"></el-date-picker>
            </el-form-item>
          </el-col>
          <!-- 是否合作方-->
          <el-col :md="24" :lg="8" :xl="8">
            <el-form-item prop="isPartners" :class="{detail: basicForm.showRedFlag}" :label="$t('enterpriseInfoManage.projCompanyInfoManage.partnerOrNot')">
              <select-dictionary v-model="basicForm.isPartners" :dictTypeCode="'ZD0003'" :store="$store"
                                 :placeholder="$t('common.pleaseSelect')">
              </select-dictionary>
            </el-form-item>
          </el-col>
          <!-- 业务类型-->
          <el-col :md="24" :lg="8" :xl="8">
            <el-form-item prop="bizStatus" :class="{detail: basicForm.showRedFlag}" :label="$t('enterpriseInfoManage.supplierInfoManage.businessType')">
              <!--<select-dictionary v-model="basicForm.fincrmEnterpriseBusinessDto.bizStatus" :dictTypeCode="''" :store="$store"-->
              <!--:placeholder="$t('common.pleaseSelect')">-->
              <!--</select-dictionary>-->
              <el-input v-model="basicForm.bizType" :disabled="true" :placeholder="$t('common.pleaseInput')"></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 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 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="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" v-if="basicForm.stampWay === '2'">
            <el-form-item prop="noElectronicReason" :label="$t('enterpriseInfoManage.supplierInfoManage.noApplyReason')">
              <el-input 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"></el-date-picker>
            </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 v-model="basicForm.validContacts" :disabled="true"></el-input>
            </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 v-model="basicForm.validAccounts" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-tabs type="card">
        <!-- 业务操作信息 -->
        <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.businessOperateInfo')">
          <business-operate-info ref="operate" :enterpriseType="enterpriseType"></business-operate-info>
        </el-tab-pane>
        <!-- 企业工商信息 -->
        <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.businessInfo')">
          <business-info ref="business"></business-info>
        </el-tab-pane>
        <!-- 企业资质信息 -->
        <el-tab-pane :label="$t('enterpriseInfoManage.supplierInfoManage.qualificationInfo')">
          <qualification-info ref="qualification"></qualification-info>
        </el-tab-pane>
      </el-tabs>
    </dialog-edit>
  </div>
</template>

<script>
import * as format from '@/filters/index.js'
import { DialogEdit, dymForm, authButton, SelectDictionary, validate } from 'newepoch-components'
// 业务操作信息
import BusinessOperateInfo from '@/pages/cyjg/businessRegionInfo/projectManage/businessOperateInfo.vue'
// 企业工商信息
import BusinessInfo from '@/pages/cyjg/financialRegionInfo/businessInfo.vue'
// 刷新提示--企业信息变更
import RefreshHintEdit from '@/pages/enterpriseInfoManage/supplierInfoManage/refreshHintEdit.vue'
// 企业资质信息
import qualificationInfo from '@/pages/cyjg/businessRegionInfo/projectManage/qualificationInfo.vue'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
import storage from '@/utils/storage'
import BaseEdit from '@/pages/baseEditPage.js'
// import { mothedsEvent } from '@/filters/index.js'
export default {
  extends: new BaseEdit(),
  name: 'projCompanyInfoManageEdit',
  components: {
    DialogEdit,
    dymForm,
    authButton,
    BusinessOperateInfo,
    BusinessInfo,
    RefreshHintEdit,
    qualificationInfo,
    SelectDictionary
  },
  data () {
    return {
      appendToBody: true,
      enterpriseType: 'projectCompany',
      handleFlag: false,
      refreshFlag: false,
      refreshModel: '',
      item: {},
      queryParas: {
        keyId: '',
        tagCode: '150'
      },
      basicForm: {},
      formRules: {
        enterpriseName: [{ required: true, message: this.$i18n.messages[this.$i18n.locale].regMsg.enterpriseInfoManage.enterpriseName, trigger: 'blur' },
          { validator: validate.enterpriseNameValidate, trigger: 'blur' }]
      }
    }
  },
  computed: {
    api () {
      return supplierInfoManageApi.enterpriseModified
    }
  },
  methods: {
    // 刷新比较
    compareFun (data) {
      if (data) {
        data.forEach(it => {
          // 企业名称
          if (it.modifyField === 'name') {
            this.$set(this.basicForm, 'showEnterpriseNameRedFlag', true)
          }
          // 企业性质
          if (it.modifyField === 'enterpriseNature') {
            this.$set(this.basicForm, 'showEnterpriseNatureRedFlag', true)
          }
          // 企业等级
          if (it.modifyField === 'enterpriseGrade') {
            this.$set(this.basicForm, 'showEnterpriseGradeRedFlag', 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.fincrmEnterpriseInfoDTO.enterpriseNature = format.formatDictDefoult($this.basicForm.enterpriseNature)
          // 企业等级
          data.fincrmEnterpriseBusinessDTO.enterpriseGrade = format.formatDictDefoult($this.basicForm.enterpriseGrade)
          // 是否合作方
          if (!$this.basicForm.isPartners || $this.basicForm.isPartners === '') {
            data.fincrmEnterpriseBusinessDTO.partnerFlag = 0
          } else {
            data.fincrmEnterpriseBusinessDTO.partnerFlag = $this.basicForm.isPartners
          }
          // 业务类型
          // data.fincrmEnterpriseBusinessDTO.bizType = $this.basicForm.bizType
          // 企业业务ID
          data.fincrmEnterpriseBusinessDTO.keyId = $this.basicForm.enterpriseBusId
          // 企业详情ID
          data.fincrmEnterpriseInfoDTO.keyId = $this.basicForm.enterpriseInfoId
          // 企业名称
          data.industryCommerceDTO.name = $this.basicForm.enterpriseName
          // 修改类型
          data.updateEnterpriseType = 2
          // 统一社会信用代码
          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
          if ($this.basicForm.enterpriseNature === -1 || $this.basicForm.enterpriseNature === '-1') {
            $this.basicForm.enterpriseNature = ''
          }
          if ($this.basicForm.enterpriseGrade === -1 || $this.basicForm.enterpriseGrade === '-1') {
            $this.basicForm.enterpriseGrade = ''
          }
          if ($this.basicForm.isPartners === -1 || $this.basicForm.isPartners === '-1') {
            $this.basicForm.isPartners = ''
          }
          // 业务开展时间
          $this.basicForm.bizStartTime = format.formatCheckDatetime($this.basicForm.bizStartTime)
          // 有效期至
          $this.basicForm.stampExpiryTime = format.formatDateNull($this.basicForm.stampExpiryTime)
          // 操作等级难度
          $this.basicForm.optDifficultyLevel = format.formatDictDefoultNew($this.basicForm.optDifficultyLevel)
          // 营业执照核准日期
          $this.basicForm.approvedTime = format.formatDateNull($this.basicForm.approvedTime)
          // 无提单天数计算
          let day = 0
          if (res.data.lastLadingTime && res.data.lastLadingTime !== -2209017600000) {
            let lastLadingTime = res.data.lastLadingTime
            day = format.timeAgo(lastLadingTime)
          }
          $this.basicForm.noBillDays = day
        }
      })
    }
  },
  watch: {
    visible (val) {
      let $this = this
      if (val) {
        this.$nextTick(() => {
          let operate = this.$refs.operate
          let qualification = this.$refs.qualification
          let business = this.$refs.business
          business.pa = this.form
          operate.pa = this.form
          let pa = this.form
          if (operate.currentId !== pa.enterpriseId.toString()) {
            this.sourceData = []
          }
          this.$set(operate.searchForm, 'enterpriseId', pa.enterpriseId.toString())
          this.$set(operate.searchForm, 'tagCode', pa.tagCode.toString())
          operate.reloadContract = !operate.reloadContract
          qualification.loadSourceData({ customerId: this.form.enterpriseId })
          business.getNetWork()
          operate.handleFilter()
        })
        this.queryParas.keyId = this.form.enterpriseId
        $this.handleFilter()
      }
    }
  }
}
</script>

<style scoped>

</style>
