<!--
  @description: 申报材料-企业资质-查看
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020-5-23
-->
<template>
  <div>
    <el-button v-if="ChangeDetailBtn" type="primary" style="margin-bottom: 10px" @click="handleChangeDetail">
      查看变更内容
    </el-button>
    <div>
      <el-table
        ref="smallTable"
        :data="tableData"
      >
        <!-- 序号 -->
        <el-table-column
          :label="language.Serialnumber"
          type="index"
          width="60px"
          align="center"
        />
        <!-- 证书名称 -->
        <el-table-column
          :label="language.Certificatename"
          prop="certificateName"
          header-align="center"
          min-width="160"
        />
        <!-- 证书编号 -->
        <el-table-column
          :label="language.Certificatenumber"
          header-align="center"
          prop="certificateNo"
          min-width="120"
        />
        <!-- 发证单位 -->
        <el-table-column
          :label="language.Certificationunit"
          header-align="center"
          prop="issuingUnit"
          min-width="200"
        />
        <!-- 发证日期 -->
        <el-table-column
          :label="language.Dateofissue"
          align="center"
          prop="issuingTime"
          min-width="110"
        />
        <!-- 有效期至 -->
        <el-table-column
          :label="language.Validuntil"
          prop="validityEndTime"
          align="center"
          min-width="110"
        />
        <!-- 证书扫描 -->
        <el-table-column
          :label="language.Certificatescanningcopy"
          header-align="center"
          min-width="160"
        >
          <template slot-scope="scope">
            <downloadFile :data="scope.row.certificateScanData" />
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="审核状态"
          prop="auditStatus"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span v-for="(item,index) in auditStatusList" v-if="scope.row.auditStatus === item.typecode" :key="index">
              {{ item.typename }}
            </span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
    <!--审核信息-->
    <inforaMtionAuditDetail v-if="!judgePageData.detailType" />
    <!--查看变更内容弹框-->
    <consignContractSelectDialog :dialog-data="consignContractSelectDialog" />
  </div>
</template>

<script>

/* 接口*/
import { listCertificatePages, listCertificateAuditPages } from '@/api/supplier/supplierCertificate'// 暂存 ，获取,删除
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins'// 供应商-公用方法参数
import { declareHegSupperGroupMixin } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperGroupMixin'// 供应商-字典
import { supplierGroupMixin } from '@/views/supplier/mixins/supplierGroupMixin'
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile'// 附件
import pagination from '@comp/common/pagination/pagination'// 分页
import consignContractSelectDialog from '@/views/supplier/editorDeclaration/enterpriseQualification/enterpriseQualificationDifference-dialog' // 查看变更内容-弹窗
import inforaMtionAuditDetail from '@/views/supplier/editorDeclaration/inforaMtionAudit/inforaMtionAudit-detail'// 审报材料-审核信息
import { mapGetters } from 'vuex'
export default {
  name: 'EnterpriseQualificationDetail',
  components: {
    pagination, // 分页
    downloadFile,
    consignContractSelectDialog,
    inforaMtionAuditDetail // 审核信息
  },
  mixins: [ListMixin, declareHegSupperMixins, declareHegSupperGroupMixin, supplierGroupMixin],
  props: {
    // 查看状态
    judgePageData: {
      type: Object,
      default: function() {
        return {
          detailType: 'dialog', // 查看形式 dialog 弹框
          departId: ''
        }
      }
    }
  },
  data() {
    return {
      tableData: [], // 列表信息
      bizType: this.$route.params.bizType,
      loading: true,
      ChangeDetailBtn: false, // 查看变更内容
      listCertificatePagesDto: {
        departId: '',
        tabType: '02', // 切换内容——企业资质
        auditStatus: '', // 审核状态:00审核中,01通过,02驳回
        certificateName: '', // 证书名称
        certificateNo: '', // 证书编号
        createTimeBegin: '', // 创建时间开始
        createTimeEnd: '', // 创建时间结束
        // departId: this.searchForm.departId,
        departName: '',
        isOperation: '', // 业务操作 保存:00 提交:01
        issuingTimeBegin: '', // 发证时间开始
        issuingTimeEnd: '', // 发证时间结束
        issuingUnit: '', // 发证单位
        orderBy: '', // 排序
        pageNo: 1, // 当前页
        pageSize: 10, // 每页条数
        useStatus: '' // 有效状态 00:临时(草稿) 01:有效 02:作废
      },
      consignContractSelectDialog: {
        dialog: false // 变更查看
      }
    }
  },
  computed: {
    /* language 国际化*/
    ...mapGetters(['language'])
  },
  created() {
    this.ChangeDetailBtn = this.bizType === '02' ? [] : false // 判断是否是变更审核
    this.listCertificatePagesDto.departId = this.$route.params.supplierId || this.judgePageData.departId// 供应商id
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
      // 判断是否为初审审核页面
      if (this.$route.meta.type === 'declarationFirst' || this.$route.meta.type === 'declarationChange' || this.$route.meta.type === 'audit' || this.judgePageData.detailType === 'dialog') {
        // declarationFirst 编辑申报材料查看 declarationChange 申报材料变更时 audit 初审审核时
        this.listCertificatePages()// 非审核时-查询企业信息
      } else { // 入库审核
        this.listCertificateAuditPages()// 审核时-查询企业信息
      }
    },
    // 非审核时-查询企业信息
    listCertificatePages() {
      const params = this.getQueryParams()// 查询条件
      listCertificatePages(params).then(response => {
        this.assemblyData(response)// 组装数据
      }).catch(() => {
      })
    },
    // 审核时-查询企业信息
    listCertificateAuditPages() {
      const params = this.getQueryParams()// 查询条件
      listCertificateAuditPages(params).then(response => {
        this.assemblyData(response)// 组装数据
      }).catch(() => {
      })
    },
    // 组装数据
    assemblyData(response) {
      this.paginationData.total = response.data.total
      const tableData = response.data.records
      tableData.forEach((item) => {
        item.issuingTime = this.$Moment(item.issuingTime).format(this.momentDate)// 发证日期
        if (item.longTerm === '01') { // 有效期至为长期
          item.validityEndTime = '长期'
        } else { // 有效期至非长期
          if (item.validityEndTime) item.validityEndTime = this.$Moment(item.validityEndTime).format(this.momentDate)// 有效期至
        }
        // 证书扫描
        item.certificateScanData = {
          ...this.certificateScanData,
          bizId: item.id
        }
      })
      this.tableData = tableData
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.listCertificatePagesDto)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 查看变更记录弹框
    handleChangeDetail() {
      this.consignContractSelectDialog.dialog = true
    }
  }
}
</script>

<style lang="less" scoped>
</style>
