<template>
  <!-- 此組件用与附件审查流程 -->
  <div class="file-review" v-loading="loading">
    <ul class="upload-info-box">
      <li>
        上传用户：<span class="text">{{ uploadInfo.applyUserName }}</span>
      </li>
      <li>
        文件说明：<span class="text">{{ uploadInfo.remark }}</span>
      </li>
    </ul>
    <el-table size="small" :data="fileInfos" style="width: 100%">
      <el-table-column prop="fileName" label="文件名称"> </el-table-column>
      <el-table-column prop="secretLevel" label="文件密级" width="120">
        <template slot-scope="scope">
          {{ getSecretLevelName(scope.row.secretLevel) }}
        </template>
      </el-table-column>
      <el-table-column prop="encryptedSize" label="文件大小（Byte）"> </el-table-column>
      <el-table-column prop="uploadTime" label="上传时间"> </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="downloadFile(scope.row)">下载</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "AceFileReview",
  inject: ["processShell"],
  data() {
    return {
      uploadInfo: {
        applyUserId: "",
        applyUserName: "",
        remark: "",
        manageUserId: "",
        applyDepId: "",
        applyDepName: "",
        applyTime: "",
        flowCode: "",
        id: "",
      },
      loading: false,
      formId: "",
      allSecretLevels: [],
      fileInfos: [],
      fileConfiguration: null,
    };
  },
  created() {
    this.init();
  },
  methods: {
    downloadFile(file) {
      window.open(this.getDownloadFileUrl(file), "_blank");
    },
    getDownloadFileUrl(file) {
      return this.$http.adornFileUploaderUrl("fileDownload/downloadReviewFile", "configurationKey=" + encodeURI(this.fileConfiguration.configurationKey) + "&fileToken=" + file.id);
    },
    getSecretLevelName(secretLevel) {
      let current = this.allSecretLevels.filter((item) => {
        return item.value == secretLevel;
      });
      return current[0].name;
    },
    getReviewFile() {
      this.$http({
        method: "get",
        url: this.$http.adornUrl(`/bpm/FileReview/${this.formId}`, this.$cookie.get("appName")),
      }).then(({ data }) => {
        if (data.code === 40000) {
          this.uploadInfo = data.instance;
        } else {
          this.$alert(data.msg, "错误提示", {
            confirmButtonText: "确定",
          });
        }
      });
    },
    init() {
      this.loading = true;
      this.formId = this.processShell.nodeInfo.flow.businessKey;
      //   let uploadFormId = this.$route.query["uploadFormId"];
      this.getReviewFile();
      this.$http({
        method: "post",
        url: this.$http.adornFileUploaderUrl("fileConfiguration/loadReviewFile"),
        params: {
          formId: this.formId,
        },
      }).then(({ data }) => {
        this.loading = false;
        if (data.code === 40000) {
          this.allSecretLevels = data.allSecretLevels;
          this.fileInfos = data.fileInfos;
          this.fileConfiguration = data.fileConfiguration;
        } else {
          this.$alert(data.msg, "错误提示", {
            confirmButtonText: "确定",
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.upload-info-box {
  background-color: #f5f7fa;
  padding: 10px 15px;
  margin: 10px 0;
  > li {
    color: rgba(0, 0, 0, 0.6);
    padding: 6px 0;
    .text {
      color: rgba(0, 0, 0, 0.9);
    }
  }
}
</style>
