index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="add">
  6. <el-button type="primary" size="mini" @click="add">添加</el-button>
  7. </el-col>
  8. <el-col :span="24" class="list">
  9. <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit" @delete="toDelete"></data-table>
  10. </el-col>
  11. </el-col>
  12. </el-row>
  13. </div>
  14. </template>
  15. <script>
  16. import { mapState, createNamespacedHelpers } from 'vuex';
  17. const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
  18. export default {
  19. metaInfo() {
  20. return { title: this.$route.meta.title };
  21. },
  22. name: 'index',
  23. props: {},
  24. components: {},
  25. data: function () {
  26. return {
  27. opera: [
  28. {
  29. label: '编辑',
  30. method: 'edit',
  31. },
  32. {
  33. label: '删除',
  34. method: 'delete',
  35. },
  36. ],
  37. fields: [
  38. { label: '机构代码或邀请码', prop: 'code', model: 'code' },
  39. { label: '姓名', prop: 'name', model: 'name' },
  40. { label: '手机号', prop: 'phone', model: 'phone', options: { maxLength: 11, minLength: 11, type: 'number' } },
  41. { label: '机构名称', prop: 'deptname', model: 'deptname' },
  42. ],
  43. list: [],
  44. total: 0,
  45. // 分配权限
  46. dialog: false,
  47. formfields: [
  48. { label: '用户名', model: 'name' },
  49. { label: '机构名称', model: 'deptname' },
  50. { label: '权限', model: 'menus', custom: true },
  51. ],
  52. form: {
  53. menus: [],
  54. },
  55. rules: {},
  56. // 菜单列表
  57. menuList: [],
  58. };
  59. },
  60. async created() {
  61. await this.search();
  62. },
  63. methods: {
  64. ...adminLogin(['query', 'fetch', 'update', 'delete']),
  65. // 查询列表
  66. async search({ skip = 0, limit = 10, ...info } = {}) {
  67. if (this.user.role == '1' || this.user.role == '2') info.pid = this.user.id;
  68. let res = await this.query({ skip, limit, role: '2', ...info });
  69. if (this.$checkRes(res)) {
  70. this.$set(this, `list`, res.data);
  71. this.$set(this, `total`, res.total);
  72. }
  73. },
  74. // 修改
  75. toEdit({ data }) {
  76. this.$router.push({ path: '/adminCenter/mechanism/detail', query: { id: data.id } });
  77. },
  78. // 删除
  79. async toDelete({ data }) {
  80. let res = await this.delete(data.id);
  81. if (this.$checkRes(res)) {
  82. this.$message({
  83. message: '信息修改成功',
  84. type: 'success',
  85. });
  86. this.search();
  87. }
  88. },
  89. // 添加数据
  90. add() {
  91. this.$router.push({ path: '/adminCenter/mechanism/detail' });
  92. },
  93. },
  94. computed: {
  95. ...mapState(['user']),
  96. },
  97. watch: {},
  98. };
  99. </script>
  100. <style lang="less" scoped>
  101. .main {
  102. .add {
  103. text-align: right;
  104. margin: 0 0 10px 0;
  105. }
  106. }
  107. </style>