2<!--
  @description: 投标人提出问题回复
  @Modifier: haoFx
  @routerPath:/bidding/projectDrive/clarificationQuestionReply/clarificationQuestionAdd
  @date: 2020/3/13-14:11
-->
<template>
  <div>
    <editor v-model="clarificationParam.content" style="margin: 12px 0" />
    <!--附件-->
    <upload
      ref="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 :loading="confirmLoading" type="primary" @click="previewBulletin">
          预览
        </el-button>
        <el-button @click="back">
          返 回
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api*/
import { getEditClarificationInfo, chooseAnwserClarificationTemplate, saveAnwserClarificationInfo } from '@/api/bidding/bidClarification'// 澄清
/* 常用方法*/
import { randomData } from '@/assets/js/utils/index'
/* 混合开发方法-参数字段*/
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
      // 回复澄清-获取相应的参数
      clarificationData: {
        questionDetailIdList: [], // 问题详情集合Id
        questionIdList: []// 问题Id集合
      },
      // 保存公告内容参数
      clarificationParam: {
        clarificationId: this.$route.query.clarificationId, // 澄清id 新增时不需要传
        content: '', // 澄清内容
        contentTest: '', // 公告转码内容
        questionDetailIdList: [], // 问题详情集合Id
        questionIdList: []// 问题Id集合
      }
    }
  },
  created() {
    this.initData() // 获取澄清内容编辑信息
  },
  methods: {
    // 获取澄清内容编辑信息
    initData() {
      // 判断是否有澄清Id
      if (this.$route.query.clarificationId) {
        const clarificationId = this.$route.query.clarificationId// 澄清Id
        getEditClarificationInfo(clarificationId).then(res => {
          this.clarificationParam.content = res.data.content// 公告内容
          // 回复澄清-获取相应的参数
          this.clarificationData = {
            questionDetailIdList: res.data.questionIdDetailList, // 问题详情集合Id
            questionIdList: res.data.questionIdList// 问题Id集合
          }
        })
      } else {
        this.clarificationData = JSON.parse(sessionStorage.getItem('setClarification'))// 回复澄清-获取相应的参数
        this.clarificationParam.clarificationId = randomData()// 随机生成ID
        this.upLoadData.bizId = this.clarificationParam.clarificationId
        this.initTemplate()// 初始化获取模版
      }
    },
    // 初始化获取模版
    initTemplate() {
      const data = {
        questionDetailIdList: this.clarificationData.questionDetailIdList, // 问题详情集合Id
        clarificationTemplateId: ''// 澄清模板id 不传为默认模板
      }
      chooseAnwserClarificationTemplate(data).then(response => {
        this.clarificationParam.content = response.data.templateContent// 模板内容
        this.clarificationParam.clarificationTemplateId = response.data.clarificationTemplateId// 模板id
      }).catch(() => {

      })
    },
    // 返回
    back() {
      if (this.$route.query.clarificationId) { // 编辑时返回的路由
        this.$router.push({
          path: '/bidding/projectDrive/clarification/clarificationList',
          query: {
            ...this.$route.query
          }
        })
      } else { // 新增时返回的路由
        this.$router.push({
          path: '/bidding/projectDrive/clarificationQuestionReply/clarificationQuestionList',
          query: {
            ...this.$route.query
          }
        })
      }
    },
    // 预览公告
    previewBulletin(type) {
      const data = {
        ...this.clarificationParam,
        ...this.clarificationData// 回复澄清-获取相应的参数
      }
      this.confirmLoading = true
      saveAnwserClarificationInfo(data).then(response => {
        this.confirmLoading = false
        this.$router.push({
          path: '/bidding/projectDrive/clarificationQuestionReply/submitClarification',
          query: {
            ...this.$route.query,
            clarificationId: response.data.clarificationId// 澄清Id
          }
        })
      }).catch(() => {
        this.confirmLoading = false
      })
    }
  }
}
</script>

<style scoped>
</style>
