fix: 解决商品上一版遗留的各种小bug关键部分已添加fix注释。完成的TODO也已添加fix标记

This commit is contained in:
puhui999 2023-05-17 18:24:34 +08:00
parent 3c4a39df01
commit 4ddba9d454
10 changed files with 216 additions and 218 deletions

View File

@ -82,3 +82,8 @@ export const getSpu = (id: number) => {
export const deleteSpu = (id: number) => { export const deleteSpu = (id: number) => {
return request.delete({ url: `/product/spu/delete?id=${id}` }) return request.delete({ url: `/product/spu/delete?id=${id}` })
} }
// 导出商品 Spu
export const exportUser = (params) => {
return request.download({ url: '/product/spu/export', params })
}

View File

@ -1,19 +1,19 @@
<template> <template>
<div class="upload-box"> <div class="upload-box">
<el-upload <el-upload
:action="updateUrl"
list-type="picture-card"
:class="['upload', drag ? 'no-border' : '']"
v-model:file-list="fileList" v-model:file-list="fileList"
:multiple="true" :accept="fileType.join(',')"
:limit="limit" :action="updateUrl"
:headers="uploadHeaders"
:before-upload="beforeUpload" :before-upload="beforeUpload"
:class="['upload', drag ? 'no-border' : '']"
:drag="drag"
:headers="uploadHeaders"
:limit="limit"
:multiple="true"
:on-error="uploadError"
:on-exceed="handleExceed" :on-exceed="handleExceed"
:on-success="uploadSuccess" :on-success="uploadSuccess"
:on-error="uploadError" list-type="picture-card"
:drag="drag"
:accept="fileType.join(',')"
> >
<div class="upload-empty"> <div class="upload-empty">
<slot name="empty"> <slot name="empty">
@ -40,15 +40,15 @@
</div> </div>
<el-image-viewer <el-image-viewer
v-if="imgViewVisible" v-if="imgViewVisible"
@close="imgViewVisible = false"
:url-list="[viewImageUrl]" :url-list="[viewImageUrl]"
@close="imgViewVisible = false"
/> />
</div> </div>
</template> </template>
<script setup lang="ts" name="UploadImgs"> <script lang="ts" name="UploadImgs" setup>
import { PropType } from 'vue' import { PropType } from 'vue'
import type { UploadFile, UploadProps, UploadUserFile } from 'element-plus'
import { ElNotification } from 'element-plus' import { ElNotification } from 'element-plus'
import type { UploadProps, UploadFile, UploadUserFile } from 'element-plus'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { getAccessToken, getTenantId } from '@/utils/auth' import { getAccessToken, getTenantId } from '@/utils/auth'
@ -88,8 +88,19 @@ const uploadHeaders = ref({
'tenant-id': getTenantId() 'tenant-id': getTenantId()
}) })
const fileList = ref<UploadUserFile[]>(props.modelValue) const fileList = ref<UploadUserFile[]>()
// fix:
watch(
() => props.modelValue,
(data) => {
if (!data) return
fileList.value = data
},
{
deep: true,
immediate: true
}
)
/** /**
* @description 文件上传之前判断 * @description 文件上传之前判断
* @param rawFile 上传的文件 * @param rawFile 上传的文件
@ -116,9 +127,11 @@ const beforeUpload: UploadProps['beforeUpload'] = (rawFile) => {
interface UploadEmits { interface UploadEmits {
(e: 'update:modelValue', value: UploadUserFile[]): void (e: 'update:modelValue', value: UploadUserFile[]): void
} }
const emit = defineEmits<UploadEmits>() const emit = defineEmits<UploadEmits>()
const uploadSuccess = (response, uploadFile: UploadFile) => { const uploadSuccess = (response, uploadFile: UploadFile) => {
if (!response) return if (!response) return
// TODO urlfileList
uploadFile.url = response.data uploadFile.url = response.data
emit('update:modelValue', fileList.value) emit('update:modelValue', fileList.value)
message.success('上传成功') message.success('上传成功')
@ -159,35 +172,40 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
} }
</script> </script>
<style scoped lang="scss"> <style lang="scss" scoped>
.is-error { .is-error {
.upload { .upload {
:deep(.el-upload--picture-card), :deep(.el-upload--picture-card),
:deep(.el-upload-dragger) { :deep(.el-upload-dragger) {
border: 1px dashed var(--el-color-danger) !important; border: 1px dashed var(--el-color-danger) !important;
&:hover { &:hover {
border-color: var(--el-color-primary) !important; border-color: var(--el-color-primary) !important;
} }
} }
} }
} }
:deep(.disabled) { :deep(.disabled) {
.el-upload--picture-card, .el-upload--picture-card,
.el-upload-dragger { .el-upload-dragger {
cursor: not-allowed; cursor: not-allowed;
background: var(--el-disabled-bg-color) !important; background: var(--el-disabled-bg-color) !important;
border: 1px dashed var(--el-border-color-darker); border: 1px dashed var(--el-border-color-darker);
&:hover { &:hover {
border-color: var(--el-border-color-darker) !important; border-color: var(--el-border-color-darker) !important;
} }
} }
} }
.upload-box { .upload-box {
.no-border { .no-border {
:deep(.el-upload--picture-card) { :deep(.el-upload--picture-card) {
border: none !important; border: none !important;
} }
} }
:deep(.upload) { :deep(.upload) {
.el-upload-dragger { .el-upload-dragger {
display: flex; display: flex;
@ -199,14 +217,17 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
overflow: hidden; overflow: hidden;
border: 1px dashed var(--el-border-color-darker); border: 1px dashed var(--el-border-color-darker);
border-radius: v-bind(borderRadius); border-radius: v-bind(borderRadius);
&:hover { &:hover {
border: 1px dashed var(--el-color-primary); border: 1px dashed var(--el-color-primary);
} }
} }
.el-upload-dragger.is-dragover { .el-upload-dragger.is-dragover {
background-color: var(--el-color-primary-light-9); background-color: var(--el-color-primary-light-9);
border: 2px dashed var(--el-color-primary) !important; border: 2px dashed var(--el-color-primary) !important;
} }
.el-upload-list__item, .el-upload-list__item,
.el-upload--picture-card { .el-upload--picture-card {
width: v-bind(width); width: v-bind(width);
@ -214,11 +235,13 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
background-color: transparent; background-color: transparent;
border-radius: v-bind(borderRadius); border-radius: v-bind(borderRadius);
} }
.upload-image { .upload-image {
width: 100%; width: 100%;
height: 100%; height: 100%;
object-fit: contain; object-fit: contain;
} }
.upload-handle { .upload-handle {
position: absolute; position: absolute;
top: 0; top: 0;
@ -233,6 +256,7 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
background: rgb(0 0 0 / 60%); background: rgb(0 0 0 / 60%);
opacity: 0; opacity: 0;
transition: var(--el-transition-duration-fast); transition: var(--el-transition-duration-fast);
.handle-icon { .handle-icon {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -240,15 +264,18 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
justify-content: center; justify-content: center;
padding: 0 6%; padding: 0 6%;
color: aliceblue; color: aliceblue;
.el-icon { .el-icon {
margin-bottom: 15%; margin-bottom: 15%;
font-size: 140%; font-size: 140%;
} }
span { span {
font-size: 100%; font-size: 100%;
} }
} }
} }
.el-upload-list__item { .el-upload-list__item {
&:hover { &:hover {
.upload-handle { .upload-handle {
@ -256,6 +283,7 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
} }
} }
} }
.upload-empty { .upload-empty {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -263,12 +291,14 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
font-size: 12px; font-size: 12px;
line-height: 30px; line-height: 30px;
color: var(--el-color-info); color: var(--el-color-info);
.el-icon { .el-icon {
font-size: 28px; font-size: 28px;
color: var(--el-text-color-secondary); color: var(--el-text-color-secondary);
} }
} }
} }
.el-upload__tip { .el-upload__tip {
line-height: 15px; line-height: 15px;
text-align: center; text-align: center;

View File

@ -349,22 +349,35 @@ const remainingRouter: AppRouteRecordRaw[] = [
{ {
path: '/product', path: '/product',
component: Layout, component: Layout,
name: 'ProductManagementEdit', name: 'Product',
meta: { meta: {
hidden: true hidden: true
}, },
children: [ children: [
{ {
path: 'productManagementAdd', // TODO @puhui999最好拆成 add 和 edit 两个路由;添加商品;修改商品 path: 'productSpuAdd', // TODO @puhui999最好拆成 add 和 edit 两个路由;添加商品;修改商品 fix
component: () => import('@/views/mall/product/spu/addForm.vue'), component: () => import('@/views/mall/product/spu/addForm.vue'),
name: 'ProductManagementAdd', name: 'ProductSpuAdd',
meta: { meta: {
noCache: true, noCache: true,
hidden: true, hidden: true,
canTo: true, canTo: true,
icon: 'ep:edit', icon: 'ep:edit',
title: '添加商品', title: '添加商品',
activeMenu: '/product/product-management' activeMenu: '/product/product-spu'
}
},
{
path: 'productSpuEdit/:spuId(\\d+)',
component: () => import('@/views/mall/product/spu/addForm.vue'),
name: 'productSpuEdit',
meta: {
noCache: true,
hidden: true,
canTo: true,
icon: 'ep:edit',
title: '编辑商品',
activeMenu: '/product/product-spu'
} }
} }
] ]

View File

@ -3,21 +3,21 @@
<el-tabs v-model="activeName"> <el-tabs v-model="activeName">
<el-tab-pane label="商品信息" name="basicInfo"> <el-tab-pane label="商品信息" name="basicInfo">
<BasicInfoForm <BasicInfoForm
ref="BasicInfoRef" ref="basicInfoRef"
v-model:activeName="activeName" v-model:activeName="activeName"
:propFormData="formData" :propFormData="formData"
/> />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="商品详情" name="description"> <el-tab-pane label="商品详情" name="description">
<DescriptionForm <DescriptionForm
ref="DescriptionRef" ref="descriptionRef"
v-model:activeName="activeName" v-model:activeName="activeName"
:propFormData="formData" :propFormData="formData"
/> />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="其他设置" name="otherSettings"> <el-tab-pane label="其他设置" name="otherSettings">
<OtherSettingsForm <OtherSettingsForm
ref="OtherSettingsRef" ref="otherSettingsRef"
v-model:activeName="activeName" v-model:activeName="activeName"
:propFormData="formData" :propFormData="formData"
/> />
@ -31,88 +31,55 @@
</el-form> </el-form>
</ContentWrap> </ContentWrap>
</template> </template>
<script lang="ts" name="ProductManagementForm" setup> <script lang="ts" name="ProductSpuForm" setup>
import { cloneDeep } from 'lodash-es'
import { useTagsViewStore } from '@/store/modules/tagsView' import { useTagsViewStore } from '@/store/modules/tagsView'
import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components' import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components'
import type { SpuType } from '@/api/mall/product/management/type/spuType' // api // api
import * as managementApi from '@/api/mall/product/management/spu' import * as ProductSpuApi from '@/api/mall/product/spu'
import * as PropertyApi from '@/api/mall/product/property' import * as PropertyApi from '@/api/mall/product/property'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const { push, currentRoute } = useRouter() // const { push, currentRoute } = useRouter() //
const { query } = useRoute() // const { params } = useRoute() //
const { delView } = useTagsViewStore() // const { delView } = useTagsViewStore() //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const activeName = ref('basicInfo') // Tag const activeName = ref('basicInfo') // Tag
const BasicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>() // Ref const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>() // Ref
const DescriptionRef = ref<ComponentRef<typeof DescriptionForm>>() // Ref const descriptionRef = ref<ComponentRef<typeof DescriptionForm>>() // Ref
const OtherSettingsRef = ref<ComponentRef<typeof OtherSettingsForm>>() // Ref const otherSettingsRef = ref<ComponentRef<typeof OtherSettingsForm>>() // Ref
const formData = ref<SpuType>({ // spu
name: '213', // const formData = ref<ProductSpuApi.SpuType>({
name: '', //
categoryId: null, // categoryId: null, //
keyword: '213', // keyword: '', //
unit: null, // unit: null, //
picUrl: picUrl: '', //
'http://127.0.0.1:48080/admin-api/infra/file/4/get/6ffdf8f5dfc03f7ceec1ff1ebc138adb8b721a057d505ccfb0e61a8783af1371.png', // sliderPicUrls: [], //
sliderPicUrls: [ introduction: '', //
{ deliveryTemplateId: 1, //
name: 'http://127.0.0.1:48080/admin-api/infra/file/4/get/6ffdf8f5dfc03f7ceec1ff1ebc138adb8b721a057d505ccfb0e61a8783af1371.png',
url: 'http://127.0.0.1:48080/admin-api/infra/file/4/get/6ffdf8f5dfc03f7ceec1ff1ebc138adb8b721a057d505ccfb0e61a8783af1371.png'
}
], //
introduction: '213', //
deliveryTemplateId: 0, //
specType: false, // specType: false, //
subCommissionType: false, // subCommissionType: false, //
skus: [ skus: [
{ {
/** price: 0, //
* 商品价格单位 TODO @puhui999注释放在尾巴哈简洁一点~ marketPrice: 0, //
*/ costPrice: 0, //
price: 0, barCode: '', //
/** picUrl: '', //
* 市场价单位 stock: 0, //
*/ weight: 0, //
marketPrice: 0, volume: 0, //
/** subCommissionFirstPrice: 0, //
* 成本价单位 subCommissionSecondPrice: 0 //
*/
costPrice: 0,
/**
* 商品条码
*/
barCode: '',
/**
* 图片地址
*/
picUrl: '',
/**
* 库存
*/
stock: 0,
/**
* 商品重量单位kg 千克
*/
weight: 0,
/**
* 商品体积单位m^3 平米
*/
volume: 0,
/**
* 一级分销的佣金单位
*/
subCommissionFirstPrice: 0,
/**
* 二级分销的佣金单位
*/
subCommissionSecondPrice: 0
} }
], ],
description: '5425', // description: '', //
sort: 1, // sort: 0, //
giveIntegral: 1, // giveIntegral: 0, //
virtualSalesCount: 1, // virtualSalesCount: 0, //
recommendHot: false, // recommendHot: false, //
recommendBenefit: false, // recommendBenefit: false, //
recommendBest: false, // recommendBest: false, //
@ -122,11 +89,11 @@ const formData = ref<SpuType>({
/** 获得详情 */ /** 获得详情 */
const getDetail = async () => { const getDetail = async () => {
const id = query.id as unknown as number const id = params.spuId as number
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { try {
const res = (await managementApi.getSpu(id)) as SpuType const res = (await ProductSpuApi.getSpu(id)) as ProductSpuApi.SpuType
formData.value = res formData.value = res
// id // id
// TODO @puhui999 propertyName id + uniapp // TODO @puhui999 propertyName id + uniapp
@ -134,7 +101,7 @@ const getDetail = async () => {
const PropertyS = await PropertyApi.getPropertyListAndValue({ propertyIds }) const PropertyS = await PropertyApi.getPropertyListAndValue({ propertyIds })
await nextTick() await nextTick()
// //
BasicInfoRef.value.addAttribute(PropertyS) basicInfoRef.value.addAttribute(PropertyS)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -145,54 +112,37 @@ const getDetail = async () => {
const submitForm = async () => { const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
const newSkus = JSON.parse(JSON.stringify(formData.value.skus)) //skus使 //
// TODO
// //
try { try {
await unref(BasicInfoRef)?.validate() await unref(basicInfoRef)?.validate()
await unref(DescriptionRef)?.validate() await unref(descriptionRef)?.validate()
await unref(OtherSettingsRef)?.validate() await unref(otherSettingsRef)?.validate()
// TODO @puhui server const deepCopyFormData = cloneDeep(unref(formData.value)) // fix: server
// //
formData.value.skus.forEach((item) => { deepCopyFormData.skus.forEach((item) => {
// sku name // sku name
item.name = formData.value.name item.name = deepCopyFormData.name
// skusvalue
if (formData.value.specType) {
item.properties.forEach((item2) => {
delete item2.valueName
})
}
}) })
// //
const newSliderPicUrls = [] const newSliderPicUrls = []
formData.value.sliderPicUrls.forEach((item) => { deepCopyFormData.sliderPicUrls.forEach((item) => {
// //
// TODO @puhui999 object // TODO @puhui999 object fix
if (typeof item === 'object') { typeof item === 'object' ? newSliderPicUrls.push(item.url) : newSliderPicUrls.push(item)
newSliderPicUrls.push(item.url)
} else {
newSliderPicUrls.push(item)
}
}) })
formData.value.sliderPicUrls = newSliderPicUrls deepCopyFormData.sliderPicUrls = newSliderPicUrls
// //
const data = formData.value as SpuType const data = deepCopyFormData as ProductSpuApi.SpuType
// skus. const id = params.spuId as number
const id = query.id as unknown as number
if (!id) { if (!id) {
await managementApi.createSpu(data) await ProductSpuApi.createSpu(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await managementApi.updateSpu(data) await ProductSpuApi.updateSpu(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
close() close()
} catch (e) {
// ,skus
if (typeof e === 'string') {
formData.value.skus = newSkus
}
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -200,41 +150,40 @@ const submitForm = async () => {
/** /**
* 重置表单 * 重置表单
* fix:先注释保留如果后期没有使用到则移除
*/ */
const resetForm = async () => { // const resetForm = async () => {
formData.value = { // formData.value = {
name: '', // // name: '', //
categoryId: 0, // // categoryId: 0, //
keyword: '', // // keyword: '', //
unit: '', // // unit: '', //
picUrl: '', // // picUrl: '', //
sliderPicUrls: [], // // sliderPicUrls: [], //
introduction: '', // // introduction: '', //
deliveryTemplateId: 0, // // deliveryTemplateId: 0, //
selectRule: '', // selectRule: '',
specType: false, // // specType: false, //
subCommissionType: false, // // subCommissionType: false, //
description: '', // // description: '', //
sort: 1, // // sort: 1, //
giveIntegral: 1, // // giveIntegral: 1, //
virtualSalesCount: 1, // // virtualSalesCount: 1, //
recommendHot: false, // // recommendHot: false, //
recommendBenefit: false, // // recommendBenefit: false, //
recommendBest: false, // // recommendBest: false, //
recommendNew: false, // // recommendNew: false, //
recommendGood: false // // recommendGood: false //
} // }
} // }
/** 关闭按钮 */ /** 关闭按钮 */
const close = () => { const close = () => {
// TODO @puhui999 reset close
resetForm()
delView(unref(currentRoute)) delView(unref(currentRoute))
push('/product/product-management') push('/product/product-spu')
} }
/** 初始化 */ /** 初始化 */
onMounted(() => { onMounted(async () => {
getDetail() await getDetail()
}) })
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<el-form ref="ProductManagementBasicInfoRef" :model="formData" :rules="rules" label-width="120px"> <el-form ref="productSpuBasicInfoRef" :model="formData" :rules="rules" label-width="120px">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="商品名称" prop="name"> <el-form-item label="商品名称" prop="name">
@ -54,7 +54,7 @@
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="商品轮播图" prop="sliderPicUrls"> <el-form-item label="商品轮播图" prop="sliderPicUrls">
<UploadImgs v-model="formData.sliderPicUrls" /> <UploadImgs v-model:modelValue="formData.sliderPicUrls" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
@ -86,36 +86,36 @@
<!-- 多规格添加--> <!-- 多规格添加-->
<el-col :span="24"> <el-col :span="24">
<el-form-item v-if="formData.specType" label="商品属性"> <el-form-item v-if="formData.specType" label="商品属性">
<!-- TODO @puhui999参考 https://admin.java.crmeb.net/store/list/creatProduct --> <!-- TODO @puhui999参考 https://admin.java.crmeb.net/store/list/creatProduct fix-->
<el-button class="mr-15px mb-10px" @click="AttributesAddFormRef.open">添加规格</el-button> <el-button class="mr-15px mb-10px" @click="attributesAddFormRef.open">添加规格</el-button>
<ProductAttributes :attribute-data="attributeList" /> <ProductAttributes :propertyList="propertyList" />
</el-form-item> </el-form-item>
<template v-if="formData.specType && attributeList.length > 0"> <template v-if="formData.specType && propertyList.length > 0">
<el-form-item label="批量设置"> <el-form-item label="批量设置">
<SkuList :attributeList="attributeList" :is-batch="true" :prop-form-data="formData" /> <SkuList :is-batch="true" :prop-form-data="formData" :propertyList="propertyList" />
</el-form-item> </el-form-item>
<el-form-item label="属性列表"> <el-form-item label="属性列表">
<SkuList :attributeList="attributeList" :prop-form-data="formData" /> <SkuList :prop-form-data="formData" :propertyList="propertyList" />
</el-form-item> </el-form-item>
</template> </template>
<el-form-item v-if="!formData.specType"> <el-form-item v-if="!formData.specType">
<SkuList :attributeList="attributeList" :prop-form-data="formData" /> <SkuList :prop-form-data="formData" :propertyList="propertyList" />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
</el-form> </el-form>
<ProductAttributesAddForm ref="AttributesAddFormRef" @success="addAttribute" /> <ProductAttributesAddForm ref="attributesAddFormRef" @success="addAttribute" />
</template> </template>
<script lang="ts" name="ProductManagementBasicInfoForm" setup> <script lang="ts" name="ProductSpuBasicInfoForm" setup>
import { PropType } from 'vue' import { PropType } from 'vue'
import { defaultProps, handleTree } from '@/utils/tree' import { defaultProps, handleTree } from '@/utils/tree'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import type { SpuType } from '@/api/mall/product/management/type/spuType' import type { SpuType } from '@/api/mall/product/spu'
import { UploadImg, UploadImgs } from '@/components/UploadFile' import { UploadImg, UploadImgs } from '@/components/UploadFile'
import { copyValueToTarget } from '@/utils'
import { ProductAttributes, ProductAttributesAddForm, SkuList } from './index' import { ProductAttributes, ProductAttributesAddForm, SkuList } from './index'
import * as ProductCategoryApi from '@/api/mall/product/category' import * as ProductCategoryApi from '@/api/mall/product/category'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { copyValueToTarget } from '@/utils'
const message = useMessage() // const message = useMessage() //
@ -126,17 +126,14 @@ const props = defineProps({
}, },
activeName: propTypes.string.def('') activeName: propTypes.string.def('')
}) })
const AttributesAddFormRef = ref() // TODO @puhui999 const attributesAddFormRef = ref() // TODO @puhui999 fix
const ProductManagementBasicInfoRef = ref() // Ref TODO @puhui999 const productSpuBasicInfoRef = ref() // Ref TODO @puhui999 fix
// TODO @puhui999attributeList propertyList // TODO @puhui999attributeList propertyList fix
const attributeList = ref([]) // const propertyList = ref([]) //
/** 添加商品属性 */ // TODO @puhui999propFormData /** 添加商品属性 */
// TODO @puhui999propFormData fix: ProductAttributesAddForm使propFormData
const addAttribute = (property: any) => { const addAttribute = (property: any) => {
if (Array.isArray(property)) { Array.isArray(property) ? (propertyList.value = property) : propertyList.value.push(property)
attributeList.value = property
return
}
attributeList.value.push(property)
} }
const formData = reactive<SpuType>({ const formData = reactive<SpuType>({
name: '', // name: '', //
@ -171,10 +168,15 @@ watch(
() => props.propFormData, () => props.propFormData,
(data) => { (data) => {
if (!data) return if (!data) return
// fix使 copyValueToTarget 使 formData.value = data
copyValueToTarget(formData, data) copyValueToTarget(formData, data)
// fix: url
formData.sliderPicUrls = data['sliderPicUrls'].map((item) => ({
url: item
}))
}, },
{ {
deep: true, // fix: ,
immediate: true immediate: true
} }
) )
@ -185,8 +187,8 @@ watch(
const emit = defineEmits(['update:activeName']) const emit = defineEmits(['update:activeName'])
const validate = async () => { const validate = async () => {
// //
if (!ProductManagementBasicInfoRef) return if (!productSpuBasicInfoRef) return
return await unref(ProductManagementBasicInfoRef).validate((valid) => { return await unref(productSpuBasicInfoRef).validate((valid) => {
if (!valid) { if (!valid) {
message.warning('商品信息未完善!!') message.warning('商品信息未完善!!')
emit('update:activeName', 'basicInfo') emit('update:activeName', 'basicInfo')
@ -212,7 +214,7 @@ const changeSubCommissionType = () => {
/** 选择规格 */ /** 选择规格 */
const onChangeSpec = () => { const onChangeSpec = () => {
// //
attributeList.value = [] propertyList.value = []
// sku // sku
formData.skus = [ formData.skus = [
{ {

View File

@ -1,5 +1,5 @@
<template> <template>
<el-form ref="DescriptionFormRef" :model="formData" :rules="rules" label-width="120px"> <el-form ref="descriptionFormRef" :model="formData" :rules="rules" label-width="120px">
<!--富文本编辑器组件--> <!--富文本编辑器组件-->
<el-form-item label="商品详情" prop="description"> <el-form-item label="商品详情" prop="description">
<Editor v-model:modelValue="formData.description" /> <Editor v-model:modelValue="formData.description" />
@ -7,11 +7,11 @@
</el-form> </el-form>
</template> </template>
<script lang="ts" name="DescriptionForm" setup> <script lang="ts" name="DescriptionForm" setup>
import type { SpuType } from '@/api/mall/product/management/type/spuType' import type { SpuType } from '@/api/mall/product/spu'
import { Editor } from '@/components/Editor' import { Editor } from '@/components/Editor'
import { PropType } from 'vue' import { PropType } from 'vue'
import { copyValueToTarget } from '@/utils'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { copyValueToTarget } from '@/utils'
const message = useMessage() // const message = useMessage() //
const props = defineProps({ const props = defineProps({
@ -21,7 +21,7 @@ const props = defineProps({
}, },
activeName: propTypes.string.def('') activeName: propTypes.string.def('')
}) })
const DescriptionFormRef = ref() // Ref const descriptionFormRef = ref() // Ref
const formData = ref<SpuType>({ const formData = ref<SpuType>({
description: '' // description: '' //
}) })
@ -29,7 +29,6 @@ const formData = ref<SpuType>({
const rules = reactive({ const rules = reactive({
description: [required] description: [required]
}) })
/** /**
* 富文本编辑器如果输入过再清空会有残留需再重置一次 * 富文本编辑器如果输入过再清空会有残留需再重置一次
*/ */
@ -45,7 +44,6 @@ watch(
immediate: true immediate: true
} }
) )
/** /**
* 将传进来的值赋值给formData * 将传进来的值赋值给formData
*/ */
@ -53,10 +51,11 @@ watch(
() => props.propFormData, () => props.propFormData,
(data) => { (data) => {
if (!data) return if (!data) return
// fix使 copyValueToTarget 使 formData.value = data
copyValueToTarget(formData.value, data) copyValueToTarget(formData.value, data)
}, },
{ {
deep: true, // fix: ,
immediate: true immediate: true
} }
) )
@ -67,8 +66,8 @@ watch(
const emit = defineEmits(['update:activeName']) const emit = defineEmits(['update:activeName'])
const validate = async () => { const validate = async () => {
// //
if (!DescriptionFormRef) return if (!descriptionFormRef) return
return unref(DescriptionFormRef).validate((valid) => { return await unref(descriptionFormRef).validate((valid) => {
if (!valid) { if (!valid) {
message.warning('商品详情为完善!!') message.warning('商品详情为完善!!')
emit('update:activeName', 'description') emit('update:activeName', 'description')

View File

@ -1,5 +1,5 @@
<template> <template>
<el-form ref="OtherSettingsFormRef" :model="formData" :rules="rules" label-width="120px"> <el-form ref="otherSettingsFormRef" :model="formData" :rules="rules" label-width="120px">
<el-row> <el-row>
<!-- TODO @puhui999横着三个哈 fix--> <!-- TODO @puhui999横着三个哈 fix-->
<el-col :span="24"> <el-col :span="24">
@ -55,8 +55,8 @@
<script lang="ts" name="OtherSettingsForm" setup> <script lang="ts" name="OtherSettingsForm" setup>
import type { SpuType } from '@/api/mall/product/spu' import type { SpuType } from '@/api/mall/product/spu'
import { PropType } from 'vue' import { PropType } from 'vue'
import { copyValueToTarget } from '@/utils'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { copyValueToTarget } from '@/utils'
const message = useMessage() // const message = useMessage() //
@ -68,7 +68,7 @@ const props = defineProps({
activeName: propTypes.string.def('') activeName: propTypes.string.def('')
}) })
const OtherSettingsFormRef = ref() // Ref const otherSettingsFormRef = ref() // Ref
// //
const formData = ref<SpuType>({ const formData = ref<SpuType>({
sort: 1, // sort: 1, //
@ -100,7 +100,7 @@ const checkboxGroup = ref<string[]>([]) // 选中的推荐选项
const onChangeGroup = () => { const onChangeGroup = () => {
// TODO @puhui999 recommendfix // TODO @puhui999 recommendfix
recommendOptions.forEach(({ value }) => { recommendOptions.forEach(({ value }) => {
formData.value[value] = checkboxGroup.value.includes(value) ? true : false formData.value[value] = checkboxGroup.value.includes(value)
}) })
} }
@ -111,22 +111,28 @@ watch(
() => props.propFormData, () => props.propFormData,
(data) => { (data) => {
if (!data) return if (!data) return
// fix使 copyValueToTarget 使 formData.value = data
copyValueToTarget(formData.value, data) copyValueToTarget(formData.value, data)
recommendOptions.forEach(({ value }) => {
// TODO fix:
if (formData.value[value] && !checkboxGroup.value.includes(value)) {
checkboxGroup.value.push(value)
}
})
}, },
{ {
deep: true, // fix: ,
immediate: true immediate: true
} }
) )
/** /**
* 表单校验 * 表单校验
*/ */
const emit = defineEmits(['update:activeName']) const emit = defineEmits(['update:activeName'])
const validate = async () => { const validate = async () => {
// //
if (!OtherSettingsFormRef) return if (!otherSettingsFormRef) return
return await unref(OtherSettingsFormRef).validate((valid) => { return await unref(otherSettingsFormRef).validate((valid) => {
if (!valid) { if (!valid) {
message.warning('商品其他设置未完善!!') message.warning('商品其他设置未完善!!')
emit('update:activeName', 'otherSettings') emit('update:activeName', 'otherSettings')
@ -139,14 +145,4 @@ const validate = async () => {
}) })
} }
defineExpose({ validate }) defineExpose({ validate })
onMounted(async () => {
await nextTick()
// TODO fix:
checkboxGroup.value = []
recommendOptions.forEach(({ value }) => {
if (formData.value[value]) {
checkboxGroup.value.push(value)
}
})
})
</script> </script>

View File

@ -54,14 +54,14 @@ const inputVisible = computed(() => (index) => {
const InputRef = ref() //Ref const InputRef = ref() //Ref
const attributeList = ref([]) // const attributeList = ref([]) //
const props = defineProps({ const props = defineProps({
attributeData: { propertyList: {
type: Array, type: Array,
default: () => {} default: () => {}
} }
}) })
watch( watch(
() => props.attributeData, () => props.propertyList,
(data) => { (data) => {
if (!data) return if (!data) return
attributeList.value = data attributeList.value = data
@ -80,6 +80,7 @@ const handleClose = (index, valueIndex) => {
/** 显示输入框并获取焦点 */ /** 显示输入框并获取焦点 */
const showInput = async (index) => { const showInput = async (index) => {
attributeIndex.value = index attributeIndex.value = index
// TODO
// refRef // refRef
InputRef.value[index]!.input!.focus() InputRef.value[index]!.input!.focus()
} }

View File

@ -25,13 +25,13 @@
</template> </template>
</el-table-column> </el-table-column>
</template> </template>
<!-- TODO @puhui999 controls-position=" " 可以去掉哈不然太长了手动输入更方便 --> <!-- TODO @puhui999 controls-position=" " 可以去掉哈不然太长了手动输入更方便 fix -->
<el-table-column align="center" label="商品条码" min-width="168"> <el-table-column align="center" label="商品条码" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input v-model="row.barCode" class="w-100%" /> <el-input v-model="row.barCode" class="w-100%" />
</template> </template>
</el-table-column> </el-table-column>
<!-- TODO @puhui999用户输入的时候是按照元分主要是我们自己用 --> <!-- TODO @puhui999用户输入的时候是按照元分主要是我们自己用fix -->
<el-table-column align="center" label="销售价(元)" min-width="168"> <el-table-column align="center" label="销售价(元)" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number v-model="row.price" :min="0" class="w-100%" /> <el-input-number v-model="row.price" :min="0" class="w-100%" />
@ -96,7 +96,7 @@ const props = defineProps({
type: Object as PropType<SpuType>, type: Object as PropType<SpuType>,
default: () => {} default: () => {}
}, },
attributeList: { propertyList: {
type: Array, type: Array,
default: () => [] default: () => []
}, },
@ -142,7 +142,7 @@ watch(
} }
) )
// TODO @ chatgpt // TODO @ chatgpt fix
/** 生成表数据 */ /** 生成表数据 */
const generateTableData = (data: any[]) => { const generateTableData = (data: any[]) => {
// fix: 使mapfor // fix: 使mapfor
@ -207,8 +207,8 @@ const build = (propertyValuesList: Property[][]) => {
/** 监听属性列表生成相关参数和表头 */ /** 监听属性列表生成相关参数和表头 */
watch( watch(
() => props.attributeList, () => props.propertyList,
(attributeList) => { (propertyList) => {
// //
if (!formData.value.specType) return if (!formData.value.specType) return
// 使 // 使
@ -229,15 +229,15 @@ watch(
] ]
} }
// //
if (JSON.stringify(attributeList) === '[]') return if (JSON.stringify(propertyList) === '[]') return
// //
tableHeaders.value = [] tableHeaders.value = []
// //
attributeList.forEach((item, index) => { propertyList.forEach((item, index) => {
// nameindex // nameindex
tableHeaders.value.push({ prop: `name${index}`, label: item.name }) tableHeaders.value.push({ prop: `name${index}`, label: item.name })
}) })
generateTableData(attributeList) generateTableData(propertyList)
}, },
{ {
deep: true, deep: true,

View File

@ -8,7 +8,7 @@
class="-mb-15px" class="-mb-15px"
label-width="68px" label-width="68px"
> >
<!-- TODO @puhui999https://admin.java.crmeb.net/store/index使 + --> <!-- TODO @puhui999https://admin.java.crmeb.net/store/index使 + fix-->
<el-form-item label="品牌名称" prop="name"> <el-form-item label="品牌名称" prop="name">
<el-input <el-input
v-model="queryParams.name" v-model="queryParams.name"
@ -351,11 +351,11 @@ const resetQuery = () => {
const openForm = (id?: number) => { const openForm = (id?: number) => {
// //
if (typeof id === 'number') { if (typeof id === 'number') {
push('/product/productManagementAdd?id=' + id) push('/product/productSpuEdit/' + id)
return return
} }
// //
push('/product/productManagementAdd') push('/product/productSpuAdd')
} }
// TODO @puhui999fix: // TODO @puhui999fix:
@ -377,8 +377,11 @@ onMounted(async () => {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.demo-table-expand { .demo-table-expand {
padding-left: 42px;
:deep(.el-form-item__label) { :deep(.el-form-item__label) {
width: 82px; width: 82px;
font-weight: bold;
color: #99a9bf; color: #99a9bf;
} }
} }