  <!--
  @description:企业资质
  @Modifier:qk
  @routerPath:supplierDeclaration/supplier/enterpriseQualification
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <div>
      <section>
        <div style="margin-bottom:10px;">
          <el-button type="primary" @click="addCertificate('')">
            {{ language.Addcertificate }}
          </el-button>
          <el-button
            size="mini"
            style="color: red;font-size:18px;"
            type="text"
          >
            （必填）
          </el-button>
        </div>
        <div>
          <el-table
            ref="smallTable"
            v-loading="loading"
            :data="tableData"
            width="100%"
          >
            <!-- 序号 -->
            <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
              :label="language.operation"
              align="center"
              width="160"
            >
              <!-- 编辑 查看 删除 -->
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  @click.stop="addCertificate(scope.row.id,scope.row.oldId)"
                >
                  [编辑]
                </el-link>
                <el-link
                  type="primary"
                  @click.stop="seeCertificate(scope.row)"
                >
                  [查看]
                </el-link>
                <el-link
                  type="primary"
                  @click.stop="deleteCertificate(scope.row)"
                >
                  [删除]
                </el-link>
              </template>
            </el-table-column>
          </el-table>
          <!--分页组件-->
          <pagination :pagination-data="paginationData" @change="loadData" />
        </div>
        <!-- 审核意见 -->
        <inforaMtionAudit />
        <!-- 添加证书/编辑证书 -->
        <denterpriseQualification :data="certificateData" @consignContractInfo="consignContractInfo" />
        <!-- 查看证书 -->
        <denterpriseQualificationsee v-if="dialogDetailData.dialog" :data="dialogDetailData" @consignContractInfo="consignContractInfo" />
      </section>
    </div>
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <!-- 编辑申报材料 -->
          <template v-if="pageType==='declarationFirst'">
            <el-button @click="prevStep">
              上一步
            </el-button>
            <el-button :loading="confirmLoading" type="primary" @click="nextStep('form')">
              下一步
            </el-button>
          </template>
          <!-- 申报材料变更 -->
          <template v-if="pageType==='declarationChange'">
            <el-button :loading="confirmLoading" type="primary" @click="submitData('form')">
              提交
            </el-button>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* 接口*/
import { removeCertificate, listCertificatePages } from '@/api/supplier/supplierCertificate'// 暂存 ，获取,删除
// import { listChangeableCertificatePages } from '@/api/supplier/supplierChange'
import { changeSupplierInfoSubmit } from '@/api/supplier/supplierChange'// 基本信息变更提交
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins'// 供应商-公用方法参数
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile'// 附件
import inforaMtionAudit from '../inforaMtionAudit/inforaMtionAudit-detail'// 审核信息
import pagination from '@comp/common/pagination/pagination'// 分页
import denterpriseQualification from './enterpriseQualification-dialog' // 添加证书/编辑证书
import denterpriseQualificationsee from './enterpriseQualificationsee-dialog' // 查看证书
import { mapGetters } from 'vuex'
export default {
  name: 'ProjectManagerTenderList',
  components: {
    pagination, // 分页
    denterpriseQualification,
    denterpriseQualificationsee,
    inforaMtionAudit,
    downloadFile
  },
  mixins: [ListMixin, declareHegSupperMixins],
  data() {
    return {
      pageType: this.$route.meta.type, // 当前页面所处状态 declarationFirst 编辑申报材料查看 declarationChange 申报材料变更时
      tableData: [], // 列表信息
      searchForm: {
        departId: this.$route.query.departId// 机构id
      },
      confirmLoading: false, // Loading
      // 添加证书/编辑证书弹框
      certificateData: {
        dialog: false, // 弹框展示状态
        id: '', // 证书id-编辑时才会有证书id
        oldId: '' // 修改时用的Id
      },
      // 查看证书弹框
      dialogDetailData: {
        dialog: false, // 弹框展示状态
        id: '', // 证书id-编辑时才会有证书id
        oldId: '' // 修改时用的Id
      },
      loading: true
    }
  },
  computed: {
    /* language 国际化*/
    ...mapGetters(['language'])
  },
  created() {
    // 查询企业接口
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      listCertificatePages(params).then(response => {
        this.loading = false
        this.paginationData.total = response.data.total
        const tableData = response.data.records
        tableData.forEach((item, index) => {
          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
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 添加证书/编辑证书-回填
    consignContractInfo(val) {
      this.paginationData.pageNo = 0
      this.paginationData.pageSize = 10
      this.loadData()// 获取数据
    },
    // 新增/编辑
    addCertificate(id, oldId) {
      this.certificateData = {
        dialog: true,
        id: id, // 证书id-编辑时才会有证书id
        oldId: oldId // 修改时用的Id
      }
    },
    // 查看
    seeCertificate(row) {
      this.dialogDetailData = {
        dialog: true,
        id: row.id,
        oldId: row.oldId // 修改时用的Id
      }
    },
    // 删除
    deleteCertificate(row) {
      this.$confirm('确定删除改记录么?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = [{
          oldId: row.oldId, // 原始id
          departId: row.departId, // 机构id
          id: row.id // 项目id
        }]
        removeCertificate(data).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          // 获取列表信息
          this.loadData()
        })
      }).catch(() => {
      })
    },
    // 保存数据接口下一步
    saveData(type) {
      this.confirmLoading = true// btnLoding
      // route携带参数
      const pathData = {
        ...this.$route.query
      }
      if (type === 'next') { // 下一步
        this.$emit('stepPage', 'next', pathData)// 步骤条切换方法 next 下一步
      } else if (type === 'save') { // 保存
      }
      this.confirmLoading = false// btnLoding
    },
    // 申报材料变更-提交
    submitData() {
      this.$confirm('确认提交审核吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = this.searchForm
        changeSupplierInfoSubmit(data).then((response) => {
          if (response.header.ret === '0') {
            // 修改状态
            this.$nextTick(() => {
              this.$emit('showStatuschage')// 传给父集组件参数-审核状态-审核图片展示
            })
            this.saveData('save')
            this.$message({
              type: 'success',
              message: '提交成功'
            })
          } else {
            this.$message({
              type: 'warning',
              message: '提交失败'
            })
          }
        })
      }).catch(() => {
      })
    },
    // 上一步
    prevStep() {
      // route携带参数
      const pathData = {
        ...this.$route.query
      }
      this.$emit('stepPage', 'prev', pathData)// 步骤条切换方法 prev 上一步
    },
    // 暂存，进行下一步
    nextStep(formName) {
      this.saveData('next')// 下一步
    }
  }
}
</script>
<style lang="less" scoped>
</style>
