<!--
  @description: 今日开标列表主页面 -点击项目或标段数字查看-项目标段列表弹框
  @Modifier: haoFx
  @routerPath:
  @date: 2020/3/18-11:27
-->
<template>
  <div>
    <el-dialog
      :visible.sync="dialogTableVisible"
      :fullscreen="true"
      custom-class="el-dialog__body-p8"
      title="项目标段列表"
    >
      <section class="main">
        <div style="margin-bottom: 10px">
          <el-radio-group v-model="packageParams.isSatisfyThreeBidder" @change="handlePackRadio">
            <el-radio label="">
              全部
            </el-radio>
            <el-radio label="01">
              满足三家
            </el-radio>
            <el-radio label="00">
              不足三家
            </el-radio>
          </el-radio-group>
        </div>
        <div>
          <el-table
            :data="tableData"
          >
            <el-table-column
              type="index"
              label="序号"
              width="60px"
              align="center"
            />
            <el-table-column
              header-align="center"
              prop="tenderNo"
              align="center"
              label="项目编号"
              width="160"
            />
            <el-table-column
              header-align="center"
              prop="tenderName"
              label="项目名称"
              min-width="230"
            />
            <el-table-column
              header-align="center"
              prop="openStageType"
              label="开标类型"
              min-width="75"
              align="center"
              :formatter="formatOpenStageType"
            />
            <el-table-column
              header-align="center"
              label="标段编号"
              prop="packNo"
              min-width="180"
            />
            <el-table-column
              header-align="center"
              label="标段名称"
              prop="packName"
              align="left"
              min-width="200"
            />
            <el-table-column
              header-align="center"
              label="有效投标家数"
              prop="validBidderNumber"
              align="right"
              min-width="110"
            />
            <el-table-column
              header-align="center"
              label="操作"
              align="center"
              width="150"
            >
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  @click="getInto(scope.row)"
                >
                  进入
                </el-link>
                <el-link
                  v-if="scope.row.isShowDetail==='01'"
                  type="warning"
                  @click="viewBidders(scope.row)"
                >
                  查看投标人
                </el-link>
              </template>
            </el-table-column>
          </el-table>
          <!--分页组件-->
          <pagination :pagination-data="paginationData" @change="loadData" />
        </div>
      </section>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!--供应商列表组件-->
    <biddingSuppliersList ref="biddingSuppliers" />
  </div>
</template>

<script>
/* 接口*/
import { listOpeningTenderPackagePages, getOpenBidStartTimeIsStart } from '@api/bidding/bidOpening'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import biddingSuppliersList from './biddingSuppliers-list'
import { bidOpeningRedisConfigMixin } from '../mixins/bidOpeningRedisConfigMixin'

export default {
  name: 'ProjectPackList',
  components: {
    pagination, // 分页
    biddingSuppliersList
  },
  mixins: [ListMixin, bidOpeningRedisConfigMixin],
  data() {
    return {
      // 开标类型
      openStageTypeList: [
        { typename: '商务技术经济标', typecode: '00' },
        { typename: '商务技术标', typecode: '01' },
        { typename: '经济标', typecode: '02' },
        { typename: '商务技术标', typecode: '03' }
      ],
      dialogTableVisible: false, // 弹框是否打开
      tableData: [],
      packageParams: {
        isSatisfyThreeBidder: '', // 是否满足三家投标人 00 不满足三家 01 满足三家 null为全部
        openStageType: '', // 00一次开标阶段(商务技术经济)，01非价格开标阶段(商务技术)，02价格开标阶段(经济)
        stageIds: '', // 阶段id集合
        bidDocumentDecryptionMethod: '', // 投标文件解密方式 00:投标人解密 01:服务端集中解密
        openBidStartTime: '' // 开标时间
      },
      packageNumber: 0 // 标包个数
    }
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 打开弹框
    openDialog(item, type) {
      this.packageParams.isSatisfyThreeBidder = type
      this.packageParams.openStageType = item.openStageType
      this.packageParams.stageIds = item.stageIds // 阶段id集合
      this.packageParams.bidDocumentDecryptionMethod = item.bidDocumentDecryptionMethod // 投标文件解密方式 00:投标人解密 01:服务端集中解密
      this.packageParams.openBidStartTime = item.openBidStartTime // 开标时间
      this.packageNumber = item.packageNumber
      // 获取列表信息
      this.loadData()
      this.dialogTableVisible = true
    },
    // 获取项目标段列表
    loadData() {
      const params = {
        ...this.packageParams,
        pageNo: this.paginationData.pageNo,
        pageSize: this.paginationData.pageSize
      }
      listOpeningTenderPackagePages(params).then(response => {
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 点击筛选标段类型
    handlePackRadio(val) {
      this.packageParams.isSatisfyThreeBidder = val
      this.loadData()
    },
    // 进入
    getInto(item) {
      this.getOpenBidStart(item)
    },
    // 获取是否有已开启标段
    getOpenBidStart(item) {
      const params = {
        openStageType: item.openStageType,
        stageIds: item.stageId
      }
      // 项目经理-获取该开标时间段是否已有开启的标段
      getOpenBidStartTimeIsStart(params).then(response => {
        // 已开启 isStartOpeningStatus 00:未开启 01:已开启
        if (response.data.isStartOpeningStatus === '01') {
          // packageNumber标包个数大于1 表示分包项目否则未不分包
          if (this.packageNumber > 1) {
            // 分包
            this.$router.push({
              path: this.decryptionPath.packagePath,
              query: {
                ...this.$route.query
              }
            })
          } else {
            // 不分包
            this.$router.push({
              path: this.decryptionPath.noPackagePath,
              query: {
                ...this.$route.query
              }
            })
          }
        } else {
          this.$router.push({
            path: '/bidOpeningHall/openingHall',
            query: {
              ...this.$route.query
            }
          })
        }
      }).catch(() => {
      })
    },
    // 查看投标人
    viewBidders(row) {
      const rowData = {
        ...row,
        bidDocumentDecryptionMethod: this.packageParams.bidDocumentDecryptionMethod
      }
      this.$refs.biddingSuppliers.openDialog(rowData)
    },
    // 表格字典值替换文本-开标类型
    formatOpenStageType(row, column, cellValue) {
      return filterDictText(this.openStageTypeList, cellValue)
    }
  }
}
</script>

<style scoped lang="less">
  @import "../index";
/deep/.el-dialog__footer{
  position: absolute;
  bottom: 0;
  width: 100%;
}
</style>
