index.vue 4.7 KB

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