<template>
  <div class="ele-body">
    <el-card shadow="never">
      <div class="upload" style="margin-bottom: 20px">
        <el-button
          type="primary"
          size="small"
          style="margin-right: 20px"
          @click="uploadFile"
          >上传文件</el-button
        >
        <input type="file" style="display: none" ref="file" />
        <div
          style="display: inline-block; margin-left: 20px; cursor: pointer"
          v-show="Object.keys(file).length > 0"
          :data-path="file.path"
          @click="downloadFile"
        >
          {{ file.fileName }}
        </div>
        <span style="padding:0 20px;"></span>
        <span style="color:red">(备注：支持Word，execl，ppt，pdf)</span>
      </div>
      <el-table
        height="calc(100vh - 220px)"
        :data="dataList"
        :loading="loading"
      >
        <el-table-column
          label="部门名称"
          align="center"
          min-width="120"
          show-overflow-tooltip
          prop="deptName"
        ></el-table-column>
        <el-table-column label="基础目标" align="center">
          <el-table-column
            label="牵头次数"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.basicTaskInfo.leaderNum || "/" }}
            </template>
          </el-table-column>
          <el-table-column
            label="配合次数"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.basicTaskInfo.cooperateNum || "/" }}
            </template>
          </el-table-column>
          <el-table-column
            label="承担分数"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.basicTaskInfo.bearScore || "/" }}
            </template>
          </el-table-column>
          <el-table-column
            label="牵头承担分数"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.basicTaskInfo.leaderBearScore || "/" }}
            </template>
          </el-table-column>
          <el-table-column
            label="评分"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.basicTaskInfo.points || "/" }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="重点专项" align="center">
          <el-table-column
            label="参与次数"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.specialPowerInfo.partyNum || "/" }}
            </template>
          </el-table-column>
          <el-table-column
            label="评分"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.specialPowerInfo.points || "/" }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="刚性约束" align="center">
          <el-table-column
            label="参与次数"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.rigidityConstraintInfo.partyNum || "/" }}
            </template>
          </el-table-column>
          <el-table-column
            label="评分"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.rigidityConstraintInfo.points || "/" }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="总分" align="center">
          <el-table-column
            label="参与次数"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.summaryInfo.partyNum || "/" }}
            </template>
          </el-table-column>
          <el-table-column
            label="评分"
            align="center"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.summaryInfo.points || "/" }}
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import summaryApi from "@/api/second/taskSummary";
export default {
  data() {
    return {
      dataList: [],
      loading: false,
      file: {},
      uploading: false,
    };
  },
  created() {
    this.loading = true;
    summaryApi
      .getSummaryList()
      .then((res) => {
        let data = res.data;
        if (data.code == 0) {
          this.dataList = data.data;
        } else {
          this.dataList = [];
        }
      })
      .catch((e) => {
        this.dataList = [];
      })
      .finally(() => {
        this.loading = false;
      });
    this.getFile();
  },
  methods: {
    getFile() {
      summaryApi
        .getReportDataSummaryAttach()
        .then((res) => {
          let data = res.data;
          if (data.code == 0) {
            this.file = {
              fileName: data.data.fileName,
              path: data.data.filePath,
            };
          } else {
            this.file = {};
          }
        })
        .catch((e) => {
          this.file = {};
        });
    },
    downloadFile($event) {
      let element = $event.target;
      let path = element.getAttribute("data-path");
      window.location.href = path;
    },
    uploadFile() {
      let input = this.$refs.file;
      input.click();
      let upload;
      input.addEventListener(
        "change",
        (upload = (e) => {
          input.removeEventListener("change", upload);
          if (this.uploading) {
            this.$message({
              type: "warning",
              message: "正在上传",
            });
            return;
          }
          this.uploading = true;
          let file = e.target.files[0];
          if (!file) {
            this.uploading = false;
            return;
          }
          let MAXSIZE = 5 * 1024 * 1024;
          if (file.size > MAXSIZE) {
            this.$message.error("上传文件不得超过5M");
          }
          let formData = new FormData();
          formData.append("file", file);
          summaryApi
            .uploadReportDataSummaryAttach(formData)
            .then((res) => {
              let data = res.data;
              if (data.code == 0) {
                this.$message({
                  type: "success",
                  message: "上传文件成功",
                });
              } else {
                this.$message.error(data.msg);
              }
            })
            .catch((e) => {
              this.$message.error(e);
            })
            .finally((e) => {
              this.uploading = false;
              this.getFile();
            });
        })
      );
    },
  },
};
</script>

<style>
</style>