|
@@ -98,14 +98,14 @@
|
|
|
<el-form-item v-if="formData.specType" label="商品属性">
|
|
|
<!-- TODO @puhui999:参考 https://admin.java.crmeb.net/store/list/creatProduct 添加规格好做么?添加的时候,不用输入备注哈 fix-->
|
|
|
<el-button class="mr-15px mb-10px" @click="attributesAddFormRef.open">添加规格</el-button>
|
|
|
- <ProductAttributes :propertyList="propertyList" />
|
|
|
+ <ProductAttributes :propertyList="propertyList" @success="generateSkus" />
|
|
|
</el-form-item>
|
|
|
<template v-if="formData.specType && propertyList.length > 0">
|
|
|
<el-form-item label="批量设置">
|
|
|
<SkuList :is-batch="true" :prop-form-data="formData" :propertyList="propertyList" />
|
|
|
</el-form-item>
|
|
|
<el-form-item label="属性列表">
|
|
|
- <SkuList :prop-form-data="formData" :propertyList="propertyList" />
|
|
|
+ <SkuList ref="skuListRef" :prop-form-data="formData" :propertyList="propertyList" />
|
|
|
</el-form-item>
|
|
|
</template>
|
|
|
<el-form-item v-if="!formData.specType">
|
|
@@ -114,7 +114,7 @@
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
</el-form>
|
|
|
- <ProductAttributesAddForm ref="attributesAddFormRef" @success="addAttribute" />
|
|
|
+ <ProductAttributesAddForm ref="attributesAddFormRef" :propertyList="propertyList" />
|
|
|
</template>
|
|
|
<script lang="ts" name="ProductSpuBasicInfoForm" setup>
|
|
|
import { PropType } from 'vue'
|
|
@@ -141,15 +141,11 @@ const attributesAddFormRef = ref() // 添加商品属性表单 TODO @puhui999:
|
|
|
const productSpuBasicInfoRef = ref() // 表单Ref TODO @puhui999:小写开头哈 fix
|
|
|
// TODO @puhui999:attributeList 改成 propertyList,会更统一一点 fix
|
|
|
const propertyList = ref([]) // 商品属性列表
|
|
|
-/** 添加商品属性 */
|
|
|
-// TODO @puhui999:propFormData 算出来 fix: 因为ProductAttributesAddForm添加属性成功回调得使用不能完全依赖于propFormData
|
|
|
-const addAttribute = (property: any) => {
|
|
|
- Array.isArray(property) ? (propertyList.value = property) : propertyList.value.push(property)
|
|
|
-}
|
|
|
+const skuListRef = ref() // 商品属性列表Ref
|
|
|
/** 调用 SkuList generateTableData 方法*/
|
|
|
-// const generateSkus(propertyList){
|
|
|
-// skuList.value.generateTableData()
|
|
|
-// }
|
|
|
+const generateSkus = (propertyList) => {
|
|
|
+ skuListRef.value.generateTableData(propertyList)
|
|
|
+}
|
|
|
const formData = reactive<SpuType>({
|
|
|
name: '', // 商品名称
|
|
|
categoryId: null, // 商品分类
|
|
@@ -191,6 +187,26 @@ watch(
|
|
|
formData.sliderPicUrls = data['sliderPicUrls'].map((item) => ({
|
|
|
url: item
|
|
|
}))
|
|
|
+ // 只有是多规格才处理
|
|
|
+ if (formData.specType) {
|
|
|
+ // TODO @puhui999:可以直接拿 propertyName 拼接处规格 id + 属性,可以看下商品 uniapp 详情的做法
|
|
|
+ // fix: 直接拿返回的 skus 属性逆向生成出 propertyList
|
|
|
+ const properties = []
|
|
|
+ formData.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 })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ propertyList.value = properties
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
// fix: 去掉深度监听只有对象引用发生改变的时候才执行,解决改一动多的问题
|
|
@@ -217,7 +233,7 @@ const validate = async () => {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
-defineExpose({ validate, addAttribute })
|
|
|
+defineExpose({ validate })
|
|
|
|
|
|
/** 分销类型 */
|
|
|
const changeSubCommissionType = () => {
|