index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <span v-show="view === 'list'">
  6. <el-col :span="24" class="one"> <span>活动标题</span> </el-col>
  7. <el-col :span="24" class="two">
  8. <search-1 :form="searchForm" @onSubmit="search" @toReset="toClose"></search-1>
  9. </el-col>
  10. <el-col :span="24" class="thr">
  11. <el-button type="primary" size="mini" @click="toAdd()">新增</el-button>
  12. </el-col>
  13. <el-col :span="24" class="four">
  14. <data-table :fields="fields" :opera="opera" @query="search" :data="list" :total="total" @edit="toEdit" @del="toDel" @manage="toManage">
  15. </data-table>
  16. </el-col>
  17. </span>
  18. <detail v-if="view === 'info'" :id="id" @toBack="toBack"></detail>
  19. </el-col>
  20. </el-row>
  21. </div>
  22. </template>
  23. <script>
  24. const _ = require('lodash');
  25. import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
  26. const { mapActions } = createNamespacedHelpers('platformAct');
  27. const { mapActions: dictData } = createNamespacedHelpers('dictData');
  28. export default {
  29. name: 'index',
  30. props: {},
  31. components: {
  32. search1: () => import('./search/search-1.vue'),
  33. detail: () => import('./parts/detail.vue'),
  34. },
  35. data: function () {
  36. const that = this;
  37. return {
  38. view: 'list',
  39. // 列表
  40. opera: [
  41. { label: '修改', method: 'edit' },
  42. { label: '商品管理', method: 'manage' },
  43. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  44. ],
  45. fields: [
  46. { label: '活动标题', model: 'act_time.title' },
  47. {
  48. label: '活动类型',
  49. model: 'type',
  50. format: (i) => {
  51. let data = that.act_typeList.find((f) => f.value == i);
  52. if (data) return data.label;
  53. else return '暂无';
  54. },
  55. },
  56. { label: '活动时间', model: 'act_time.value' },
  57. {
  58. label: '是否开启',
  59. model: 'is_use',
  60. format: (i) => {
  61. let data = that.isuseList.find((f) => f.value == i);
  62. if (data) return data.label;
  63. else return '暂无';
  64. },
  65. },
  66. {
  67. label: '是否在首页显示',
  68. model: 'show_index',
  69. format: (i) => {
  70. let data = that.isuseList.find((f) => f.value == i);
  71. if (data) return data.label;
  72. else return '暂无';
  73. },
  74. },
  75. { label: '排序', model: 'sort' },
  76. ],
  77. list: [],
  78. total: 0,
  79. // 查询
  80. searchForm: {},
  81. // 是否开启
  82. isuseList: [],
  83. id: '',
  84. // type: '',
  85. act_typeList: [],
  86. };
  87. },
  88. async created() {
  89. await this.searchOther();
  90. await this.search();
  91. },
  92. methods: {
  93. ...dictData({ dictQuery: 'query' }),
  94. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  95. // 查询
  96. async search({ skip = 0, limit = this.$limit, ...info } = {}) {
  97. const condition = _.cloneDeep(this.searchForm);
  98. let res = await this.query({ skip, limit, ...condition, ...info });
  99. if (this.$checkRes(res)) {
  100. this.$set(this, 'list', res.data);
  101. this.$set(this, 'total', res.total);
  102. }
  103. },
  104. // 新增
  105. toAdd() {
  106. let id = '';
  107. this.$set(this, `id`, id);
  108. this.$set(this, `view`, 'info');
  109. },
  110. // 修改
  111. async toEdit({ data }) {
  112. this.$set(this, `id`, data.id);
  113. this.$set(this, `view`, 'info');
  114. },
  115. toBack() {
  116. this.view = 'list';
  117. },
  118. // 商品管理
  119. async toManage({ data }) {
  120. this.$router.push({ path: './act/parts/goods', query: { id: data.id, type: data.type } });
  121. },
  122. // 删除
  123. async toDel({ data }) {
  124. let res = await this.delete(data._id);
  125. if (this.$checkRes(res)) {
  126. this.$message({ type: `success`, message: `刪除信息成功` });
  127. this.search();
  128. }
  129. },
  130. // 重置
  131. toClose() {
  132. this.searchForm = {};
  133. this.search();
  134. },
  135. // 查询其他信息
  136. async searchOther() {
  137. let res;
  138. // 是否使用
  139. res = await this.dictQuery({ code: 'use' });
  140. if (this.$checkRes(res)) {
  141. this.$set(this, `isuseList`, res.data);
  142. }
  143. // 活动类型
  144. res = await this.dictQuery({ code: 'act_type' });
  145. if (this.$checkRes(res)) {
  146. this.$set(this, `act_typeList`, res.data);
  147. }
  148. },
  149. },
  150. computed: {
  151. ...mapState(['user']),
  152. },
  153. metaInfo() {
  154. return { title: this.$route.meta.title };
  155. },
  156. watch: {
  157. test: {
  158. deep: true,
  159. immediate: true,
  160. handler(val) {},
  161. },
  162. },
  163. };
  164. </script>
  165. <style lang="less" scoped>
  166. .main {
  167. .one {
  168. margin: 0 0 10px 0;
  169. span:nth-child(1) {
  170. font-size: 20px;
  171. font-weight: 700;
  172. margin-right: 10px;
  173. }
  174. }
  175. .two {
  176. margin: 0 0 10px 0;
  177. }
  178. .thr {
  179. margin: 0 0 10px 0;
  180. }
  181. }
  182. </style>