<!--
  @description:招标-邀请函-邀请函
  @Modifier: hfx
  @routerPath:/bidding/projectDrive/invitation/tabs/makeTenderingInvitation-add
  @date: 2020/1/2-10:16
-->
<template>
  <div>
    <!--邀请函编辑页面-->
    <section v-if="toggle">
      <!--      <div class="clearfix">
        <el-link :underline="false" type="primary" class="fr" @click="toggleMakeTenderingBulletin()">切换邀请函模板</el-link>
      </div>-->
      <editor v-model="bulletinParam.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 :disabled="!isContent" :loading="confirmLoading" type="primary" @click="previewBulletin">
            预览
          </el-button>
        </div>
      </div>
    </section>

    <!--邀请函预览提交页面-->
    <submitTenderingInvitation
      v-show="!toggle"
      ref="bulletinContent"
    />

    <!--邀请函模板-->
    <makeTenderingInvitationDialog ref="makeTenderingBulletin" />
  </div>
</template>

<script>
/* api*/
import { makeTenderingInvitation, saveInvitationContent } from '@/api/bidding/bidInvitation'
/* 混合开发方法-参数字段*/
import { tenderStageTimeRule } from '@/views/bidding/bulletin/mixins/tenderStageTimeRule.js'// 招标公告-时间规则
import { tenderInvtationMixin } from './../mixins/tenderInvtationMixin.js'// 招标公告-时间规则
/* 组件 */
import editor from '@comp/common/editor/editor' // 富文本编辑器组件
import submitTenderingInvitation from './submitTenderingInvitation' // 邀请函预览提交页面
import makeTenderingInvitationDialog from './makeTenderingInvitation-dialog' // 邀请函模板弹框组件
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'MakeTenderingInvitationAdd',
  components: {
    editor,
    submitTenderingInvitation,
    makeTenderingInvitationDialog,
    upload// 文件上传
  },
  mixins: [tenderStageTimeRule, tenderInvtationMixin],
  data() {
    return {
      confirmLoading: false, // 控制按钮重复点击Loding
      // 保存邀请函内容参数
      bulletinParam: {
        invitationId: this.$route.query.invitationId, // 邀请函Id
        content: '', // 邀请函内容
        contentTest: '' // 邀请函转码内容
      },
      isContent: false, // 是否已制作公告
      toggle: true // 切换现在预览页面或者公告编辑页面
    }
  },
  created() {
    // 上传附件参数
    this.upLoadData.bizId = this.$route.query.invitationId // 业务主键Id
  },
  mounted() {
    this.getTenderBulletin() // 获取邀请函模板
  },
  methods: {
    getTenderBulletin() {
      if (!this.bulletinParam.invitationId) return
      makeTenderingInvitation(this.bulletinParam.invitationId).then(response => {
        this.bulletinParam.content = response.data
        // 公告是否有内容
        if (this.bulletinParam.content) {
          this.isContent = true
        }
      }).catch(() => {

      })
    },
    // 上一步
    prevStep() {
      // router携带参数
      const pathData = {
        ...this.$route.query
      }
      this.$emit('stepPage', 'prev', pathData)// 步骤条切换方法 prev 上一步
    },
    // 预览邀请函
    previewBulletin() {
      // 时间规则校验成功执行 then
      this.tenderStageTimeRule().then(() => {
        this.confirmLoading = true
        saveInvitationContent(this.bulletinParam).then(response => {
          this.$refs.bulletinContent.getBulletinPdf()
          this.toggle = false // 保存成功切换为预览pdf页面
          this.confirmLoading = false
        }).catch(() => {
          this.confirmLoading = false
        })
      })
    },
    /*    // 切换邀请函模板
    toggleMakeTenderingBulletin() {
      this.$refs.makeTenderingBulletin.selectTemplate()
    },*/
    // 附件上传
    changeFile(file, fileList) {
      this.fileList = fileList
    }
  }
}
</script>

<style scoped>
</style>
