|
@@ -18,16 +18,28 @@
|
|
>
|
|
>
|
|
{{ value.name }}
|
|
{{ value.name }}
|
|
</el-tag>
|
|
</el-tag>
|
|
- <el-input
|
|
|
|
- v-show="inputVisible(index)"
|
|
|
|
|
|
+ <el-select
|
|
:id="`input${index}`"
|
|
:id="`input${index}`"
|
|
:ref="setInputRef"
|
|
:ref="setInputRef"
|
|
|
|
+ v-show="inputVisible(index)"
|
|
v-model="inputValue"
|
|
v-model="inputValue"
|
|
- class="!w-20"
|
|
|
|
|
|
+ filterable
|
|
|
|
+ allow-create
|
|
|
|
+ default-first-option
|
|
|
|
+ :reserve-keyword="false"
|
|
size="small"
|
|
size="small"
|
|
|
|
+ class="!w-30"
|
|
@blur="handleInputConfirm(index, item.id)"
|
|
@blur="handleInputConfirm(index, item.id)"
|
|
@keyup.enter="handleInputConfirm(index, item.id)"
|
|
@keyup.enter="handleInputConfirm(index, item.id)"
|
|
- />
|
|
|
|
|
|
+ @change="handleInputConfirm(index, item.id)"
|
|
|
|
+ >
|
|
|
|
+ <el-option
|
|
|
|
+ v-for="item2 in attributeOptions"
|
|
|
|
+ :key="item2.id"
|
|
|
|
+ :label="item2.name"
|
|
|
|
+ :value="item2.name"
|
|
|
|
+ />
|
|
|
|
+ </el-select>
|
|
<el-button
|
|
<el-button
|
|
v-show="!inputVisible(index)"
|
|
v-show="!inputVisible(index)"
|
|
class="button-new-tag ml-1"
|
|
class="button-new-tag ml-1"
|
|
@@ -42,7 +54,6 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
-import { ElInput } from 'element-plus'
|
|
|
|
import * as PropertyApi from '@/api/mall/product/property'
|
|
import * as PropertyApi from '@/api/mall/product/property'
|
|
import { PropertyAndValues } from '@/views/mall/product/spu/components'
|
|
import { PropertyAndValues } from '@/views/mall/product/spu/components'
|
|
import { propTypes } from '@/utils/propTypes'
|
|
import { propTypes } from '@/utils/propTypes'
|
|
@@ -68,6 +79,7 @@ const setInputRef = (el: any) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const attributeList = ref<PropertyAndValues[]>([]) // 商品属性列表
|
|
const attributeList = ref<PropertyAndValues[]>([]) // 商品属性列表
|
|
|
|
+const attributeOptions = ref([] as PropertyApi.PropertyValueVO[]) // 商品属性名称下拉框
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
propertyList: {
|
|
propertyList: {
|
|
type: Array,
|
|
type: Array,
|
|
@@ -100,15 +112,25 @@ const handleCloseProperty = (index: number) => {
|
|
}
|
|
}
|
|
|
|
|
|
/** 显示输入框并获取焦点 */
|
|
/** 显示输入框并获取焦点 */
|
|
-const showInput = async (index) => {
|
|
|
|
|
|
+const showInput = async (index: number) => {
|
|
attributeIndex.value = index
|
|
attributeIndex.value = index
|
|
inputRef.value[index].focus()
|
|
inputRef.value[index].focus()
|
|
|
|
+ // 获取属性下拉选项
|
|
|
|
+ await getAttributeOptions(attributeList.value[index].id)
|
|
}
|
|
}
|
|
|
|
|
|
/** 输入框失去焦点或点击回车时触发 */
|
|
/** 输入框失去焦点或点击回车时触发 */
|
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
|
const handleInputConfirm = async (index: number, propertyId: number) => {
|
|
const handleInputConfirm = async (index: number, propertyId: number) => {
|
|
if (inputValue.value) {
|
|
if (inputValue.value) {
|
|
|
|
+ // 重复添加校验
|
|
|
|
+ // TODO @芋艿:需要测试下
|
|
|
|
+ if (attributeList.value[index].values.find((item) => item.name === inputValue.value)) {
|
|
|
|
+ message.warning('已存在相同属性值,请重试')
|
|
|
|
+ attributeIndex.value = null
|
|
|
|
+ inputValue.value = ''
|
|
|
|
+ return
|
|
|
|
+ }
|
|
// 保存属性值
|
|
// 保存属性值
|
|
try {
|
|
try {
|
|
const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value })
|
|
const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value })
|
|
@@ -122,4 +144,9 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
|
|
attributeIndex.value = null
|
|
attributeIndex.value = null
|
|
inputValue.value = ''
|
|
inputValue.value = ''
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/** 获取商品属性下拉选项 */
|
|
|
|
+const getAttributeOptions = async (propertyId: number) => {
|
|
|
|
+ attributeOptions.value = await PropertyApi.getPropertyValueSimpleList(propertyId)
|
|
|
|
+}
|
|
</script>
|
|
</script>
|