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

<script>
import topInfo from '@/layout/common/topInfo.vue';
import searchInfo from '@/layout/common/searchInfo.vue';
import otheruserList from '@/layout/otheruser/otheruserList.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: otheruser } = createNamespacedHelpers('otheruser');
const { mapActions: character } = createNamespacedHelpers('character');
export default {
  name: 'index',
  props: {},
  components: {
    topInfo, //头部导航
    searchInfo, //搜素
    otheruserList, //其他用户列表
  },
  data: () => ({
    topTitle: '其他用户',
    display: 'ck',
    debtTable: [],
    total: 0,
    info: [],
    search: {},
    limit: '',
    skip: '',
  }),
  created() {
    this.searchInfo();
  },
  computed: {},
  methods: {
    ...otheruser(['query', 'delete']),
    ...character({ userquery: 'query' }),

    ...otheruser(['query', 'delete', 'update']),
    async searchInfo({ skip, limit = 10, ...info } = {}) {
      skip = this.skip;

      const res = await this.query({ skip, limit, ...(info = this.info) });
      this.$set(this, `debtTable`, res.data);
      this.$set(this, `total`, res.total);
    },
    // 添加
    add() {
      this.$router.push({ path: '/otheruser/detail' });
    },
    // 删除
    async deleteRow(id) {
      const res = await this.delete(id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.searchInfo();
    },
    async clickRest(id) {
      let data = {};
      data.id = id;
      data.passwd = process.env.VUE_APP_USER_PASSWD;
      const res = await this.update(data);
      if (res.errcode === 0) {
        this.$message({
          message: '密码重置成功',
          type: 'success',
        });
      }
    },
    //搜索
    async sousuo(search) {
      console.log(search);
      this.$set(this, `info`, search);
      this.searchInfo();
    },
    //分页

    async handleCurrentChange({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);
      this.$set(this, `limit`, limit);
      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>
