index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24">
  5. <el-col :span="24" class="add" style="text-align:right;padding: 10px 20px;">
  6. <el-button size="mini" type="primary" @click="toAdd" icon="el-icon-plus">添加{{ theme }}</el-button>
  7. </el-col>
  8. <el-col :span="24" class="main">
  9. <data-table :fields="fields" :opera="opera" @edit="toEdit" :data="list" :total="total" @delete="toDelete" @query="search"></data-table>
  10. </el-col>
  11. <el-dialog :title="theme" width="60%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
  12. <el-form ref="form" :model="form" label-width="100px">
  13. <el-form-item label="用户名称" prop="name">
  14. <el-input v-model="form.name" placeholder="请输入用户名称"></el-input>
  15. </el-form-item>
  16. <el-form-item label="手机号" prop="phone">
  17. <el-input v-model="form.phone" placeholder="请输入手机号" :minlength="11" :maxlength="11"></el-input>
  18. </el-form-item>
  19. <el-form-item label="登录密码" prop="password">
  20. <el-input v-model="form.password" placeholder="请输入登录密码" show-password></el-input>
  21. </el-form-item>
  22. <el-form-item label="身份证号" prop="cardnumber">
  23. <el-input v-model="form.cardnumber" placeholder="请输入身份证号" :minlength="18" :maxlength="18"></el-input>
  24. </el-form-item>
  25. <el-form-item label="邮箱" prop="email">
  26. <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
  27. </el-form-item>
  28. <el-form-item label="地址" prop="addr">
  29. <el-input v-model="form.addr" placeholder="请输入地址"></el-input>
  30. </el-form-item>
  31. <el-form-item label="头像图片" prop="img_path">
  32. <upload :limit="1" :data="form.img_path" type="img_path" :url="'/files/imgpath/upload'" @upload="uploadSuccess"></upload>
  33. </el-form-item>
  34. <el-form-item label="简介" prop="resume">
  35. <el-input v-model="form.resume" placeholder="请输入备注"></el-input>
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button @click="handleClose">返回</el-button>
  39. <el-button type="primary" @click="handleSave()">提交</el-button>
  40. </el-form-item>
  41. </el-form>
  42. </el-dialog>
  43. </el-col>
  44. </el-row>
  45. </div>
  46. </template>
  47. <script>
  48. import upload from '@/components/uploadone.vue';
  49. import dataTable from '@/components/data-table.vue';
  50. import { mapState, createNamespacedHelpers } from 'vuex';
  51. const { mapActions: users } = createNamespacedHelpers('users');
  52. export default {
  53. name: 'index',
  54. props: {},
  55. components: {
  56. dataTable,
  57. upload,
  58. },
  59. data: function() {
  60. return {
  61. theme: 'vip用户',
  62. opera: [
  63. {
  64. label: '编辑',
  65. icon: 'el-icon-edit',
  66. method: 'edit',
  67. },
  68. {
  69. label: '删除',
  70. icon: 'el-icon-delete',
  71. method: 'delete',
  72. confirm: true,
  73. },
  74. ],
  75. fields: [
  76. { label: '姓名', prop: 'name', filter: 'input' },
  77. { label: '电话', prop: 'phone', filter: 'input' },
  78. { label: '用戶类型', prop: 'role', format: i => (i == '2' ? 'vip用户' : '无法识别') },
  79. { label: '状态', prop: 'status', format: i => (i == '1' ? '审核通过' : '') },
  80. ],
  81. list: [],
  82. total: 0,
  83. dialog: false,
  84. form: {},
  85. };
  86. },
  87. created() {
  88. this.search();
  89. },
  90. methods: {
  91. ...users(['create', 'query', 'update', 'delete']),
  92. async search({ skip = 0, limit = 10, ...info } = {}) {
  93. if (this.user.code.length == 3) {
  94. const res = await this.query({ skip, limit, role: '2', ...info });
  95. if (this.$checkRes(res)) {
  96. this.$set(this, `list`, res.data);
  97. this.$set(this, `total`, res.total);
  98. }
  99. }
  100. },
  101. // 添加
  102. toAdd() {
  103. this.dialog = true;
  104. },
  105. // 提交
  106. async handleSave() {
  107. if (this.form.id) {
  108. let res = await this.update(this.form);
  109. this.$message({
  110. message: '修改信息成功',
  111. type: 'success',
  112. });
  113. this.handleClose();
  114. } else {
  115. let data = this.form;
  116. data.status = '1';
  117. data.code = this.user.code;
  118. data.role = '2';
  119. let res = await this.create(data);
  120. if (this.$checkRes(res)) {
  121. this.$message({
  122. message: '添加信息成功',
  123. type: 'success',
  124. });
  125. this.handleClose();
  126. }
  127. }
  128. },
  129. // 修改
  130. toEdit({ data }) {
  131. this.$set(this, 'form', data);
  132. this.dialog = true;
  133. },
  134. // 刪除
  135. async toDelete({ data }) {
  136. const res = await this.delete(data.id);
  137. if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
  138. },
  139. // 取消
  140. handleClose() {
  141. this.dialog = false;
  142. this.form = {};
  143. },
  144. uploadSuccess({ type, data }) {
  145. this.$set(this.form, `${type}`, data.uri);
  146. },
  147. },
  148. computed: {
  149. ...mapState(['user']),
  150. pageTitle() {
  151. return `${this.$route.meta.title}`;
  152. },
  153. },
  154. metaInfo() {
  155. return { title: this.$route.meta.title };
  156. },
  157. };
  158. </script>
  159. <style lang="less" scoped></style>