<template>
  <div id="index">
    <el-col :span="24" class="debt">
      <el-col :span="24" class="top">
        <topInfo :topTitle="topTitle" :display="display" @add="add"></topInfo>
      </el-col>
      <el-col :span="24" class="main">
        <el-col :span="24" class="search">
          <searchInfo @sousuo="sousuo"></searchInfo>
        </el-col>
        <el-col :span="24" class="list">
          <characterList :total="total" @handleCurrentChange="handleCurrentChange" :debtTable="debtTable" @deleteRow="deleteRow"></characterList>
        </el-col>
      </el-col>
    </el-col>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import searchInfo from '@/layout/common/searchInfo.vue';
import characterList from '@/layout/character/characterList.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: character } = createNamespacedHelpers('character');
export default {
  name: 'index',
  props: {},
  components: {
    topInfo, //头部导航
    searchInfo, //搜素
    characterList, //角色列表
  },
  data: () => ({
    total: 0,
    topTitle: '角色管理',
    display: 'bk',
    debtTable: [],
    skip: '',
    info: {},
  }),
  created() {
    this.searchInfo();
  },
  computed: {},
  methods: {
    ...character(['query', 'delete']),

    async searchInfo({ skip, limit = 10, ...info } = {}) {
      info = this.info;
      skip = this.skip;
      const res = await this.query({ skip, limit, ...info });
      console.log(res.total);
      this.$set(this, `debtTable`, res.data);
      this.$set(this, `total`, res.total);
    },
    // 添加
    add() {
      this.$router.push({ path: '/character/detail' });
    },
    // 删除
    async deleteRow(id) {
      const res = await this.delete(id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.searchInfo();
    },
    async handleCurrentChange({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);

      this.searchInfo();
    },
    async sousuo(search) {
      console.log(search);
      this.$set(this, `info`, search);
      this.searchInfo();
    },
  },
};
</script>

<style lang="less" scoped>
.top {
  height: 50px;
  margin: 0 0 10px 0;
}
.main {
  height: 765px;
  background: #ffffff;
}
.search {
  width: 97%;
  height: 35px;
  margin: 20px;
}
.list {
  padding: 0 20px;
}
</style>
