From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目

---
 src/views/mall/product/spu/form/ProductPropertyAddForm.vue |  148 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 148 insertions(+), 0 deletions(-)

diff --git a/src/views/mall/product/spu/form/ProductPropertyAddForm.vue b/src/views/mall/product/spu/form/ProductPropertyAddForm.vue
new file mode 100644
index 0000000..f45281b
--- /dev/null
+++ b/src/views/mall/product/spu/form/ProductPropertyAddForm.vue
@@ -0,0 +1,148 @@
+<!-- 鍟嗗搧鍙戝竷 - 搴撳瓨浠锋牸 - 娣诲姞灞炴�� -->
+<template>
+  <Dialog v-model="dialogVisible" title="娣诲姞鍟嗗搧灞炴��">
+    <el-form
+      ref="formRef"
+      v-loading="formLoading"
+      :model="formData"
+      :rules="formRules"
+      label-width="80px"
+      @keydown.enter.prevent="submitForm"
+    >
+      <el-form-item label="灞炴�у悕绉�" prop="name">
+        <el-select
+          v-model="formData.name"
+          :reserve-keyword="false"
+          allow-create
+          class="!w-360px"
+          default-first-option
+          filterable
+          placeholder="璇烽�夋嫨灞炴�у悕绉般�傚鏋滀笉瀛樺湪锛屽彲鎵嬪姩杈撳叆閫夋嫨"
+        >
+          <el-option
+            v-for="item in attributeOptions"
+            :key="item.id"
+            :label="item.name"
+            :value="item.name"
+          />
+        </el-select>
+      </el-form-item>
+    </el-form>
+    <template #footer>
+      <el-button :disabled="formLoading" type="primary" @click="submitForm">纭� 瀹�</el-button>
+      <el-button @click="dialogVisible = false">鍙� 娑�</el-button>
+    </template>
+  </Dialog>
+</template>
+<script lang="ts" setup>
+import * as PropertyApi from '@/api/mall/product/property'
+
+defineOptions({ name: 'ProductPropertyForm' })
+
+const { t } = useI18n() // 鍥介檯鍖�
+const message = useMessage() // 娑堟伅寮圭獥
+
+const dialogVisible = ref(false) // 寮圭獥鐨勬槸鍚﹀睍绀�
+const formLoading = ref(false) // 琛ㄥ崟鐨勫姞杞戒腑
+const formData = ref({
+  name: ''
+})
+const formRules = reactive({
+  name: [{ required: true, message: '鍚嶇О涓嶈兘涓虹┖', trigger: 'blur' }]
+})
+const formRef = ref() // 琛ㄥ崟 Ref
+const attributeList = ref([]) // 鍟嗗搧灞炴�у垪琛�
+const attributeOptions = ref([] as PropertyApi.PropertyVO[]) // 鍟嗗搧灞炴�у悕绉颁笅鎷夋
+const props = defineProps({
+  propertyList: {
+    type: Array,
+    default: () => {}
+  }
+})
+
+watch(
+  () => props.propertyList, // 瑙e喅 props 鏃犳硶鐩存帴淇敼鐖剁粍浠剁殑闂
+  (data) => {
+    if (!data) return
+    attributeList.value = data
+  },
+  {
+    deep: true,
+    immediate: true
+  }
+)
+
+/** 鎵撳紑寮圭獥 */
+const open = async () => {
+  dialogVisible.value = true
+  resetForm()
+  // 鍔犺浇鍒楄〃
+  await getAttributeOptions()
+}
+defineExpose({ open }) // 鎻愪緵 open 鏂规硶锛岀敤浜庢墦寮�寮圭獥
+
+/** 鎻愪氦琛ㄥ崟 */
+const submitForm = async () => {
+  // 1.1 閲嶅娣诲姞鏍¢獙
+  for (const attrItem of attributeList.value) {
+    if (attrItem.name === formData.value.name) {
+      return message.error('璇ュ睘鎬у凡瀛樺湪锛岃鍕块噸澶嶆坊鍔�')
+    }
+  }
+  // 1.2 鏍¢獙琛ㄥ崟
+  if (!formRef) return
+  const valid = await formRef.value.validate()
+  if (!valid) return
+
+  // 2.1 鎯呭喌涓�锛氬睘鎬у悕宸插瓨鍦紝鍒欑洿鎺ヤ娇鐢ㄥ苟缁撴潫
+  const existProperty = attributeOptions.value.find((item) => item.name === formData.value.name)
+  if (existProperty) {
+    // 娣诲姞鍒板睘鎬у垪琛�
+    attributeList.value.push({
+      id: existProperty.id,
+      ...formData.value,
+      values: []
+    })
+    // 鍏抽棴寮圭獥
+    dialogVisible.value = false
+    return
+  }
+
+  // 2.2 鎯呭喌浜岋細濡傛灉鏄笉瀛樺湪鐨勫睘鎬э紝鍒欓渶瑕佹墽琛屾柊澧�
+  // 鎻愪氦璇锋眰
+  formLoading.value = true
+  try {
+    const data = formData.value as PropertyApi.PropertyVO
+    const propertyId = await PropertyApi.createProperty(data)
+    // 娣诲姞鍒板睘鎬у垪琛�
+    attributeList.value.push({
+      id: propertyId,
+      ...formData.value,
+      values: []
+    })
+    // 鍏抽棴寮圭獥
+    message.success(t('common.createSuccess'))
+    dialogVisible.value = false
+  } finally {
+    formLoading.value = false
+  }
+}
+
+/** 閲嶇疆琛ㄥ崟 */
+const resetForm = () => {
+  formData.value = {
+    name: ''
+  }
+  formRef.value?.resetFields()
+}
+
+/** 鑾峰彇鍟嗗搧灞炴�т笅鎷夐�夐」 */
+const getAttributeOptions = async () => {
+  formLoading.value = true
+  try {
+    attributeOptions.value = await PropertyApi.getPropertySimpleList()
+  } finally {
+    formLoading.value = false
+  }
+}
+</script>

--
Gitblit v1.8.0