<!--
  @description: 招标项目-项目管理-定标-中标通知书列表
  @author: 肖文龙/haoFx
  @routerPath:/bidding/projectDrive/calibration/letterAcceptance
  @date: 2019-11-16 16:12:35
  isCanOperate: true可以操作 false不可以查看只有查看权限
-->
<template>
  <div class="main">
    <div v-if="tenderBase.isCanOperate" class="clearfix">
      <div class="mb10 fr">
        <!--isMoreWinningBidder 00非多中标人 && 未发送显示则按钮-->
        <el-button
          v-if="formDataNotice.isMoreWinningBidder==='00' && formDataNotice.isWinBiddingNoticeStatus==='00'"
          type="primary"
          @click="dialogDealNoticeClick('01')"
        >
          发送中标通知书
        </el-button>
        <!--isExistsNotWinningBidder如果不存在(01)未中标人 && 未发送结果通知书 则显示’发送结果通知书’按钮-->
        <el-button
          v-if="formDataNotice.isExistsNotWinningBidder==='01' && formDataNotice.resultNoticeStatus==='00'"
          type="primary"
          @click="dialogDealNoticeClick('00')"
        >
          发送结果通知书
        </el-button>
      </div>
    </div>
    <section>
      <el-table
        v-loading="loading"
        :data="tableData"
      >
        <el-table-column
          type="index"
          label="序号"
          align="center"
          width="60"
        />
        <el-table-column

          header-align="center"
          prop="supplierName"
          label="投标供应商"
          min-width="200"
        />
        <el-table-column
          prop="linknNme"
          label="联系人"
          min-width="100"
        />
        <el-table-column
          prop="linkerTel"
          label="联系电话"
          align="center"
          width="100"
        />
        <el-table-column
          prop="isWinBiding"
          label="是否中标"
          width="80"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.isWinBiding === '00'" class="status2">否</span>
            <span v-if="scope.row.isWinBiding === '01'" class="status1">是</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="sendTime"
          label="发送时间"
          align="center"
          width="140"
        />
        <el-table-column
          prop="receiveTime"
          label="查看通知书时间"
          align="center"
          width="140"
        />
        <el-table-column
          prop="auditStatus"
          label="审核状态"
          align="center"
        >
          <template slot-scope="scope">
            {{ filterDictText(auditStatusOptions,scope.row.auditStatus) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" min-width="100">
          <template slot-scope="scope">
            <!--sMoreWinningBidder(是否有多个中标人) 01 是-->
            <template v-if="formDataNotice.isMoreWinningBidder === '01' && scope.row.isWinBiding === '01'">
              <!--中标 && 不是审核通过情况显示发送按钮-->
              <el-link
                v-if="scope.row.auditStatus!=='00' && scope.row.auditStatus!=='01'"
                type="primary"
                @click="dialogDealNoticeClick('01',scope.row)"
              >
                [发送中标通知书]
              </el-link>
            </template>
            <el-link
              v-if="scope.row.isWinBiding === '00' && formDataNotice.resultNoticeStatus === '01'"
              type="primary"
              @click="see(scope.row,'00')"
            >
              [查看结果通知书]
            </el-link>
            <el-link
              v-if="scope.row.isWinBiding === '01' && scope.row.auditStatus && scope.row.auditStatus!=='02'"
              type="primary"
              @click="see(scope.row,'01')"
            >
              [查看中标通知书]
            </el-link>
            <template v-if="letterAcceptanceConfigType">
              <el-link
                v-if="scope.row.auditStatus"
                type="primary"
                @click="handleDetail(scope.row.id)"
              >
                [流程追踪]
              </el-link>
            </template>
          </template>
        </el-table-column>
      </el-table>
    </section>
    <!--流程追踪查看弹框-->
    <flow-detail-dialog ref="tracingFlow" />
  </div>
</template>
<script>
import { queryResultNoticeList, getResultnoticeStatus } from '@/api/bidding/bidCalibration'
import flowDetailDialog from '@views/work/process/flowDetail-dialog' //  流程追踪组件
import { initGroupMixin } from '@/mixins/initGroupMixin' // 公共审核状态字典数据
import { filterDictText } from '@/assets/js/utils' // 匹配字典值
export default {
  name: 'BidWinningNotice',
  components: {
    flowDetailDialog
  },
  mixins: [initGroupMixin],
  data() {
    return {
      letterAcceptanceConfigType: false, // true启动工作流 false普通审核
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      loading: true,
      packInfo: this.$store.getters.packInfo, // 标包信息-当前
      // 中标通知书列表部分
      tableData: [],
      // 是否已发送中标/结果通知书
      formDataNotice: {
        isExistsNotWinningBidder: '', // 是否存在未中标人 00:否 01:是 如果不存在(00)，不显示’发送结果通知书’按钮
        isMoreWinningBidder: '', // 是否有多个中标人 00:否 01:是
        isWinBiddingNoticeStatus: '', // 中标通知书状态 00:否 01:是 单个中标人时，根据此值进行按钮显隐的处理
        resultNoticeStatus: '' // 结果通知书状态 00:否 01:是 (00 未发送 01 已发送)
      },
      supplierId: '' // 中标供应商id
    }
  },
  created() {
    // 根据键获取正式配置
    this.$store.dispatch('getSystemConfigValue', 'zsNotice-audit-config').then(() => {
      this.letterAcceptanceConfigType = this.$store.getters.systemConfigVo.configType // true启动工作流 false普通审核
    }).catch(() => {
    })
    // 是否已确定中标人
    this.isSend()
    // 获取供应商中标或未中标列表
    this.getSupplierList()
  },
  methods: {
    filterDictText,
    // 获取供应商中标或未中标列表
    getSupplierList() {
      const data = {
        stageId: this.packInfo.stageId
      }
      queryResultNoticeList(data).then(response => {
        if (response.header.ret === '0') {
          this.tableData = response.data
          this.loading = false
        }
      }).catch(() => {
        this.loading = false
      })
    },
    // 是否已确定中标人
    isSend() {
      // 是否已发布中标通知书/结果通知书
      const stageId = this.packInfo.stageId
      getResultnoticeStatus(stageId).then(res => {
        this.formDataNotice = res.data
      })
    },
    // 查看通知书
    see(row, type) {
      // 00 否 结果通知书 01 是中标通知书
      if (type === '00') {
        this.$router.push({
          path: '/bidding/projectDrive/calibration/tenderResultNotice',
          query: {
            ...this.$route.query,
            noticeId: row.id
          }
        })
      } else {
        this.$router.push({
          path: '/bidding/projectDrive/calibration/tenderNotice',
          query: {
            ...this.$route.query,
            noticeId: row.id
          }
        })
      }
    },
    // 发送中标通知书或结果通知书
    dialogDealNoticeClick(type, row) {
      let path = ''
      let noticeId = '' // 通知书id
      if (type === '01') { // 中标通知书
        path = '/bidding/projectDrive/calibration/letterAcceptanceNoticeDetail'
        // 是否有多个中标人 00:否 01:是 非多中标人
        if (this.formDataNotice.isMoreWinningBidder === '00') {
          const isWinBidingData = this.tableData.filter(i => i.isWinBiding === '01')
          if (isWinBidingData.length > 0) {
            this.supplierId = isWinBidingData[0].supplierId
            noticeId = isWinBidingData[0].id
          }
        } else {
          this.supplierId = row.supplierId
          noticeId = row.id
        }
      } else { // 00 结果通知书
        path = '/bidding/projectDrive/calibration/letterAcceptanceResultNoticeDetail'
      }
      this.$router.push({
        path: path,
        query: {
          ...this.$route.query,
          supplierId: this.supplierId,
          noticeId: noticeId
        }
      })
    },
    // 流程追踪详情
    handleDetail(id) {
      this.$refs.tracingFlow.openDialogInitData(id)
    }
  }
}
</script>
<style lang="less" scoped>

</style>
