|
8 | 8 | <el-text class="mx-1">属性值:</el-text>
|
9 | 9 | <el-tag
|
10 | 10 | v-for="(value, valueIndex) in item.values"
|
11 |
| - :key="value.name" |
| 11 | + :key="value.id" |
12 | 12 | :disable-transitions="false"
|
13 | 13 | class="mx-1"
|
14 | 14 | closable
|
|
22 | 22 | v-model="inputValue"
|
23 | 23 | class="!w-20"
|
24 | 24 | size="small"
|
25 |
| - @blur="handleInputConfirm(index)" |
26 |
| - @keyup.enter="handleInputConfirm(index)" |
| 25 | + @blur="handleInputConfirm(index, item.id)" |
| 26 | + @keyup.enter="handleInputConfirm(index, item.id)" |
27 | 27 | />
|
28 | 28 | <el-button
|
29 | 29 | v-show="!inputVisible(index)"
|
|
40 | 40 |
|
41 | 41 | <script lang="ts" name="ProductAttributes" setup>
|
42 | 42 | import { ElInput } from 'element-plus'
|
| 43 | +import * as PropertyApi from '@/api/mall/product/property' |
43 | 44 |
|
| 45 | +const { t } = useI18n() // 国际化 |
| 46 | +const message = useMessage() // 消息弹窗 |
44 | 47 | const inputValue = ref('') // 输入框值
|
45 | 48 | const attributeIndex = ref<number | null>(null) // 获取焦点时记录当前属性项的index
|
46 | 49 | // 输入框显隐控制
|
@@ -79,9 +82,16 @@ const showInput = async (index) => {
|
79 | 82 | InputRef.value[index]!.input!.focus()
|
80 | 83 | }
|
81 | 84 | /** 输入框失去焦点或点击回车时触发 */
|
82 |
| -const handleInputConfirm = (index) => { |
| 85 | +const handleInputConfirm = async (index, propertyId) => { |
83 | 86 | if (inputValue.value) {
|
84 |
| - attributeList.value[index].values.push({ name: inputValue.value }) |
| 87 | + // 保存属性值 |
| 88 | + try { |
| 89 | + const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value }) |
| 90 | + attributeList.value[index].values.push({ id, name: inputValue.value }) |
| 91 | + message.success(t('common.createSuccess')) |
| 92 | + } catch { |
| 93 | + message.error('添加失败,请重试') // TODO 缺少国际化 |
| 94 | + } |
85 | 95 | }
|
86 | 96 | attributeIndex.value = null
|
87 | 97 | inputValue.value = ''
|
|
0 commit comments