index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div id="role">
  3. <el-row>
  4. <el-col :span="24" class="add" style="text-align:right;padding: 10px 20px;">
  5. <el-button size="mini" type="primary" @click="toAdd" icon="el-icon-plus">添加{{ theme }}</el-button>
  6. </el-col>
  7. <el-col :span="24" class="main">
  8. <data-table :fields="fields" @delete="toDelete" :data="list" :opera="opera" @edit="toEdit" :total="total" @query="search"></data-table>
  9. </el-col>
  10. <el-dialog :title="theme" width="60%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
  11. <data-form :data="form" :fields="formFields" @save="toSave" :isNew="dialogIsNew"></data-form>
  12. </el-dialog>
  13. </el-row>
  14. </div>
  15. </template>
  16. <script>
  17. import dataForm from '@/components/form.vue';
  18. import dataTable from '@/components/data-table.vue';
  19. import { mapState, createNamespacedHelpers } from 'vuex';
  20. const { mapActions } = createNamespacedHelpers('authUser');
  21. export default {
  22. name: 'role',
  23. props: {},
  24. components: { dataTable, dataForm },
  25. data: function() {
  26. return {
  27. theme: '管理员',
  28. dialog: false,
  29. form: {},
  30. dialogIsNew: true,
  31. opera: [
  32. {
  33. label: '编辑',
  34. icon: 'el-icon-edit',
  35. method: 'edit',
  36. },
  37. {
  38. label: '删除',
  39. icon: 'el-icon-delete',
  40. method: 'delete',
  41. confirm: true,
  42. },
  43. ],
  44. fields: [
  45. { label: '机构代码或邀请码', prop: 'code', model: 'code' },
  46. { label: '姓名', prop: 'name', model: 'name' },
  47. { label: '机构名称', prop: 'deptname', model: 'deptname' },
  48. { label: '手机号', prop: 'phone', model: 'phone', options: { maxLength: 11, minLength: 11, type: 'number' } },
  49. ],
  50. formFields: [
  51. { label: '机构代码或邀请码', prop: 'code', model: 'code' },
  52. { label: '姓名', prop: 'name', model: 'name' },
  53. { label: '机构名称', prop: 'deptname', model: 'deptname' },
  54. { label: '手机号', prop: 'phone', model: 'phone', options: { maxLength: 11, minLength: 11, type: 'number' } },
  55. { label: '密码', prop: 'passwd', model: 'passwd', type: 'password' },
  56. ],
  57. list: [],
  58. total: 0,
  59. };
  60. },
  61. created() {
  62. this.search();
  63. },
  64. methods: {
  65. ...mapActions(['query', 'create', 'update', 'delete']),
  66. async search({ skip = 0, limit = 10, ...info } = {}) {
  67. const res = await this.query({ skip, limit, ...info, pid: this.user.uid, role: '0' });
  68. if (this.$checkRes(res)) {
  69. this.$set(this, `list`, res.data.reverse());
  70. this.$set(this, `total`, res.total);
  71. }
  72. },
  73. // 添加
  74. toAdd() {
  75. this.dialog = true;
  76. },
  77. toEdit({ data }) {
  78. this.$set(this, 'form', data);
  79. this.dialog = true;
  80. this.dialogIsNew = false;
  81. },
  82. async toSave({ isNew, data }) {
  83. let res;
  84. let msg;
  85. if (isNew) {
  86. data.pid = this.user.uid;
  87. data.role = '0';
  88. res = await this.create(data);
  89. msg = '创建成功';
  90. } else {
  91. res = await this.update(data);
  92. msg = '修改成功';
  93. }
  94. if (this.$checkRes(res, msg, res.errmsg)) {
  95. this.handleClose();
  96. this.search();
  97. }
  98. },
  99. async toDelete({ data }) {
  100. const res = await this.delete(data.id);
  101. if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
  102. },
  103. handleClose() {
  104. this.dialog = false;
  105. this.form = {};
  106. this.dialogIsNew = true;
  107. },
  108. },
  109. computed: {
  110. ...mapState(['user']),
  111. pageTitle() {
  112. return `${this.$route.meta.title}`;
  113. },
  114. },
  115. metaInfo() {
  116. return { title: this.$route.meta.title };
  117. },
  118. };
  119. </script>
  120. <style lang="less" scoped></style>