From 4a554fa22565225b065de4b1f6182b1114bfd0bb Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:28:46 +0700 Subject: [PATCH] feat(profile/salary): select input auto insert value on blur --- src/modules/04_registry/components/Salary.vue | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/modules/04_registry/components/Salary.vue b/src/modules/04_registry/components/Salary.vue index cb2652e24..4d81a9fe8 100644 --- a/src/modules/04_registry/components/Salary.vue +++ b/src/modules/04_registry/components/Salary.vue @@ -281,7 +281,9 @@ map-options option-label="name" :options="opLevel" + @input-value="inputPositionLevel" @new-value="createValue" + @blur.stop="inputPositionLevelBlur" option-value="name" hide-bottom-space use-input @@ -1268,6 +1270,27 @@ const formDataSalary = reactive({ doc: "", }); +const tempPositionLevelInput = ref(""); + +function inputPositionLevel(v: string) { + if (!!v) tempPositionLevelInput.value = v; +} + +function inputPositionLevelBlur() { + if (tempPositionLevelInput.value === formDataSalary.levelPosition) return; + + if ( + !optionStore.optipnLevel.some( + (v) => v.name === tempPositionLevelInput.value + ) + ) { + createValue(tempPositionLevelInput.value); + } + + formDataSalary.levelPosition = tempPositionLevelInput.value; + tempPositionLevelInput.value = ""; +} + const opPos = ref([]); const opType = ref([]); const opLevel = ref([]); @@ -2115,7 +2138,7 @@ function coppyForm() { formDataSalary.doc = formDataSalary.doc; } -function createValue(val: any, done: any) { +function createValue(val: any, done?: any) { if (val.length > 0) { const maxId = optionStore.optipnLevel.reduce((max: any, item: any) => { const itemId = typeof item.id === "number" ? item.id : parseInt(item.id); @@ -2130,7 +2153,7 @@ function createValue(val: any, done: any) { optionStore.optipnLevel.push(newObj); } - done(newObj, "toggle"); + done?.(newObj, "toggle"); } }