WIP rework search
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
:autofocus="autofocus",
|
:autofocus="autofocus",
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
:error="error"
|
:error="error"
|
||||||
|
@focus="e => $emit('focus', e)"
|
||||||
)
|
)
|
||||||
template(v-slot:prepend, v-if="iconLeft")
|
template(v-slot:prepend, v-if="iconLeft")
|
||||||
slot(name="iconLeft")
|
slot(name="iconLeft")
|
||||||
@@ -85,7 +86,7 @@ export default {
|
|||||||
height: String,
|
height: String,
|
||||||
error: Boolean,
|
error: Boolean,
|
||||||
},
|
},
|
||||||
emits: ["update:modelValue"],
|
emits: ["update:modelValue", "focus"],
|
||||||
computed: {
|
computed: {
|
||||||
value: {
|
value: {
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
@@ -1,33 +1,51 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
.flex
|
.flex
|
||||||
.col
|
.col
|
||||||
base-input(v-model="fullName", debounce="500", size="M" )
|
base-select.search(
|
||||||
.state(v-if="showMessageBar")
|
width="100%",
|
||||||
.row
|
size="M",
|
||||||
.col {{ message }}
|
placeholder="Найти пациента",
|
||||||
.col
|
icon-left,
|
||||||
q-btn(
|
hide-dropdown-icon,
|
||||||
@click="createPerson"
|
use-input
|
||||||
|
:input-debounce="500"
|
||||||
|
:items="candidates",
|
||||||
|
custom-option,
|
||||||
|
:filter-fn="filterFn",
|
||||||
|
:popup-content-style="{height: candidates?.length > 3 ? '216px' : ''}"
|
||||||
|
v-model="value"
|
||||||
|
ref="selectRef"
|
||||||
)
|
)
|
||||||
q-icon(name="app:icon-plus", size="12px", left)
|
//template(#selected)
|
||||||
span Создать
|
// .text-dark.text-sm.font-medium(v-if="person") {{ person.last_name + ' ' + person.first_name + ' ' + person.patronymic }}
|
||||||
.candidates
|
template(v-slot:iconLeft)
|
||||||
.row.w-full(
|
q-icon.search-icon(name="app:search", size="20px")
|
||||||
v-for="candidate in candidates",
|
template(v-slot:customOption="{props, data}")
|
||||||
key="candidate.id",
|
.w-full.item.px-4.py-2.flex.gap-x-3.cursor-pointer(
|
||||||
@click="pickPerson(candidate)"
|
v-bind="props"
|
||||||
)
|
)
|
||||||
.col {{ candidate.last_name + ' ' + candidate.first_name + ' ' + candidate.patronymic }}
|
.flex.flex-col.gap-y-1
|
||||||
|
.text-dark.text-sm.font-medium {{ data.last_name + ' ' + data.first_name + ' ' + data.patronymic }}
|
||||||
|
template(v-slot:beforeOptions)
|
||||||
|
.h-10.w-full.px-4.pt-3.pb-2.flex.items-center
|
||||||
|
span.text-m.grey-color {{message}}
|
||||||
|
span.text-m.primary-color.cursor-pointer.pl-1(@click="createPerson") Создать
|
||||||
|
template(v-slot:noOption)
|
||||||
|
.h-10.w-full.px-4.pt-3.pb-2.flex.items-center
|
||||||
|
span.text-m.grey-color {{message}}
|
||||||
|
span.text-m.primary-color.cursor-pointer.pl-1(@click="createPerson") Создать
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import BaseInput from "./BaseInput.vue";
|
import BaseInput from "./BaseInput.vue";
|
||||||
import { fetchWrapper } from "@/shared/fetchWrapper";
|
import { fetchWrapper } from "@/shared/fetchWrapper";
|
||||||
import { v_model } from "@/shared/mixins/v-model";
|
import { v_model } from "@/shared/mixins/v-model";
|
||||||
|
import BaseSelect from "@/components/base/BaseSelect.vue";
|
||||||
export default {
|
export default {
|
||||||
name: "BaseInputWithSearch",
|
name: "BaseInputWithSearch",
|
||||||
components: {
|
components: {
|
||||||
BaseInput,
|
BaseInput,
|
||||||
|
BaseSelect,
|
||||||
},
|
},
|
||||||
mixins: [v_model],
|
mixins: [v_model],
|
||||||
emits: ["createPerson"],
|
emits: ["createPerson"],
|
||||||
@@ -37,6 +55,7 @@ export default {
|
|||||||
message: "",
|
message: "",
|
||||||
showMessageBar: true,
|
showMessageBar: true,
|
||||||
candidates: [],
|
candidates: [],
|
||||||
|
person: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -51,40 +70,50 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
fullName(val) {
|
pickedFullName(val) {
|
||||||
if (!val || val === this.pickedFullName) return;
|
this.$refs?.selectRef?.updateInputValue(val, true);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
createPerson() {
|
||||||
|
this.$emit("createPerson");
|
||||||
|
},
|
||||||
|
filterFn(val, update) {
|
||||||
fetchWrapper.get(`persons/?full_name=${val}`).then((result) => {
|
fetchWrapper.get(`persons/?full_name=${val}`).then((result) => {
|
||||||
|
update(() => {
|
||||||
this.candidates = result;
|
this.candidates = result;
|
||||||
this.showMessageBar = true;
|
this.showMessageBar = true;
|
||||||
this.message = `Нужный ${val} не найден?`;
|
this.message = `Нужный ${val} не найден?`;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
value() {
|
test(slotProps) {
|
||||||
this.fullName = this.pickedFullName;
|
console.log(slotProps);
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
pickPerson(person) {
|
|
||||||
this.value = { ...person };
|
|
||||||
},
|
|
||||||
createPerson() {
|
|
||||||
this.$emit("createPerson");
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="sass" scoped>
|
<style lang="sass" scoped>
|
||||||
.candidates
|
.search-icon :deep(path)
|
||||||
max-height: 400px
|
fill: var(--font-grey-color)
|
||||||
overflow-y: auto
|
|
||||||
|
|
||||||
.row
|
.search :deep(.q-field__prepend)
|
||||||
border: 1px solid black
|
padding-right: 4px
|
||||||
cursor: pointer
|
|
||||||
|
.plus :deep(path)
|
||||||
|
fill: var(--default-white)
|
||||||
|
|
||||||
|
.grey-color
|
||||||
|
color: var(--font-grey-color)
|
||||||
|
|
||||||
|
.primary-color
|
||||||
|
color: var(--btn-blue-color)
|
||||||
|
|
||||||
|
.item
|
||||||
|
border-bottom: 1px solid var(--gray-secondary)
|
||||||
|
&:last-child
|
||||||
|
border-bottom: none
|
||||||
&:hover
|
&:hover
|
||||||
background: gray
|
background-color: var(--gray-thirdly)
|
||||||
|
|
||||||
.state
|
|
||||||
background: yellow
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
.flex.flex-col.gap-y-2
|
.flex.flex-col.gap-y-2
|
||||||
base-input-container(:label="label", :style="{width: width, ...sizeVariable}")
|
base-input-container(:label="label", :style="{width: width, ...sizeVariable}")
|
||||||
q-select.select(
|
q-select.select(
|
||||||
|
ref="selectRef"
|
||||||
v-model="value",
|
v-model="value",
|
||||||
:options="items",
|
:options="items",
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
@@ -15,17 +16,13 @@
|
|||||||
dropdown-icon="app:down-arrow",
|
dropdown-icon="app:down-arrow",
|
||||||
:menu-offset="[0, 8]",
|
:menu-offset="[0, 8]",
|
||||||
:use-input="useInput",
|
:use-input="useInput",
|
||||||
|
:input-debounce="inputDebounce",
|
||||||
:placeholder="useInput && placeholder ? placeholder : ''",
|
:placeholder="useInput && placeholder ? placeholder : ''",
|
||||||
@filter="filterFn",
|
@filter="filterFn",
|
||||||
:popup-content-style="popupContentStyle"
|
:popup-content-style="popupContentStyle"
|
||||||
)
|
)
|
||||||
template(v-slot:selected)
|
template(v-slot:selected)
|
||||||
span(v-if="!value?.icon", :class="placeholderColor") {{ textSelect }}
|
slot(name="selected")
|
||||||
q-icon.selected-icon(
|
|
||||||
v-else,
|
|
||||||
:name="iconSelect",
|
|
||||||
size="24px"
|
|
||||||
)
|
|
||||||
template(v-slot:option="scope", v-if="!customOption")
|
template(v-slot:option="scope", v-if="!customOption")
|
||||||
q-item(v-bind="scope.itemProps", style="justify-content: center", v-if="value?.icon")
|
q-item(v-bind="scope.itemProps", style="justify-content: center", v-if="value?.icon")
|
||||||
q-item-section(avatar, style="padding: 0px; min-width: 0px")
|
q-item-section(avatar, style="padding: 0px; min-width: 0px")
|
||||||
@@ -37,9 +34,7 @@
|
|||||||
slot(
|
slot(
|
||||||
name="customOption",
|
name="customOption",
|
||||||
:props="itemProps",
|
:props="itemProps",
|
||||||
:label="opt.label"
|
:data="opt"
|
||||||
:avatar="opt.avatar",
|
|
||||||
:medcard="opt.medcard"
|
|
||||||
)
|
)
|
||||||
template(v-slot:prepend, v-if="iconLeft")
|
template(v-slot:prepend, v-if="iconLeft")
|
||||||
slot(name="iconLeft")
|
slot(name="iconLeft")
|
||||||
@@ -77,6 +72,7 @@ export default {
|
|||||||
clearable: Boolean,
|
clearable: Boolean,
|
||||||
size: String,
|
size: String,
|
||||||
useInput: Boolean,
|
useInput: Boolean,
|
||||||
|
inputDebounce: Number,
|
||||||
iconLeft: Boolean,
|
iconLeft: Boolean,
|
||||||
iconRight: Boolean,
|
iconRight: Boolean,
|
||||||
customOption: Boolean,
|
customOption: Boolean,
|
||||||
@@ -163,6 +159,11 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
updateInputValue(value, noFilter) {
|
||||||
|
this.$refs?.selectRef?.updateInputValue(value, noFilter);
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<style lang="sass">
|
<style lang="sass">
|
||||||
|
|||||||
Reference in New Issue
Block a user