上传
This commit is contained in:
@@ -33,6 +33,38 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col
|
||||
:span="8"
|
||||
:offset="0"
|
||||
v-for="fieldItem in diyFieldList"
|
||||
:key="fieldItem.clueParamId"
|
||||
>
|
||||
<el-form-item :label="fieldItem.label" :prop="fieldItem.field">
|
||||
<component :is="componentMap[fieldItem.component]" v-model="form[fieldItem.field]">
|
||||
<template v-if="fieldItem.component == 'Select'">
|
||||
<el-option
|
||||
v-for="item in fieldItem.options"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="fieldItem.component == 'Radio'">
|
||||
<el-radio v-for="item in fieldItem.options" :key="item.id" :label="item.id">
|
||||
{{ item.name }}
|
||||
</el-radio>
|
||||
</template>
|
||||
<template v-else-if="fieldItem.component == 'Checkbox'">
|
||||
<el-checkbox
|
||||
v-for="item in fieldItem.options"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</template>
|
||||
</component>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12" :offset="0">
|
||||
@@ -51,7 +83,7 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-row :gutter="20" v-if="!formLoading">
|
||||
<el-col :span="24" :offset="0">
|
||||
<el-form-item label="轮播图" prop="carouselImages">
|
||||
<UploadImgs v-model="form.carouselImages" height="100px" width="100px" />
|
||||
@@ -143,21 +175,25 @@
|
||||
</el-tabs>
|
||||
<div class="mt-20px flex justify-center">
|
||||
<el-button type="primary" @click="onSubmit">保存</el-button>
|
||||
<el-button plain>重置</el-button>
|
||||
<el-button plain @click="router.replace('/MiniMall/product')">返回列表</el-button>
|
||||
</div>
|
||||
<ProductAttributesAddForm ref="attributesAddFormRef" :propertyList="form.productSpecList" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
import { getDiyFieldList } from '@/api/mall/product/productField'
|
||||
import * as PropertyApi from '@/api/mall/product/property'
|
||||
import * as ProductApi from '@/api/mall/product/index'
|
||||
import ProductAttributesAddForm from './Comp/ProductAttributesAddForm.vue'
|
||||
import * as BrandApi from '@/api/mall/product/brand'
|
||||
import * as CategoryApi from '@/api/mall/product/category'
|
||||
import { handleTree } from '@/utils/tree'
|
||||
import { isObject } from '@/utils/is.ts'
|
||||
import { componentMap } from '@/components/Form/src/componentMap'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
@@ -184,7 +220,11 @@ const opts = ref({
|
||||
category: []
|
||||
})
|
||||
|
||||
const diyFieldList = ref([])
|
||||
async function getOptions() {
|
||||
getDiyFieldList().then((data) => {
|
||||
diyFieldList.value = data
|
||||
})
|
||||
BrandApi.getSimpleBrandList().then((data) => {
|
||||
opts.value.brand = data || []
|
||||
})
|
||||
@@ -329,24 +369,35 @@ const spuForm = ref()
|
||||
|
||||
function onSubmit() {
|
||||
spuForm.value.validate(async (valid) => {
|
||||
if (valid && validateSku()) {
|
||||
// 深拷贝一份, 这样最终 server 端不满足,不需要影响原始数据
|
||||
const deepCopyFormData = cloneDeep(unref(form.value))
|
||||
deepCopyFormData.productSpecList = deepCopyFormData.skuList
|
||||
if (deepCopyFormData.productCategory && deepCopyFormData.productCategory.length) {
|
||||
deepCopyFormData.productCategory = deepCopyFormData.productCategory.at(-1)
|
||||
}
|
||||
delete deepCopyFormData.skuList
|
||||
// 校验都通过后提交表单
|
||||
const data = deepCopyFormData
|
||||
const id = route.query.id
|
||||
if (!id) {
|
||||
await ProductApi.createProduct(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await ProductApi.updateProduct(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
try {
|
||||
if (valid && validateSku()) {
|
||||
// 深拷贝一份, 这样最终 server 端不满足,不需要影响原始数据
|
||||
const deepCopyFormData = cloneDeep(unref(form.value))
|
||||
deepCopyFormData.productSpecList = deepCopyFormData.skuList
|
||||
if (deepCopyFormData.productCategory && deepCopyFormData.productCategory.length) {
|
||||
deepCopyFormData.productCategory = deepCopyFormData.productCategory.at(-1)
|
||||
}
|
||||
delete deepCopyFormData.skuList
|
||||
// 校验都通过后提交表单
|
||||
let data = {
|
||||
...deepCopyFormData,
|
||||
diyParams: {}
|
||||
}
|
||||
for (let i = 0; i < diyFieldList.value.length; i++) {
|
||||
const element = diyFieldList.value[i]
|
||||
data.diyParams[element.field] = data[element.field]
|
||||
}
|
||||
const id = route.query.id
|
||||
if (!id) {
|
||||
await ProductApi.createProduct(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await ProductApi.updateProduct(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -414,10 +465,15 @@ const getDetail = async () => {
|
||||
formLoading.value = true
|
||||
try {
|
||||
const res = await ProductApi.getProduct(route.query.id)
|
||||
const propList = getPropertyList(res.productSpecList)
|
||||
let diyField = {}
|
||||
if (res.diyParams) {
|
||||
diyField = isObject(res.diyParams) ? res.diyParams : JSON.parse(res.diyParams)
|
||||
}
|
||||
const propList = getPropertyList(res?.productSpecList || [])
|
||||
form.value = {
|
||||
...res,
|
||||
skuList: res.productSpecList,
|
||||
...diyField,
|
||||
skuList: res?.productSpecList || [],
|
||||
productSpecList: propList
|
||||
}
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user