index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div id="index">
  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-show="view === 'list'">
  12. <el-col :span="24" class="one"> <span>套装管理</span> </el-col>
  13. <el-col :span="24" class="two">
  14. <search-1 :form="searchForm" @onSubmit="toSearch" @toReset="toClose"></search-1>
  15. </el-col>
  16. <el-col :span="24" class="thr">
  17. <el-button type="primary" size="mini" @click="toAdd()">新增</el-button>
  18. </el-col>
  19. <el-col :span="24" class="four">
  20. <data-table
  21. ref="dataTable"
  22. :fields="fields"
  23. :opera="opera"
  24. @query="search"
  25. :data="list"
  26. :total="total"
  27. @edit="toEdit"
  28. @del="toDel"
  29. @manage="toManage"
  30. >
  31. </data-table>
  32. </el-col>
  33. </span>
  34. <detail v-if="view === 'info'" :id="id" @toBack="toBack"></detail>
  35. </el-col>
  36. </el-row>
  37. <e-dialog :dialog="dialog" @toClose="toClose">
  38. <template v-slot:info>
  39. <el-table :data="set" border size="mini">
  40. <el-table-column label="店铺名称" prop="shop_name" align="center">
  41. <template #default="{ row }">
  42. <p>{{ row.shop_name }}</p>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="商品名称" prop="goods_name" align="center">
  46. <template #default="{ row }">
  47. <p>{{ row.goods_name }}</p>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="规格名称" prop="spec_name" align="center">
  51. <template #default="{ row }">
  52. <p>{{ row.spec_name }}</p>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="组合套装数量" prop="set_num" align="center">
  56. <template #default="{ row }">
  57. <p>{{ row.set_num }}</p>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="套装销售金额" prop="set_money" align="center">
  61. <template #default="{ row }">
  62. <p>{{ row.set_money }}</p>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. </template>
  67. </e-dialog>
  68. </div>
  69. </template>
  70. <script>
  71. const _ = require('lodash');
  72. import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
  73. const { mapActions } = createNamespacedHelpers('goodsSet');
  74. const { mapActions: dictData } = createNamespacedHelpers('dictData');
  75. export default {
  76. name: 'index',
  77. props: {},
  78. components: {
  79. search1: () => import('./parts/search-1.vue'),
  80. detail: () => import('./detail.vue'),
  81. },
  82. data: function () {
  83. const that = this;
  84. return {
  85. loadings: true,
  86. view: 'list',
  87. // 列表
  88. opera: [
  89. { label: '修改', method: 'edit' },
  90. { label: '商品管理', method: 'manage' },
  91. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  92. ],
  93. fields: [
  94. { label: '套装名称', model: 'name' },
  95. // { label: '店铺名称', model: 'shop', format: (i) => i.join(',') },
  96. // { label: '商品', model: 'goods', format: (i) => i.join(',') },
  97. // { label: '规格', model: 'spec', format: (i) => i.join(',') },
  98. { label: '套装销售金额', model: 'sell_money' },
  99. { label: '运费', model: 'freight' },
  100. {
  101. label: '是否开启',
  102. model: 'is_use',
  103. format: (i) => {
  104. let data = that.isuseList.find((f) => f.value == i);
  105. if (data) return data.label;
  106. else return '暂无';
  107. },
  108. },
  109. ],
  110. list: [],
  111. total: 0,
  112. // 查询
  113. searchForm: {},
  114. // 是否开启
  115. isuseList: [],
  116. id: '',
  117. // 查询条件
  118. searchQuery: {},
  119. set: [],
  120. // 弹框
  121. dialog: { title: '信息管理', show: false, type: '1' },
  122. };
  123. },
  124. created() {
  125. this.searchOther();
  126. this.search();
  127. },
  128. methods: {
  129. ...dictData({ dictQuery: 'query' }),
  130. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  131. toSearch() {
  132. this.$refs.dataTable.resetPage();
  133. let res = this.$refs.dataTable.getPageConfig();
  134. this.search(res);
  135. },
  136. // 查询
  137. async search({ skip = 0, limit = this.$limit, ...others } = {}) {
  138. const condition = _.cloneDeep(this.searchForm);
  139. let query = { skip, limit, ...others };
  140. if (Object.keys(condition).length > 0) query = { ...query, ...condition };
  141. let res = await this.query(query);
  142. if (this.$checkRes(res)) {
  143. this.$set(this, 'list', res.data);
  144. this.$set(this, 'total', res.total);
  145. this.$set(this, `searchQuery`, query);
  146. }
  147. this.loadings = false;
  148. },
  149. // 新增
  150. toAdd() {
  151. let id = '';
  152. this.$set(this, `id`, id);
  153. this.$set(this, `view`, 'info');
  154. },
  155. // 修改
  156. async toEdit({ data }) {
  157. this.$set(this, `id`, data.id);
  158. this.$set(this, `view`, 'info');
  159. },
  160. toBack() {
  161. this.view = 'list';
  162. this.search(this.searchQuery);
  163. },
  164. // 商品管理
  165. async toManage({ data }) {
  166. this.$set(this, `set`, data.set);
  167. this.dialog = { title: '信息管理', show: true, type: '1' };
  168. },
  169. // 关闭
  170. toClose() {
  171. this.set = [];
  172. this.searchForm = {};
  173. this.dialog = { title: '信息管理', show: false, type: '1' };
  174. this.search();
  175. },
  176. // 删除
  177. async toDel({ data }) {
  178. let res = await this.delete(data._id);
  179. if (this.$checkRes(res)) {
  180. this.$message({ type: `success`, message: `刪除信息成功` });
  181. this.search(this.searchQuery);
  182. }
  183. },
  184. // 查询其他信息
  185. async searchOther() {
  186. let res;
  187. // 是否使用
  188. res = await this.dictQuery({ code: 'use' });
  189. if (this.$checkRes(res)) this.$set(this, `isuseList`, res.data);
  190. },
  191. },
  192. computed: {
  193. ...mapState(['user']),
  194. },
  195. metaInfo() {
  196. return { title: this.$route.meta.title };
  197. },
  198. watch: {
  199. test: {
  200. deep: true,
  201. immediate: true,
  202. handler(val) {},
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="less" scoped>
  208. .main {
  209. .one {
  210. margin: 0 0 10px 0;
  211. span:nth-child(1) {
  212. font-size: 20px;
  213. font-weight: 700;
  214. margin-right: 10px;
  215. }
  216. }
  217. .two {
  218. margin: 0 0 10px 0;
  219. }
  220. .thr {
  221. margin: 0 0 10px 0;
  222. }
  223. }
  224. .el-col {
  225. margin: 10px 0;
  226. }
  227. </style>