index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div id="card-1">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one"> <span>优惠券管理</span> </el-col>
  6. <el-col :span="24" class="two">
  7. <search-1
  8. :form="searchForm"
  9. :statusList="statusList"
  10. @onSubmit="search"
  11. @toReset="toClose"
  12. @querySearch="querySearch"
  13. :shopList="shopList"
  14. :discount_typeList="discount_typeList"
  15. ></search-1>
  16. </el-col>
  17. <el-col :span="24" class="thr">
  18. <el-button type="primary" size="mini" @click="toAdd()">新增</el-button>
  19. </el-col>
  20. <el-col :span="24" class="four">
  21. <data-table
  22. :select="true"
  23. :selected="selected"
  24. @handleSelect="handleSelect"
  25. :fields="fields"
  26. :opera="opera"
  27. @query="search"
  28. :data="list"
  29. :total="total"
  30. @edit="toEdit"
  31. @del="toDel"
  32. >
  33. </data-table>
  34. </el-col>
  35. </el-col>
  36. </el-row>
  37. </div>
  38. </template>
  39. <script>
  40. const _ = require('lodash');
  41. import { mapState, createNamespacedHelpers } from 'vuex';
  42. const { mapActions } = createNamespacedHelpers('coupon');
  43. const { mapActions: dictData } = createNamespacedHelpers('dictData');
  44. const { mapActions: shop } = createNamespacedHelpers('shop');
  45. export default {
  46. name: 'card-1',
  47. props: {},
  48. components: { search1: () => import('./parts/search-1.vue') },
  49. data: function () {
  50. const that = this;
  51. return {
  52. // 查询
  53. searchForm: {},
  54. list: [],
  55. total: 0,
  56. opera: [
  57. { label: '修改', method: 'edit' },
  58. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  59. ],
  60. fields: [
  61. {
  62. label: '发行方',
  63. model: 'issue',
  64. format: (i) => {
  65. let data = that.issueList.find((f) => f.value == i);
  66. if (data) return data.label;
  67. else return '暂无';
  68. },
  69. },
  70. // { label: '商铺', model: 'shop.name' },
  71. { label: '优惠券名称', model: 'name' },
  72. { label: '优惠券数量', model: 'num' },
  73. {
  74. label: '减免方式',
  75. model: 'discount_type',
  76. format: (i) => {
  77. let data = that.discount_typeList.find((f) => f.value == i);
  78. if (data) return data.label;
  79. else return '暂无';
  80. },
  81. },
  82. {
  83. label: '是否使用',
  84. model: 'status',
  85. format: (i) => {
  86. let data = that.statusList.find((f) => f.value == i);
  87. if (data) return data.label;
  88. else return '暂无';
  89. },
  90. },
  91. ],
  92. // 多选值
  93. selected: [],
  94. // 发行方
  95. issueList: [],
  96. // 是否使用
  97. statusList: [],
  98. // 商铺
  99. shopList: [],
  100. // 减免方式
  101. discount_typeList: [],
  102. };
  103. },
  104. async created() {
  105. await this.search();
  106. await this.searchOther();
  107. },
  108. methods: {
  109. ...shop({ shopQuery: 'query' }),
  110. ...dictData({ dictQuery: 'query' }),
  111. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  112. // 查询
  113. async search({ skip = 0, limit = 10, ...info } = {}) {
  114. let condition = _.cloneDeep(this.searchForm);
  115. let res = await this.query({ skip, limit, ...condition, ...info });
  116. if (this.$checkRes(res)) {
  117. this.$set(this, 'list', res.data);
  118. this.$set(this, 'total', res.total);
  119. }
  120. },
  121. // 新增
  122. toAdd() {
  123. this.$router.push({ path: '/system/coupon/detail' });
  124. },
  125. // 修改
  126. async toEdit({ data }) {
  127. this.$router.push({ path: '/system/coupon/detail', query: { id: data.id } });
  128. },
  129. async toDel({ data }) {
  130. let res = await this.delete(data._id);
  131. if (this.$checkRes(res)) {
  132. this.$message({ type: `success`, message: `刪除信息成功` });
  133. this.search();
  134. }
  135. },
  136. toClose() {
  137. this.searchForm = {};
  138. this.search();
  139. },
  140. // 多选
  141. handleSelect(data) {
  142. this.$emit('handleSelect');
  143. },
  144. // 查询其他信息
  145. async searchOther() {
  146. let res;
  147. // 发行方
  148. res = await this.dictQuery({ code: 'coupon_issue', value: '0' });
  149. if (this.$checkRes(res)) {
  150. this.$set(this, `issueList`, res.data);
  151. }
  152. // 使用状态
  153. res = await this.dictQuery({ code: 'use' });
  154. if (this.$checkRes(res)) {
  155. this.$set(this, `statusList`, res.data);
  156. }
  157. // 减免方式
  158. res = await this.dictQuery({ code: 'coupon_discount_type' });
  159. if (this.$checkRes(res)) {
  160. this.$set(this, `discount_typeList`, res.data);
  161. }
  162. },
  163. // 店铺名称远程查询
  164. async querySearch(value) {
  165. let res = await this.shopQuery({ name: value });
  166. if (this.$checkRes(res)) {
  167. this.$set(this, 'shopList', res.data);
  168. }
  169. },
  170. },
  171. computed: {
  172. ...mapState(['user']),
  173. },
  174. metaInfo() {
  175. return { title: this.$route.meta.title };
  176. },
  177. watch: {
  178. test: {
  179. deep: true,
  180. immediate: true,
  181. handler(val) {},
  182. },
  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. </style>