diff --git a/src/api/sales/product.js b/src/api/sales/product.js new file mode 100644 index 0000000..fffc06c --- /dev/null +++ b/src/api/sales/product.js @@ -0,0 +1,91 @@ +import request from '@/utils/request.js'; +export const search = (params) => { + return request({ + url: '/mall/product/admin/product/page', + method: 'get', + params, + }); +}; +export const detail = (id) => { + return request({ + url: '/mall/product/admin/product/' + id, + method: 'get', + }); +}; +export const create = (data) => { + return request({ + url: '/mall/product/admin/product', + method: 'post', + data, + }); +}; +export const update = (data) => { + return request({ + url: '/mall/product/admin/product/' + data.id, + method: 'put', + data, + }); +}; +export const remove = (params) => { + return request({ + url: '/mall/product/admin/product', + method: 'delete', + params, + }); +}; + +export const searchAttrs = (id) => { + return request({ + url: '/mall/product/admin/productAttributeGroup/' + id, + method: 'get', + }); +}; +export const createAttrs = (data) => { + return request({ + url: '/mall/product/admin/productAttributeGroup', + method: 'post', + data, + }); +}; +export const updateAttrs = (data) => { + return request({ + url: '/mall/product/admin/productAttributeGroup/' + data.id, + method: 'post', + data, + }); +}; +export const removeAttrs = (params) => { + return request({ + url: '/mall/product/admin/productAttributeGroup', + method: 'delete', + params, + }); +}; + +export const searchAttrsValue = (id) => { + return request({ + url: '/mall/product/admin/productAttribute/' + id, + method: 'get', + }); +}; +export const createAttrsValue = (data) => { + return request({ + url: '/mall/product/admin/productAttribute', + method: 'post', + data, + }); +}; +export const updateAttrsValue = (data) => { + return request({ + url: '/mall/product/admin/productAttribute/' + data.id, + method: 'post', + data, + }); +}; +export const removeAttrsValue = (params) => { + return request({ + url: '/mall/product/admin/productAttribute', + method: 'delete', + params, + }); +}; diff --git a/src/components/ElEditor.vue b/src/components/ElEditor.vue index f551002..7af2c41 100644 --- a/src/components/ElEditor.vue +++ b/src/components/ElEditor.vue @@ -28,7 +28,7 @@ const editor = ref(null); const options = { bounds: '.el-editor', - debug: 'warn', + debug: 'error', modules: { toolbar: [ ['bold', 'italic', 'underline', 'strike'], @@ -137,7 +137,7 @@ margin-left: 20px; border: 1px solid #d1d5db; &.--app { - width: 320px; + width: 375px; } &.--pc { width: 640px; diff --git a/src/store/modules/sales/product.js b/src/store/modules/sales/product.js index 57d109e..55dd755 100644 --- a/src/store/modules/sales/product.js +++ b/src/store/modules/sales/product.js @@ -1,4 +1,5 @@ -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, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ code: 'ProductManagement', @@ -11,6 +12,24 @@ const state = () => ({ opts: { init: false, category: [], + status: [ + { + label: '全部商品', + value: 0, + }, + { + label: '已上架', + value: 1, + }, + { + label: '未上架', + value: 2, + }, + { + label: '库存紧张', + value: 3, + }, + ], tag: [ { label: '爆款', @@ -53,14 +72,15 @@ const mutations = { setOpts: (state, data) => (state.opts = data), }; const actions = { - search: async ({ state, commit }) => { + search: async ({ state, commit, rootGetters }) => { let data = { ...state.condition }; data.productStatus = (data.productStatus || []).join(','); if (data.productStatus === '0') { delete data.productStatus; } - let res = await api.search(data); - commit('setList', res); + let res = await api.search({ ...rootGetters['local/page'](state.code), ...data }); + commit('setList', res?.records || []); + commit('setTotal', res?.total || 0); if (!res) { ElMessage.error('查询商品列表失败'); } @@ -70,14 +90,11 @@ const actions = { commit('setOpts', { ...state.opts, init: true, - category: await api.search(), + category: await categoryAPI.search(), }); }, - detail: async ({ state, dispatch }, id) => { - if (!state.list.length) { - await dispatch('search'); - } - let res = state.list.find((item) => item.id === id); + detail: async (context, id) => { + let res = await api.detail(id); if (!res) { ElMessage.error('加载详情失败'); } diff --git a/src/store/modules/sales/productAttrsGroup.js b/src/store/modules/sales/productAttrsGroup.js new file mode 100644 index 0000000..85be335 --- /dev/null +++ b/src/store/modules/sales/productAttrsGroup.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.searchAttrs(id); + if (!res) { + ElMessage.error('查询商品属性分组列表失败'); + } + return res || []; + }, + save: async ({ dispatch }, data) => { + let save = data.id ? api.updateAttrs : api.createAttrs; + 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.remove({ 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/views/sales/product/form/step1.vue b/src/views/sales/product/form/step1.vue index 73d05c7..fcac0e8 100644 --- a/src/views/sales/product/form/step1.vue +++ b/src/views/sales/product/form/step1.vue @@ -2,9 +2,9 @@