<!--
  @description: 变更公告模板编辑
  @Modifier: haoFx
  @routerPath: /bidding/projectDrive/changeBulletin/makeChangeBulletinAdd
  @date: 2020/3/12-13:50
-->
<template>
  <div class="main">
    <!--变更公告模板编辑 平台制作-->
    <section>
      <editor v-model="formData.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"
      />
    </section>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="prevStep">
          上一步
        </el-button>
        <el-button :loading="confirmLoading" type="primary" @click="previewBulletin">
          预览
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api*/
import { addChangeBulletin, changeBulletinContentHtmlToPDF } from '@/api/bidding/changeBulletin'
import { upLoadFileUrl } from '@/api/common/uploadCenter' // 文件上传地址
/* 混入公共方法 */
import { changeBulletinCommon } from './mixins/changeBulletinCommon'
import editor from '@comp/common/editor/editor' // 富文本编辑器组件
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'MakeTenderingBulletinAdd',
  components: {
    editor,
    upload// 文件上传
  },
  mixins: [changeBulletinCommon],
  data() {
    return {
      fileList: [], // 附件列表
      importFileUrl: upLoadFileUrl, // 文件上传地址
      // 保存公告内容参数
      formData: {
        content: '' // 公告内容
      },
      isSubmit: '00' // 是否提交 00否 01是
    }
  },
  mounted() {
    this.upLoadData.bizId = this.changeBulletinId
  },
  methods: {
    // 上一步
    prevStep() {
      this.$router.push({
        path: this.changeBulletinPath.changeBulletinAddPath, // 路径动态变更
        query: {
          ...this.$route.query
        }
      })
    },
    // 预览公告
    previewBulletin() {
      const data = this.assemblyData()// 保存组装数据
      this.confirmLoading = true
      addChangeBulletin(data).then(response => {
        this.changeBulletinContent()
        this.confirmLoading = false// btnLoding
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 生成pdf
    changeBulletinContent() {
      changeBulletinContentHtmlToPDF(this.changeBulletinId).then(response => {
        this.$router.push({
          path: this.changeBulletinPath.submitChangeBulletinPath, // 路径动态变更
          query: {
            ...this.$route.query
          }
        })
      }).catch(() => {

      })
    },
    // 附件上传
    changeFile(file, fileList) {
      this.fileList = fileList
    }
  }
}
</script>

<style scoped lang="less">

</style>
