<template >
  <div>
    <el-button
      class="generatereport"
      @click="generateReport"
      :disabled="multiple"
      v-hasPermi="['plant:generatereport:export']"
      >{{ $t('生成报告') }}</el-button>
    <form ref="downloadFileForm" :action="downloadAction" target="FORMSUBMIT">
<!--      <input name="type" :value="upload.type" hidden />-->
    </form>
    <el-table v-loading="loading" :data="generatereportList" @selection-change="handleSelectionChange" :height="clientHeight" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column :label="$t('导出模块')" align="center" prop="menuName" />
    </el-table>
  </div>
</template>

<script>
  import { listMenu } from "@/api/system/menu";
  import { exportReport } from "@/api/plant/generatereport";

  export default {
    name: "Generatereport",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 生成报告导出模块表格数据
        generatereportList: [],
        //页面高度
        clientHeight:300,
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          menuType: "C",
          isReport: 1
        },
        //地址
        downloadAction: process.env.VUE_APP_BASE_API + '/plant/generatereport/export',
      }
    },
    created() {
      //设置表格高度对应屏幕高度
      this.$nextTick(() => {
        this.clientHeight = (document.body.clientHeight - 80) * 0.8
      })
      this.getList();
    },
    methods: {
      /** 查询生成报告导出模块 */
      getList() {
        this.loading = true;
        listMenu(this.queryParams).then(response => {
          this.generatereportList = response.data;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.menuId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 生成报告按钮操作 */
      generateReport(row) {
        // const ids = row.menuId || this.ids;
          this.$refs['downloadFileForm'].submit()
      },
    }
  }
</script>

<style>
  .generatereport {
    float: right;
    margin: 20px 50px 10px 0;
  }
</style>
