From 4c4e1972de4febd8b22ba0f27e1bd4158ff2513f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Sun, 24 Apr 2022 14:46:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=95=86=E5=93=81SKU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.test | 2 +- src/api/sales/product.js | 4 +- .../operation/recommend/recommendProduct.js | 3 +- src/store/modules/sales/productAttrsGroup.js | 2 +- src/store/modules/sales/productAttrsValue.js | 49 ++++++++ src/store/modules/sales/productPicker.js | 16 +-- src/views/global/login.vue | 2 + src/views/operation/limit/index.vue | 13 +- src/views/operation/limit/product.vue | 15 ++- src/views/operation/recommend/index.vue | 4 +- src/views/sales/product/form/step2.vue | 114 +++++++++--------- src/views/sales/product/picker.vue | 15 ++- vite.config.js | 2 +- 13 files changed, 156 insertions(+), 85 deletions(-) create mode 100644 src/store/modules/sales/productAttrsValue.js diff --git a/.env.test b/.env.test index 4204265..2e0cf99 100644 --- a/.env.test +++ b/.env.test @@ -1,2 +1,2 @@ -VITE_BASE_URL=http://k8s-horse-gateway.mashibing.cn/ +VITE_BASE_URL=https://k8s-horse-gateway.mashibing.cn/ VITE_REQUEST_TIMEOUT=20000 diff --git a/src/api/sales/product.js b/src/api/sales/product.js index fffc06c..733af3a 100644 --- a/src/api/sales/product.js +++ b/src/api/sales/product.js @@ -50,7 +50,7 @@ export const createAttrs = (data) => { export const updateAttrs = (data) => { return request({ url: '/mall/product/admin/productAttributeGroup/' + data.id, - method: 'post', + method: 'put', data, }); }; @@ -78,7 +78,7 @@ export const createAttrsValue = (data) => { export const updateAttrsValue = (data) => { return request({ url: '/mall/product/admin/productAttribute/' + data.id, - method: 'post', + method: 'put', data, }); }; diff --git a/src/store/modules/operation/recommend/recommendProduct.js b/src/store/modules/operation/recommend/recommendProduct.js index 069e09f..283ed14 100644 --- a/src/store/modules/operation/recommend/recommendProduct.js +++ b/src/store/modules/operation/recommend/recommendProduct.js @@ -51,8 +51,7 @@ const actions = { return res; }, save: async ({ dispatch }, data) => { - let save = data.id ? api.update : api.create; - let res = await save(data); + let res = await api.create(data); if (res) { ElMessage.success('保存成功'); dispatch('search'); diff --git a/src/store/modules/sales/productAttrsGroup.js b/src/store/modules/sales/productAttrsGroup.js index 85be335..fdf24d9 100644 --- a/src/store/modules/sales/productAttrsGroup.js +++ b/src/store/modules/sales/productAttrsGroup.js @@ -28,7 +28,7 @@ const actions = { } else { try { await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); - let res = await api.remove({ id: ids.join(',') }); + let res = await api.removeAttrs({ id: ids.join(',') }); if (res) { ElMessage.success('删除成功'); dispatch('search'); diff --git a/src/store/modules/sales/productAttrsValue.js b/src/store/modules/sales/productAttrsValue.js new file mode 100644 index 0000000..605bbb5 --- /dev/null +++ b/src/store/modules/sales/productAttrsValue.js @@ -0,0 +1,49 @@ +import * as api from '@/api/sales/product.js'; +import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; +const state = () => ({}); +const getters = {}; +const mutations = {}; +const actions = { + search: async (context, id) => { + let res = await api.searchAttrsValue(id); + if (!res) { + ElMessage.error('查询商品属性分组列表失败'); + } + return res || []; + }, + save: async ({ dispatch }, data) => { + let save = data.id ? api.updateAttrsValue : api.createAttrsValue; + let res = await save(data); + if (res) { + ElMessage.success('保存成功'); + dispatch('search'); + } else { + ElMessage.error('保存失败'); + } + return res; + }, + remove: async ({ dispatch }, ids) => { + if (!ids.length) { + ElMessage.warning('请选择要删除的数据'); + } else { + try { + await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); + let res = await api.removeAttrsValue({ id: ids.join(',') }); + if (res) { + ElMessage.success('删除成功'); + dispatch('search'); + } else { + ElMessage.error('删除失败'); + } + } catch (e) { + console.info('取消删除', e); + } + } + }, +}; +export default { + state, + getters, + mutations, + actions, +}; diff --git a/src/store/modules/sales/productPicker.js b/src/store/modules/sales/productPicker.js index 4e10d31..8ce277a 100644 --- a/src/store/modules/sales/productPicker.js +++ b/src/store/modules/sales/productPicker.js @@ -1,10 +1,9 @@ -import * as api from '@/api/sales/category.js'; +import * as categoryAPI from '@/api/sales/category.js'; +import * as api from '@/api/sales/product.js'; import { ElMessage } from '@/plugins/element-plus'; const state = () => ({ code: 'ProductPicker', - condition: { - orderIs: [], - }, + condition: {}, list: [], total: 0, summary: [], @@ -23,9 +22,10 @@ const mutations = { setOpts: (state, data) => (state.opts = data), }; const actions = { - search: async ({ state, commit }) => { - let res = await api.search(state.condition); - commit('setList', res); + search: async ({ state, commit, rootGetters }) => { + let res = await api.search({ ...rootGetters['local/page'](state.code), ...state.condition }); + commit('setList', res?.records || []); + commit('setTotal', res?.total || 0); if (!res) { ElMessage.error('查询商品列表失败'); } @@ -35,7 +35,7 @@ const actions = { commit('setOpts', { ...state.opts, init: true, - category: await api.search(), + category: await categoryAPI.search({ pageIndex: 1, length: 9999 }), }); }, }; diff --git a/src/views/global/login.vue b/src/views/global/login.vue index 326a9a2..83cfd3b 100644 --- a/src/views/global/login.vue +++ b/src/views/global/login.vue @@ -52,6 +52,8 @@ phone: '', password: '', verifyCode: '', + systemId: 1, + clientId: 2, }); const rules = reactive({ diff --git a/src/views/operation/limit/index.vue b/src/views/operation/limit/index.vue index 4ce2db7..9fa1428 100644 --- a/src/views/operation/limit/index.vue +++ b/src/views/operation/limit/index.vue @@ -80,6 +80,7 @@ await store.dispatch('limitActivity/search'); loading.value = false; }; + onActivated(handleSearch); /* 表单 */ const refsForm = ref(null); @@ -191,10 +192,18 @@ slots: { default: ({ row }) => (
- handleUpdateTime(row)}> + handleUpdateTime(row)} + > 设置时段 - handleUpdateProduct(row)}> + handleUpdateProduct(row)} + > 设置商品 handleCreate(row)}> diff --git a/src/views/operation/limit/product.vue b/src/views/operation/limit/product.vue index 8b2b4a8..2e6fdcc 100644 --- a/src/views/operation/limit/product.vue +++ b/src/views/operation/limit/product.vue @@ -33,7 +33,7 @@ - +
@@ -47,9 +47,6 @@ const list = computed(() => store.state.limitProduct.list); const total = computed(() => store.state.limitProduct.total); const opts = computed(() => store.state.limitProduct.opts); - if (!unref(opts).init) { - store.dispatch('limitProduct/load', route.params.id); - } /* 查询订单 */ const state = reactive({ @@ -68,6 +65,7 @@ }; const handleSearch = async () => { loading.value = true; + await store.dispatch('limitProduct/load', route.params.id); await store.dispatch('limitProduct/search'); loading.value = false; }; @@ -92,6 +90,7 @@ }, { deep: true } ); + onActivated(handleSearch); const refsPicker = ref(null); const handleCreate = async () => { @@ -106,6 +105,14 @@ const handleSku = (row) => { console.info(row); }; + const handlePick = async (rows) => { + loading.value = true; + await store.dispatch('limitProduct/save', { + activityTimeId: state.condition.activityTimeId, + productId: rows.map((item) => item.id), + }); + loading.value = false; + }; /* 列表配置 */ const config = reactive({ diff --git a/src/views/operation/recommend/index.vue b/src/views/operation/recommend/index.vue index 83ddeb4..9151e12 100644 --- a/src/views/operation/recommend/index.vue +++ b/src/views/operation/recommend/index.vue @@ -75,7 +75,9 @@ }; // 保存 const handlePick = async (rows) => { - console.info(rows); + loading.value = true; + await store.dispatch('recommendProduct/save', { productIdList: rows.map((item) => item.id) }); + loading.value = false; }; /* 操作 */ diff --git a/src/views/sales/product/form/step2.vue b/src/views/sales/product/form/step2.vue index 25ac74c..d39ef6c 100644 --- a/src/views/sales/product/form/step2.vue +++ b/src/views/sales/product/form/step2.vue @@ -1,70 +1,72 @@