refactor: get link options
This commit is contained in:
parent
e286551bca
commit
f0fae04018
@ -5,7 +5,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
ref="autocomplete"
|
ref="autocomplete"
|
||||||
:options="options"
|
:options="options.data"
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:size="attrs.size || 'sm'"
|
:size="attrs.size || 'sm'"
|
||||||
:variant="attrs.variant"
|
:variant="attrs.variant"
|
||||||
@ -31,10 +31,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { call } from 'frappe-ui'
|
|
||||||
import Autocomplete from '@/components/frappe-ui/Autocomplete.vue'
|
import Autocomplete from '@/components/frappe-ui/Autocomplete.vue'
|
||||||
|
import { watchDebounced } from '@vueuse/core'
|
||||||
|
import { createResource } from 'frappe-ui'
|
||||||
import { useAttrs, computed, ref } from 'vue'
|
import { useAttrs, computed, ref } from 'vue'
|
||||||
import { computedAsync, watchDebounced } from '@vueuse/core'
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
doctype: {
|
doctype: {
|
||||||
@ -55,8 +55,12 @@ const valuePropPassed = computed(() => 'value' in attrs)
|
|||||||
|
|
||||||
const value = computed({
|
const value = computed({
|
||||||
get: () => (valuePropPassed.value ? attrs.value : props.modelValue),
|
get: () => (valuePropPassed.value ? attrs.value : props.modelValue),
|
||||||
set: (val) =>
|
set: (val) => {
|
||||||
emit(valuePropPassed.value ? 'change' : 'update:modelValue', val?.value),
|
return (
|
||||||
|
val?.value &&
|
||||||
|
emit(valuePropPassed.value ? 'change' : 'update:modelValue', val?.value)
|
||||||
|
)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const autocomplete = ref(null)
|
const autocomplete = ref(null)
|
||||||
@ -64,22 +68,36 @@ const text = ref('')
|
|||||||
|
|
||||||
watchDebounced(
|
watchDebounced(
|
||||||
() => autocomplete.value?.query,
|
() => autocomplete.value?.query,
|
||||||
(val) => (text.value = val),
|
(val) => {
|
||||||
{ debounce: 500 }
|
if (text.value === val) return
|
||||||
|
text.value = val
|
||||||
|
options.update({
|
||||||
|
params: {
|
||||||
|
txt: val,
|
||||||
|
doctype: props.doctype,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
options.reload()
|
||||||
|
},
|
||||||
|
{ debounce: 300, immediate: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
const options = computedAsync(async () => {
|
const options = createResource({
|
||||||
let options = await call('frappe.desk.search.search_link', {
|
url: 'frappe.desk.search.search_link',
|
||||||
|
cache: [props.doctype, text.value],
|
||||||
|
method: 'POST',
|
||||||
|
params: {
|
||||||
txt: text.value,
|
txt: text.value,
|
||||||
doctype: props.doctype,
|
doctype: props.doctype,
|
||||||
})
|
},
|
||||||
options = options?.map((option) => {
|
transform: (data) => {
|
||||||
return {
|
return data.map((option) => {
|
||||||
label: option.value,
|
return {
|
||||||
value: option.value,
|
label: option.value,
|
||||||
}
|
value: option.value,
|
||||||
})
|
}
|
||||||
return options
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const labelClasses = computed(() => {
|
const labelClasses = computed(() => {
|
||||||
|
|||||||
@ -135,7 +135,7 @@
|
|||||||
:value="contact[field.name]"
|
:value="contact[field.name]"
|
||||||
:doctype="field.doctype"
|
:doctype="field.doctype"
|
||||||
:placeholder="field.placeholder"
|
:placeholder="field.placeholder"
|
||||||
@change="(e) => e && field.change(e)"
|
@change="(e) => field.change(e)"
|
||||||
/>
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
v-else
|
v-else
|
||||||
|
|||||||
@ -118,7 +118,7 @@
|
|||||||
<Link
|
<Link
|
||||||
value=""
|
value=""
|
||||||
doctype="Contact"
|
doctype="Contact"
|
||||||
@change="(e) => e && addContact(e)"
|
@change="(e) => addContact(e)"
|
||||||
>
|
>
|
||||||
<template #target="{ togglePopover }">
|
<template #target="{ togglePopover }">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@ -204,7 +204,7 @@
|
|||||||
:value="lead.data[field.name]"
|
:value="lead.data[field.name]"
|
||||||
:doctype="field.doctype"
|
:doctype="field.doctype"
|
||||||
:placeholder="field.placeholder"
|
:placeholder="field.placeholder"
|
||||||
@change="(e) => e && field.change(e)"
|
@change="(e) => field.change(e)"
|
||||||
>
|
>
|
||||||
<template
|
<template
|
||||||
v-if="field.create"
|
v-if="field.create"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user