diff --git a/src/api/mall/product/spu.ts b/src/api/mall/product/spu.ts index 0cf20df9..be681f36 100644 --- a/src/api/mall/product/spu.ts +++ b/src/api/mall/product/spu.ts @@ -1,6 +1,6 @@ import request from '@/config/axios' import { useUserStore } from '@/store/modules/user'; -const UserVO = useUserStore(); + export interface Property { propertyId?: number // 属性编号 propertyName?: string // 属性名称 @@ -59,14 +59,14 @@ export interface Spu { stock?: number // 商品库存 createTime?: Date // 商品创建时间 status?: number // 商品状态 + types?: number // 商品类型 } // 获得 Spu 列表 export const getSpuPage = (params: PageParam) => { // /product/spu/page return request.get({ url: '/product/spu/pageWithCreator',params:{ - ...params, - creator:UserVO.user.id + ...params }}) } diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index d112713e..ad96fc2f 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -345,6 +345,7 @@ const remainingRouter: AppRouteRecordRaw[] = [ } ] }, + { path: '/mall/product', // 商品中心 component: Layout, @@ -353,6 +354,45 @@ const remainingRouter: AppRouteRecordRaw[] = [ hidden: true }, children: [ + { + path: 'containergoods/add', + component: () => import('@/views/mall/product/containergoods/form/index.vue'), + name: 'ProductPickupAdd', + meta: { + noCache: false, // 需要缓存 + hidden: true, + canTo: true, + icon: 'ep:edit', + title: '商品添加', + activeMenu: '/mall/product/containergoods' + } + }, + { + path: 'spu/edit/:id(\\d+)', + component: () => import('@/views/mall/product/containergoods/form/index.vue'), + name: 'ProductPickupEdit', + meta: { + noCache: true, + hidden: true, + canTo: true, + icon: 'ep:edit', + title: '商品编辑', + activeMenu: '/mall/product/containergoods' + } + }, + { + path: 'spu/detail/:id(\\d+)', + component: () => import('@/views/mall/product/containergoods/form/index.vue'), + name: 'ProductPickupDetail', + meta: { + noCache: true, + hidden: true, + canTo: true, + icon: 'ep:view', + title: '商品详情', + activeMenu: '/mall/product/containergoods' + } + }, { path: 'spu/add', component: () => import('@/views/mall/product/spu/form/index.vue'), diff --git a/src/views/mall/product/containergoods/components/SkuList.vue b/src/views/mall/product/containergoods/components/SkuList.vue new file mode 100644 index 00000000..2ffb37d0 --- /dev/null +++ b/src/views/mall/product/containergoods/components/SkuList.vue @@ -0,0 +1,576 @@ + + diff --git a/src/views/mall/product/containergoods/components/SkuTableSelect.vue b/src/views/mall/product/containergoods/components/SkuTableSelect.vue new file mode 100644 index 00000000..307208c6 --- /dev/null +++ b/src/views/mall/product/containergoods/components/SkuTableSelect.vue @@ -0,0 +1,95 @@ + + + diff --git a/src/views/mall/product/containergoods/components/SpuShowcase.vue b/src/views/mall/product/containergoods/components/SpuShowcase.vue new file mode 100644 index 00000000..b8527e05 --- /dev/null +++ b/src/views/mall/product/containergoods/components/SpuShowcase.vue @@ -0,0 +1,144 @@ + + + + diff --git a/src/views/mall/product/containergoods/components/SpuTableSelect.vue b/src/views/mall/product/containergoods/components/SpuTableSelect.vue new file mode 100644 index 00000000..4775e117 --- /dev/null +++ b/src/views/mall/product/containergoods/components/SpuTableSelect.vue @@ -0,0 +1,303 @@ + + + diff --git a/src/views/mall/product/containergoods/components/index.ts b/src/views/mall/product/containergoods/components/index.ts new file mode 100644 index 00000000..e2cbe73d --- /dev/null +++ b/src/views/mall/product/containergoods/components/index.ts @@ -0,0 +1,54 @@ +import SkuList from './SkuList.vue' +import { Spu } from '@/api/mall/product/spu' + +interface PropertyAndValues { + id: number + name: string + values?: PropertyAndValues[] +} + +interface RuleConfig { + // 需要校验的字段 + // 例:name: 'name' 则表示校验 sku.name 的值 + // 例:name: 'productConfig.stock' 则表示校验 sku.productConfig.name 的值,此处 productConfig 表示我在 Sku 上扩展的属性 + name: string + // 校验规格为一个毁掉函数,其中 arg 为需要校验的字段的值。 + // 例:需要校验价格必须大于0.01 + // { + // name:'price', + // rule:(arg: number) => arg > 0.01 + // } + rule: (arg: any) => boolean + // 校验不通过时的消息提示 + message: string +} + +/** + * 获得商品的规格列表 - 商品相关的公共函数 + * + * @param spu + * @return PropertyAndValues 规格列表 + */ +const getPropertyList = (spu: Spu): PropertyAndValues[] => { + // 直接拿返回的 skus 属性逆向生成出 propertyList + const properties: PropertyAndValues[] = [] + // 只有是多规格才处理 + if (spu.specType) { + spu.skus?.forEach((sku) => { + sku.properties?.forEach(({ propertyId, propertyName, valueId, valueName }) => { + // 添加属性 + if (!properties?.some((item) => item.id === propertyId)) { + properties.push({ id: propertyId!, name: propertyName!, values: [] }) + } + // 添加属性值 + const index = properties?.findIndex((item) => item.id === propertyId) + if (!properties[index].values?.some((value) => value.id === valueId)) { + properties[index].values?.push({ id: valueId!, name: valueName! }) + } + }) + }) + } + return properties +} + +export { SkuList, PropertyAndValues, RuleConfig, getPropertyList } diff --git a/src/views/mall/product/containergoods/form/DeliveryForm.vue b/src/views/mall/product/containergoods/form/DeliveryForm.vue new file mode 100644 index 00000000..6800d237 --- /dev/null +++ b/src/views/mall/product/containergoods/form/DeliveryForm.vue @@ -0,0 +1,96 @@ + + + diff --git a/src/views/mall/product/containergoods/form/DescriptionForm.vue b/src/views/mall/product/containergoods/form/DescriptionForm.vue new file mode 100644 index 00000000..2980aa46 --- /dev/null +++ b/src/views/mall/product/containergoods/form/DescriptionForm.vue @@ -0,0 +1,81 @@ + + + diff --git a/src/views/mall/product/containergoods/form/InfoForm.vue b/src/views/mall/product/containergoods/form/InfoForm.vue new file mode 100644 index 00000000..28bd309b --- /dev/null +++ b/src/views/mall/product/containergoods/form/InfoForm.vue @@ -0,0 +1,142 @@ + + + diff --git a/src/views/mall/product/containergoods/form/OtherForm.vue b/src/views/mall/product/containergoods/form/OtherForm.vue new file mode 100644 index 00000000..e7e63580 --- /dev/null +++ b/src/views/mall/product/containergoods/form/OtherForm.vue @@ -0,0 +1,91 @@ + + + diff --git a/src/views/mall/product/containergoods/form/ProductAttributes.vue b/src/views/mall/product/containergoods/form/ProductAttributes.vue new file mode 100644 index 00000000..1bb24ffe --- /dev/null +++ b/src/views/mall/product/containergoods/form/ProductAttributes.vue @@ -0,0 +1,162 @@ + + + + diff --git a/src/views/mall/product/containergoods/form/ProductPropertyAddForm.vue b/src/views/mall/product/containergoods/form/ProductPropertyAddForm.vue new file mode 100644 index 00000000..f45281b1 --- /dev/null +++ b/src/views/mall/product/containergoods/form/ProductPropertyAddForm.vue @@ -0,0 +1,148 @@ + + + diff --git a/src/views/mall/product/containergoods/form/SkuForm.vue b/src/views/mall/product/containergoods/form/SkuForm.vue new file mode 100644 index 00000000..18cd0296 --- /dev/null +++ b/src/views/mall/product/containergoods/form/SkuForm.vue @@ -0,0 +1,194 @@ + + + diff --git a/src/views/mall/product/containergoods/form/index.vue b/src/views/mall/product/containergoods/form/index.vue new file mode 100644 index 00000000..62f796db --- /dev/null +++ b/src/views/mall/product/containergoods/form/index.vue @@ -0,0 +1,205 @@ + + diff --git a/src/views/mall/product/containergoods/index.vue b/src/views/mall/product/containergoods/index.vue new file mode 100644 index 00000000..fbacbb45 --- /dev/null +++ b/src/views/mall/product/containergoods/index.vue @@ -0,0 +1,458 @@ + + + + diff --git a/src/views/mall/product/spu/form/index.vue b/src/views/mall/product/spu/form/index.vue index c4e4b7b2..53289b0a 100644 --- a/src/views/mall/product/spu/form/index.vue +++ b/src/views/mall/product/spu/form/index.vue @@ -174,7 +174,8 @@ const submitForm = async () => { // 如果是前端选的图 typeof item === 'object' ? newSliderPicUrls.push(item.url) : newSliderPicUrls.push(item) }) - deepCopyFormData.sliderPicUrls = newSliderPicUrls + deepCopyFormData.sliderPicUrls = newSliderPicUrls; + deepCopyFormData.types = 0; // 校验都通过后提交表单 const data = deepCopyFormData as ProductSpuApi.Spu const id = params.id as unknown as number diff --git a/src/views/mall/product/spu/index.vue b/src/views/mall/product/spu/index.vue index e12403ce..38dab192 100644 --- a/src/views/mall/product/spu/index.vue +++ b/src/views/mall/product/spu/index.vue @@ -287,7 +287,8 @@ const queryParams = ref({ tabType: 0, name: '', categoryId: undefined, - createTime: undefined + createTime: undefined, + types:0 }) // 查询参数 const queryFormRef = ref() // 搜索的表单Ref