<template>
  <div class="main">
    <!-- 鉴定日志 -->
    <el-card style="margin-bottom: 5px">
      <t-search :search="search" @searchClick="searchClick" />
    </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 :tableData="tableData" :tableLoading="tableLoading" @handleSelectionChange="handleSelectionChange" />
      <el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange"
        layout="total, prev, pager, next, sizes" :page-size="pagination.pageSize" :page-sizes="[10, 50, 100, 500,1000]"
        :current-page="pagination.pageNum" :total="pagination.total">
      </el-pagination>
      <!-- <page-total
        :page="page"
        @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange"
      /> -->
    </el-card>
  </div>
</template>
<script>
import {
  queryPage,
  selectAllNumber,
  downloadExcel,
  deleteByIds,
} from "@/api/archives-management/dailyManagement/operationLog";
import tSearch from "./components/search";
import tTable from "./components/table";
import { getButtonList } from "@/api/user";
import { URL_PREFIX } from "@/utils/url-prefix";
import { mixin } from "@/mixins/common";
import { mapState, mapGetters, mapActions } from "vuex";
import { clearObjValue, dateFormatT, message } from "@/utils/common";
export default {
  mixins: [mixin],
  data() {
    return {
      search: {
        operatorChn: "",
        time: "",
      },
      tableData: [],
      pagination: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      tableLoading: false,
      multipleSelection: [],
      showButtons: {
        pldc: false,
      },
    };
  },
  components: {
    tSearch,
    tTable,
  },
  computed: {
    ...mapState({
      // tableData: (state) => state.operatorNote.tableData,
      // page: (state) => state.operatorNote.page,
    }),
  },
  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;
    },
    delAll() {
      if (!this.multipleSelection.length) {
        message("warning", "请选择要删除的内容!", 3000);
        return;
      }
      let ids = this.multipleSelection.map((ele) => ele.id).join(",");
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteByIds({
            ids,
          }).then((res) => {
            message("success", "删除成功", 3000);
            this.getData();
          });
        })
        .catch(() => {});
    },
    getData() {
      this.tableLoading = true;
      this.params = {
        operatorChn: this.search.operatorChn,
        page: this.pagination.pageNum,
        limit: this.pagination.pageSize,
        roleName: sessionStorage.getItem("roles"),
        logType: "6",
      };
      queryPage(this.params)
        .then((res) => {
          this.tableData = res.body.list;
          this.pagination.total = res.body.total;
        })
        .finally((res) => {
          this.tableLoading = false;
        });
    },
    searchClick(val) {
      switch (val) {
        case 1:
          this.getData();
          break;
        case 2:
          clearObjValue(this.search);
          break;
      }
    },
    getInfo() {
      return;
      let params = {
        roleName: sessionStorage.getItem("roles"),
      };
      selectAllNumber(params).then((res) => {
        if (res.msg == "日志达到了上线请及时清理日志") {
          this.$notify({
            title: "警告",
            message: res.msg,
            type: "warning",
          });
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleCurrentChange(val) {
      this.pagination.pageNum = val;
      this.getData();
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val;
      this.getData();
    },
    getButtonListqx(btnData) {
      getButtonList(btnData).then((res) => {
        res.body.list.forEach((item) => {
          this.showButtons[item.key] = true;
        });
      });
    },
  },
  created() {
    this.getData();
    // this.getInfo();
    let btnData = {
      menuid: this.$getMenuId(
        sessionStorage.getItem("routerIdList"),
        this.$route.path
      ),
      roleid: sessionStorage.getItem("roleid"),
    };
    this.getButtonListqx(btnData);
  },
};
</script>
<style lang="scss" scoped>
.main {
  // padding: 10px;
}
</style>
