<template>
  <div>
    <el-card style="margin-bottom: 5px">
      <t-search :search="search" @searchClick="searchClick" @historySearch="historySearch" />
    </el-card>
    <el-card :body-style="{ padding: '5px 10px' }">
      <div style="padding-bottom:5px;text-align:right">
        <el-button @click="exportAll" size="mini" v-if="showButtons.pldc" type="primary">批量导出</el-button>
      </div>
      <t-table :table-data="tableData" :table-loading="tableLoading" @handleSelectionChange="handleSelectionChange" />
      <el-pagination layout="total, prev, pager, next, sizes" :page-size="pagination.pageSize"
        :page-sizes="[10, 50, 100, 500,1000]" :current-page="pagination.pageNum" :total="pagination.total"
        @current-change="handleCurrentChange" @size-change="handleSizeChange" />
    </el-card>
  </div>
</template>
  <script>
import tSearch from "./components/search.vue";
import tTable from "./components/table.vue";
import { clearObjValue,message } from "@/utils/common";
import { getButtonList } from "@/api/user";
import { URL_PREFIX } from "@/utils/url-prefix";
import { queryPage } from "@/api/archives-management/dailyManagement/operationLog";
export default {
  components: {
    tSearch,
    tTable,
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      pagination: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      search: {
        operatorChn: "",
      },
      multipleSelection: [],
      showButtons: {
        pldc: false,
      },
    };
  },
  created() {
    this.getData();
    // this.getInfo();
    let btnData = {
      menuid: this.$getMenuId(
        sessionStorage.getItem("routerIdList"),
        this.$route.path
      ),
      roleid: sessionStorage.getItem("roleid"),
    };
    this.getButtonListqx(btnData);
  },
  methods: {
    exportAll() {
      if (!this.multipleSelection.length) {
        message("warning", "请选择要导出的内容!", 3000)
        return
      }
      let ids = this.multipleSelection.length
        ? this.multipleSelection.map((ele) => ele.id).join(",")
        : "";
      window.location.href =
        URL_PREFIX + "/point-strategy/v/operLogger/downloadExcel?ids=" + ids;
    },
    getButtonListqx(btnData) {
      getButtonList(btnData).then((res) => {
        res.body.list.forEach((item) => {
          this.showButtons[item.key] = true;
        });
      });
    },
    searchClick(val) {
      switch (val) {
        case 1:
          this.getData();
          break;
        case 2:
          clearObjValue(this.search);
          break;
      }
    },
    getData() {
      this.tableLoading = true;
      this.params = {
        logType: "1",
        operatorChn: this.search.operatorChn,
        page: this.pagination.pageNum,
        limit: this.pagination.pageSize,
        roleName: sessionStorage.getItem("roles"),
      };
      queryPage(this.params)
        .then((res) => {
          this.tableData = res.body.list;
          this.pagination.total = res.body.total;
        })
        .finally((res) => {
          this.tableLoading = false;
        });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //  点击历史搜索记录的时候触发
    historySearch(val) {
      this.search.operatorChn = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.pagination.pageNum = val;
      this.getData();
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val;
      this.getData();
    },
  },
};
</script>
