<!--
  @description: 招标项目-归档-查看归档详情
  @Modifier：肖文龙
  @routerPath:
  @date：  2019/12/03
-->
<template>
  <div>
    <table class="tableData mb10">
      <tr>
        <td>招标编号</td>
        <td>{{ fromData.tenderNo }}</td>
        <td>标段（包）名称</td>
        <td>{{ fromData.packName }}</td>
      </tr>
      <tr>
        <td>归档状态</td>
        <td>{{ filterDictText(archiveStatusList,fromData.archiveStatus) }}</td>
        <td>标段（包）状态</td>
        <td>{{ filterDictText(packStatusList,fromData.packStatus) }}</td>
      </tr>
      <!-- <tr>
        <td>归档文件</td>
        <td colspan="3">
          <downloadFile :file-list="fromData.archiveFile" />
        </td>
      </tr> -->
    </table>
    <dl class="projectInfoDetail">
      <dt>
        <p class="projectInfoDetail_icon">
          <i class="iconfont icon-biaoduanbaoxinxi" />
        </p>
        文件列表
        <!--当接口回调成功后才展示-->
        <el-button v-if="fromData.archiveStatus&&zipFileData.isUpdateOtherFile" size="mini" type="primary" @click="dowloadArchivedFile">
          下载项目所有文件
        </el-button>
      </dt>
      <dd>
        <el-table
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="fileIndexName"
            label="文件目录名称"
            header-align="center"
            align="left"
            min-width="300"
          />
          <el-table-column
            prop="uploadTypeName"
            label="上传"
            width="200px"
            align="center"
          />
          <el-table-column
            prop="storagePeriod"
            label="保管期（年）"
            width="120px"
            align="center"
          />
          <el-table-column
            prop="isMustArchive"
            label="是否必须归档"
            width="120px"
            align="center"
          >
            <template slot-scope="scope">
              {{ filterDictText(isMustArchiveList, scope.row.isMustArchive) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="uploadTime"
            label="上传时间"
            align="center"
            width="160px"
          />
          <el-table-column
            prop="tenderDocumentReceiveEndTime"
            label="文件"
            header-align="center"
            align="left"
            min-width="300px"
          >
            <template slot-scope="scope">
              <downloadFile :file-list="scope.row.archiveFileList" />
            </template>
          </el-table-column>
        </el-table>
      </dd>
    </dl>
    <!--其他归档文件-->
    <div>
      <!--00 未归档-->
      <div v-if="fromData.archiveStatus==='00'">
        <upload
          ref="upload"
          :on-change="archivedOtherFileChange"
          :auto-delete="true"
          :auto-upload="true"
          :data="archivedOtherFileData"
          title="其他文件"
          file-ref="fileRef"
        />
      </div>
      <!--01 已归档-->
      <div v-if="fromData.archiveStatus==='01'">
        <table class="tableData mb10">
          <tr class="singleRow">
            <td>其他文件</td>
            <td colspan="3">
              <downloadFile :data="archivedOtherFileData" :on-change="archivedOtherFileChange" />
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</template>
<script>
/* api */
import { downLoadFile } from '@/api/common/uploadCenter'
import { getArchiveList, updateArchiveOtherFileStatus, getAllProjectZipFile } from '@/api/bidding/bidArchive.js'
/* 公用方法 */
import { filterDictText, download } from '@/assets/js/utils'// 常用方法
/* 混入-字典信息 */
import { tenderArchivedGroup, bidArchiveddGroup } from './../mixins/bidArchivedGroupMixin'// 字典信息
import { bidArchived } from './../mixins/bidArchivedMixin'// 公共方法
/* 组件 */
import downloadFile from '@comp/common/updownload/downloadFile'// 附件下载
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'ArchivedCompDetail',
  components: {
    downloadFile, // 附件下载
    upload
  },
  props: {
    // 项目信息
    packId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      ...tenderArchivedGroup, // 字典信息
      ...bidArchiveddGroup,
      ...bidArchived, // 公共方法
      loading: false, // 列表loading
      tableData: [], // 归档文件列表
      // 项目信息
      fromData: {
        archiveId: '', // 归档id
        tenderNo: '', // 项目编号
        packName: '', // 标段名称
        packStatus: '', // 标段状态 00 项目未生效 01 项目已生效
        archiveStatus: '', // 归档状态 00 未归档 01 已归档
        archiveFile: [] // 归档文件
      },
      // 下载所有项目文件
      zipFileData: {
        archiveId: '', // 归档id
        isUpdateOtherFile: ''// 是否修改了其他附件 00:否 01:是
      }
    }
  },
  created() {
    // 查询数据
    this.initData()
  },
  methods: {
    filterDictText,
    // 触发-返回父组件回调函数事件
    initCalBack() {
      // 只有（招标项目-驱动）需要
      this.$emit('call-back', {
        archiveId: this.fromData.archiveId, // 归档id
        archiveStatus: this.fromData.archiveStatus, // 归档状态
        isUpdateOtherFile: this.fromData.isUpdateOtherFile// 是否修改了其他附件 00:否 01:是
      })
    },
    // 查询数据
    initData() {
      this.loading = true
      getArchiveList({ packId: this.packId }).then(res => {
        // 归档文件列表
        this.tableData = [...res.data.archiveFileDetailVoList]
        delete res.data.archiveFileDetailVoList
        // 归档项目信息
        this.fromData = {
          ...res.data,
          archiveFile: res.data.archiveFile || []
        }
        this.archivedOtherFileData.bizId = this.fromData.archiveId // 其他文件上传业务主键id
        this.initCalBack()// 触发-返回父组件回调函数事件
        this.loading = false
      })
    },
    // 归档其他文件操作变更事件
    archivedOtherFileChange(file, fileList) {
      if (fileList.length > 0) { // 上传了
        this.zipFileData.isUpdateOtherFile = '01'// 01 是
      } else { // 未上传
        this.zipFileData.isUpdateOtherFile = '00'// 00 否
      }
      this.initCalBack()// 触发-返回父组件回调函数事件
      const data = { archiveId: this.fromData.archiveId }// 归档id
      updateArchiveOtherFileStatus(data).then(res => {
      })
    },
    // 下载项目所有归档文件
    dowloadArchivedFile() {
      const data = {
        ...this.zipFileData,
        archiveId: this.fromData.archiveId // 归档id
      }
      return getAllProjectZipFile(data).then(res => {
        const fileTitle = res.data.title
        // const url = downLoadFileUrl + '?fileId=' + res.data.fileId + '&fileType=' + res.data.fileType
        // console.log(url)
        // downloadUrlFile(url)
        const params = {
          fileId: res.data.fileId,
          fileType: res.data.fileType
        }
        downLoadFile(params).then((res) => {
          download(res, fileTitle + '.zip')
        })
      }).catch(() => {
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
