<!--
  @description: 招标项目-项目管理-定标-结果通知书
  @author: 肖文龙/haoFx
  @routerPath:/bidding/projectDrive/calibration/letterAcceptanceResultNoticeDetail
  @date:2019-11-16 18:23:06
-->
<template>
  <div class="main">
    <table class="tableData">
      <tr class="singleRow">
        <td>通知书名称</td>
        <td colspan="3">
          {{ formData.noticeTitle }}
        </td>
      </tr>
    </table>
    <div style="padding:10px 0px">
      <table class="bidderList_table">
        <thead class="title">
          <th>投标人/投标人名称</th>
          <th>联系人</th>
          <th>联系电话</th>
          <th>邮箱</th>
        </thead>
        <tbody>
          <tr v-for="(item,index) in formData.supplierVos" :key="index">
            <td>{{ item.supplierName }}</td>
            <td>{{ item.linknNme }}</td>
            <td>{{ item.linkerTel }}</td>
            <td>{{ item.email }}</td>
          </tr>
        </tbody>
      </table>
    </div>
    <table class="tableData">
      <tr class="singleRow">
        <td>通知书内容</td>
        <td colspan="3">
          <el-button v-if="systemSourceType==='01'" type="primary" @click="makeNotice('00')">
            制作中标结果通知书
          </el-button>
          <el-button v-if="systemSourceType==='00'" type="primary" @click="makeNotice('01')">
            生成中标结果通知书
          </el-button>
          <el-upload
            ref="upload"
            style="display:inline-block;margin-left:10px"
            accept=".pdf"
            :action="upLoadFileUrl"
            :data="upLoadData"
            :show-file-list="false"
            :headers="importHeaders"
            multiple
            :on-success="onSuccess"
          >
            <el-button type="primary" @click="uploadBefore($event)">
              附件：(请上传已盖章公告pdf文件,不要超过500M)
            </el-button>
          </el-upload>
        </td>
      </tr>
    </table>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="back">
          返 回
        </el-button>
      </div>
    </div>
    <!-- <uploadDialog v-if="dialogData.visible" :dialog-data="dialogData" /> -->
  </div>
</template>
<script>
import { webConfirmResultNoticeComplete } from '@api/bidding/bidCalibration'
/* api*/
import { saveTenderNotice, getResultNotice, queryBaseNoticeInfo } from '@api/bidding/bidCalibration'
/* 混入 */
import { bidResultNoticeMixin } from './../mixins/bidResultNoticeMixin'// 公共参数
// import uploadDialog from './upload-dialog'
import Cookies from 'js-cookie'
/* 组件 */
import downloadFile from '@comp/common/updownload/downloadFile'// 文件下载组件
import { upLoadFileUrl } from '@/api/common/uploadCenter'
export default {
  name: 'LetterAcceptanceResultNoticeDialog',
  components: {
    // uploadDialog,
    downloadFile
  },
  mixins: [bidResultNoticeMixin],
  data() {
    return {
      // dialogData: {
      //   visible: false
      // },
      upLoadData: {
        bizId: '', // 业务主键Id
        fileType: 'winBidResultNoticeContent '// 文件类型
      },
      systemSourceType: '', // 系统来源-是否使用工具制作
      packInfo: this.$store.getters.packInfo, // 标包信息-当前
      // 展示信息
      formData: {
        id: '', // 主键
        noticeContent: '', // 通知书内容
        noticeTitle: '', // 通知书标题
        supplierVos: [] // 投标人列表
      },
      upLoadFileUrl: upLoadFileUrl,
      importHeaders: {} // cookie信息
    }
  },
  created() {
    this.importHeaders['X-AUTH-TOKEN'] = Cookies.get('X-AUTH-TOKEN')
    // 获取系统来源
    this.$store.dispatch('getSystemSource', 'resultNotice').then(() => {
      // 系统来源-是否使用工具制作结果通知书
      this.systemSourceType = this.$store.getters.systemSourceVo.systemSourceCode // 01 工具制作模式 00 平台制作模式
    }).catch(() => {
    })
  },
  mounted() {
    this.getResultNotice()
  },
  beforeDestroy() {
    clearInterval(this.resultNoticeInterval)// 清除定时器
  },
  methods: {
    onSuccess(val) {
      const data = {
        noticeId: this.upLoadData.bizId, // 公告Id
        fileId: val.data.fileId// 公告Id
      }
      webConfirmResultNoticeComplete(data).then((res) => {
      })
    },
    uploadBefore(ev) {
      if (!this.isUpload) {
        this.$message.error('请先制作中标结果通知书')
        ev.stopPropagation()
      }
    },
    // 获取中标通知书详情
    getResultNotice() {
      const data = {
        ...this.formData,
        packId: this.packInfo.packId,
        stageId: this.packInfo.stageId,
        supplierInfo: [...this.formData.supplierVos]
      }
      getResultNotice(data).then(res => {
        this.formData = res.data
      }).catch(() => {

      })
    },
    // 制作中标结果通知书
    makeNotice(type) {
      const data = {
        ...this.formData,
        noticeType: '00', // 通知书种类 00结果通知书 01中标通知书
        packId: this.packInfo.packId,
        stageId: this.packInfo.stageId,
        tenderId: this.$route.query.id, // 项目Id
        supplierInfo: [...this.formData.supplierVos]
      }
      delete data.supplierVos // 删除回显vo 不保存字段
      delete data.attachment // 附件 不保存字段
      saveTenderNotice(data).then(res => {
        // this.dialogData.noticeId = res.data.noticeId
        // this.dialogData.visible = true
        // 00 启动工具制作
        if (type === '00') {
          window.open(`${res.data.openUrl}`, '_self') // 调用工具使用
          this.noticeInterval(res.data.noticeId) // 定时器调用是否提交成功
          this.upLoadData.bizId = res.data.noticeId
          this.isUpload = true
        } else {
          // 01 平台生成
          this.$router.push({
            path: '/bidding/projectDrive/calibration/makeLetterAcceptanceResultNotice',
            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
      }
      queryBaseNoticeInfo(data).then((res) => {
        // noticeStatus： 00未上传  01已上传
        const { noticeStatus } = res.data
        // 审核状态
        if (noticeStatus === '01') {
          this.back()
        }
      })
    },
    // 返回
    back() {
      this.$router.push({
        path: '/bidding/projectDrive/calibration/letterAcceptance',
        query: {
          ...this.$route.query
        }
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
