<!--
  @description: 开标监控列表
  @Modifier: yangzy
  @routerPath: /bidding/bidingOpeningMonitor-list
  @date: 2021/02/01 14:08:18
-->
<template>
  <table-crud
    ref="tableCrud"
    :search-form.sync="searchForm"
    :advanced-search="false"
    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-date-picker
          v-model="searchForm.openBidStartTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="disabledPickerOptions"
          @change="createTimeChange"
        />
      </el-form-item>
    </template>

    <template v-slot:GXTable>
      <div class="mb10">
        <el-button type="primary" plain @click="exportOpenBidMonitorResult">
          导出待开标项目
        </el-button>
      </div>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
      >
        <el-table-column
          type="index"
          label="序号"
          min-width="60px"
          align="center"
        />
        <el-table-column
          prop="tenderNo"
          header-align="center"
          label="招标项目编号"
          min-width="140"
        />
        <el-table-column
          header-align="center"
          prop="tenderName"
          label="招标项目名称"
          min-width="230"
        />
        <el-table-column
          label="开标时间/技术标开标时间"
          prop="openBidStartTime"
          align="center"
          min-width="140"
        />
        <el-table-column
          label="经济标开标时间"
          prop="economicOpenBidStartTime"
          align="center"
          min-width="140"
        />
        <el-table-column
          align="center"
          prop="qualificationMethod"
          label="资格审查方式"
          min-width="100"
        >
          <template slot-scope="scope">
            {{ filterDictText(phaseTypeList, scope.row.qualificationMethod) }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="decryptionMethod"
          label="解密方式"
          min-width="100"
        >
          <template slot-scope="scope">
            {{ filterDictText(decryptionMethodList, scope.row.decryptionMethod) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="isTwoBidOpening"
          label="是否两步开标"
          min-width="100"
          align="center"
        >
          <template slot-scope="scope">
            {{ filterDictText(openingMethodList, scope.row.isTwoBidOpening) }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          width="250"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="beforeBidOpeningDetail(scope.row)"
            >
              [开标前数据查看]
            </el-link>
            <el-link
              type="primary"
              @click="bidOpeningDetail(scope.row)"
            >
              [开标数据监控]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </table-crud>
</template>
<script>
/* 接口*/
import { getOpenBidMonitorResultPage, exportOpenBidMonitorResult } from '@/api/bidding/bidOpening'// 获取开标监控项目列表
/* 公用方法*/
import { filterDictText, download } from '@/assets/js/utils'// 常用方法

export default {
  name: 'BidOpeningMonitorList',
  data() {
    return {
      loading: true,
      /* 字典信息-start */
      openingMethodList: [], // 是否两步开标
      phaseTypeList: [], // 资格审查方式
      decryptionMethodList: [], // 解密方式
      /* 字典信息-end */
      params: '',
      // 搜索
      openBidStartTime: [], // 开标时间 不传给后端只做回显
      searchForm: {
        openBidStartTime: [],
        openBidStartTimeStart: '', // 开标开始时间
        openBidStartTimeEnd: '', // 开标结束时间
        tenderNo: '' // 项目编号
      },
      tableData: []
    }
  },
  created() {
    // 字典信息
    this.initGroup()
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 获取字典方法
    initGroup() {
      const data = [
        'openingMethod', // 开标方式
        'decryptionMethod', // 解密方式
        'phaseType' // 资格审查方式
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 创建时间选择
    createTimeChange(val) {
      this.searchForm.openBidStartTimeStart = this.$Moment(val[0]).format(this.momentSaveFormat)// 开始日期
      this.searchForm.openBidStartTimeEnd = this.$Moment(val[1]).format(this.momentSaveFormat)// 结束日期
    },
    // 获取数据
    loadData(params, callback) {
      this.params = params
      getOpenBidMonitorResultPage(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 开标前数据查看
    beforeBidOpeningDetail(row) {
      this.$router.push({
        name: 'bidingBeforeOpeningMonitor-detail',
        params: {
          tenderId: row.id, // 项目id
          openBidStartTime: row.openBidStartTime, // 开标时间/技术标开标时间
          economicOpenBidStartTime: row.economicOpenBidStartTime // 经济标开标时间
        }
      })
    },
    // 开标数据监控
    bidOpeningDetail(row) {
      this.$router.push({
        name: 'bidingOpeningMonitor-detail',
        params: {
          tenderId: row.id, // 项目id
          openBidStartTime: row.openBidStartTime, // 开标时间/技术标开标时间
          economicOpenBidStartTime: row.economicOpenBidStartTime, // 经济标开标时间
          isTwoBidOpening: row.isTwoBidOpening, // 是否两步开标
          decryptionMethod: row.decryptionMethod // 是否客户端解密
        }
      })
    },
    // 导出待开标项目数据
    exportOpenBidMonitorResult() {
      const data = {
        ...this.params,
        exportDataType: 'OPEN_BID_MONITOR_LIST' // 导出数据类型
      }
      exportOpenBidMonitorResult(data).then(res => {
        download(res, '开标监控招标项目信息.xls')
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
