<!--
  @description: 生成资审结果通知书
  @Modifier: haoFx
  @routerPath:/bidding/projectDrive/calibration/makePrequalificationResultNotice
  @date: 2020-2-26-19:26
-->
<template>
  <div class="main">
    <section>
      <editor v-model="bulletinParam.noticeContent" style="margin: 12px 0" />
      <!--资审结果通知书附件上传-->
      <upload
        ref="upload"
        :on-change="changeFile"
        :data="upLoadData"
        :file-list="fileList"
        :auto-delete="true"
        :auto-upload="true"
        :action="importFileUrl"
        title="资审结果通知书附件"
        file-ref="fileRef"
      />
      <!--保存按钮-->
      <div class="but_footer">
        <div class="but_footer-h" />
        <div class="but_footer-but">
          <el-button type="primary" @click="saveZsResultNotice">
            提 交
          </el-button>
          <el-button @click="back">
            返 回
          </el-button>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
/* api*/
import { saveZsNoticeContent, choosezsnoticeTemplate, submitResultZsNotice } from '@/api/bidding/bidCalibration'
import { upLoadFileUrl } from '@/api/common/uploadCenter' // 文件上传地址
import editor from '@comp/common/editor/editor' // 富文本编辑器组件
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'MakeLetterAcceptanceNotice',
  components: {
    editor,
    upload// 文件上传
  },
  data() {
    return {
      // 上传附件参数
      upLoadData: {
        bizId: this.$route.query.noticeId, // 业务主键Id
        fileType: 'winBidResultZsNoticeAttachment '// 资审结果附件类型
      },
      fileList: [], // 附件列表
      importFileUrl: upLoadFileUrl, // 文件上传地址
      // 保存资审结果通知书内容参数
      bulletinParam: {
        noticeId: this.$route.query.noticeId, // 资审合格通知书Id
        noticeContent: '', // 资审合格通知书内容
        noticeType: '00' // 通知书种类 00结果通知书 01中标通知书
      }
    }
  },
  mounted() {
    this.initTemplate() // 获取资审结果通知书模板
  },
  methods: {
    // 初始化获取模版
    initTemplate() {
      const data = {
        noticeTemplateId: '', // 通知书模板id 不传为默认模板
        noticeId: this.bulletinParam.noticeId, // 通知书id
        noticeType: this.bulletinParam.noticeType // 通知书类型 01:中标通知书 00:中标结果通知书
      }
      choosezsnoticeTemplate(data).then(res => {
        this.bulletinParam.noticeContent = res.data.templateContent// 中标通知书内容
        this.bulletinParam.noticeTemplateId = res.data.noticeTemplateId // 模版Id
      })
    },
    // 返回
    back() {
      this.$router.push({
        path: '/bidding/projectDrive/calibration/prequalificationResultNoticeDetail',
        query: {
          ... this.$route.query
        }
      })
    },
    // 预览资审结果通知书
    saveZsResultNotice() {
      saveZsNoticeContent(this.bulletinParam).then(response => {
        // 提交
        this.submitZsResultNoticeContent()
      }).catch(() => {
      })
    },
    // 提交
    submitZsResultNoticeContent() {
      submitResultZsNotice(this.bulletinParam).then(response => {
        this.$router.push({
          path: '/bidding/projectDrive/calibration/confirmQualifiedResult',
          query: {
            ... this.$route.query
          }
        })
        this.confirmLoading = false
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 附件上传
    changeFile(file, fileList) {
      this.fileList = fileList
    }
  }
}
</script>

<style scoped lang="less">

</style>

