<!--
  @description: 采购人-竞价类-采购结果
  @author: gmy
  @routerPath:/procurement/procurementDrive/offerResultContent/offerResultBidding
  @date: 2020-5-26 15:54:58
-->
<template>
  <div>
    <!--    供应商数据-->
    <div class="main">
      <el-table
        ref="smallTable"
        :data="tableData"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          align="center"
          label="供应商名称"
          prop="supplierName"
          width="200"
        />
        <el-table-column
          header-align="center"
          prop="linker"
          label="联系人"
          min-width="80"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="linkerTel"
          label="联系人电话"
          width="120"
          align="center"
        />
        <el-table-column
          header-align="center"
          label="报价时间"
          prop="offerTime"
          align="center"
          min-width="110"
        />
        <el-table-column
          header-align="center"
          label="最终报价(元)"
          prop="finalPrice"
          align="center"
          min-width="110"
        />
        <el-table-column
          header-align="center"
          label="排名"
          prop="sort"
          align="center"
          min-width="80"
        />
        <el-table-column
          header-align="center"
          label="确定成交人"
          align="center"
        >
          <template slot-scope="scope">
            <el-checkbox :checked="scope.row.isWinBiding === '01'" :disabled="!isEdit" @change="checkSupplier(scope.row)" />
          </template>
        </el-table-column>
      </el-table>
      <p class="title">
        补充说明
      </p>
      <el-form
        ref="formData"
        :model="formData"
        label-width="120px"
      >
        <table class="from_table">
          <tr>
            <td style="width:3%">
              <el-form-item label="注意事项">
                <label slot="label" style="padding-left:20px;">原因说明</label>
              </el-form-item>
            </td>
            <td>
              <el-input
                v-if="isEdit"
                v-model="formData.remark"
                :rows="2"
                type="textarea"
                placeholder="请输入内容"
              />
              <span v-else>
                {{ formData.remark }}
              </span>
            </td>
          </tr>
        </table>
      </el-form>
    </div>
    <!--    保存 下一步-->
    <div v-if="isEdit" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <gx-button :code="'001_006_013'" type="primary" @click="submitResult">
            提 交
          </gx-button>
        </div>
      </div>
    </div>
    <!-- 审核状态图片 -->
    <div class="procurement_auditStatus">
      <!-- 待审核 -->
      <img v-if="auditStatus === '00'" src="@assets/img/common/audit/auditWait.png" alt="">
      <!-- 审核通过 -->
      <img v-if="auditStatus ==='01'" src="@assets/img/common/audit/auditOk.png" alt="">
      <!-- 审核不通过 -->
      <img v-if="auditStatus ==='02'" src="@assets/img/common/audit/auditNo.png" alt="">
    </div>
  </div>
</template>

<script>
/** api接口 */
import { queryBiddingWinningResultInfo, saveBiddingResults } from '@api/procurement/procurementResult.js'
export default {
  name: 'ProcurementResultBiddingListVue',
  inject: ['getTenderBase'],
  data() {
    return {
      // 是否可编辑
      isEdit: false,
      // 供应商列表
      tableData: [],
      // 获取项目信息
      tenderBase: this.getTenderBase(),
      // 选中供应商
      supplierIds: [],
      // 审核状态
      auditStatus: '',
      // 采购结果提交参数
      formData: {
        packId: '',
        tenderId: '',
        supplierIds: '', // 选中供应商
        remark: '' // 原因
      }
    }
  },
  created() {
    // 采购结果查询
    this.winningResultInfo()
  },
  methods: {
    // 采购结果查询
    winningResultInfo() {
      const params = {
        packId: this.tenderBase.packId
      }
      queryBiddingWinningResultInfo(params).then((res) => {
        // 供应商列表
        this.tableData = res.data.winningSupplierList
        // 原因
        this.formData.remark = res.data.remark
        // 审核状态
        this.auditStatus = res.data.auditStatus
        if (res.data.auditStatus === '00' || res.data.auditStatus === '01') {
          this.isEdit = false
        } else {
          this.isEdit = true
        }
        // 选中数据生成
        this.supplierIds = []
        this.tableData.forEach((item) => {
          if (item.isWinBiding === '01') {
            this.supplierIds.push(item.supplierId)
          }
        })
      })
    },
    // 选中生成数据
    checkSupplier(row) {
      if (this.supplierIds.indexOf(row.supplierId) === -1) {
        // 选中
        this.supplierIds.push(row.supplierId)
      } else {
        // 取消选中
        this.supplierIds.splice(this.supplierIds.indexOf(row.supplierId), 1)
      }
    },
    // 提交
    submitResult() {
      // 未选中供应商
      if (this.supplierIds.length === 0) {
        this.$message({
          message: '请选择成交供应商！',
          type: 'warning'
        })
        return
      }
      this.formData.packId = this.tenderBase.packId
      this.formData.tenderId = this.tenderBase.tenderId
      // 选中供应商
      this.formData.supplierIds = this.supplierIds.join(',')
      saveBiddingResults(this.formData).then((res) => {
        this.$message({
          message: '操作成功！',
          type: 'success'
        })
        // 采购结果查询
        this.winningResultInfo()
      })
    }
  }
}
</script>

<style scoped>
.procurement_auditStatus{
  position: absolute;
  top:-10px;
  right:60px;
}
</style>
