<!--
  @description:重新招标查看
  @Modifier: haofengxian
  @routerPath:/bidding/projectDrive/rebiddingRecord/rebiddingRecordDetail
  @date: 2020-5-13-10:42
-->
<template>
  <div class="main">
    <div class="page-title">
      1.基本信息
    </div>
    <table class="tableData">
      <tr class="singleRow">
        <td>标段（包）</td>
        <td colspan="3">
          <packDetail :pack-list="selectPackList" />
        </td>
      </tr>
      <!--   <tr class="singleRow">
        <td>重新制作招标文件</td>
        <td colspan="3">
          {{ formData.isChangeDoc==='01'?'是':'否' }}
        </td>
      </tr>-->
      <tr class="singleRow">
        <td>重新招标原因</td>
        <td colspan="3">
          {{ formData.rebiddingRecord }}
        </td>
      </tr>
      <tr class="singleRow">
        <td>异常报告附件</td>
        <td colspan="3">
          <downloadFile ref="downloadFile" :data="upLoadData" />
        </td>
      </tr>
    </table>

    <div class="page-title">
      2.沿用投标人
    </div>
    <div>
      <el-table v-loading="loading" :data="packBidderList" width="100%">
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          header-align="center"
          label="标段（包）编号"
          prop="packNo"
          align="left"
          min-width="200"
        />
        <el-table-column
          label="购标投标人家数"
          header-align="center"
          prop="buydocnumber"
          min-width="230"
        />
        <el-table-column
          label="沿用投标人家数"
          header-align="center"
          prop="usersuppliernumber"
          min-width="230"
        />
        <el-table-column header-align="center" label="操作" width="200">
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="selectedBidder(scope.row, scope.$index)"
            >
              [已选投标人]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--保存按钮-->
    <div v-if="isShowBackBtn" class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="back">
          返 回
        </el-button>
      </div>
    </div>
    <selected-follow-bidder-list-dialog
      ref="selectedFollowBidder"
      @supplierSelect="supplierSelect"
    />
  </div>
</template>

<script>
/* 接口*/
import { getRebiddingRecordInfoByRebiddingRecordId } from '@api/bidding/rebiddingRecord'
/* 选择标包组件*/
import packDetail from '@comp/bidding/packComponent/packDetail' // 关联标包渲染组件
import downloadFile from '@comp/common/updownload/downloadFile'
import selectedFollowBidderListDialog from './selectedFollowBidderList-dialog'

export default {
  name: 'RebiddingRecordAdd',
  components: {
    'selected-follow-bidder-list-dialog': selectedFollowBidderListDialog, // 已选沿用投标人弹框
    packDetail,
    downloadFile // 文件下载
  },
  data() {
    return {
      loading: false, // 沿用投标人列表loading
      isShowBackBtn: this.$route.meta.isShowBackBtn, // 详情页是否显示返回按钮
      packBidderList: [], // 沿用投标人列表
      selectPackList: [], // 获取的已选择的标段（包）
      // 保存/回显信息
      formData: {
        isChangeDoc: '00', // 是否变更(重新制作)文件 00:否 01:是
        isOperation: '', // 业务操作 保存:00 提交:01
        isSubmit: '', // 是否提交 00否 01是
        orderBy: '', // 排序
        packInfoList: [], // 包段阶段信息
        rebiddingRecord: '', // 重新招标原因
        rebiddingRecordId: '' // 重新招标记录id
      },
      // 上传附件参数
      upLoadData: {
        bizId: '', // 业务主键Id
        fileType: 'rebidding_exception_file_base' // 文件类型
      }
    }
  },
  created() {
    this.initData() // 获取重新招标内容
  },
  methods: {
    // 获取重新招标
    initData() {
      const rebiddingRecordId = sessionStorage.getItem('bizId')
      this.upLoadData.bizId = rebiddingRecordId
      // 判断是否有重新招标Id
      if (rebiddingRecordId) {
        getRebiddingRecordInfoByRebiddingRecordId(rebiddingRecordId)
          .then(res => {
            this.formData = res.data
            // 重新招标购标投标人家数列表
            this.packBidderList = this.formData.packInfoList
            // 获取的已选择的标段（包）
            this.selectPackList = this.formData.packInfoList
          })
          .catch(() => {})
      }
    },
    // 查看已选投标人
    selectedBidder(row, index) {
      if (row.rebiddingSupplierInfo) {
        const rowData = {
          isShowRemoveBtn: false, // 是否显示移除按钮
          packIndex: index, // 标段索引
          rebiddingSupplierInfo: row.rebiddingSupplierInfo // 已选投标人信息
        }
        this.$refs.selectedFollowBidder.openDialog(rowData)
      }
    },
    // 已选沿用投标人
    supplierSelect(data, index) {
      this.packBidderList[index].usersuppliernumber = String(
        this.packBidderList[index].rebiddingSupplierInfo.length
      ) // 前沿投标家数
      this.formData.packInfoList = this.packBidderList
    },
    back() {
      this.$router.push({
        path: '/bidding/projectDrive/rebiddingRecord/rebiddingRecordList',
        query: {
          ...this.$route.query
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
/deep/.file-list {
  .fileBtn,
  li {
    margin-bottom: 0 !important;
  }
  .name {
    margin-right: 0 !important;
  }
}
</style>
