<!--
  @description: 归档·-项目归档列表
  @Modifier: 肖文龙
  @routerPath: /bidArchived/tenderArchived-list
  @date: 2020/12/14
-->
<template>
  <table-crud
    ref="tableCrud"
    :search-form="searchForm"
    search-label-width="100px"
    @on-load="loadData"
  >
    <template v-slot:header>
      项目归档列表
    </template>
    <template v-slot:search="search">
      <el-form-item label="招标项目编号">
        <el-input
          v-model.trim="searchForm.tenderNo"
          placeholder="招标项目编号"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item label="招标项目名称">
        <el-input
          v-model.trim="searchForm.tenderName"
          placeholder="招标项目名称"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <!--招标方式-->
      <el-form-item
        label="招标方式"
      >
        <el-select v-model="searchForm.tenderMethod" placeholder="请选择">
          <el-option
            v-for="(item,index) in bidTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        label="资格审查方式"
        prop="qualificationMethod"
      >
        <el-select v-model="searchForm.qualificationMethod" placeholder="请选择">
          <el-option
            v-for="item in phaseTypeList"
            :key="item.typecode"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        label="创建日期"
      >
        <!--创建日期-->
        <el-date-picker
          v-model="createTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="createTimeChange"
        />
      </el-form-item>
    </template>
    <template v-slot:GXTable>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          prop="tenderNo"
          align="center"
          label="招标项目编号"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="tenderName"
          label="招标项目名称"
          min-width="230"
        />
        <el-table-column
          :formatter="formatTenderMethod"
          header-align="center"
          prop="tenderMethod"
          label="招标方式"
          width="80"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="managerName"
          label="项目经理"
          width="90"
        />
        <el-table-column
          header-align="center"
          label="标段（包）名称"
          prop="packName"
          align="left"
          min-width="200"
        />
        <el-table-column
          header-align="center"
          label="标段（包）编号"
          prop="packNo"
          align="left"
          min-width="160"
        />
        <el-table-column
          label="归档状态"
          prop="packStatus"
          width="130"
        >
          <template slot-scope="scope">
            {{ filterDictText(archiveStatusList,scope.row.isArchive) }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          width="100"
        >
          <template slot-scope="scope">
            <!-- isArchive 00 未归档 -->
            <el-link
              v-if="scope.row.isArchive==='00'"
              type="primary"
              @click.stop="archived(scope.row)"
            >
              [归档]
            </el-link>
            <!-- isArchive 01 已归档 -->
            <el-link
              v-if="scope.row.isArchive==='01'"
              type="primary"
              @click.stop="archived(scope.row)"
            >
              [查看归档]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </table-crud>
</template>
<script>
/* 接口*/
import { listTenderProjectArchivePages } from '@/api/bidding/biddingProject'// 招标项目-归档列表
/* 公用方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 混入-字典信息 */
import { tenderArchivedGroup } from './../mixins/bidArchivedGroupMixin'// 字典信息
export default {
  name: 'TenderProjectList',
  data() {
    return {
      /* 字典信息-start */
      bidTypeList: [], // 招标方式
      phaseTypeList: [], // 资格审查方式
      ...tenderArchivedGroup,
      /* 字典信息-end */
      loading: true,
      // 搜索
      createTime: [], // 创建时间 不传给后端只做回显
      searchForm: {
        createBeginTime: '', // 创建开始时间
        createEndTime: '', // 创建结束时间
        qualificationMethod: '', // 00资格预审,01 资格后审
        tenderMethod: '', // 招标方式 : 公开招标 00 邀请招标 01
        tenderName: '', // 项目名称
        tenderNo: '' // 项目编号
      },
      tableData: []
    }
  },
  created() {
    // 字典信息
    this.initGroup()
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 获取字典方法
    initGroup() {
      const data = [
        'bidType', // 招标方式
        'phaseType' // 资格审查方式
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 表格字典值替换文本-招标方式
    formatTenderMethod(row, column, cellValue) {
      return filterDictText(this.bidTypeList, cellValue)
    },
    // 创建时间选择
    createTimeChange(val) {
      this.searchForm.createBeginTime = val[0]// 开始日期
      this.searchForm.createEndTime = val[1]// 结束日期
    },
    // 获取数据
    loadData(params, callback) {
      listTenderProjectArchivePages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 归档
    archived(row) {
      this.$router.push({
        name: 'tenderArchived-detail',
        params: {
          packId: row.packId
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
