<!--
  @description: 代理机构-项目管理-定标-确定资审结果新增/查看公用页面
  @author: 肖文龙
  @routerPath:/bidding/projectDrive/calibration/confirmQualified
  @date： 2019-11-21 10:35:27
  isCanOperate: true可以操作 false不可以查看只有查看权限
-->
<template>
  <div class="main">
    <section v-if=" tenderBase.isCanOperate" class="clearfix mb16">
      <div class="fr">
        <template v-if="is_detail">
          <el-button type="primary" @click="submit('00')">
            保存
          </el-button>
          <el-button type="primary" @click="submit('01')">
            提交
          </el-button>
        </template>
        <template v-if="!is_detail && systemSource==='01' && bidPlanType==='00'">
          <!--（00未推送、01已推送）-->
          <el-button v-if="pushWuziLogInfo==='00'" type="primary" :loading="handlePushResultLoading" @click="handlePushResult">
            发送资格预审结果
          </el-button>
        </template>
      </div>
    </section>
    <!--供应商列表-->
    <section>
      <el-table
        :data="is_show?tableData:tableData[0]?[tableData[0]]:[]"
      >
        <el-table-column
          type="index"
          label="序号"
          align="center"
          width="60"
        />
        <el-table-column
          header-align="center"
          prop="supplierName"
          label="投标供应商"
        />
        <el-table-column
          prop="isRecommend"
          label="评标结论"
          align="center"
          width="80"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.isRecommend === '01'">符合</span>
            <span v-else-if="scope.row.isRecommend === '00'">不符合</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="qualificationResult"
          label="资审结果"
          align="center"
        >
          <template slot-scope="scope">
            <el-select
              v-if="is_detail && tenderBase.isCanOperate"
              v-model="scope.row.qualificationResult"
              placeholder="请选择"
            >
              <el-option label="合格" value="01" />
              <el-option label="不合格" value="02" />
            </el-select>
            <div v-else>
              <span v-if="scope.row.qualificationResult === '01'">合格</span>
              <span v-if="scope.row.qualificationResult === '02'">不合格</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="reason"
          label="不合格原因"
          align="center"
        >
          <template slot-scope="scope">
            <el-input
              v-if="is_detail && tenderBase.isCanOperate"
              v-model="scope.row.reason"
              :rows="2"
              type="textarea"
              placeholder="请输入内容"
            />
            <span v-else>{{ scope.row.reason }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="more">
        <span v-if="is_show" class="pointer" @click="is_show=false">
          收起更多（0）
          <i class="el-icon-arrow-up" />
        </span>
        <span v-else class="pointer" @click="is_show=true">
          展开更多（{{ tableData.length>0?tableData.length -1:0 }}）
          <i class="el-icon-arrow-down" />
        </span>
      </div>
    </section>
  </div>
</template>

<script>
import {
  waitingDeterminePrequalificationResults,
  getDeterminePrequalificationResults,
  saveDeterminePrequalificationResults
} from '@/api/bidding/bidCalibration'
import { pushPrequalification, getPushWuziLogInfo } from '@api/huanengwuzids'
import { getPlanType } from '@api/purchasePlan/pretcloudPurchasescheme'
export default {
  name: 'ConfirmQualified',
  inject: ['getDriveTask'],
  data() {
    return {
      handlePushResultLoading: false, // 发送资格预审结果loading
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      is_show: true, // 确定资审结果列表展示状态
      packInfo: this.$store.getters.packInfo, // 标包信息-当前
      is_detail: false, // 是否可编辑状态 false 不可编辑 true 可编辑
      formData: { // 保存-提交
        isOperation: '', // 00 保存 01提交
        qualificationId: '' // 资审结果Id，
        /* isRecommend: '', // 是否推荐 00:否 01:是
        packId: '', // 标段id
        qualificationResult: '', // 资审结果01 合格02不合格
        reason: '', // 不合格原因
        stageId: '', // 阶段id
        supplierId: '', // 投标供应商id
        supplierName: '', // 投标供应商
        tenderId: this.$route.query.id // 项目id*/
      },
      tableData: [], // 供应商列表
      systemSource: '', // 系统来源 00:新产品 01:hn
      bidPlanType: '', // 招标计划类型:00“带招标方案”，01“自建项目
      pushWuziLogInfo: '' // （00未推送、01已推送）
    }
  },
  created() {
    // 获取系统配置
    this.getSystemDecryptMethod()
    this.initData()
  },
  methods: {
    // 初始化供应商信息
    initList() {
      const stageId = this.packInfo.stageId
      waitingDeterminePrequalificationResults(stageId).then(res => {
        this.tableData = res.data.dataList
      })
    },
    // 是否已提交
    initData() {
      const data = {
        stageId: this.packInfo.stageId
      }
      getDeterminePrequalificationResults(data).then(res => {
        // 01 已提交 是否展示编辑状态
        if (res.data.btnClickStatus === '01') {
          this.is_detail = false
          this.tableData = res.data.dataList
        } else {
          this.is_detail = true
          this.initList() // 查询已确定资审结果
        }
      })
    },
    // 提交// 保存
    submit(isOperation) {
      saveDeterminePrequalificationResults(this.tableData, isOperation).then(res => {
        // 00 保存 01提交
        if (isOperation === '00') {
          this.$message({
            message: '保存成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '提交成功',
            type: 'success'
          })
          this.getDriveTask()// 刷新驱动开启下一节点
        }
        this.initData()
      })
    },
    // 推送资格预审结果
    handlePushResult() {
      this.handlePushResultLoading = true
      pushPrequalification(this.packInfo.stageId, this.packInfo.packId).then(res => {
        this.$message.success(res.header.msg)
        this.handlePushResultLoading = false
      }).catch(() => {
        this.handlePushResultLoading = false
      })
    },
    /* 系统来源 00:新产品 01:hn*/
    getSystemDecryptMethod() {
      this.$store.dispatch('getSystemSourceConfig').then(() => {
        this.systemSource = this.$store.getters.systemConfigSourceVo.systemSource
        if (this.systemSource === '01') {
          // 获取招标计划类型
          this.getBidPlanType()
          this.getPushWuziLogInfoConfig()
        }
      }).catch(() => {
      })
    },
    // 获取招标计划类型  招标计划类型:00“带招标方案”，01“自建项目
    getBidPlanType() {
      getPlanType(this.packInfo.packId).then(res => {
        this.bidPlanType = res.data
      }).catch(() => {
      })
    },
    // 获取推送物资记录 （00未推送、01已推送）
    getPushWuziLogInfoConfig() {
      const pushType = 'PUSH-ZSJG'
      getPushWuziLogInfo(this.packInfo.packId, pushType).then(res => {
        this.pushWuziLogInfo = res.data
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
