<template>
  <el-dialog
    width="90%"
    top="2vh"
    :visible.sync="visible"
    :title="'预览'"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <hm-preview v-if="dataForm.content" :content="dataForm.content" :height="height" />
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
import hmPreview from './load_content'
const Base64 = require('js-base64').Base64

export default {
  components: { hmPreview },
  data() {
    return {
      visible: false,
      height: 'calc(100vh - 200px)',
      dataForm: {
        id: '',
        projectId: '',
        name: '',
        description: '',
        content: ''
      }
    }
  },
  methods: {
    init() {
      this.visible = true
      this.$nextTick(() => {
        this.dataForm.projectId = window.SITE_CONFIG['projectId']
        this.getInfo()
      })
    },
    // 获取信息
    getInfo() {
      this.$http.get('/hz_quguang/crf/template', { params: { crfId: this.dataForm.id }}).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        if (res.data) {
          this.dataForm.content = Base64.decode(res.data.content)
          this.dataForm = { ...this.dataForm }
        }
      }).catch(() => {})
    }
  }
}
</script>
