<!--企业资质信息-->
<template>
  <div class="crm-main">
    <data-table :queryParas="queryParas" :sourceData.sync="sourceData" :loadCount.sync="loadCount" :showPage="false"
                :columns="columns" :operateBtnLayout="operateBtnLayout">
      <template slot="headButton">
        <el-row>
          <el-col :span="24" class="textRight">
            <auth-button icon="iconfont iconbaoliyewuxinxichaxun" size="medium" type="primary"
                         @click="gotoQualific"
                         :label="$t('enterpriseInfoManage.supplierInfoManage.qualificationNet')"
                         :menuCode="menuId" perms="qualView" :openPerms="true"></auth-button>
          </el-col>
        </el-row>
      </template>
      <template slot="orderNum" slot-scope="scope">
        {{scope.data.$index}}
      </template>
      <el-table-column align="center" min-width="100px" :label="$t('common.operate')" fixed="right">
        <template slot-scope="scope">
          <btn-download :xhr="$xhr" :fileID="scope.row.fileId"
                        :menuCode="menuId" perms="qualDownload" :openPerms="true"></btn-download>
        </template>
      </el-table-column>
    </data-table>
  </div>
</template>

<script>
import { DataTable, authButton, btnDownload } from 'newepoch-components'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/companyApi'
import * as format from '@/filters/index'
import { ZIZHIWANG } from '@/constant.js'
import storage from '@/utils/storage'
export default {
  name: 'qualificationInfo',
  components: {
    DataTable,
    authButton,
    btnDownload
  },
  props: {
    enterpriseInfo: {
      type: Object,
      default: function () {
        return {}
      }
    }
  },
  data () {
    return {
      sourceData: [],
      queryParas: {},
      loadCount: 0,
      operateBtnLayout: '',
      columns: [
        // 序号
        {
          prop: 'orderNum',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.orderNum,
          width: '80px'
        },
        // 资质类型
        {
          prop: 'certificateType',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.qualificationType,
          width: '200px'
        },
        // 资质证书号
        {
          prop: 'certificateNumber',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.qualificationCertificateNum,
          width: '200px'
        },
        // 资质名称
        {
          prop: 'fileName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.qualificationName,
          width: '200px'
        },
        // 发证日期
        {
          prop: 'issuanceTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.openDate,
          width: '150px',
          format: (row) => { return format.formatDateNull(row.issuanceTime) }
        },
        // 证书有效期
        {
          prop: 'expiryTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.validityPeriod,
          width: '150px',
          format: (row) => { return format.formatDateNull(row.expiryTime) }
        },
        // 发证机关
        {
          prop: 'licensingAuthority',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.certificationAuthority,
          width: '200px'
        }
      ]
    }
  },
  computed: {
    api: function () {
      return {}
    },
    menuId () {
      return storage.getLocal('params').menuId
    }
  },
  mounted () {
    this.loadData({ customerId: storage.getLocal('params').enterpriseId })
  },
  methods: {
    gotoQualific () {
      window.open(ZIZHIWANG)
    },
    loadData (parmas) {
      var that = this
      supplierInfoManageApi.refreshHintEditApi.getCertificateList(parmas).then(res => {
        if (res.data && res.data.length > 0) {
          res.data.forEach((it, index) => {
            it.orderNum = index + 1
          })
          that.sourceData = res.data
        }
      })
    }
  }
}
</script>

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