From d04facca0b6ee81db216d3eef6ff1adcbe467c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Fri, 15 Apr 2022 15:56:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B4=BB=E5=8A=A8=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=AE=B5CURD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{limit.js => limit/limitActivity.js} | 7 ++ src/api/operation/limit/limitTime.js | 36 ++++++++++ src/components/TableList.vue | 2 +- .../modules/operation/limit/limitActivity.js | 12 +++- .../modules/operation/limit/limitTime.js | 17 ++--- src/views/operation/limit/index.vue | 2 +- src/views/operation/limit/time.vue | 65 ++++++++++++------- 7 files changed, 107 insertions(+), 34 deletions(-) rename src/api/operation/{limit.js => limit/limitActivity.js} (82%) create mode 100644 src/api/operation/limit/limitTime.js diff --git a/src/api/operation/limit.js b/src/api/operation/limit/limitActivity.js similarity index 82% rename from src/api/operation/limit.js rename to src/api/operation/limit/limitActivity.js index b862336..f722d6a 100644 --- a/src/api/operation/limit.js +++ b/src/api/operation/limit/limitActivity.js @@ -26,6 +26,13 @@ export const update = (data) => { data, }); }; +export const online = (params) => { + return request({ + url: '/mall/marketing/activity/online/' + params.id, + method: 'put', + params, + }); +}; export const remove = (idList) => { return request({ url: '/mall/marketing/activity', diff --git a/src/api/operation/limit/limitTime.js b/src/api/operation/limit/limitTime.js new file mode 100644 index 0000000..bc56bcb --- /dev/null +++ b/src/api/operation/limit/limitTime.js @@ -0,0 +1,36 @@ +import request from '@/utils/request.js'; +export const search = (params) => { + return request({ + url: '/mall/marketing/activityTime', + method: 'get', + params, + }); +}; +export const create = (data) => { + return request({ + url: '/mall/marketing/activityTime', + method: 'post', + data, + }); +}; +export const update = (data) => { + return request({ + url: '/mall/marketing/activityTime/' + data.id, + method: 'put', + data, + }); +}; +export const enable = (params) => { + return request({ + url: '/mall/marketing/activityTime/enable/' + params.id, + method: 'put', + params, + }); +}; +export const remove = (idList) => { + return request({ + url: '/mall/marketing/activityTime', + method: 'delete', + params: { idList }, + }); +}; diff --git a/src/components/TableList.vue b/src/components/TableList.vue index 9b30fe3..4ef8ccd 100644 --- a/src/components/TableList.vue +++ b/src/components/TableList.vue @@ -300,7 +300,7 @@ } handleSearch(); }, - { deep: true, immediate: props.config.autoSearch !== false } + { deep: true, immediate: props.config.autoSearch === true } ); // 代理原生函数 const handleProxy = (fnName, args) => { diff --git a/src/store/modules/operation/limit/limitActivity.js b/src/store/modules/operation/limit/limitActivity.js index f9e9d0a..6c29d31 100644 --- a/src/store/modules/operation/limit/limitActivity.js +++ b/src/store/modules/operation/limit/limitActivity.js @@ -1,4 +1,4 @@ -import * as api from '@/api/operation/limit.js'; +import * as api from '@/api/operation/limit/limitActivity.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ code: 'LimitActivity', @@ -48,6 +48,16 @@ const actions = { } return res; }, + online: async ({ dispatch }, data) => { + let res = await api.online({ id: data.id, isOnline: data.isOnline }); + if (res) { + ElMessage.success('保存成功'); + dispatch('search'); + } else { + ElMessage.error('保存失败'); + } + return res; + }, save: async ({ dispatch }, data) => { let save = data.id ? api.update : api.create; data = _.cloneDeep(data); diff --git a/src/store/modules/operation/limit/limitTime.js b/src/store/modules/operation/limit/limitTime.js index 8503473..bc8483a 100644 --- a/src/store/modules/operation/limit/limitTime.js +++ b/src/store/modules/operation/limit/limitTime.js @@ -1,4 +1,4 @@ -import * as api from '@/api/sales/category.js'; +import * as api from '@/api/operation/limit/limitTime.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ code: 'LimitTime', @@ -25,11 +25,11 @@ const mutations = { setOpts: (state, data) => (state.opts = data), }; const actions = { - search: async ({ state, commit }) => { + search: async ({ commit, state }) => { let res = await api.search(state.condition); commit('setList', res); if (!res) { - ElMessage.error('查询商品分类列表失败'); + ElMessage.error('查询活动时间段列表失败'); } return res; }, @@ -60,12 +60,13 @@ const actions = { } return res; }, - sort: async (context, data) => { - let res = await api.sort(data); + enable: async ({ dispatch }, data) => { + let res = await api.enable({ id: data.id, isEnable: data.isEnable }); if (res) { - ElMessage.success(`移动前序号:${data.oldSort + 1};移动后序号:${data.currentSort + 1}`); + ElMessage.success('保存成功'); + dispatch('search'); } else { - ElMessage.error('保存排序失败'); + ElMessage.error('保存失败'); } return res; }, @@ -75,7 +76,7 @@ const actions = { } else { try { await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); - let res = await api.remove({ id: ids.join(',') }); + let res = await api.remove(ids.join(',')); if (res) { ElMessage.success('删除成功'); dispatch('search'); diff --git a/src/views/operation/limit/index.vue b/src/views/operation/limit/index.vue index 6b9d3cb..4ce2db7 100644 --- a/src/views/operation/limit/index.vue +++ b/src/views/operation/limit/index.vue @@ -136,7 +136,7 @@ // 上下架 const handleEnable = async (row) => { loading.value = true; - await store.dispatch('limitActivity/save', row); + await store.dispatch('limitActivity/online', row); loading.value = false; }; // 删除 diff --git a/src/views/operation/limit/time.vue b/src/views/operation/limit/time.vue index 197a3e3..674e865 100644 --- a/src/views/operation/limit/time.vue +++ b/src/views/operation/limit/time.vue @@ -37,21 +37,12 @@ /* 列表查询 */ const state = reactive({ condition: { - name: null, - status: null, + activityId: route.params.id, }, }); - watch( - () => state.condition, - (value) => { - store.commit('limitTime/setCondition', _.cloneDeep(value)); - }, - { immediate: true, deep: true } - ); const handleReset = () => { state.condition = { - name: null, - status: null, + activityId: route.params.id, }; }; const handleSearch = async () => { @@ -59,13 +50,26 @@ await store.dispatch('limitTime/search'); loading.value = false; }; + onActivated(() => { + if (state.condition.activityId !== route.params.id) { + handleReset(); + } + }); + watch( + () => state.condition, + (value) => { + store.commit('limitTime/setCondition', _.cloneDeep(value)); + handleSearch(); + }, + { immediate: true, deep: true } + ); /* 操作 */ // 新增 const handleCreate = () => { store.commit('limitTime/setList', [ ...unref(list), - { edit: true, name: null, startTime: null, endTime: null, enabled: true }, + { edit: true, timeName: null, startTime: null, endTime: null, isEnable: true, activityId: route.params.id }, ]); }; // 设置商品 @@ -73,11 +77,18 @@ router.push({ name: 'UpdateLimitProduct', params: { id: route.params.id } }); }; // 启用 - const handleEnable = (row, value) => { - row.enabled = value; + const handleEnable = async (row) => { + if (row.id) { + loading.value = true; + await store.dispatch('limitTime/enable', row); + loading.value = false; + } }; // 编辑 const handleUpdate = (row) => { + if (row.edit) { + store.dispatch('limitTime/save', row); + } row.edit = !row.edit; }; // 删除 @@ -96,30 +107,30 @@ label: '秒杀时段名称', minWidth: 160, slots: { - default: ({ row }) => (row.edit ? : row.name), + default: ({ row }) => (row.edit ? : row.timeName), }, }, { label: '开始时间', width: 160, slots: { - default: ({ row }) => (row.edit ? : row.startTime), + default: ({ row }) => + row.edit ? : row.startTime, }, }, { - label: '活动状态', + label: '结束时间', width: 160, slots: { - default: ({ row }) => (row.edit ? : row.endTime), + default: ({ row }) => + row.edit ? : row.endTime, }, }, { label: '启用', width: 100, slots: { - default: ({ row }) => ( - handleEnable(row, enabled)} /> - ), + default: ({ row }) => handleEnable(row)} />, }, }, { @@ -129,10 +140,18 @@ slots: { default: ({ row }) => (
- handleUpdate(row)}> + handleUpdate(row)} + > {row.edit ? '保存' : '编辑'} - handleRemove([row])}> + handleRemove([row])} + > 删除