<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="list">
          <zhidaoList :tableData="tableData" :total="total" @deleteRow="deleteRow" @select="select"></zhidaoList>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import topInfo from '@/layout/custom/topInfo.vue';
import zhidaoList from '@/layout/zhidao/zhidaoList.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: tGuidanceUnit } = createNamespacedHelpers('tGuidanceUnit');

export default {
  name: 'index',
  props: {},
  components: {
    topInfo, //头部导航
    zhidaoList, //列表
  },
  data: () => ({
    topTitle: '指导单位管理',
    display: 'block',
    tableData: [],
    total: 0,
  }),
  created() {
    this.select();
  },
  computed: {},
  methods: {
    ...tGuidanceUnit(['create', 'delete', 'update', 'fetch', 'query']),
    async select({ skip = 0, limit = 10, ...info } = {}) {
      const res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `tableData`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    add() {
      this.$router.push({ path: '/zhidao/detail' });
    },
    async deleteRow({ id, skip = 0, limit = 10, ...info } = {}) {
      const res = await this.delete(id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.select({ skip, limit, ...info });
    },
  },
};
</script>

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