Merge remote-tracking branch 'origin/master-vue3' into master-vue3

# Conflicts:
#	sheep/components/s-wallet-card/s-wallet-card.vue
This commit is contained in:
owen
2023-12-09 23:00:11 +08:00
3 changed files with 77 additions and 30 deletions
+44
View File
@@ -156,3 +156,47 @@ function getDayjsTime(time) {
return dayjs.unix(parseInt(time));
}
}
/**
* 从商品 SKU 数组中,转换出商品属性的数组
*
* 类似结构:[{
* id: // 属性的编号
* name: // 属性的名字
* values: [{
* id: // 属性值的编号
* name: // 属性值的名字
* }]
* }]
*
* @param skus 商品 SKU 数组
*/
export function convertProductPropertyList(skus) {
let result = [];
for (const sku of skus) {
if (!sku.properties) {
continue
}
for (const property of sku.properties) {
// ① 先处理属性
let resultProperty = result.find(item => item.id === property.propertyId)
if (!resultProperty) {
resultProperty = {
id: property.propertyId,
name: property.propertyName,
values: []
}
result.push(resultProperty)
}
// ② 再处理属性值
let resultValue = resultProperty.values.find(item => item.id === property.valueId)
if (!resultValue) {
resultProperty.values.push({
id: property.valueId,
name: property.valueName
})
}
}
}
return result;
}