<template>
  <div class="app-container">
    <el-card style="width: 70%; margin: auto" shadow="always">
      <el-button type="primary" style="float: right" size="small" @click="close">关闭</el-button>
      <el-descriptions class="margin-top" title="公文信息" :column="2" border>
        <el-descriptions-item>
          <template slot="label">
            发文字号
          </template>
          {{ offical.issuedNum }}
        </el-descriptions-item>
        <!--        <el-descriptions-item>-->
        <!--          <template slot="label">-->
        <!--            密级-->
        <!--          </template>-->
        <!--          <dict-tag :options="dict.type.secret_level" :value="offical.issuedLevel"/>-->
        <!--        </el-descriptions-item>-->
        <el-descriptions-item :span="2">
          <template slot="label">
            发文标题
          </template>
          {{ offical.issuedName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            收文时间
          </template>
          {{ offical.receiveDate }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            办理期限
          </template>
          {{ offical.deadline }}
        </el-descriptions-item>
        <el-descriptions-item :span="2">
          <template slot="label">
            紧急程度
          </template>
          <dict-tag :options="dict.type.urgency" :value="offical.urgency"/>
        </el-descriptions-item>
        <el-descriptions-item :span="2" content-style="height: 100px;">
          <template slot="label">
            简介
          </template>
          {{ offical.remarks }}
        </el-descriptions-item>
        <el-descriptions-item :span="2" content-style="height: 100px;">
          <template slot="label"> 文件</template>
          <div v-for="item in offical.fileList">
            {{ item.fjmc }}
            <el-button
              style="margin-left: 20px"
              plain type="primary"
              size="mini"
              @click="handleExport(item)">下载
            </el-button>
          </div>
        </el-descriptions-item>
      </el-descriptions>
      <br/>
    </el-card>
  </div>
</template>

<script>
import {getInitiator, received} from "@/api/smartSchool/indexMould/myTask/documentFlow";

export default {
  name: "Reviewer",
  dicts: ['secret_level', 'urgency'],
  data() {
    return {
      offical: {},
      isRead: 0,
    }
  },
  created() {
    this.id = this.$route.query && this.$route.query.id
    this.isRead = this.$route.query?.isRead
    this.getData()
  },
  beforeDestroy() {
    if (!this.isRead) {
      this.receivedState()
    }
  },
  methods: {
    getData() {
      getInitiator(this.id).then((res) => {
        if (res.code == 200) {
          this.offical = res.offical
        }
      })
    },
    //调用接口改变阅读状态
    receivedState() {
      received(this.id)
    },
    close() {
      const obj = {path: '/indexMould/myTask/documentFlow'};
      this.$tab.closeOpenPage(obj);
    },
    //导出文件
    handleExport(file) {
      this.download('schoolOffical/downloadFile', {
        id: file.id
      }, file.fjmc)
    },
  }
}
</script>

<style scoped>
.body {
  height: 50px;
}
</style>
