mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-08-23 06:21:54 +08:00
fix: 1、修复营销活动相关页面打不开的问题 2、修复 spu 添加失败的问题 2、重构 spu 的 sku 校验方式为通用配置的方式
This commit is contained in:
@@ -328,24 +328,15 @@ const tableHeaders = ref<{ prop: string; label: string }[]>([]) // 多属性表
|
||||
* 保存时,每个商品规格的表单要校验下。例如说,销售金额最低是 0.01 这种。
|
||||
*/
|
||||
const validateSku = () => {
|
||||
const checks = ['price', 'marketPrice', 'costPrice']
|
||||
let warningInfo = '请检查商品各行相关属性配置,'
|
||||
let validate = true // 默认通过
|
||||
for (const sku of formData.value!.skus!) {
|
||||
// 作为活动组件的校验
|
||||
if (props.isActivityComponent) {
|
||||
for (const rule of props?.ruleConfig) {
|
||||
const arg = getValue(sku, rule.name)
|
||||
if (!rule.rule(arg)) {
|
||||
validate = false // 只要有一个不通过则直接不通过
|
||||
warningInfo += rule.message
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (checks.some((check) => sku[check] < 0.01)) {
|
||||
for (const rule of props?.ruleConfig) {
|
||||
const arg = getValue(sku, rule.name)
|
||||
if (!rule.rule(arg)) {
|
||||
validate = false // 只要有一个不通过则直接不通过
|
||||
warningInfo = '商品相关价格不能低于 0.01 元!!'
|
||||
warningInfo += rule.message
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@@ -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, PropertyAndValues, RuleConfig, getPropertyList }
|
||||
|
Reference in New Issue
Block a user