<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">
          <bannerList :debtTable="debtTable" @handleCurrentChange="handleCurrentChange" :total="total" @deleteRow="deleteRow"></bannerList>
        </el-col>
      </el-col>
    </el-col>
  </div>
</template>

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

    async searchInfo({ skip = 0, limit = 10, ...info } = {}) {
      info = this.info;
      const res = await this.query({ skip, limit, ...info });
      console.log(res.data);

      this.$set(this, `debtTable`, res.data);
      this.$set(this, `total`, res.total);
    },
    // 添加
    add() {
      this.$router.push({ path: '/banner/detail' });
    },
    // 删除
    async deleteRow(id) {
      const res = await this.delete(id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.searchInfo();
    },
    //分页
    async handleCurrentChange({ skip, limit, currentPage }) {
      const res = await this.query({ skip, limit });
      this.$set(this, `debtTable`, res.data);
    },
    //搜索
    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>
