
<!--
  @description: 【 单一来源 || 竞谈 】 多轮报价
  @Modifier：ysg
  @routerPath: procurement/procurementDrive/procurementDocumentsPurchase/evaluationResults/manyTablePrice
  @date：  2020-10-11 14:24:28
-->
<template>
  <div class="main framCon">
    <div v-if="roleCode === 'OFF_EXPERT' && vetoBtnFlag" class="mr10 vetoBtn pointer" @click="vetoBtn">
      <span>否决</span>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleTabClick">
      <el-tab-pane v-for="(item, index) in tabNextList" :key="index" :label="item.stageName" :name="index+''" />
    </el-tabs>
    <div class="page-title">
      1.供应商报价
    </div>
    <el-table v-loading="loading" :data="pricelist" style="width: 100%;" border class="mb16">
      <el-table-column v-if="roleCode === 'OFF_EXPERT'" label="" width="80" align="center">
        <template slot-scope="scope">
          <el-radio v-model="radioValOfferId" :disabled="scope.row.offerStatus==='02'" :label="scope.row.offerId" @change.native="currentRadio(scope.row)">
            {{ '' }}
          </el-radio>
        </template>
      </el-table-column>
      <el-table-column header-align="center" type="index" label="序号" align="center" />
      <el-table-column prop="supplierName" label="供应商名称" align="center" />
      <el-table-column prop="offerStatus" label="报价状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.offerStatus === '01'">正常</span>
          <span v-if="scope.row.offerStatus === '02'">
            <el-link
              :underline="false"
              size="mini"
              type="primary"
              @click="rejectedVeto(scope.row)"
            >
              已否决
            </el-link>
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="offerTotal" label="不含税总价（元）" header-align="center" align="right">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.offerTotal) }}</span>
        </template>
      </el-table-column>
      <!-- 行项目暂时隐藏 使用报价单号弹框 -->
      <!-- <el-table-column
        header-align="center"
        label="行项目报价"
        align="center"
      >
        <template slot-scope="scope">
          <el-link
            :underline="false"
            size="mini"
            type="primary"
            @click="openDialog(scope.row)"
          >
            行项目报价
          </el-link>
        </template>
      </el-table-column> -->
      <!-- 报价单 -->
      <el-table-column
        header-align="center"
        label="报价单"
        align="center"
      >
        <template slot-scope="scope">
          <el-link
            :underline="false"
            size="mini"
            type="primary"
            @click="offerSingleClick(scope.row)"
          >
            {{ scope.row.negRecordCode }}
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <div v-if="nextRoundlist.isShowStageOfferBtn === '00' && nextRoundlist.isLast === '00' && nextRoundlist.nextIsLast !== null && nextRoundlist.nextIsLast !== ''">
      <div class="page-title">
        3.下一轮次信息
      </div>
      <table class="tableData mb16">
        <tr>
          <td v-if="getTenderBase.tenderMethod === '13'">
            <span>报价截止时间</span>
          </td>
          <td v-if="getTenderBase.tenderMethod === '13'">
            <span>{{ nextRoundlist.nextQuoteEndTime && $Moment(nextRoundlist.nextQuoteEndTime).format(momentDateTime) }}</span>
          </td>
          <td>
            <span>是否最终轮次</span>
          </td>
          <td>
            <span v-if="nextRoundlist.nextIsLast === '00'">否</span>
            <span v-if="nextRoundlist.nextIsLast === '01'">是</span>
          </td>
        </tr>
        <tr>
          <td>
            <span>入围供应商</span>
          </td>
          <td colspan="3">
            <span>{{ nextRoundlist.nextWinningSuppliers }}</span>
          </td>
        </tr>
        <tr>
          <td>
            <span>报价说明文件</span>
          </td>
          <td colspan="3">
            <downloadFile :data="procurementFile" />
          </td>
        </tr>
      </table>
    </div>
    <!--  v-if="nextRoundlist.isShowStageOfferBtn === '01'"  projectStatus项目状态 05采购终止-->
    <div v-if="nextRoundlist.isShowStageOfferBtn === '01' && roleCode !== 'OFF_EXPERT'&&projectStatus" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-con">
          <el-button type="primary" @click="openNew">
            开启新轮次
          </el-button>
        </div>
      </div>
    </div>
    <!-- 编辑状态下行项目报价弹框 -->
    <priceReviewLineItemInfo :dialog-data="priceReviewDialog" />
    <!-- 开启新轮次 -->
    <procurementEvalutionNewRounds :dialog-data="openNewDialog" :drive-info="driveInfo" :next-winning-name="nextWinningName" @consignContractInfo="consignContractInfo" />
    <!-- 否决详情 -->
    <procurementEvalutionVetoDetail :dialog-data="vetoDialog" :reject-veto-obj="rejectVetoObj" />
    <!-- 否决原因填写 -->
    <procurementEvalutionVetoReason :dialog-data="vetoReasonDialog" :radio-val="radioVal" @vetoReasonSave="vetoReasonSave" />
    <!--  查看供应商报价信息弹框-->
    <procurementSuplierOffer :dialog-data="supplierOfferDialog" />
  </div>
</template>

<script>
/* api*/
import {
  queryProtProjectProcurementStageOfferList,
  openningNewRoundsByOfferStageId,
  viewNegativeStageSupplierInfo,
  queryOpenDetailEvalDictateStatus,
  protProjectProcurementStageSupplierNegative
} from '@api/procurement/procurementEvaluation'
import {
  saveOfferStage
} from '@/api/procurement/procurementOffer' // 报价大厅表格数据请求
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile' // 文件回显组件
import { moneyFormat } from '@/assets/js/utils'
import priceReviewLineItemInfo from '../../procurementEvaluation/procurementPriceReview/procurementPriceReviewLineItemInfo-dialog' // 行项目报价组件
import procurementEvalutionNewRounds from './procurementEvalutionNewRounds-dialog' // 行项目报价组件
import procurementEvalutionVetoDetail from './procurementEvalutionVetoDetail-dialog' // 否决详情
// import procurementEvalutionVetoReason from './procurementEvalutionVetoReason-dialog' //  填写否决原因
import procurementSuplierOffer from '@/views/procurement/components/procurementLookSupplierOffer-dialog'// 查看供应商报价弹框
export default {
  components: {
    priceReviewLineItemInfo, // 行项目报价组件
    procurementEvalutionNewRounds, // 开启新轮次
    procurementEvalutionVetoDetail,
    // procurementEvalutionVetoReason,
    downloadFile,
    procurementSuplierOffer// 查看供应商报价弹框
  },
  inject: ['getTenderBase'],
  mixins: [],
  props: {
    tableData: {
      type: Object,
      default: function() {
        return {}
      }
    },
    driveInfo: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: false, // loading效果
      vetoDialog: { // 否决详情
        dialog: false //  false 关闭   true 打开
      },
      vetoReasonDialog: {
        dialog: false //  false 关闭   true 打开
      },
      openNewDialog: {
        dialog: false, //  false 关闭   true 打开
        tenderMethod: '',
        offerStageId: ''
      },
      priceReviewDialog: {
        dialog: false, //  false 关闭   true 打开
        id: [] // 供应商报价id
      }, // 行项目报价弹框
      projectStatus: false, // 项目状态 采购终止
      metaType: this.$route.meta.type, // 路由meta信息
      pricelist: [], // 价格评审表格数据
      nextRoundlist: {}, // 下一轮次信息展示
      activeName: '0', // 默认展示第一个tab选中
      stageNo: 1,
      tabList: [],
      tabNextList: [], // 下一轮次信息
      getTenderBase: this.getTenderBase(),
      // 开启新轮次数据
      Rounddata: {
        packId: '',
        isLast: '',
        tenderId: '', // 项目id
        offerIds: '', // 开启新伦次的供应商的id集合\
        remarkFileBizId: ''
      },
      nextWinningName: '', // 供应商名字 列表 逗号隔开
      nextWinningNameOferIds: '', // 供应商OferId
      rejectVetoObj: {}, // 否决详情的数据
      radioVal: {},
      radioValOfferId: '', // 选择的OfferId
      roleCode: '', // 角色code
      vetoBtnFlag: false, // 否决按钮是否展示
      procurementFile: {
        bizId: '', // 业务主键Id
        fileType: ''// 文件类型
      }, // 附件信息
      // 供应商报价单查看弹框
      supplierOfferDialog: {
        dialog: false,
        stageId: '', // 轮次id
        packId: '', // 标段id
        supplierId: '' // 供应商id
      }
    }
  },
  watch: {
    driveInfo(val) {
      if (val) {
        // 关闭loading
      }
    }
  },
  mounted() {
    // 判断是否为项目经理查看页面
    // this.getTenderBase.tenderMethod === '13' 竞谈
    this.openNewDialog.tenderMethod = this.getTenderBase.tenderMethod
    this.roleCode = this.$store.getters.info.currentRol.roleCode
    this.viewPriceEvaluation()
    this.projectStatus = this.getTenderBase.purchaseProjectStatus !== '05' // 获取采购项目状态 05采购终止  不显示开启新论次
  },
  methods: {
    moneyFormat, // 千分位
    // 打开行项目报价弹框
    // openDialog(row) {
    //   this.priceReviewDialog.dialog = true
    //   this.priceReviewDialog.id = row.offerId
    // },
    // 报价单弹框打开
    offerSingleClick(row) {
      this.supplierOfferDialog.stageId = row.stageId // 轮次id
      this.supplierOfferDialog.packId = this.driveInfo.packId || this.getTenderBase.packId // 项目标段id
      this.supplierOfferDialog.supplierId = row.supplierId // 项目标段id
      this.supplierOfferDialog.dialog = true
    },
    // 项目经理查看价格评审数据
    viewPriceEvaluation() {
      this.loading = true
      const data = {
        packId: this.driveInfo.packId || this.getTenderBase.packId
      }
      queryProtProjectProcurementStageOfferList(data).then(res => {
        // 关闭loading
        this.loading = false
        // 所有数据
        this.tabList = res.data.offerList
        this.tabNextList = res.data.stageList
        // 下一轮次信息
        this.nextRoundlist = res.data.stageList[0]
        // 默认进来 表格的数据是第一个
        this.pricelist = res.data.offerList[0]
        this.activeName = '0'
        // 否决按钮是否展示
        if (this.nextRoundlist.isShowNegativeBtn === '01') {
          this.vetoBtnFlag = true
        } else if (this.nextRoundlist.isShowNegativeBtn === '00') {
          this.vetoBtnFlag = false
        }
        // 为每一个增加一个自己的名字
        this.tabNextList.forEach((item, index) => {
          if (index === 0) {
            this.$set(item, 'stageName', '首轮报价')
          } else if (index !== 0 && item.isLast === '00') {
            this.$set(item, 'stageName', '第' + (index + 1) + '轮报价')
          } else if (index !== 0 && item.isLast === '01') {
            this.$set(item, 'stageName', '最终轮')
          }
        })
        // 如果是最终轮 且 竞争性谈判   则查询开启详细状态按钮的状态
        if (res.data.isLast === '01' && this.getTenderBase.tenderMethod === '13') {
          const data = {
            packId: this.driveInfo.packId || this.getTenderBase.packId // "标段ID"
          }
          // 请求接口 开启新轮次按钮的展示状态
          queryOpenDetailEvalDictateStatus(data).then(res => {
            if (res.header.ret === '0') {
              // 如果是true 则展示 否者隐藏
              if (res.data) {
              // 子组件往父组件传递值 开启详细状态按钮的值
                this.$emit('showOpenDetail', true)
              } else {
                this.$emit('showOpenDetail', false)
              }
            }
          })
        } else if (this.nextRoundlist.isLast === '00') {
          this.$emit('showOpenDetail', false)
        }
        this.fileParameters()
        // 一共有多少轮次
        this.stageNo = res.data.stageNo
      }).catch(() => {
        this.loading = false
      })
    },
    // tab切换
    handleTabClick(tab, event) {
      // 让点击的轮次赋值到当前表格的数据
      this.pricelist = this.tabList[tab.index]
      // 下一轮次信息数据
      this.nextRoundlist = this.tabNextList[tab.index]
      this.activeName = String(tab.index)
      this.fileParameters()
      // 否决按钮是否展示
      if (this.nextRoundlist.isShowNegativeBtn === '01') {
        this.vetoBtnFlag = true
      } else if (this.nextRoundlist.isShowNegativeBtn === '00') {
        this.vetoBtnFlag = false
      }
    },
    // 开启新轮次
    openNew() {
      const nameArr = []
      const nameoOferIds = []
      this.pricelist.forEach(opt => {
        if (opt.offerStatus === '01') {
          nameArr.push(opt.supplierName)
          nameoOferIds.push(opt.offerId)
        }
      })
      this.nextWinningName = nameArr.join(',')
      this.nextWinningNameOferIds = nameoOferIds.join(',')
      this.openNewDialog.offerStageId = this.nextRoundlist.offerStageId
      this.openNewDialog.dialog = true
    },
    // 已否决弹出框
    rejectedVeto(row) {
      const data = {
        packId: this.driveInfo.packId || this.getTenderBase.packId, // "标段ID",
        stageId: row.stageId, // "轮次ID",
        supplierId: row.supplierId, // "供应商ID",
        supplierName: row.supplierName // "供应商名称"
      }
      viewNegativeStageSupplierInfo(data).then(res => {
        if (res.header.ret === '0') {
          this.rejectVetoObj = res.data
          this.vetoDialog.dialog = true
        }
      })
    },
    // ----------提交新轮次------------

    // 文件参数
    fileParameters() {
      // 判断是商务评审还是技术评审
      this.procurementFile.fileType = 'prot_procurement_stage_remark_file_base'
      this.procurementFile.bizId = this.nextRoundlist.offerStageId
    },
    // 关闭弹框触发的回调
    consignContractInfo(openNewRoundData) {
      if (openNewRoundData) {
        // 获取报价截止时间 单一来源未 ''
        //  获取是否为最终轮次的字段
        this.Rounddata.isLast = openNewRoundData.isLast
        this.Rounddata.tenderId = this.getTenderBase.tenderId
        this.Rounddata.packId = this.driveInfo.packId || this.getTenderBase.packId
        this.Rounddata.offerIds = this.nextWinningNameOferIds
        this.Rounddata.remarkFileBizId = this.nextRoundlist.offerStageId
        if (this.getTenderBase.tenderMethod === '13') {
          this.Rounddata.quoteEndTime = openNewRoundData.EndTime
        } else {
          this.Rounddata.quoteEndTime = ''
        }
        // 延迟调用确认框
        setTimeout(() => {
          // 调用开启新伦次方法
          this.setNewRounds()
        }, 500)
      }
    },
    // 点击了确定开启新轮次
    setNewRounds() {
      // this.$confirm('确定开启新轮次报价吗？', '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   confirmButtonClass: 'confirmBtn',
      //   cancelButtonClass: 'cancelBtn',
      //   type: 'warning'
      // })
      //   .then(() => {
      //     // 调用开启新轮次方法 供应商和评标的都要调用接口
      //     this.setNewRound(this.Rounddata)
      //     // 不调用评标开启新轮次方法 只调用供应商的
      //     // this.openningNewRoundsByOffer(this.Rounddata)
      //   })
      //   .catch(() => {})
      this.setNewRound(this.Rounddata)
    },
    // 供应商开启新伦次方法
    setNewRound(data) {
      saveOfferStage(data)
        .then(res => {
          if (res.header.ret === '0') {
            this.openNewDialog.dialog = false
            this.$message.success(res.header.msg)
            // 开启完新轮次 重新获取数据
            this.viewPriceEvaluation()
          } else {
            this.$message.error(res.header.msg)
          }
        })
        .catch(() => {
        })
    },
    // 评标开始新轮次接口
    openningNewRoundsByOffer() {
      const data = {
        packId: this.driveInfo.packId || this.getTenderBase.packId,
        offerStageId: this.nextRoundlist.offerStageId, // '报价轮次表ID'
        nextIsLast: this.Rounddata.isLast, // '下一轮次是否是最后一轮次 00否 01是'
        nextWinningSuppliers: this.nextWinningName, // 下一轮次入围供应商列表，多个逗号分隔
        fileType: 'prot_procurement_stage_remark_file_base'// 报价说明文件,文件类型
      }
      if (this.getTenderBase.tenderMethod === '13') {
        data.nextQuoteEndTime = this.Rounddata.quoteEndTime
      } else {
        data.nextQuoteEndTime = ''
      }
      openningNewRoundsByOfferStageId(data)
        .then(res => {
          if (res.header.ret === '0') {
            this.$message.success(res.header.msg)
            // 开启完新轮次 重新获取数据
            this.viewPriceEvaluation()
          }
        })
        .catch((res) => {
          this.$message.error(res.header.msg)
        })
    },
    // 否决选择
    currentRadio(row) {
      // radio按钮的选择
      this.radioValOfferId = row.offerId
      // 选中的当前行信息
      this.radioVal = row
    },
    // 点击否决按钮
    vetoBtn() {
      if (JSON.stringify(this.radioVal) !== '{}') {
        this.vetoReasonDialog.dialog = true
      } else {
        this.$message.warning('请选择一个供应商！')
      }
    },
    // 提交填写否决原因
    vetoReasonSave(reasonContent) {
      const data = {
        evalExpertId: this.getTenderBase.evalExpertId, // "评委ID",
        negativeReason: reasonContent,
        packId: this.driveInfo.packId || this.getTenderBase.packId,
        stageId: this.radioVal.stageId,
        supplierId: this.radioVal.supplierId,
        supplierName: this.radioVal.supplierName
      }
      protProjectProcurementStageSupplierNegative(data).then(res => {
        if (res.header.ret === '0') {
          this.$message.success(res.data)
          this.viewPriceEvaluation()
        } else {
          this.$message.error(res.header.msg)
        }
      })
    }
  }
}
</script>

<style lang='less' scoped>
/*评审指标信息*/
.evaluationBottom  {
  width: 100%;
  margin: 20px 0;
}
.evaluationBottom  td {
  border: 1px solid #E0E0E0;
  line-height: 20px;
  padding: 9px 10px;
}
.evaluationBottom  tr td:nth-child(odd) {
  background-color: #F5F7F9;
  width: 5%;
}
.evaluationBottom  tr td:nth-child(even) {
  width: 34%;
}
.evaluationBottom  tr.singleRow td:nth-child(odd) {
  background-color: #F5F7F9;
  width: 6.5%;
}
.evaluationBottom  tr.singleRow td:nth-child(even) {
  width: calc(100%-6.5%);
}
.but_footer-con{
  margin-left: 49%;
  margin-top: 20px;
}
.framCon{
  position: relative;
}
.vetoBtn{
  position: absolute;
  right: 30px;
  top: 9px;
  z-index: 10000;
}
</style>
