diff --git a/src/api/mall/product/spu.ts b/src/api/mall/product/spu.ts
index 5555ce10..e0d4ec83 100644
--- a/src/api/mall/product/spu.ts
+++ b/src/api/mall/product/spu.ts
@@ -37,7 +37,7 @@ export interface Spu {
brandId?: number | null // 商品品牌编号
specType?: boolean // 商品规格
subCommissionType?: boolean // 分销类型
- skus: Sku[] // sku数组
+ skus?: Sku[] // sku数组
description?: string // 商品详情
sort?: number // 商品排序
giveIntegral?: number // 赠送积分
diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts
index e530c410..f7e56fd0 100644
--- a/src/router/modules/remaining.ts
+++ b/src/router/modules/remaining.ts
@@ -379,6 +379,19 @@ const remainingRouter: AppRouteRecordRaw[] = [
title: '编辑商品',
activeMenu: '/product/product-spu'
}
+ },
+ {
+ path: 'productSpuDetail/:spuId(\\d+)',
+ component: () => import('@/views/mall/product/spu/addForm.vue'),
+ name: 'productSpuDetail',
+ meta: {
+ noCache: true,
+ hidden: true,
+ canTo: true,
+ icon: 'ep:view',
+ title: '商品详情',
+ activeMenu: '/product/product-spu'
+ }
}
]
}
diff --git a/src/utils/tree.ts b/src/utils/tree.ts
index 82b5bc34..65a9345c 100644
--- a/src/utils/tree.ts
+++ b/src/utils/tree.ts
@@ -312,26 +312,30 @@ export const handleTree2 = (data, id, parentId, children, rootId) => {
* @param nodeId 需要判断在什么层级的数据
* @param level 检查的级别, 默认检查到二级
*/
-export const checkSelectedNode = (tree: any[], nodeId, level = 2) => {
+export const checkSelectedNode = (tree: any[], nodeId: any, level = 2): boolean => {
if (typeof tree === 'undefined' || !Array.isArray(tree) || tree.length === 0) {
console.warn('tree must be an array')
return false
}
+
// 校验是否是一级节点
if (tree.some((item) => item.id === nodeId)) {
return false
}
+
// 递归计数
let count = 1
// 深层次校验
- function performAThoroughValidation(arr) {
+ function performAThoroughValidation(arr: any[]): boolean {
count += 1
for (const item of arr) {
if (item.id === nodeId) {
return true
} else if (typeof item.children !== 'undefined' && item.children.length !== 0) {
- performAThoroughValidation(item.children)
+ if (performAThoroughValidation(item.children)) {
+ return true
+ }
}
}
return false
@@ -341,11 +345,15 @@ export const checkSelectedNode = (tree: any[], nodeId, level = 2) => {
count = 1
if (performAThoroughValidation(item.children)) {
// 找到后对比是否是期望的层级
- if (count >= level) return true
+ if (count >= level) {
+ return true
+ }
}
}
+
return false
}
+
/**
* 获取节点的完整结构
* @param tree 树数据
@@ -369,7 +377,10 @@ export const treeToString = (tree: any[], nodeId) => {
str += `/${item.name}`
return true
} else if (typeof item.children !== 'undefined' && item.children.length !== 0) {
- performAThoroughValidation(item.children)
+ str += `/${item.name}`
+ if (performAThoroughValidation(item.children)) {
+ return true
+ }
}
}
return false
diff --git a/src/views/mall/product/spu/addForm.vue b/src/views/mall/product/spu/addForm.vue
index 1ae1a4c2..737b5e17 100644
--- a/src/views/mall/product/spu/addForm.vue
+++ b/src/views/mall/product/spu/addForm.vue
@@ -5,6 +5,7 @@
@@ -12,6 +13,7 @@
@@ -19,6 +21,7 @@
@@ -42,11 +45,12 @@ import { convertToInteger, formatToFraction } from '@/utils'
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const { push, currentRoute } = useRouter() // 路由
-const { params } = useRoute() // 查询参数
+const { params, name } = useRoute() // 查询参数
const { delView } = useTagsViewStore() // 视图操作
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const activeName = ref('basicInfo') // Tag 激活的窗口
+const isDetail = ref(false) // 是否查看详情
const basicInfoRef = ref>() // 商品信息Ref
const descriptionRef = ref>() // 商品详情Ref
const otherSettingsRef = ref>() // 其他设置Ref
@@ -90,12 +94,13 @@ const formData = ref({
/** 获得详情 */
const getDetail = async () => {
+ console.log(name)
const id = params.spuId as number
if (id) {
formLoading.value = true
try {
const res = (await ProductSpuApi.getSpu(id)) as ProductSpuApi.Spu
- res.skus.forEach((item) => {
+ res.skus!.forEach((item) => {
// 回显价格分转元
item.price = formatToFraction(item.price)
item.marketPrice = formatToFraction(item.marketPrice)
@@ -123,7 +128,7 @@ const submitForm = async () => {
// 深拷贝一份, 这样最终 server 端不满足,不需要恢复,
const deepCopyFormData = cloneDeep(unref(formData.value))
// 兜底处理 sku 空数据
- formData.value.skus.forEach((sku) => {
+ formData.value.skus!.forEach((sku) => {
// 因为是空数据这里判断一下商品条码是否为空就行
if (sku.barCode === '') {
const index = deepCopyFormData.skus.findIndex(
@@ -171,7 +176,6 @@ const close = () => {
delView(unref(currentRoute))
push('/product/product-spu')
}
-
/** 初始化 */
onMounted(async () => {
await getDetail()
diff --git a/src/views/mall/product/spu/components/BasicInfoForm.vue b/src/views/mall/product/spu/components/BasicInfoForm.vue
index 60fc7c69..2cc5a7c2 100644
--- a/src/views/mall/product/spu/components/BasicInfoForm.vue
+++ b/src/views/mall/product/spu/components/BasicInfoForm.vue
@@ -1,5 +1,11 @@
-
+
@@ -115,18 +121,72 @@
+
+
+ {{ categoryString(row.categoryId) }}
+
+ {{ brandList.find((item) => item.id === row.brandId)?.name }}
+
+
+ {{ row.specType ? '多规格' : '单规格' }}
+
+
+ {{ row.subCommissionType ? '自行设置' : '默认设置' }}
+
+
+
+
+
+
+
+
+
+
+