fix: 1、修复营销活动相关页面打不开的问题 2、修复 spu 添加失败的问题 2、重构 spu 的 sku 校验方式为通用配置的方式

This commit is contained in:
puhui999
2023-08-31 21:13:20 +08:00
parent 264a29e451
commit f9780b636c
4 changed files with 86 additions and 28 deletions

View File

@@ -109,7 +109,12 @@
<!-- 多规格添加-->
<el-col :span="24">
<el-form-item v-if="!formData.specType">
<SkuList ref="skuListRef" :prop-form-data="formData" :propertyList="propertyList" />
<SkuList
ref="skuListRef"
:prop-form-data="formData"
:propertyList="propertyList"
:rule-config="ruleConfig"
/>
</el-form-item>
<el-form-item v-if="formData.specType" label="商品属性">
<el-button class="mr-15px mb-10px" @click="attributesAddFormRef.open">添加规格</el-button>
@@ -120,7 +125,12 @@
<SkuList :is-batch="true" :prop-form-data="formData" :propertyList="propertyList" />
</el-form-item>
<el-form-item label="属性列表">
<SkuList ref="skuListRef" :prop-form-data="formData" :propertyList="propertyList" />
<SkuList
ref="skuListRef"
:prop-form-data="formData"
:propertyList="propertyList"
:rule-config="ruleConfig"
/>
</el-form-item>
</template>
</el-col>
@@ -175,7 +185,11 @@ import { propTypes } from '@/utils/propTypes'
import { checkSelectedNode, defaultProps, handleTree, treeToString } from '@/utils/tree'
import { createImageViewer } from '@/components/ImageViewer'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { PropertyAndValues, SkuList } from '@/views/mall/product/spu/components/index.ts'
import {
PropertyAndValues,
RuleConfig,
SkuList
} from '@/views/mall/product/spu/components/index.ts'
import ProductAttributes from './ProductAttributes.vue'
import ProductPropertyAddForm from './ProductPropertyAddForm.vue'
import { basicInfoSchema } from './spu.data'
@@ -186,6 +200,30 @@ import * as ExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate'
defineOptions({ name: 'ProductSpuBasicInfoForm' })
// sku 相关属性校验规则
const ruleConfig: RuleConfig[] = [
{
name: 'stock',
rule: (arg) => arg >= 1,
message: '商品库存必须大于等于 1 '
},
{
name: 'price',
rule: (arg) => arg >= 0.01,
message: '商品销售价格必须大于等于 0.01 '
},
{
name: 'marketPrice',
rule: (arg) => arg >= 0.01,
message: '商品市场价格必须大于等于 0.01 '
},
{
name: 'costPrice',
rule: (arg) => arg >= 0.01,
message: '商品成本价格必须大于等于 0.01 '
}
]
// ====== 商品详情相关操作 ======
const { allSchemas } = useCrudSchemas(basicInfoSchema)
/** 商品图预览 */

View File

@@ -142,17 +142,17 @@ const submitForm = async () => {
await unref(otherSettingsRef)?.validate()
// 深拷贝一份, 这样最终 server 端不满足,不需要恢复,
const deepCopyFormData = cloneDeep(unref(formData.value)) as ProductSpuApi.Spu
// 兜底处理 sku 空数据
formData.value.skus!.forEach((sku) => {
// 因为是空数据这里判断一下商品条码是否为空就行
if (sku.barCode === '') {
const index = deepCopyFormData.skus!.findIndex(
(item) => JSON.stringify(item.properties) === JSON.stringify(sku.properties)
)
// 删除这条 sku
deepCopyFormData.skus!.splice(index, 1)
}
})
// 兜底处理 sku 空数据 TODO 后续没得问题就移除
// formData.value.skus!.forEach((sku) => {
// // 因为是空数据这里判断一下商品条码是否为空就行
// if (sku.barCode === '') {
// const index = deepCopyFormData.skus!.findIndex(
// (item) => JSON.stringify(item.properties) === JSON.stringify(sku.properties)
// )
// // 删除这条 sku
// deepCopyFormData.skus!.splice(index, 1)
// }
// })
deepCopyFormData.skus!.forEach((item) => {
// 给sku name赋值
item.name = deepCopyFormData.name