fix(AiEartagPicker): 修复确认选择后原始数据丢失的问题

- 添加 origin 数组以保存初始获取的数据
- 修改 handleConfirm 方法,确保选中的数据来自原始数据
This commit is contained in:
aixianling
2025-01-15 15:59:58 +08:00
parent 0a6b77943f
commit 17b28025d8

View File

@@ -16,7 +16,8 @@ export default {
return { return {
list: [], list: [],
dialog: false, dialog: false,
selected: [] selected: [],
origin: []
} }
}, },
computed: { computed: {
@@ -41,6 +42,7 @@ export default {
!/undefined/.test(this.api) && this.instance.post(this.api).then(res => { !/undefined/.test(this.api) && this.instance.post(this.api).then(res => {
if (res?.data) { if (res?.data) {
const key = this.valueKey const key = this.valueKey
this.origin = res.data ?? []
this.list = res.data?.map(v => { this.list = res.data?.map(v => {
if (typeof v == 'string') { if (typeof v == 'string') {
return {key: v, label: v} return {key: v, label: v}
@@ -54,7 +56,7 @@ export default {
handleConfirm() { handleConfirm() {
this.dialog = false this.dialog = false
this.$emit("input", this.selected) this.$emit("input", this.selected)
this.$emit("select", this.list.filter(v => this.selected.includes(v.id))) this.$emit("select", this.origin.filter(v => this.selected.includes(v?.[this.valueKey] ?? v)))
} }
} }
} }