<!-- 日志汇总查询 -->
<script>
import { dicts } from "./dicts";
import useColumns from "./columns";
import { LIST, EXPORRT } from "@/api/business/report/summary";
export default {
  name: "SummarySheet",
  dicts: [...dicts],
  components: {
    ElSuperSearch: () => import("@/components/super-search/index.vue"),
    ElSuperUxTable: () => import("@/components/super-ux-table/index.vue"),
  },
  data() {
    const { SearchColumns, TableColumns } = useColumns();
    const params = this.$init.params(SearchColumns);
    const page = this.$init.page();
    return {
      page,
      params: {
        ...params,
        dateStart: new Date().Format("yyyy-MM-dd"),
        dateOver: new Date().Format("yyyy-MM-dd"),
        logType: "3",
      },
      TableColumns,
      SearchColumns,
      size: "mini",
      loading: false,
      tableData: [],
      selectData: [],
    };
  },
  computed: {},
  methods: {
    // 重置
    useReset() {
      this.params = {
        ...this.$init.params(this.SearchColumns),
        dateStart: new Date().Format("yyyy-MM-dd"),
        dateOver: new Date().Format("yyyy-MM-dd"),
        logType: "3",
      };
      this.page = this.$init.page();
      this.useQuery(this.params, this.page);
    },
    async useQuery(params, page) {
      try {
        this.loading = true;
        let { code, rows, total } = await LIST({ ...params, ...page });
        if (code == 200) {
          this.tableData = rows;
          this.page.total = total;
        }
      } catch (error) {
      } finally {
        this.loading = false;
      }
    },
    // 导出
    async useExport() {
      try {
        this.$modal.loading("处理中，请稍后...");
        const res = await EXPORRT({ ...this.params });
        if (res) {
          const blob = new Blob([res], {
            type: "application/vnd.ms-excel;charset=UTF-8",
          });
          const downloadElement = document.createElement("a");
          const href = window.URL.createObjectURL(blob);
          downloadElement.href = href;
          downloadElement.download = `日志汇总查询${new Date().getTime()}.xlsx`;
          document.body.appendChild(downloadElement);
          downloadElement.click();
          document.body.removeChild(downloadElement);
          window.URL.revokeObjectURL(href);
        }
      } catch (error) {
      } finally {
        this.$modal.closeLoading();
      }
    },
    useSelect(selection) {
      this.selectData = selection;
    },
  },
  created() {
    this.useQuery(this.params, this.page);
  },
};
</script>

<template>
  <el-card
    v-loading="loading"
    :body-style="{
      height: '100%',
      padding: 0,
      display: 'flex',
      'flex-direction': 'column',
    }"
  >
    <el-super-search
      v-model="params"
      :size="size"
      :dict="dict"
      :columns="SearchColumns"
      @reset="useReset"
      @submit="useQuery(params, page)"
    >
    </el-super-search>

    <el-row class="my-4" style="text-align: right">
      <el-button-group>
        <el-button :size="size" @click="useExport">导 出</el-button>
      </el-button-group>
    </el-row>

    <el-super-ux-table
      v-model="tableData"
      :size="size"
      :dict="dict"
      :page="page"
      :columns="TableColumns"
      checkbox
      pagination
      convenitentOperation
      storage-key="SummarySheetSuperTable"
      @row-select="useSelect"
      @pagination="useQuery(params, page)"
    >
    </el-super-ux-table>
  </el-card>
</template>
<style scoped lang="scss">
.el-card {
  width: calc(100% - 32px);
  height: calc(100vh - 32px);
  margin: 16px;
  padding: 16px;
  border-radius: 8px;
}

.el-button-group + .el-button-group {
  margin: 0 0 0 8px;
}
</style>
