detail.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div id="goods">
  3. <template v-if="view === 'list'">
  4. <el-row>
  5. <el-col :span="24" style="padding: 10px">
  6. <el-button type="primary" size="mini" @click="toBack()">返回</el-button>
  7. </el-col>
  8. </el-row>
  9. <data-search :fields="searchFields" v-model="searchInfo" @query="search"> </data-search>
  10. <data-btn :fields="btnList" @add="toAdd"></data-btn>
  11. <data-table
  12. ref="dataTable"
  13. :fields="fields"
  14. :opera="opera"
  15. :data="list"
  16. :total="total"
  17. :limit="limit"
  18. @query="search"
  19. @edit="toEdit"
  20. @del="toDel"
  21. @reset="toReset"
  22. ></data-table>
  23. </template>
  24. <template v-else>
  25. <el-row>
  26. <el-col :span="24">
  27. <el-button type="primary" size="mini" @click="toBackList()">返回</el-button>
  28. </el-col>
  29. <el-col :span="24">
  30. <data-form :fields="infoFields" :rules="rules" v-model="form" labelWidth="150px" @save="toSave">
  31. <template #role>
  32. <el-option v-for="i in roleList" :key="i._id" :label="i.name" :value="i._id"></el-option>
  33. </template>
  34. </data-form>
  35. </el-col>
  36. </el-row>
  37. </template>
  38. </div>
  39. </template>
  40. <script>
  41. const _ = require('lodash');
  42. import methodsUtil from '@/util/opera';
  43. import { mapState, createNamespacedHelpers } from 'vuex';
  44. const { mapActions: admins } = createNamespacedHelpers('admins');
  45. const { mapActions: role } = createNamespacedHelpers('role');
  46. const { mapActions: emailResetPwd } = createNamespacedHelpers('emailResetPwd');
  47. export default {
  48. name: 'index',
  49. props: {},
  50. components: {},
  51. data: function () {
  52. return {
  53. view: 'list',
  54. fields: [
  55. { label: '名称', model: 'name' },
  56. { label: '账号', model: 'account' },
  57. { label: '角色', model: 'role.name' },
  58. ],
  59. opera: [
  60. { label: '修改', method: 'edit' },
  61. { label: '重置密码', method: 'reset' },
  62. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  63. ],
  64. btnList: [{ label: '添加', method: 'add' }],
  65. searchFields: [{ label: '名称', model: 'name' }],
  66. searchInfo: {},
  67. list: [],
  68. total: 0,
  69. limit: 10,
  70. // info部分
  71. infoFields: [
  72. { label: '名称', model: 'name' },
  73. { label: '账号', model: 'account' },
  74. { label: '角色', model: 'role', type: 'select' },
  75. { label: '邮箱', model: 'email' },
  76. { label: '密码', model: 'password', type: 'password', display: (i) => i.password == '' },
  77. ],
  78. rules: {},
  79. form: {},
  80. roleList: [],
  81. };
  82. },
  83. created() {
  84. this.searchOthers();
  85. this.search();
  86. },
  87. methods: {
  88. ...methodsUtil,
  89. ...role({ roleQuery: 'query' }),
  90. ...emailResetPwd({ pwdCreate: 'create' }),
  91. ...admins(['query', 'delete', 'fetch', 'update', 'create']),
  92. // 重置
  93. async search({ skip = 0, limit = this.limit, ...others } = {}) {
  94. others.shop = this.id;
  95. let query = { skip, limit, ...others };
  96. if (Object.keys(this.searchInfo).length > 0) query = { ...query, ...this.searchInfo };
  97. const res = await this.query(query);
  98. if (this.$checkRes(res)) {
  99. this.$set(this, `list`, res.data);
  100. this.$set(this, `total`, res.total);
  101. }
  102. },
  103. // 添加自定义
  104. initAddData() {
  105. const obj = { shop: this.id };
  106. this.$set(this, 'form', obj);
  107. },
  108. // 修改
  109. async toEdit({ data }) {
  110. const res = await this.fetch(data._id);
  111. if (this.$checkRes(res)) {
  112. let data = res.data;
  113. this.$set(this, `form`, data);
  114. this.view = 'info';
  115. } else {
  116. this.$message.error('未找到指定数据');
  117. }
  118. },
  119. // 重置密码
  120. async toReset({ data }) {
  121. this.$confirm('忘记密码,是否确认重置密码?', '提示', {
  122. confirmButtonText: '确定',
  123. cancelButtonText: '取消',
  124. type: 'warning',
  125. }).then(async () => {
  126. const res = await this.pwdCreate({ account: data.account });
  127. if (this.$checkRes(res)) {
  128. this.$message({ type: `success`, message: `重置密码成功` });
  129. this.search();
  130. }
  131. });
  132. },
  133. // 删除
  134. async toDel({ data }) {
  135. let res = await this.delete(data._id);
  136. if (this.$checkRes(res)) {
  137. this.$message({ type: `success`, message: `刪除信息成功` });
  138. this.search();
  139. }
  140. },
  141. // 保存
  142. async toSave({ data }) {
  143. let res;
  144. if (data.id) res = await this.update(data);
  145. else res = await this.create(data);
  146. if (this.$checkRes(res, `维护信息成功`, res.errmsg)) {
  147. this.search();
  148. this.toBackList();
  149. }
  150. },
  151. // 查询其他信息
  152. async searchOthers() {
  153. let res = await this.roleQuery();
  154. if (this.$checkRes(res)) {
  155. this.$set(this, `roleList`, res.data);
  156. }
  157. },
  158. // 返回
  159. toBack() {
  160. window.history.go('-1');
  161. },
  162. // 返回列表
  163. toBackList() {
  164. this.view = 'list';
  165. this.form = {};
  166. },
  167. },
  168. computed: {
  169. id() {
  170. return this.$route.query.id;
  171. },
  172. },
  173. };
  174. </script>
  175. <style lang="less" scoped></style>