<!--
  @description: 招标项目-项目管理-定标-中标通知书
  @author: 肖文龙/haoFx
  @routerPath:/bidding/projectDrive/calibration/letterAcceptanceNoticeDetail
  @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>
      <tr>
        <td>招标代理服务费收取方式</td>
        <td>{{ formData.biddingServiceFee }}</td>
        <td>项目分类</td>
        <td>
          <!--父级-->
          <span
            v-for="(item,index) in projectClassificationList"
            v-if="formData.industryName === item.typecode"
            :key="index"
          >
            {{ item.typename }}
            <!--子级-->
            <span
              v-for="(child,childIndex) in item.child"
              v-if="formData.projectIndustryCode === child.typecode"
              :key="childIndex"
            >
              {{ child.typename }}
            </span>
          </span>
        </td>
      </tr>
    </table>
    <table v-for="(item,index) in formData.noticeBidderInfoVoList" :key="index" class="tableData noticeBidderInfo">
      <tr>
        <td>投标人名称</td>
        <td>{{ item.supplierName }}</td>
        <td>中标金额（元）</td>
        <td>{{ item.bidPrice }}</td>
      </tr>
      <tr>
        <td>标准招标代理服务费（元）</td>
        <td>
          {{ item.standardServicePrice }}
          <el-popover
            placement="top-start"
            popper-class="hint"
            offset="5"
            trigger="hover"
            style="margin-left:5px;"
            content="按照委托合同服务费收取方式系统自动计算服务费金额。"
          >
            <el-button slot="reference" type="info" class="prompt">
              <i class="iconfont icon-qm" />
            </el-button>
          </el-popover>
        </td>
        <td>应收代理服务费（元）</td>
        <td>
          <money
            :thousands="true"
            :money-value="item"
            style="display: inline-block"
            name="servicePrice"
          />
          <el-popover
            placement="top-start"
            popper-class="hint"
            offset="5"
            trigger="hover"
            style="margin-left:5px;"
            content="服务费最终实际收取的金额,可编辑。"
          >
            <el-button slot="reference" type="info" class="prompt">
              <i class="iconfont icon-qm" />
            </el-button>
          </el-popover>
        </td>
      </tr>
    </table>
    <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>
        <!-- <upload
            ref="upload"
            :limit="1"
            :data="upLoadData"
            :auto-delete="true"
            :auto-upload="true"
            :disabled="true"
            file-ref="fileRef"
            accept=".pdf"
            title=""
            tip-text=""
            @onSuccess="onSuccess"
          />
          <span style="margn-left：-10px;color: #007CCC;">（请上传已盖章公告pdf文件,不要超过500M。）</span> -->
      </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>
import { saveTenderNotice, getEditResultNotice, queryBaseNoticeInfo, webConfirmResultNoticeComplete } from '@api/bidding/bidCalibration'
/* 混入 */
import { bidResultNoticeMixin } from './../mixins/bidResultNoticeMixin'// 公共参数
/* 组件 */
import money from '@comp/common/money/money'// 金额组件
import upload from '@comp/common/updownload/upload'
import Cookies from 'js-cookie'
import { upLoadFileUrl } from '@/api/common/uploadCenter'
export default {
  name: 'LetterAcceptanceNoticeDialog',
  components: {
    upload,
    money // 金额组件
  },
  mixins: [bidResultNoticeMixin],
  data() {
    return {
      upLoadFileUrl: upLoadFileUrl,
      importHeaders: {}, // cookie信息
      /* 字典信息-start */
      projectClassificationList: [], // 项目分类
      /* 字典信息-end */
      systemSourceType: '', // 系统来源-是否使用工具制作
      packInfo: this.$store.getters.packInfo, // 标包信息-当前
      tenderId: this.$route.query.id, // 项目Id
      noticeId: this.$route.query.noticeId, // 通知书id
      // 回显/提交信息
      // 文件上传
      upLoadData: {
        bizId: '', // 业务主键Id
        fileType: 'winBidNoticeContent '// 文件类型
      },
      formData: {
        noticeBidderInfoVoList: [],
        id: '',
        noticeContent: '', // 通知书内容
        noticeTitle: '' // 通知书标题
      },
      isUpload: false
    }
  },
  created() {
    this.importHeaders['X-AUTH-TOKEN'] = Cookies.get('X-AUTH-TOKEN')
    // 获取系统来源
    this.$store.dispatch('getSystemSource', 'winBidNotice').then(() => {
      // 系统来源-是否使用工具制作中标通知书
      this.systemSourceType = this.$store.getters.systemSourceVo.systemSourceCode // 01 工具制作模式 00 平台制作模式
    }).catch(() => {
    })
  },
  beforeDestroy() {
    clearInterval(this.resultNoticeInterval)// 清除定时器
  },
  mounted() {
    // 获取中标通知书详情
    this.getResultNotice()
  },
  methods: {
    uploadBefore(ev) {
      if (!this.isUpload) {
        this.$message.error('请先制作中标通知书')
        ev.stopPropagation()
      }
    },
    // 获取字典方法
    initGroup() {
      const data = [
        'projectClassification' // 项目分类
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 获取中标通知书详情
    getResultNotice() {
      // 项目分类
      this.initGroup()
      const data = {
        supplierId: this.$route.query.supplierId,
        stageId: this.packInfo.stageId,
        tenderId: this.tenderId, // 项目Id
        noticeId: this.noticeId
      }
      getEditResultNotice(data).then(res => {
        this.formData = res.data
      }).catch(() => {

      })
    },
    onSuccess(val) {
      const data = {
        noticeId: this.noticeId, // 公告Id
        fileId: val.data.fileId// 公告Id
      }
      webConfirmResultNoticeComplete(data).then((res) => {
      })
    },
    // 制作中标结果通知书
    makeNotice(type) {
      const data = {
        ...this.formData,
        noticeType: '01', // 通知书种类 00结果通知书 01中标通知书
        packId: this.packInfo.packId,
        stageId: this.packInfo.stageId,
        tenderId: this.tenderId, // 项目Id
        supplierInfo: this.formData.noticeBidderInfoVoList
      }
      delete data.noticeBidderInfoVoList
      delete data.attachment
      saveTenderNotice(data).then(res => {
        // 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 {
          this.$router.push({
            path: '/bidding/projectDrive/calibration/makeLetterAcceptanceNotice',
            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">
  .noticeBidderInfo{

    tr:first-child{
      td{
        border-top: none!important;
      }
    }
    tr:last-child{
      td {
        border-bottom: none !important;
      }
    }
  }
</style>
