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

<script>
import topInfo from '@/layout/common/topInfo.vue';
import searchInfo from '@/layout/common/searchInfo.vue';
import companyuserList from '@/layout/companyuser/companyuserList.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: companyuser } = createNamespacedHelpers('companyuser');

export default {
  name: 'index',
  display: 'block',
  props: {},
  components: {
    topInfo, //头部导航
    searchInfo, //搜素
    companyuserList, //其他用户列表
  },
  data: () => ({
    total: 0,
    topTitle: '企业用户',
    display: 'block',
    debtTable: [],
    skip: '',
    info: {},
  }),
  created() {
    this.searchInfo();
  },
  computed: {},
  methods: {
    ...companyuser(['query', 'delete']),
    async searchInfo({ skip, limit = 10, ...info } = {}) {
      skip = this.skip;
      info = this.info;
      const res = await this.query({ skip, limit, ...info });
      console.log(res);
      this.$set(this, `debtTable`, res.data);
      this.$set(this, `total`, res.total);
    },
    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();
    },
    // 删除
    async deleteRow(id) {
      const res = await this.delete(id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.searchInfo();
    },
    add() {
      this.$router.push({ path: '/companyuser/detail' });
    },
  },
};
</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>
