<!--
  @description: 邀请函制作新增
  @Modifier: haoFx/肖文龙
  @routerPath:/bidding/projectDrive/clarification/clarificationQuestionAdd
  @date: 2020/3/13-14:11
-->
<template>
  <div>
    <editor v-model="clarificationParam.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 :loading="confirmLoading" type="primary" @click="previewBulletin">
          预览
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api*/
import { getEditClarificationInfo, chooseAddendumClarificationTemplate, saveClarificationContent } from '@/api/bidding/bidClarification'// 澄清
/* 混合开发方法-参数字段*/
import { clarificationMixin } from '../../mixins/clarificationMixin'// 澄清质疑-公用参数
/* 组件*/
import editor from '@comp/common/editor/editor' // 富文本编辑器组件
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'MakeTenderingBulletinAdd',
  components: {
    editor,
    upload
  },
  mixins: [clarificationMixin],
  data() {
    return {
      confirmLoading: false, // 暂存、下一步Loding
      // 保存公告内容参数
      clarificationParam: {
        clarificationTemplateId: '', // 模板id
        clarificationId: '', // 澄清Id
        content: '' // 公告内容
      }
    }
  },
  mounted() {
    this.initData() // 获取澄清内容编辑信息
  },
  methods: {
    // 获取澄清内容编辑信息
    initData() {
      getEditClarificationInfo(this.clarificationId).then(res => {
        // 判断是否有公告内容，如果没有则初始化获取模版
        if (res.data.content) {
          this.clarificationParam.content = res.data.content// 公告内容
        } else {
          this.initTemplate()// 初始化获取模版
        }
      })
    },
    // 初始化获取模版
    initTemplate() {
      const data = {
        clarificationId: this.clarificationId, // 澄清id
        clarificationTemplateId: ''// 澄清模板id 不传为默认模板
      }
      chooseAddendumClarificationTemplate(data).then(response => {
        this.clarificationParam.content = response.data.templateContent// 模板内容
        this.clarificationParam.clarificationTemplateId = response.data.clarificationTemplateId// 模板id
      }).catch(() => {

      })
    },
    // 上一步
    prevStep() {
      this.$router.push({
        path: this.clarificationPath.clarificationAddPath,
        query: {
          ...this.$route.query
        }
      })
    },
    // 预览公告
    previewBulletin() {
      this.confirmLoading = true// btnLoding
      this.clarificationParam.clarificationId = this.clarificationId
      saveClarificationContent(this.clarificationParam).then(response => {
        this.$router.push({
          path: this.clarificationPath.submitClarificationLetterPath,
          query: {
            ...this.$route.query
          }
        })
        this.confirmLoading = false// btnLoding
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    }
  }
}
</script>

<style scoped>
</style>
