detail.vue 5.9 KB

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