|
|
|
@ -1,13 +1,5 @@
|
|
|
|
<template>
|
|
|
|
<template>
|
|
|
|
<!-- 情况一:添加/修改 -->
|
|
|
|
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px" :disabled="isDetail">
|
|
|
|
<el-form
|
|
|
|
|
|
|
|
v-if="!isDetail"
|
|
|
|
|
|
|
|
ref="productSpuBasicInfoRef"
|
|
|
|
|
|
|
|
:model="formData"
|
|
|
|
|
|
|
|
:rules="rules"
|
|
|
|
|
|
|
|
label-width="120px"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<!-- TODO 芋艿:宽度!! -->
|
|
|
|
|
|
|
|
<el-form-item label="商品名称" prop="name">
|
|
|
|
<el-form-item label="商品名称" prop="name">
|
|
|
|
<el-input
|
|
|
|
<el-input
|
|
|
|
v-model="formData.name"
|
|
|
|
v-model="formData.name"
|
|
|
|
@ -17,6 +9,7 @@
|
|
|
|
maxlength="64"
|
|
|
|
maxlength="64"
|
|
|
|
:show-word-limit="true"
|
|
|
|
:show-word-limit="true"
|
|
|
|
:clearable="true"
|
|
|
|
:clearable="true"
|
|
|
|
|
|
|
|
class="w-80!"
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="商品分类" prop="categoryId">
|
|
|
|
<el-form-item label="商品分类" prop="categoryId">
|
|
|
|
@ -24,21 +17,35 @@
|
|
|
|
v-model="formData.categoryId"
|
|
|
|
v-model="formData.categoryId"
|
|
|
|
:options="categoryList"
|
|
|
|
:options="categoryList"
|
|
|
|
:props="defaultProps"
|
|
|
|
:props="defaultProps"
|
|
|
|
class="w-1/1"
|
|
|
|
class="w-80"
|
|
|
|
clearable
|
|
|
|
clearable
|
|
|
|
placeholder="请选择商品分类"
|
|
|
|
placeholder="请选择商品分类"
|
|
|
|
filterable
|
|
|
|
filterable
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item label="商品品牌" prop="brandId">
|
|
|
|
|
|
|
|
<el-select v-model="formData.brandId" placeholder="请选择商品品牌" class="w-80">
|
|
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
|
|
v-for="item in brandList"
|
|
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
|
|
:label="item.name"
|
|
|
|
|
|
|
|
:value="item.id as number"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="商品关键字" prop="keyword">
|
|
|
|
<el-form-item label="商品关键字" prop="keyword">
|
|
|
|
<el-input v-model="formData.keyword" placeholder="请输入商品关键字" />
|
|
|
|
<el-input v-model="formData.keyword" placeholder="请输入商品关键字" class="w-80!" />
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="商品简介" prop="introduction">
|
|
|
|
<el-form-item label="商品简介" prop="introduction">
|
|
|
|
<el-input
|
|
|
|
<el-input
|
|
|
|
v-model="formData.introduction"
|
|
|
|
v-model="formData.introduction"
|
|
|
|
:rows="3"
|
|
|
|
placeholder="请输入商品名称"
|
|
|
|
placeholder="请输入商品简介"
|
|
|
|
|
|
|
|
type="textarea"
|
|
|
|
type="textarea"
|
|
|
|
|
|
|
|
:autosize="{ minRows: 2, maxRows: 2 }"
|
|
|
|
|
|
|
|
maxlength="128"
|
|
|
|
|
|
|
|
:show-word-limit="true"
|
|
|
|
|
|
|
|
:clearable="true"
|
|
|
|
|
|
|
|
class="w-80!"
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="商品封面图" prop="picUrl">
|
|
|
|
<el-form-item label="商品封面图" prop="picUrl">
|
|
|
|
@ -47,67 +54,20 @@
|
|
|
|
<el-form-item label="商品轮播图" prop="sliderPicUrls">
|
|
|
|
<el-form-item label="商品轮播图" prop="sliderPicUrls">
|
|
|
|
<UploadImgs v-model:modelValue="formData.sliderPicUrls" />
|
|
|
|
<UploadImgs v-model:modelValue="formData.sliderPicUrls" />
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="品牌" prop="brandId">
|
|
|
|
|
|
|
|
<el-select v-model="formData.brandId" placeholder="请选择">
|
|
|
|
|
|
|
|
<el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
</el-form>
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 情况二:详情 -->
|
|
|
|
|
|
|
|
<Descriptions v-if="isDetail" :data="formData" :schema="allSchemas.detailSchema">
|
|
|
|
|
|
|
|
<template #categoryId="{ row }"> {{ formatCategoryName(row.categoryId) }}</template>
|
|
|
|
|
|
|
|
<template #brandId="{ row }">
|
|
|
|
|
|
|
|
{{ brandList.find((item) => item.id === row.brandId)?.name }}
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #picUrl="{ row }">
|
|
|
|
|
|
|
|
<el-image :src="row.picUrl" class="h-60px w-60px" @click="imagePreview(row.picUrl)" />
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #sliderPicUrls="{ row }">
|
|
|
|
|
|
|
|
<el-image
|
|
|
|
|
|
|
|
v-for="(item, index) in row.sliderPicUrls"
|
|
|
|
|
|
|
|
:key="index"
|
|
|
|
|
|
|
|
:src="item.url"
|
|
|
|
|
|
|
|
class="mr-10px h-60px w-60px"
|
|
|
|
|
|
|
|
@click="imagePreview(row.sliderPicUrls)"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
</Descriptions>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { PropType } from 'vue'
|
|
|
|
import { PropType } from 'vue'
|
|
|
|
import { isArray } from '@/utils/is'
|
|
|
|
|
|
|
|
import { copyValueToTarget } from '@/utils'
|
|
|
|
import { copyValueToTarget } from '@/utils'
|
|
|
|
import { propTypes } from '@/utils/propTypes'
|
|
|
|
import { propTypes } from '@/utils/propTypes'
|
|
|
|
import { defaultProps, handleTree, treeToString } from '@/utils/tree'
|
|
|
|
import { defaultProps, handleTree, treeToString } from '@/utils/tree'
|
|
|
|
import { createImageViewer } from '@/components/ImageViewer'
|
|
|
|
|
|
|
|
import { basicInfoSchema } from './spu.data'
|
|
|
|
|
|
|
|
import type { Spu } from '@/api/mall/product/spu'
|
|
|
|
import type { Spu } from '@/api/mall/product/spu'
|
|
|
|
import * as ProductCategoryApi from '@/api/mall/product/category'
|
|
|
|
import * as ProductCategoryApi from '@/api/mall/product/category'
|
|
|
|
import * as ProductBrandApi from '@/api/mall/product/brand'
|
|
|
|
import * as ProductBrandApi from '@/api/mall/product/brand'
|
|
|
|
import * as ExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate'
|
|
|
|
import { BrandVO } from '@/api/mall/product/brand'
|
|
|
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'ProductSpuBasicInfoForm' })
|
|
|
|
defineOptions({ name: 'ProductSpuBasicInfoForm' })
|
|
|
|
|
|
|
|
|
|
|
|
// ====== 商品详情相关操作 ======
|
|
|
|
|
|
|
|
const { allSchemas } = useCrudSchemas(basicInfoSchema)
|
|
|
|
|
|
|
|
/** 商品图预览 */
|
|
|
|
|
|
|
|
const imagePreview = (args) => {
|
|
|
|
|
|
|
|
const urlList = []
|
|
|
|
|
|
|
|
if (isArray(args)) {
|
|
|
|
|
|
|
|
args.forEach((item) => {
|
|
|
|
|
|
|
|
urlList.push(item.url)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
urlList.push(args)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
createImageViewer({
|
|
|
|
|
|
|
|
urlList
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ====== end ======
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const message = useMessage() // 消息弹窗
|
|
|
|
const message = useMessage() // 消息弹窗
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
const props = defineProps({
|
|
|
|
@ -118,15 +78,16 @@ const props = defineProps({
|
|
|
|
activeName: propTypes.string.def(''),
|
|
|
|
activeName: propTypes.string.def(''),
|
|
|
|
isDetail: propTypes.bool.def(false) // 是否作为详情组件
|
|
|
|
isDetail: propTypes.bool.def(false) // 是否作为详情组件
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const productSpuBasicInfoRef = ref() // 表单 Ref
|
|
|
|
|
|
|
|
|
|
|
|
const formRef = ref() // 表单 Ref
|
|
|
|
const formData = reactive<Spu>({
|
|
|
|
const formData = reactive<Spu>({
|
|
|
|
name: '', // 商品名称
|
|
|
|
name: '', // 商品名称
|
|
|
|
categoryId: null, // 商品分类
|
|
|
|
categoryId: undefined, // 商品分类
|
|
|
|
keyword: '', // 关键字
|
|
|
|
keyword: '', // 关键字
|
|
|
|
picUrl: '', // 商品封面图
|
|
|
|
picUrl: '', // 商品封面图
|
|
|
|
sliderPicUrls: [], // 商品轮播图
|
|
|
|
sliderPicUrls: [], // 商品轮播图
|
|
|
|
introduction: '', // 商品简介
|
|
|
|
introduction: '', // 商品简介
|
|
|
|
brandId: null // 商品品牌
|
|
|
|
brandId: undefined // 商品品牌
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const rules = reactive({
|
|
|
|
const rules = reactive({
|
|
|
|
name: [required],
|
|
|
|
name: [required],
|
|
|
|
@ -163,8 +124,8 @@ watch(
|
|
|
|
const emit = defineEmits(['update:activeName'])
|
|
|
|
const emit = defineEmits(['update:activeName'])
|
|
|
|
const validate = async () => {
|
|
|
|
const validate = async () => {
|
|
|
|
// 校验表单
|
|
|
|
// 校验表单
|
|
|
|
if (!productSpuBasicInfoRef) return
|
|
|
|
if (!formRef) return
|
|
|
|
return await unref(productSpuBasicInfoRef).validate((valid) => {
|
|
|
|
return await unref(formRef).validate((valid) => {
|
|
|
|
if (!valid) {
|
|
|
|
if (!valid) {
|
|
|
|
message.warning('商品信息未完善!!')
|
|
|
|
message.warning('商品信息未完善!!')
|
|
|
|
emit('update:activeName', 'basicInfo')
|
|
|
|
emit('update:activeName', 'basicInfo')
|
|
|
|
@ -184,7 +145,7 @@ const formatCategoryName = (categoryId: number) => {
|
|
|
|
return treeToString(categoryList.value, categoryId)
|
|
|
|
return treeToString(categoryList.value, categoryId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const brandList = ref([]) // 精简商品品牌列表
|
|
|
|
const brandList = ref<BrandVO[]>([]) // 精简商品品牌列表
|
|
|
|
onMounted(async () => {
|
|
|
|
onMounted(async () => {
|
|
|
|
// 获得分类树
|
|
|
|
// 获得分类树
|
|
|
|
const data = await ProductCategoryApi.getCategoryList({})
|
|
|
|
const data = await ProductCategoryApi.getCategoryList({})
|
|
|
|
|