<!--
  @description:采购单归档
  @Modifier: zhangyawen
  @routerPath: /procurementArchived/procurementOrderArchived-detail
  @date: 2021-4-12-9:15
-->
<template>
  <div class="leave_container">
    <section class="title p0-16 clearfix">
      <template>
        <div class="title-back pointer" @click="back">
          <i class="iconfont icon-fanhui mr10" />归档信息
        </div>
      </template>
    </section>
    <section class="p0-16">
      <el-form ref="allData" label-width="160px" label-position="left">
        <div class="page-title">
          1.采购单信息
        </div>
        <div>
          <table class="from_table">
            <tr>
              <td>
                <el-form-item label="采购单编号" prop="tenderNo" />
              </td>
              <td>
                {{ archivedInfo.tenderNo }}
              </td>
              <td>
                <el-form-item label="采购单名称" prop="tenderName" />
              </td>
              <td>
                {{ archivedInfo.tenderName }}
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="是否框架" prop="planType" />
              </td>
              <td>
                {{ archivedInfo.planType && filterDictText(isFrameList,archivedInfo.planType) }}
              </td>
              <td>
                <el-form-item label="采购员" prop="sourcingUserRealName" />
              </td>
              <td>
                {{ archivedInfo.sourcingUserRealName }}
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="采购单状态" prop="purchaseProjectStatus" />
              </td>
              <td>
                {{ archivedInfo.purchaseProjectStatus && filterDictText(protprojectPurchaseProjectStatusList,archivedInfo.purchaseProjectStatus) }}
              </td>
              <td />
              <td />
            </tr>
          </table>
        </div>
      </el-form>
      <el-form ref="form" label-width="160px">
        <div class="page-title">
          <span>2.归档文件</span>
        </div>
        <el-button type="primary" :loading="exportLoading" @click="dowloadArchivedFile">
          一键下载文件
        </el-button>
        <div class="mt10">
          <el-table v-loading="loading" class="mb10" :data="tableData" border>
            <el-table-column
              type="index"
              label="序号"
              width="60"
              align="center"
            />
            <el-table-column
              label="文件目录名称"
              align="center"
              prop="fileIndexName"
              min-width="200"
            />
            <el-table-column
              label="是否必须归档"
              align="center"
              min-width="200"
            >
              <template slot-scope="scope">
                {{ scope.row.isMustArchive && filterDictText(is_must_archiveList,scope.row.isMustArchive) }}
              </template>
            </el-table-column>
            <el-table-column
              label="文件"
              header-align="center"
              align="left"
              min-width="200"
            >
              <template slot-scope="scope">
                <downloadFile v-if="scope.row.archiveFileData" dis-block="block" :data="scope.row.archiveFileData" />
                <downloadFile v-else dis-block="block" :file-list="scope.row.archiveFileList" />
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
    </section>
  </div>
</template>

<script>
/* api */
import { getProcurementArchiveList, downloadAllProjectZipFile } from '@/api/bidding/bidArchive'
/* 组件 */
import downloadFile from '@comp/common/updownload/downloadFile' // 附件下载
import { filterDictText, download } from '@/assets/js/utils'// 常用方法
/* mixins*/
import { archivedDic } from '.././mixins/dicMixins.js'
export default {
  name: 'ProcurementOrderArchivedDetail',
  components: {
    downloadFile // 附件下载
  },
  mixins: [archivedDic],
  data() {
    return {
      path: '',
      archivedInfo: {},
      exportLoading: false,
      tenderNo: this.$route.params.tenderNo,
      tableData: [],
      loading: false, // 列表loading
      protprojectPurchaseProjectStatusList: [], // 采购单状态
      is_must_archiveList: [] // 是否必须归档
    }
  },
  created() {
    // 查询数据
    this.initGroup()
    this.initData()
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      vm.path = from.path
    })
  },
  methods: {
    filterDictText,
    // 获取字典方法
    initGroup() {
      const data = [
        'protprojectPurchaseProjectStatus',
        'is_must_archive'
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 返回
    back() {
      this.$router.push({
        path: this.path
      })
    },
    // 查询数据
    initData() {
      this.loading = true
      const params = {
        tenderNo: this.tenderNo
      }
      getProcurementArchiveList(params).then(res => {
        this.archivedInfo = res.data
        this.tableData = res.data.archiveFileDetailVoList
        this.tableData.push({ fileIndexName: '其他文件', isMustArchive: '00', archiveFileData: { bizId: this.archivedInfo.archiveId, fileType: 'prot_archive_other_file' }})
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 一键下载
    dowloadArchivedFile() {
      const params = {
        archiveId: this.archivedInfo.archiveId, // 归档id
        isUpdateOtherFile: this.archivedInfo.isUpdateOtherFile, // 是否修改了其他附件
        tenderNo: this.archivedInfo.tenderNo // 采购单编号
      }
      this.exportLoading = true
      downloadAllProjectZipFile(params).then((res) => {
        download(res, `[${this.archivedInfo.tenderNo}]${this.archivedInfo.tenderName}采购单归档文件.zip`)
      }).catch((error) => {
        this.$message.warning(error)
      }).finally(() => {
        this.exportLoading = false
      })
    }
  }
}
</script>

<style lang="less" scoped>
.page-title {
  margin: 16px 0;
}
</style>
