From 372e2215f01be07c9850e3cdd498d74439df4822 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=84=E5=85=86=E7=90=A6?= <1361001127@qq.com>
Date: Mon, 12 Aug 2024 16:14:52 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E3=80=91=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81=E5=B1=9E?=
=?UTF-8?q?=E6=80=A7=E6=97=B6=E5=85=81=E8=AE=B8=E9=80=89=E6=8B=A9=E5=B7=B2?=
=?UTF-8?q?=E6=9C=89=E7=9A=84=E5=B1=9E=E6=80=A7=E5=80=BC=20Fixes=20#47?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../mall/product/spu/components/SkuList.vue | 6 +--
.../mall/product/spu/components/index.ts | 1 +
.../product/spu/form/ProductAttributes.vue | 27 ++++++++++--
.../spu/form/ProductPropertyAddForm.vue | 41 ++++++++++++++++++-
src/views/mall/product/spu/form/SkuForm.vue | 29 +++++++++++--
5 files changed, 93 insertions(+), 11 deletions(-)
diff --git a/src/views/mall/product/spu/components/SkuList.vue b/src/views/mall/product/spu/components/SkuList.vue
index 9bbd38e4..2b881a46 100644
--- a/src/views/mall/product/spu/components/SkuList.vue
+++ b/src/views/mall/product/spu/components/SkuList.vue
@@ -24,7 +24,7 @@
>
- {{ row.properties[index]?.valueName }}
+ {{ row.properties?.[index]?.valueName }}
@@ -168,7 +168,7 @@
>
- {{ row.properties[index]?.valueName }}
+ {{ row.properties?.[index]?.valueName }}
@@ -248,7 +248,7 @@
>
- {{ row.properties[index]?.valueName }}
+ {{ row.properties?.[index]?.valueName }}
diff --git a/src/views/mall/product/spu/components/index.ts b/src/views/mall/product/spu/components/index.ts
index e2cbe73d..5569bc99 100644
--- a/src/views/mall/product/spu/components/index.ts
+++ b/src/views/mall/product/spu/components/index.ts
@@ -5,6 +5,7 @@ interface PropertyAndValues {
id: number
name: string
values?: PropertyAndValues[]
+ propertyOpts?: PropertyAndValues[]
}
interface RuleConfig {
diff --git a/src/views/mall/product/spu/form/ProductAttributes.vue b/src/views/mall/product/spu/form/ProductAttributes.vue
index ffe7397d..88515829 100644
--- a/src/views/mall/product/spu/form/ProductAttributes.vue
+++ b/src/views/mall/product/spu/form/ProductAttributes.vue
@@ -18,16 +18,28 @@
>
{{ value.name }}
-
+ >
+
+
+
{
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const handleInputConfirm = async (index: number, propertyId: number) => {
if (inputValue.value) {
+ // 重复添加校验
+ if (attributeList.value[index].values.find((item) => item.name === inputValue.value)) {
+ message.warning('已存在相同属性值,请重试')
+ attributeIndex.value = null
+ inputValue.value = ''
+ return
+ }
// 保存属性值
try {
const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value })
diff --git a/src/views/mall/product/spu/form/ProductPropertyAddForm.vue b/src/views/mall/product/spu/form/ProductPropertyAddForm.vue
index 15c5a8d5..6fc9f912 100644
--- a/src/views/mall/product/spu/form/ProductPropertyAddForm.vue
+++ b/src/views/mall/product/spu/form/ProductPropertyAddForm.vue
@@ -10,7 +10,22 @@
@keydown.enter.prevent="submitForm"
>
-
+
+
+
@@ -24,6 +39,7 @@ import * as PropertyApi from '@/api/mall/product/property'
defineOptions({ name: 'ProductPropertyForm' })
+const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
@@ -37,6 +53,7 @@ const formRules = reactive({
})
const formRef = ref() // 表单 Ref
const attributeList = ref([]) // 商品属性列表
+const attrOption = ref([]) // 属性名称下拉框
const props = defineProps({
propertyList: {
type: Array,
@@ -59,6 +76,7 @@ watch(
/** 打开弹窗 */
const open = async () => {
dialogVisible.value = true
+ getAttrOption()
resetForm()
}
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
@@ -80,6 +98,16 @@ const submitForm = async () => {
...formData.value,
values: []
})
+ // 判断最终提交的属性名称是否是选择的 自己手动输入的属性名称不执行emit
+ attrOption.value.forEach((item) => {
+ if (item.name === formData.value.name) {
+ emit('success', propertyId, item.id)
+ message.success(t('common.createSuccess'))
+ dialogVisible.value = false
+ // 中断循环
+ throw new Error()
+ }
+ })
message.success(t('common.createSuccess'))
dialogVisible.value = false
} finally {
@@ -94,4 +122,15 @@ const resetForm = () => {
}
formRef.value?.resetFields()
}
+
+/** 获取商品属性下拉选项 */
+const getAttrOption = async () => {
+ formLoading.value = true
+ try {
+ const data = await PropertyApi.getPropertyPage({ pageNo: 1, pageSize: 100 })
+ attrOption.value = data.list
+ } finally {
+ formLoading.value = false
+ }
+}
diff --git a/src/views/mall/product/spu/form/SkuForm.vue b/src/views/mall/product/spu/form/SkuForm.vue
index 9cc61924..e864550d 100644
--- a/src/views/mall/product/spu/form/SkuForm.vue
+++ b/src/views/mall/product/spu/form/SkuForm.vue
@@ -1,6 +1,13 @@
-
+
-
+
From 24e69ecf3605f916c924a3f8540ef5fcbe6888bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=84=E5=85=86=E7=90=A6?= <1361001127@qq.com>
Date: Tue, 13 Aug 2024 10:11:09 +0800
Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0TODO=E6=B3=A8?=
=?UTF-8?q?=E9=87=8A=EF=BC=9B=E4=BB=A5=E6=9B=B4=E4=BC=98=E9=9B=85=E7=9A=84?=
=?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=B7=B3=E5=87=BA=E5=BE=AA=E7=8E=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../mall/product/spu/form/ProductAttributes.vue | 3 +--
.../mall/product/spu/form/ProductPropertyAddForm.vue | 12 ++++++------
src/views/mall/product/spu/form/SkuForm.vue | 1 +
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/views/mall/product/spu/form/ProductAttributes.vue b/src/views/mall/product/spu/form/ProductAttributes.vue
index 88515829..f2e8ae6a 100644
--- a/src/views/mall/product/spu/form/ProductAttributes.vue
+++ b/src/views/mall/product/spu/form/ProductAttributes.vue
@@ -31,6 +31,7 @@
class="!w-30"
@blur="handleInputConfirm(index, item.id)"
@keyup.enter="handleInputConfirm(index, item.id)"
+ @change="handleInputConfirm(index, item.id)"
>
-