2023-04-24 11:42:44 +08:00
|
|
|
|
import BasicInfoForm from './BasicInfoForm.vue'
|
|
|
|
|
import DescriptionForm from './DescriptionForm.vue'
|
|
|
|
|
import OtherSettingsForm from './OtherSettingsForm.vue'
|
2023-05-01 19:01:24 +08:00
|
|
|
|
import ProductAttributes from './ProductAttributes.vue'
|
2023-06-06 16:22:58 +08:00
|
|
|
|
import ProductPropertyAddForm from './ProductPropertyAddForm.vue'
|
2023-05-01 19:01:24 +08:00
|
|
|
|
import SkuList from './SkuList.vue'
|
2023-04-24 11:42:44 +08:00
|
|
|
|
|
2023-06-24 01:48:07 +08:00
|
|
|
|
import { Spu } from '@/api/mall/product/spu'
|
|
|
|
|
|
2023-07-02 21:46:04 +08:00
|
|
|
|
// TODO @puhui999:Properties 改成 Property 更合适?
|
2023-06-24 01:48:07 +08:00
|
|
|
|
interface Properties {
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
|
|
|
|
values?: Properties[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface RuleConfig {
|
2023-06-25 16:43:49 +08:00
|
|
|
|
// 需要校验的字段
|
|
|
|
|
// 例:name: 'name' 则表示校验 sku.name 的值
|
|
|
|
|
// 例:name: 'productConfig.stock' 则表示校验 sku.productConfig.name 的值,此处 productConfig 表示我在 Sku 上扩展的属性
|
|
|
|
|
name: string
|
|
|
|
|
// 校验规格为一个毁掉函数,其中 arg 为需要校验的字段的值。
|
|
|
|
|
// 例:需要校验价格必须大于0.01
|
|
|
|
|
// {
|
|
|
|
|
// name:'price',
|
|
|
|
|
// rule:(arg) => arg > 0.01
|
|
|
|
|
// }
|
|
|
|
|
rule: (arg: any) => boolean
|
|
|
|
|
// 校验不通过时的消息提示
|
|
|
|
|
message: string
|
2023-06-24 01:48:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-07-02 21:46:04 +08:00
|
|
|
|
* 获得商品的规格列表
|
|
|
|
|
*
|
2023-06-24 01:48:07 +08:00
|
|
|
|
* @param spu
|
2023-07-02 21:46:04 +08:00
|
|
|
|
* @return Property 规格列表
|
2023-06-24 01:48:07 +08:00
|
|
|
|
*/
|
|
|
|
|
const getPropertyList = (spu: Spu): Properties[] => {
|
|
|
|
|
// 直接拿返回的 skus 属性逆向生成出 propertyList
|
|
|
|
|
const properties: Properties[] = []
|
|
|
|
|
// 只有是多规格才处理
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-01 19:01:24 +08:00
|
|
|
|
export {
|
|
|
|
|
BasicInfoForm,
|
|
|
|
|
DescriptionForm,
|
|
|
|
|
OtherSettingsForm,
|
|
|
|
|
ProductAttributes,
|
2023-06-06 16:22:58 +08:00
|
|
|
|
ProductPropertyAddForm,
|
2023-06-24 01:48:07 +08:00
|
|
|
|
SkuList,
|
|
|
|
|
getPropertyList,
|
|
|
|
|
Properties,
|
|
|
|
|
RuleConfig
|
2023-05-01 19:01:24 +08:00
|
|
|
|
}
|