diff --git a/src/api/shop/goods/model/index.ts b/src/api/shop/goods/model/index.ts index c3d6839..07392a1 100644 --- a/src/api/shop/goods/model/index.ts +++ b/src/api/shop/goods/model/index.ts @@ -80,6 +80,8 @@ export interface Goods { goodsSpecs?: GoodsSpec[]; // 商品sku列表 goodsSkus?: GoodsSku[]; + // 单位名称 + unitName?: string; } export interface BathSet { diff --git a/src/api/shop/goodsSku/index.ts b/src/api/shop/goodsSku/index.ts index caa6df2..d7c88ba 100644 --- a/src/api/shop/goodsSku/index.ts +++ b/src/api/shop/goodsSku/index.ts @@ -2,6 +2,18 @@ import request from '@/utils/request'; import type { ApiResult, PageResult } from '@/api'; import type { GoodsSku, GoodsSkuParam } from './model'; import { MODULES_API_URL } from '@/config/setting'; +import { GoodsSpec } from '@/api/shop/goodsSpec/model'; + +export async function generateGoodsSku(data: GoodsSpec) { + const res = await request.post>( + MODULES_API_URL + '/shop/goods-sku/generateGoodsSku', + data + ); + if (res.data.code === 0) { + return res.data.data; + } + return Promise.reject(new Error(res.data.message)); +} /** * 分页查询商品sku列表 diff --git a/src/api/shop/goodsSku/model/index.ts b/src/api/shop/goodsSku/model/index.ts index c0a2266..6c4a1d6 100644 --- a/src/api/shop/goodsSku/model/index.ts +++ b/src/api/shop/goodsSku/model/index.ts @@ -10,24 +10,24 @@ export interface GoodsSku { goodsId?: number; // 规格组ID specId?: number; - // 规格值ID - specValueId?: number; - // 规格值0 - specValue0?: string; - // 规格值1 - specValue1?: string; - // 规格值2 - specValue2?: string; // 商品图片 image?: string; // 商品价格 price?: string; // 市场价格 salePrice?: string; + // 成本价 + cost?: string; // 库存 stock?: number; // sku编码 skuNo?: string; + // 唯一值 + unique?: string; + // 重量 + weight?: string; + // 体积 + volume?: string; // 状态, 0正常, 1异常 status?: number; // 备注 @@ -37,6 +37,7 @@ export interface GoodsSku { // 创建时间 createTime?: string; images?: any; + sku?: string; } /** @@ -44,5 +45,6 @@ export interface GoodsSku { */ export interface GoodsSkuParam extends PageParam { id?: number; + goodsId?: number; keywords?: string; } diff --git a/src/views/shop/goods/components/goodsEdit.vue b/src/views/shop/goods/components/goodsEdit.vue index 443cbaa..805812a 100644 --- a/src/views/shop/goods/components/goodsEdit.vue +++ b/src/views/shop/goods/components/goodsEdit.vue @@ -206,7 +206,7 @@ - +
([]); const showSpecForm = ref(false); const name = ref(); const value = ref(); - const skuList = ref([{images: []}]); + const skuList = ref([]); const fileList = ref([]); const files = ref([]); const goodsSpec = ref(); @@ -419,6 +417,7 @@ goodsName: undefined, image: undefined, content: undefined, + unitName: '', categoryId: undefined, categoryParent: undefined, categoryChildren: undefined, @@ -468,9 +467,15 @@ files: [ { required: true, - message: '请上传图片', + message: '请上传轮播图', type: 'string', - trigger: 'blur' + trigger: 'blur', + validator: async (_rule: RuleObject, value: string) => { + if (form.files?.length == 0) { + return Promise.reject('选择上传轮播图'); + } + return Promise.resolve(); + } } ], specs: [ @@ -576,11 +581,15 @@ images.value.splice(index, 1); }; - const onChange = () => { - // reload(); + const onChange = (text: string) => { + // 加载商品多规格 + if(text == 'spec'){ + listGoodsSku({goodsId: props.data?.goodsId}).then(data => { + skuList.value = data; + }) + } }; - const onDeleteItem = (index: number) => { images.value.splice(index, 1); form.image = ''; @@ -634,6 +643,16 @@ files.value.splice(index, 1); }; + /** + * 生成商品SKU列表 + */ + const generateSku = () => { + generateGoodsSku(spec.value).then(data => { + if(data){ + skuList.value = data; + } + }) + } const editorRef = ref | null>(null); const config = ref({ @@ -698,7 +717,7 @@ ...form, content: content.value, files: JSON.stringify(fileList.value), - goodsSpecs: goodsSpec.value, + goodsSpec: goodsSpec.value, goodsSkus: skuList.value }; const saveOrUpdate = isUpdate.value ? updateGoods : addGoods; @@ -722,6 +741,8 @@ (visible) => { if (visible) { images.value = []; + files.value = []; + category.value = []; if (props.data) { assignObject(form, props.data); if (props.data.image) { @@ -731,6 +752,16 @@ status: 'done' }); } + if(props.data.files){ + const arr = JSON.parse(props.data.files); + arr.map((img) => { + files.value.push({ + uid: uuid(), + url: img, + status: 'done' + }); + }); + } if(props.data.goodsSpecs){ goodsSpec.value = props.data.goodsSpecs[0]; if(props.data.specs == 1){ @@ -748,6 +779,16 @@ return d; }); } + // 商品分类 + if(props.data.categoryParent){ + category.value.push(props.data.categoryParent); + } + if(props.data.categoryChildren){ + category.value.push(props.data.categoryChildren); + } + if (props.data.content){ + content.value = props.data.content; + } isUpdate.value = true; } else { diff --git a/src/views/shop/goodsSku/components/goodsSkuEdit.vue b/src/views/shop/goodsSku/components/goodsSkuEdit.vue index 9c5f9b8..92c61f6 100644 --- a/src/views/shop/goodsSku/components/goodsSkuEdit.vue +++ b/src/views/shop/goodsSku/components/goodsSkuEdit.vue @@ -19,15 +19,94 @@ styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' } " > - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 显示 + 隐藏 + + + - - - - - - 显示 - 隐藏 - - @@ -57,12 +121,14 @@