<template>
  <el-dialog v-loading="loading" v-if="dialogVisible" :visible.sync="dialogVisible" title="详情">
    <el-form ref="form" :model="form" label-width="180px">
      <el-form-item label="安全生产责任制名称:" prop="FILE_NAME">
        <el-input v-model="form.REMARKS" disabled style="width: 70%"/>
      </el-form-item>
      <el-form-item label="规程属性:" prop="FILE_NAME">
        <el-tag
          v-for="tag in form.CATEGORY_LIST"
          :key="tag.value"
          :disable-transitions="false"
          style="margin-right: 10px">
          {{ tag.CATEGORY_NAME }}
        </el-tag>
      </el-form-item>
      <el-form-item label="类型:" prop="FILE_NAME">
        <el-tag
          v-for="tag in form.TYPES"
          :key="tag.value"
          :disable-transitions="false"
          style="margin-right: 10px">
          {{ tag.CATEGORY_NAME }}
        </el-tag>
      </el-form-item>
      <el-form-item v-if="remoteControl.keyOne" label="国民经济行业类型:" prop="FILE_NAME">
        <el-tag v-for="tag in form.SPECIFICATION_TYPES" :key="tag.value" :disable-transitions="false" style="margin-right: 10px">
          {{ tag.CATEGORY_NAME }}
        </el-tag>
      </el-form-item>
      <el-form-item label="上传时间:" prop="FILE_NAME">
        <el-input v-model="form.UPLOAD_TIME" disabled style="width: 70%"/>
      </el-form-item>
      <el-form-item label="上传人:" prop="FILE_NAME">
        <el-input v-model="form.UPLOAD_USER_NAME" disabled style="width: 70%"/>
      </el-form-item>
      <el-form-item prop="tags" label="标签:">
        <el-tag
          v-for="tag in form.labels"
          :key="tag.value"
          :disable-transitions="false"
          style="margin-right: 10px">
          {{ tag.NAME }}
        </el-tag>
      </el-form-item>
      <el-form-item label="文件详情:">
        <el-button size="small" type="primary" @click="openTextEdit({BUS_TEXT_LIBRARY_ID:form.BUS_TEXT_LIBRARY_ID})">查看文件详情</el-button>
        <el-button size="small" type="primary" @click="exportWord({BUS_TEXT_LIBRARY_ID:form.BUS_TEXT_LIBRARY_ID})">导出word</el-button>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="goBack">返 回</el-button>
    </div>
    <text-editing ref="textEditing" :disabled="true" append-to-body title="文本编辑器"/>
  </el-dialog>
</template>
<script>
import Pagination from '@/components/Pagination'
import waves from '@/directive/waves'
import { requestFN } from '@/utils/request'
import TextEditing from '../../../util/textEditing.vue'

export default {
  components: { TextEditing, Pagination },
  directives: { waves },
  data() {
    return {
      config: config,
      dialogVisible: false,
      form: {
        BUS_TEXT_LIBRARY_ID: '',
        FILE_NAME: '',
        FILE: [],
        TYPE: '',
        labels: [],
        UPLOAD_TIME: '',
        UPLOAD_USER_NAME: ''
      },
      loading: false,
      remoteControl: {
        keyOne: true
      }
    }
  },
  methods: {
    init(e) {
      this.dialogVisible = true
      this.loading = true
      this.e = e.e
      requestFN(
        '/textLibrary/goEdit',
        {
          BUS_TEXT_LIBRARY_ID: this.e.BUS_TEXT_LIBRARY_ID
        }
      ).then((data) => {
        this.loading = false
        this.form = data.data
        this.form.FILE = []
        this.remoteControl.keyOne = !(this.form.CATEGORY_LIST[0].CATEGORY_ID === '7158f688d0f34054a28a9275139298df')
      }).catch((e) => {
        this.$message.error(e)
        this.loading = false
      })
    },
    goBack() {
      this.dialogVisible = false
      this.$emit('goBack', this.e)
    },
    openTextEdit(id) {
      this.loading = true
      requestFN('textLibrary/getTextInfo', id)
        .then((data) => {
          if (data.info && data.info.TEXT_INFO && data.info.TEXT_INFO !== '') {
            this.$refs.textEditing.init({ text: data.info.TEXT_INFO })
          } else {
            this.$message.error('此数据未维护文件内容')
          }
          this.loading = false
        }).catch((e) => {
          console.log(e)
          this.loading = false
        })
    },
    exportWord(info) {
      this.loading = true
      requestFN('textLibrary/getTextInfo', info)
        .then((data) => {
          if (data.info) {
            if ((!data.info) || data.info.TEXT_INFO === '') {
              this.$message.error('没有文件导出')
            } else {
              this.$message.success('导出成功')
              window.open(config.httpurl + '/textLibrary/exportWord?BUS_TEXT_LIBRARY_ID=' + info.BUS_TEXT_LIBRARY_ID)
            }
          } else {
            this.$message.error('此数据未维护文件内容')
          }
          this.loading = false
        }).catch((e) => {
          console.log(e)
          this.loading = false
        })
    }
  }
}

</script>
