mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-08-13 09:31:53 +08:00
code review
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import SkuList from './SkuList.vue'
|
||||
import { Spu } from '@/api/mall/product/spu'
|
||||
|
||||
interface PropertyAndValues {
|
||||
id: number
|
||||
@@ -22,4 +23,32 @@ interface RuleConfig {
|
||||
message: string
|
||||
}
|
||||
|
||||
export { SkuList, PropertyAndValues, RuleConfig }
|
||||
/**
|
||||
* 获得商品的规格列表
|
||||
*
|
||||
* @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, getPropertyList, PropertyAndValues, RuleConfig }
|
||||
|
Reference in New Issue
Block a user