index.vue 5.1 KB

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