index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div id="goods">
  3. <el-row>
  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. <span v-if="view === 'list'">
  12. <el-col :span="24" class="one"> <span>团购商品管理</span> </el-col>
  13. <data-search :fields="searchFields" v-model="searchInfo" @query="search">
  14. <template #goods>
  15. <el-select
  16. v-model="searchInfo.goods"
  17. filterable
  18. clearable
  19. remote
  20. :remote-method="querySearch"
  21. placeholder="请选择商品名称"
  22. :loading="loading"
  23. size="small"
  24. style="width: 100%"
  25. >
  26. <el-option v-for="item in goodsList" :key="item._id" :label="item.name" :value="item._id"> </el-option>
  27. </el-select>
  28. </template>
  29. <template #spec>
  30. <el-select
  31. v-model="searchInfo.spec"
  32. filterable
  33. clearable
  34. remote
  35. :remote-method="specSearch"
  36. placeholder="请选择规格名称"
  37. :loading="loading"
  38. size="small"
  39. style="width: 100%"
  40. >
  41. <el-option v-for="item in specList" :key="item._id" :label="item.name" :value="item._id"> </el-option>
  42. </el-select>
  43. </template>
  44. </data-search>
  45. <data-btn :fields="btnList" @add="toAdd"></data-btn>
  46. <data-table
  47. ref="dataTable"
  48. :fields="fields"
  49. :opera="opera"
  50. :data="list"
  51. :total="total"
  52. @query="search"
  53. @edit="toEdit"
  54. @delete="toDelete"
  55. ></data-table>
  56. </span>
  57. <detail v-if="view === 'info'" :id="id" @toBack="toBack"></detail>
  58. </el-col>
  59. </el-row>
  60. </div>
  61. </template>
  62. <script>
  63. const _ = require('lodash');
  64. import { mapState, createNamespacedHelpers } from 'vuex';
  65. const { mapActions: goodsConfig } = createNamespacedHelpers('goodsConfig');
  66. const { mapActions: goods } = createNamespacedHelpers('goods'); // 商品
  67. const { mapActions: goodsSpec } = createNamespacedHelpers('goodsSpec'); // 商品规格
  68. const { mapActions: dictData } = createNamespacedHelpers('dictData');
  69. export default {
  70. name: 'index',
  71. props: {},
  72. components: {
  73. detail: () => import('./detail.vue'),
  74. },
  75. data: function () {
  76. return {
  77. loadings: true,
  78. loading: false,
  79. view: 'list',
  80. fields: [
  81. { label: '商品名称', model: 'goods.name', showTip: false },
  82. { label: '规格名称', model: 'spec.name' },
  83. { label: '团购价', model: 'price' },
  84. { label: '团长提成金额', model: 'leader_get' },
  85. { label: '运费', model: 'freight' },
  86. {
  87. label: '购买限制',
  88. model: 'buy_limit',
  89. format: (i) => {
  90. let data = this.buy_limitList.find((f) => f.value == i);
  91. if (data) return data.label;
  92. else return '';
  93. },
  94. },
  95. { label: '购买数量界限', model: 'limit_num' },
  96. ],
  97. opera: [
  98. { label: '修改', method: 'edit' },
  99. { label: '删除', method: 'delete', confirm: true, type: 'danger' },
  100. ],
  101. btnList: [{ label: '添加', method: 'add' }],
  102. searchFields: [
  103. { label: '商品名称', model: 'goods', custom: true },
  104. { label: '规格名称', model: 'spec', custom: true },
  105. ],
  106. searchInfo: {},
  107. list: [],
  108. total: 0,
  109. id: '',
  110. // 商品列表
  111. goodsList: [],
  112. // 规格列表
  113. specList: [],
  114. // 购买限制
  115. buy_limitList: [],
  116. };
  117. },
  118. created() {
  119. this.searchOthers();
  120. this.search();
  121. },
  122. methods: {
  123. ...dictData({ getDict: 'query' }),
  124. ...goods({ goodsQuery: 'query' }),
  125. ...goodsSpec({ specQuery: 'query' }),
  126. ...goodsConfig(['query', 'delete', 'fetch', 'update', 'create']),
  127. // 查询
  128. async search({ skip = 0, limit = this.$limit, ...others } = {}) {
  129. let query = { skip, limit, ...others };
  130. if (Object.keys(this.searchInfo).length > 0) query = { ...query, ...this.searchInfo };
  131. const res = await this.query(query);
  132. if (this.$checkRes(res)) {
  133. this.$set(this, `list`, res.data);
  134. this.$set(this, `total`, res.total);
  135. }
  136. this.loadings = false;
  137. },
  138. // 远程查询
  139. async querySearch(value) {
  140. this.loading = true;
  141. let res = await this.goodsQuery({ name: value });
  142. if (this.$checkRes(res)) this.$set(this, 'goodsList', res.data);
  143. this.loading = false;
  144. },
  145. async specSearch(value) {
  146. this.loading = true;
  147. let res = await this.specQuery({ name: value });
  148. if (this.$checkRes(res)) this.$set(this, 'specList', res.data);
  149. this.loading = false;
  150. },
  151. // 新增
  152. toAdd() {
  153. let id = '';
  154. this.$set(this, `id`, id);
  155. this.$set(this, `view`, 'info');
  156. },
  157. // 修改
  158. async toEdit({ data }) {
  159. this.$set(this, `id`, data._id);
  160. this.$set(this, `view`, 'info');
  161. },
  162. // 删除
  163. async toDelete({ data }) {
  164. let res = await this.delete(data._id);
  165. if (this.$checkRes(res)) {
  166. this.$message({ type: `success`, message: `刪除信息成功` });
  167. this.search();
  168. }
  169. },
  170. // 执行返回
  171. toBack() {
  172. this.view = 'list';
  173. },
  174. // 查询其他信息
  175. async searchOthers() {
  176. // 购买限制
  177. let res = await this.getDict({ code: 'buy_limit' });
  178. if (this.$checkRes(res)) this.$set(this, 'buy_limitList', res.data);
  179. },
  180. },
  181. computed: {
  182. ...mapState(['user']),
  183. },
  184. };
  185. </script>
  186. <style lang="less" scoped>
  187. .main {
  188. .one {
  189. margin: 0 0 10px 0;
  190. span:nth-child(1) {
  191. font-size: 20px;
  192. font-weight: 700;
  193. margin-right: 10px;
  194. }
  195. }
  196. .two {
  197. margin: 0 0 10px 0;
  198. }
  199. .thr {
  200. margin: 0 0 10px 0;
  201. }
  202. }
  203. .el-col {
  204. margin: 10px 0;
  205. }
  206. </style>