<!--
  @description: 采购人-采购结果 确定成交人
  @author: gmy
  @routerPath:/procurement/procurementDrive/offerResultContent/confirmConclude-add
  @date: 2020-9-2 20:06:58
-->
<template>
  <div class="main">
    <!--    供应商数据-->
    <p class="page-title">
      1.确定成交人
    </p>
    <div>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="beChosenSuppperData.supplierCandidateList"
        width="100%"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          align="left"
          label="供应商名称"
          prop="supplierName"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="linker"
          label="联系人"
          align="left"
          min-width="110"
        />
        <el-table-column
          header-align="center"
          prop="linkerTel"
          label="联系人电话"
          min-width="120"
          align="center"
        />
        <el-table-column
          header-align="center"
          label="报价时间"
          align="center"
          min-width="140"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.negRecordTime">
              {{ $Moment(scope.row.negRecordTime).format(momentDateTime) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="报价总金额（元）"
          align="right"
          min-width="110"
        >
          <template slot-scope="scope">
            <span>
              {{ moneyFormat(scope.row.offerTotalAmount) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="评标价（元）"
          align="right"
          min-width="110"
        >
          <template slot-scope="scope">
            <span>
              {{ moneyFormat(scope.row.evaluationPrice) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="最终得分"
          prop="finalScore"
          align="right"
          min-width="110"
        />
        <el-table-column
          header-align="center"
          label="排名"
          prop="ranking"
          align="center"
          min-width="80"
        />
        <el-table-column
          header-align="center"
          label="是否中选"
          align="center"
        >
          <template slot-scope="scope">
            <el-checkbox v-model="scope.row.radio" :disabled="isEdit" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" />
    </div>
    <!--    保存 下一步-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" @click="next">
            下一步
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/** api */
import { queryWinningResultInfoByPackId } from '@/api/procurement/procurementResult' // 查询中标结果信息
import { listEvalResultSupplierPages, confirmWinningResultSupplier } from '@/api/procurement/procurementEvaluation'
/** 公共方法 */
import { filterObj, moneyFormat } from '@/assets/js/utils'// 常用方法
/**  混合开发 参数 */
import { ListMixin } from '@/mixins/ListMixin'// 分页

/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页

export default {
  name: 'ProcurementResultSynthesizeAddVue',
  inject: ['getTenderBase'],
  components: {
    pagination // 分页组件
  },
  mixins: [ListMixin],
  data() {
    return {
      loading: false,
      isEdit: false, // 操作按钮是否可编辑
      // 中选供应商数据
      beChosenSuppperData: {
        // 中选供应商家数
        supplierCandidateList: []
      },
      // 中选供应商查询数据
      searchForm: {
        packId: ''
      },
      formData: {
        id: '',
        packId: '',
        mattersNeedingAttention: '' // 原因说明
      },
      // 评审报告
      procurementResponseFile: {
        bizId: '',
        fileType: ''
      },
      principalList: [],
      // 附件上传
      principalData: {
        bizId: '',
        fileType: ''
      },
      tenderBase: this.getTenderBase() // 获取项目信息
    }
  },
  created() {
    if (this.tenderBase.packId) {
      this.searchForm.packId = this.tenderBase.packId
      // 初始化查询中选的供应商列表
      this.getSupplierCandidateList()
    }
  },
  methods: {
    moneyFormat,
    // 下一步
    next() {
      // 确定选中的供应商
      const chosenSuppliers = this.getExportSupplier()
      // 调用确认中选人请求
      this.confirmWinningResultSupplierData(chosenSuppliers)
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 导出时用的参数
    getExportSupplier() {
      const supplierList = this.beChosenSuppperData.supplierCandidateList.filter(supplier => supplier.radio)// 取得已选中的报价供应商
      const chosenSuppliers = []// 供应商选中id
      supplierList.forEach(supplier => {
        chosenSuppliers.push(supplier.procedureId)
      })
      return chosenSuppliers
    },
    // 确定成交人
    confirmWinningResultSupplierData(chosenSuppliers) {
      const data = {
        packId: this.tenderBase.packId, // 项目标段id
        procedureIds: chosenSuppliers.toString() // 确定成交人id
      }
      if (data.procedureIds) {
        confirmWinningResultSupplier(data).then(res => {
          this.$router.push({ path: '/procurement/procurementDrive/offerResultContent/goodsAllot-add' })
        }).catch(() => {

        })
        return
      }
      this.$message.warning('请选择中选的供应商')
    },
    // 查询中标的供应商
    getSupplierCandidateList() {
      const data = this.getQueryParams()
      listEvalResultSupplierPages(data).then(res => {
        const { records, total } = res.data
        // 获取中选的供应商家数数据
        this.beChosenSuppperData.supplierCandidateList = records.map(curentItem => {
          return {
            ...curentItem,
            radio: curentItem.evaluationWinning === '01' // 复选框绑定值
          }
        })
        this.paginationData.total = total
        // 调用查询中标结果
        this.queryWinningResultInfo()
      }).catch(() => {

      })
    },
    /*
     查询中标结果
     入参:packId 项目标段id
    */
    queryWinningResultInfo() {
      const data = {
        packId: this.tenderBase.packId
      }
      queryWinningResultInfoByPackId(data).then(res => {
        // auditStatus 00 待审核 01 审核通过 02 不通过 待审核审核通过下 是不可编辑的
        this.isEdit = res.data.auditStatus === '00' || res.data.auditStatus === '01'
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped>

</style>
