index.vue 5.6 KB

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