<template>
  <!-- 公司文件列表（查询公司全部的文件信息） -->
  <div class="container">
    <!-- 头部 -->
    <div class="header">
      <el-form :inline="true" :model="companyFileQurey">
        <el-form-item label="文件名称">
          <el-input
            v-model="companyFileQurey.conmpanyFileName"
            placeholder="文件名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="querycompanyFile()"
            >查询</el-button
          >
          <el-button
            type="primary"
            icon="el-icon-refresh-right"
            @click="reset()"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 中间 -->
    <div class="center">
      <el-table
        :data="companyFIleList"
        style="width: 100%"
        text-align:
        center
        border
      >
        <el-table-column label="序号" width="100px" align="center">
          <template slot-scope="scope">
            {{
              (companyFileQurey.pageNum - 1) * companyFileQurey.pageSize +
              scope.$index +
              1
            }}
          </template>
        </el-table-column>
        <el-table-column
          prop="conmpanyFileName"
          label="文件名称"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="fileRemarks" label="文件备注" align="center">
        </el-table-column>
        <el-table-column prop="userName" label="提交人" align="center">
        </el-table-column>
        <el-table-column prop="submitTime" label="上传时间" align="center">
        </el-table-column>
        <el-table-column prop="prop" label="操作" width="130px" align="center">
          <template slot-scope="scope">
            <el-button type="success" size="mini" @click="download(scope.row)"
              >点击下载</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 尾部 -->
    <div class="footer">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="companyFileQurey.pageNum"
        :page-size="companyFileQurey.pageSize"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
    <!-- <div >

    </div> -->
  </div>
</template>

<script>
import { queryBypage,getFileUrl } from "@/api/companyFile";
export default {
  data() {
    return {
      companyFileQurey: {
        conmpanyFileName: null,

        pageNum: 1,
        pageSize: 10,
        companyId: null,
      },
      companyFIleList: [], //公司合同文件表格区域
      total: 0,
    };
  },
  created() {
    this.companyFileQurey.companyId = this.$store.getters.companyId;
    this.getCompanyFileList();
  },
  methods: {
    //重置
    reset() {
      this.companyFileQurey = {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        userId: null,
      };
      this.companyFileQurey.companyId = this.$store.getters.companyId;
      this.getCompanyFileList();
    },
    //下载
    async download(row) {
      
      console.log(row);
       var a = document.createElement("a"); //创建一个<a></a>标签 
       a.href=(await getFileUrl(row.companyFile)).data 
      // //a.href = process.env.VUE_APP_BASE_API + row.companyFile; // 给a标签的href属性值加上地址，注意，这里是绝对路径，不用加 点. 
      a.target = "_blank";
      a.style.display = "none"; // 障眼法藏起来a标签
      document.body.appendChild(a); // 将a标签追加到文档对象中
      a.click(); // 模拟点击了a标签，会触发a标签的href的读取，浏览器就会自动下载了
      a.remove(); // 一次性的，用完就删除a标签
    },
    //查询
    querycompanyFile() {
      this.companyFileQurey.pageNum = 1;
      this.getCompanyFileList();
    },
    //分页查询(查询全公司的)
    getCompanyFileList() {
      queryBypage(this.companyFileQurey)
        .then((res) => {
          if (res.success) {
            this.companyFIleList = res.data.list;
            this.total = res.data.total;
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          this.$message.error("获取数据失败");
        });
    },
    //换页val 当前页的页数
    handleCurrentChange(val) {
      this.companyFileQurey.pageNum = val;
      this.getCompanyFileList();
    },
  },
};
</script>

<style scoped>
 .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: #99a9bf;
  }
  .bg-purple {
    background: #d3dce6;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
.container {
  padding: 10px;
}
.header {
  padding: 10px;
}
.center {
  margin-bottom: 10px;
}
.footer {
  text-align: right;
}
</style>