<!--
  @description:编辑终止公告
  @Modifier: haofengxian
  @routerPath:/bidding/projectDrive/stopbiddingRecord/makeStopbiddingRecordAdd
  @date: 2020-5-13-13:32
-->
<template>
  <div class="main">
    <!--终止公告模板编辑-->
    <section>
      <editor v-model="formData.content" style="margin: 12px 0" />
      <!--终止公告附件上传-->
      <upload
        ref="upload"
        :data="upLoadData"
        :auto-delete="true"
        :auto-upload="true"
        title="终止公告附件"
        file-ref="fileRef"
      />
      <!--保存按钮-->
      <div class="but_footer">
        <div class="but_footer-h" />
        <div class="but_footer-but">
          <el-button @click="prevStep">
            上一步
          </el-button>
          <el-button type="primary" @click="previewStopbiddingBulletin">
            预览
          </el-button>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
/* api*/
import { makeStopbiddingBulletin, saveStopbiddingBulletinContent } from '@api/bidding/stopbiddingRecord'
import editor from '@comp/common/editor/editor' // 富文本编辑器组件
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'MakeTenderingBulletinAdd',
  components: {
    editor,
    upload// 文件上传
  },
  data() {
    return {
      // 保存公告内容参数
      formData: {
        content: '' // 公告内容
      },
      upLoadData: {
        bizId: '',
        fileType: 'stopbidding_bulletin_file_base'// 终止招标附件类型
      }
    }
  },
  mounted() {
    this.getStopbiddingBulletin()
  },
  methods: {
    // 上一步
    prevStep() {
      this.$router.push({
        path: '/bidding/projectDrive/stopbiddingRecord/stopbiddingRecordAdd', // 路径动态变更
        query: {
          ...this.$route.query
        }
      })
    },
    // 制作终止公告
    getStopbiddingBulletin() {
      const stopbiddingRecordId = sessionStorage.getItem('stopbiddingRecordId') // 终止招标记录id
      makeStopbiddingBulletin(stopbiddingRecordId).then(response => {
        this.formData.content = response.data.content
        this.formData.stopbiddingBulletinId = response.data.stopbiddingBulletinId // 终止公告id
        this.upLoadData.bizId = response.data.stopbiddingBulletinId// 终止公告id
        sessionStorage.setItem('bizId', this.formData.stopbiddingBulletinId)
      }).catch(() => {
      })
    },
    // 终止公告模板
    previewStopbiddingBulletin() {
      saveStopbiddingBulletinContent(this.formData).then(response => {
        this.$router.push({
          path: '/bidding/projectDrive/stopbiddingRecord/submitStopbiddingRecord', // 路径动态变更
          query: {
            ...this.$route.query
          }
        })
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
