<!--
  @description: 生成结果公示
  @Modifier: haoFx
  @routerPath: /bidding/projectDrive/calibration/makeCandidateBulletin-add
  @date: 2020-2-25-10:36
-->
<template>
  <div class="main">
    <section>
      <editor v-model="bulletinParam.content" 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 :loading="confirmLoading" type="primary" @click="previewBulletin">
            预览
          </el-button>
          <el-button @click="back">
            返 回
          </el-button>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
/* api*/
import { getResultBulletinContent, chooseResultBulletinTemplate, saveResultBulletinContent } from '@/api/bidding/bidCalibration'
import { upLoadFileUrl } from '@/api/common/uploadCenter' // 文件上传地址
import editor from '@comp/common/editor/editor' // 富文本编辑器组件
import upload from '@comp/common/updownload/upload' // 附件上传组件
/* 混入公共方法*/
import { bidResultBulletinCommon } from '../mixins/bidResultBulletinCommon'
export default {
  name: 'MakeTenderingBulletinAdd',
  components: {
    editor,
    upload// 文件上传
  },
  mixins: [bidResultBulletinCommon],
  data() {
    return {
      confirmLoading: false, // 控制按钮重复点击Loding
      fileList: [], // 附件列表
      importFileUrl: upLoadFileUrl, // 文件上传地址
      // 保存结果公示内容参数
      bulletinParam: {
        winBidResultBulletinId: '', // 结果公示Id
        content: '', // 结果公示内容
        contentTest: '' // 结果公示转码内容
      }
    }
  },
  mounted() {
    this.getTenderBulletin() // 获取招标结果公示模板
  },
  methods: {
    // 获取招标结果公示模板
    getTenderBulletin() {
      getResultBulletinContent(this.winBidResultBulletinId).then(res => {
        // 判断是否有公告内容，如果没有则初始化获取模版
        if (res.data) {
          this.bulletinParam.content = res.data// 公告内容
        } else {
          this.initTemplate()// 初始化获取模版
        }
      })
    },
    // 初始化获取模版
    initTemplate() {
      const data = {
        bulletinTemplateId: '', // 结果公示模板id 不传为默认模板
        winBidResultBulletinId: this.winBidResultBulletinId// 结果公示id
      }
      chooseResultBulletinTemplate(data).then(res => {
        this.bulletinParam.content = res.data.templateContent// 候选人公示内容
        this.bulletinParam.bulletinTemplateId = res.data.bulletinTemplateId// 模版Id
      })
    },
    // 返回
    back() {
      this.$router.push({
        path: '/bidding/projectDrive/calibration/successfulPublicity-add',
        query: {
          ... this.$route.query
        }
      })
    },
    // 预览结果公示
    previewBulletin() {
      this.confirmLoading = true
      this.bulletinParam.winBidResultBulletinId = this.winBidResultBulletinId// 结果公示id
      saveResultBulletinContent(this.bulletinParam).then(response => {
        this.$router.push({
          path: '/bidding/projectDrive/calibration/submitResultBulletin',
          query: {
            ... this.$route.query
          }
        })
        this.confirmLoading = false
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 附件上传
    changeFile(file, fileList) {
      this.fileList = fileList
    }
  }
}
</script>

<style scoped lang="less">

</style>
