<!--
  @description: 招标项目-项目管理-定标-资格预审通知书-发送资格预审结果通知书
  @Modifier: haoFx
  @routerPath:/bidding/projectDrive/calibration/prequalificationResultNoticeDetail
  @date: 2020/2/6-10:58
-->
<template>
  <div class="main">
    <table class="tableData">
      <tr class="singleRow">
        <td>通知书名称</td>
        <td colspan="3">
          {{ fromData.noticeTitle }}
        </td>
      </tr>
    </table>
    <table class="bidderList_table">
      <thead class="title">
        <th>投标人/投标人名称</th>
        <th>联系人</th>
        <th>联系电话</th>
        <th>邮箱</th>
      </thead>
      <tbody>
        <tr v-for="(item ,index) in fromData.supplierInfos" :key="index">
          <td>{{ item.supplierName }}</td>
          <td>{{ item.linkman }}</td>
          <td>{{ item.linkerTel }}</td>
          <td>{{ item.email }}</td>
        </tr>
      </tbody>
    </table>
    <table class="tableData">
      <tr class="singleRow">
        <td>通知书内容</td>
        <td colspan="3">
          <el-button v-if="systemSourceType==='01'" type="primary" @click="checkSendPrequalificationResultNotice('00')">
            制作资格预审结果通知书
          </el-button>
          <el-button v-if="systemSourceType==='00'" type="primary" @click="checkSendPrequalificationResultNotice('01')">
            生成资格预审结果通知书
          </el-button>
        </td>
      </tr>
      <tr class="singleRow">
        <td>附件</td>
        <td colspan="3" />
      </tr>
    </table>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="back">
          返 回
        </el-button>
      </div>
    </div>
  </div>
</template>
<script>
/* api*/
import { getZsResultNotice, saveZsNotice, queryBaseZsnoticeInfo } from '@api/bidding/bidCalibration'
export default {
  name: 'PrequalificationResultNoticeAdd',
  data() {
    return {
      systemSourceType: '', // 系统来源-是否使用工具制作
      tenderId: this.$route.query.id, // 项目Id
      packInfo: this.$store.getters.packInfo, // 标包信息-当前
      fromData: {
        id: '', // 主键
        noticeContent: '', // 通知书内容
        noticeTitle: '', // 通知书标题
        noticeType: '', // 通知书种类 00结果通知书 01中标通知书
        supplierInfos: []
      }
    }
  },
  created() {
    // 获取系统来源
    this.$store.dispatch('getSystemSource', 'zsResultNotice').then(() => {
      // 系统来源-是否使用工具制作资审结果通知书
      this.systemSourceType = this.$store.getters.systemSourceVo.systemSourceCode // 01 工具制作模式 00 平台制作模式
    }).catch(() => {
    })
  },
  mounted() {
    this.getZsResultNotice()
  },
  beforeDestroy() {
    clearInterval(this.resultNoticeInterval)// 清除定时器
  },
  methods: {
    // 获取资审合格通知书详情
    getZsResultNotice() {
      const data = {
        stageId: this.packInfo.stageId,
        tenderId: this.tenderId // 项目Id
      }
      getZsResultNotice(data).then(res => {
        if (res.data) {
          this.fromData = res.data
        }
      }).catch(() => {

      })
    },
    // 制作资格预审结果通知书
    checkSendPrequalificationResultNotice(type) {
      const data = {
        ...this.fromData,
        noticeType: '00', // 通知书种类 00结果通知书 01中标通知书
        packId: this.packInfo.packId,
        stageId: this.packInfo.stageId,
        tenderId: this.tenderId, // 项目Id
        supplierInfo: [...this.fromData.supplierInfos]
      }
      delete data.supplierInfos // 删除回显vo 不保存字段
      delete data.attachment
      saveZsNotice(data).then(res => {
        // 00 启动工具制作
        if (type === '00') {
          window.open(`${res.data.openUrl}`, '_self') // 调用工具使用
          this.noticeInterval(res.data.noticeId) // 定时器调用是否提交成功
        } else {
          this.$router.push({
            path: '/bidding/projectDrive/calibration/makePrequalificationResultNotice',
            query: {
              ...this.$route.query,
              noticeId: res.data.noticeId // 通知书id
            }
          })
        }
      })
    },
    // 定时器-通知书预览
    noticeInterval(noticeId) {
      this.queryNoticeStatus(noticeId)
      this.resultNoticeInterval = setInterval(() => {
        this.queryNoticeStatus(noticeId)
      }, 2000)
    },
    // 查询通知书是否提交
    queryNoticeStatus(noticeId) {
      const data = {
        noticeId
      }
      queryBaseZsnoticeInfo(data).then((res) => {
        // noticeStatus： 00未上传  01已上传
        const { noticeStatus } = res.data
        // 审核状态
        if (noticeStatus === '01') {
          this.back()
        }
      })
    },
    // 返回
    back() {
      this.$router.push({
        path: '/bidding/projectDrive/calibration/confirmQualifiedResult',
        query: {
          ...this.$route.query
        }
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>

