index.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="index">
  5. <el-col :span="24" class="top">
  6. <topInfo :topTitle="pageTitle"></topInfo>
  7. </el-col>
  8. <el-col :span="24" class="add" style="text-align:right">
  9. <el-button size="mini" type="primary" @click="$router.push({ path: './detail' })" icon="el-icon-plus">添加用户</el-button>
  10. </el-col>
  11. <el-col :span="24" class="main">
  12. <data-table :fields="fields" @delete="toDelete" :data="list" :opera="opera" @edit="toEdit" :total="total" @query="search"></data-table>
  13. </el-col>
  14. </el-col>
  15. </el-row>
  16. </div>
  17. </template>
  18. <script>
  19. import topInfo from '@/layout/public/top.vue';
  20. import dataTable from '@/components/data-table.vue';
  21. import { mapState, createNamespacedHelpers } from 'vuex';
  22. const { mapActions: users } = createNamespacedHelpers('users');
  23. export default {
  24. name: 'index',
  25. props: {},
  26. components: {
  27. topInfo,
  28. dataTable,
  29. },
  30. data: function() {
  31. return {
  32. opera: [
  33. {
  34. label: '修改',
  35. icon: 'el-icon-edit',
  36. method: 'edit',
  37. },
  38. {
  39. label: '删除',
  40. icon: 'el-icon-delete',
  41. method: 'delete',
  42. confirm: true,
  43. },
  44. ],
  45. fields: [
  46. { label: '邀请码', prop: 'code' },
  47. { label: '用户名', prop: 'name', filter: 'input' },
  48. { label: '机构名称', prop: 'deptname', filter: 'input' },
  49. { label: '电话', prop: 'phone', filter: 'input' },
  50. ],
  51. list: [],
  52. total: 0,
  53. };
  54. },
  55. created() {
  56. this.search();
  57. },
  58. methods: {
  59. ...users(['query', 'fetch', 'create', 'update', 'delete']),
  60. async search({ skip = 0, limit = 10, ...info } = {}) {
  61. const res = await this.query({ skip, limit, pid: this.user.uid, ...info });
  62. if (this.$checkRes(res)) {
  63. this.$set(this, `list`, res.data);
  64. this.$set(this, `total`, res.total);
  65. }
  66. },
  67. toEdit({ data }) {
  68. this.$router.push({ path: './detail', query: { id: data.id } });
  69. },
  70. async toDelete({ data }) {
  71. const res = await this.delete(data.id);
  72. if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
  73. },
  74. },
  75. computed: {
  76. ...mapState(['user']),
  77. pageTitle() {
  78. return `${this.$route.meta.title}`;
  79. },
  80. },
  81. metaInfo() {
  82. return { title: this.$route.meta.title };
  83. },
  84. };
  85. </script>
  86. <style lang="less" scoped>
  87. .add {
  88. padding: 0 20px;
  89. }
  90. .main {
  91. padding: 0 20px;
  92. }
  93. </style>