<template>
  <div>
    <el-dialog
      title="查看"
      width="60%"
      :close-on-click-modal="false"
      @close="closeDialog"
      :visible.sync="visible">
      <div style="margin-left: 20px;margin-right: 20px">
        <e-desc title="基本信息" column="2">
          <e-desc-item label="公告主题名称">{{dataForm.title}}</e-desc-item>
          <e-desc-item label="级别">{{dataForm.levelName}}</e-desc-item>
          <e-desc-item span="2" style="min-height: 80px" label="公告内容">{{dataForm.content}}</e-desc-item>
        </e-desc>
        <e-desc title="详细信息" column="2">
          <e-desc-item span="2" label="附件">
            <div v-for="(item, index) in dataForm.attachList" style="display: inline">
              <span v-if="index > 0">,</span>
              <a :key="item.fileName + index" type="primary" href="#" @click="previewFile(item.fileName, item.url)">{{ item.fileName }}</a>
            </div>
          </e-desc-item>
          <e-desc-item span="2" style="min-height: 80px" label="备注说明">{{dataForm.notes}}</e-desc-item>
        </e-desc>
      </div>
      <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">返回</el-button>
    </span>
    </el-dialog>
    <!-- 文件预览 -->
    <preview-component v-if="previewVisible" ref="preview"/>
  </div>
</template>

<script>
  import EDesc from '../common/e-desc'
  import EDescItem from '../common/e-desc-item'
  import { getAnnouncementInfo } from '@/api/msg'
  import PreviewComponent from '../common/preview-component'
  export default {
    name: 'announcement-detail',
    components: {
      PreviewComponent,
      EDesc,
      EDescItem
    },
    data () {
      return {
        visible: false,
        previewVisible: false,
        fileList: [],
        id: 0,
        dataForm: {
          attachList: []
        }
      }
    },
    methods: {
      async init (id) {
        this.visible = true
        this.id = id || 0
        this.dataForm = {}
        this.getAnnouncementInfo()
      },
      getAnnouncementInfo () {
        getAnnouncementInfo(this.id).then(({data}) => {
          if (data && data.code === '200') {
            this.dataForm = data.data
          }
        })
      },
      // 关闭页面
      closeDialog () {
        this.visible = false
        this.$emit('refreshDataList')
      },
      // 预览
      previewFile (fileName, url) {
        this.previewVisible = true
        this.$nextTick(() => {
          this.$refs.preview.init(fileName, url)
        })
      }
    }
  }
</script>

<style scoped>
.my-line{
  border-bottom: 1px solid #c0c4cc;
  margin-bottom: 10px;
}
.title{
  padding: 10px 0 ;
}
</style>
