[WIP] Добавил поиск на модальное окно выбора льгот, правки кода

This commit is contained in:
megavrilinvv
2023-04-20 16:22:25 +03:00
parent 3776ac6c7d
commit 4e2865d143
5 changed files with 94 additions and 34 deletions

View File

@@ -2,12 +2,18 @@
.selection-wrapper.flex .selection-wrapper.flex
.left-side.flex.flex-col.gap-y-4 .left-side.flex.flex-col.gap-y-4
.flex.font-bold.text-xl Категории .flex.font-bold.text-xl Категории
base-input(placeholder="Поиск", outlined, :width="300") base-input(
.flex.items-center.cursor-pointer placeholder="Поиск",
@keyup.enter="searchCategory",
v-model="searchBenefit",
outlined,
:width="300",
iconLeft
)
q-icon( q-icon(
name="app:icon-search", name="app:icon-search",
size="18px", size="20px",
style="color: var(--font-dark-blue-color)" style="color: var(--font-grey-color)"
) )
.field.flex.flex-col.overflow-y-scroll .field.flex.flex-col.overflow-y-scroll
.flex.items-center( .flex.items-center(
@@ -24,7 +30,11 @@
.name.flex.items-center.font-medium.text-xm {{benefit.name}} .name.flex.items-center.font-medium.text-xm {{benefit.name}}
.buttons-group.flex.py-4.px-8.justify-center .buttons-group.flex.py-4.px-8.justify-center
base-button.text-base.font-semibold(outlined, :size="40", @click="closeModalCategories") Отменить base-button.text-base.font-semibold(outlined, :size="40", @click="closeModalCategories") Отменить
base-button.text-base.font-semibold(:size="40", @click="saveCategories(selected[0])") Сохранить base-button.text-base.font-semibold(
v-if="selected.length > 0",
:size="40",
@click="saveCategories(selected[0])"
) Сохранить
.right-side.flex.px-14.font-bold.relative .right-side.flex.px-14.font-bold.relative
q-icon(name="app:icon-cancel").text-sm.absolute.top-4.right-4.cursor-pointer(@click="closeModalCategories") q-icon(name="app:icon-cancel").text-sm.absolute.top-4.right-4.cursor-pointer(@click="closeModalCategories")
.flex.py-10.gap-y-6.flex-col(v-if="selected.length > 0 && selected[0]?.name !== 'Без льготы'") .flex.py-10.gap-y-6.flex-col(v-if="selected.length > 0 && selected[0]?.name !== 'Без льготы'")
@@ -58,10 +68,12 @@ export default {
shiftSelected: Function, shiftSelected: Function,
closeModalCategories: Function, closeModalCategories: Function,
saveCategories: Function, saveCategories: Function,
showModal: Boolean,
}, },
data() { data() {
return { return {
selected: [], selected: [],
searchBenefit: "",
}; };
}, },
computed: { computed: {
@@ -75,6 +87,11 @@ export default {
return this.selected[0]?.privileges.split(","); return this.selected[0]?.privileges.split(",");
}, },
}, },
methods: {
searchCategory() {
this.$emit("search", this.searchBenefit);
},
},
watch: { watch: {
selected: { selected: {
immediate: true, immediate: true,
@@ -83,6 +100,12 @@ export default {
if (this.selected.length >= 2) this.selected.shift(); if (this.selected.length >= 2) this.selected.shift();
}, },
}, },
showModal: {
immediate: true,
handler(newVal) {
if (!newVal) this.searchBenefit = "";
},
},
}, },
}; };
</script> </script>
@@ -91,6 +114,7 @@ export default {
.selection-wrapper .selection-wrapper
width: 895px width: 895px
height: 660px height: 660px
font-feature-settings: 'pnum' on, 'lnum' on
.left-side .left-side
width: 364px width: 364px

View File

@@ -22,10 +22,12 @@
:autogrow="autogrow", :autogrow="autogrow",
:square="square", :square="square",
:standout="standout" :standout="standout"
:accept="accept" :accept="accept",
hide-bottom-space hide-bottom-space
) )
slot.cursor-pointer template(v-slot:prepend, v-if="iconLeft")
slot
slot.cursor-pointer(v-if="!iconLeft")
</template> </template>
<script> <script>
@@ -85,6 +87,7 @@ export default {
disabled: Boolean, disabled: Boolean,
label: String, label: String,
readonly: Boolean, readonly: Boolean,
iconLeft: Boolean,
}, },
emits: ["update:modelValue"], emits: ["update:modelValue"],
computed: { computed: {

View File

@@ -13,7 +13,8 @@
.font-semibold.text-sm.whitespace-nowrap {{insurance.insuranceLabel}} .font-semibold.text-sm.whitespace-nowrap {{insurance.insuranceLabel}}
.flex.w-full.justify-between.items-center.gap-4( .flex.w-full.justify-between.items-center.gap-4(
v-for="field in insurance.fields", v-for="field in insurance.fields",
:key="insurance.insuranceKey + field.key" :key="insurance.insuranceKey + field.key",
:style="{marginTop: field.label === 'Документы' ? '20px' : null}"
) )
.label-field.font-sm.text-sm.whitespace-nowrap {{`${field.label} :`}} .label-field.font-sm.text-sm.whitespace-nowrap {{`${field.label} :`}}
.avatar-field.flex.gap-3.items-center.h-10.w-10(v-if="field.type === 'avatar'") .avatar-field.flex.gap-3.items-center.h-10.w-10(v-if="field.type === 'avatar'")
@@ -25,7 +26,7 @@
.replace-photo.font-medium.text-base.cursor-pointer( .replace-photo.font-medium.text-base.cursor-pointer(
v-if="isEdit", v-if="isEdit",
@click="changeModal(insurance.insuranceKey)" @click="changeModal(insurance.insuranceKey)"
) {{ basic[insurance.insuranceKey][field.key] ? "Заменить фото" : "Добавить фото"}} ) {{ basic[insurance.insuranceKey][field.key] ? "Заменить фото" : "Добавить фото" }}
base-modal( base-modal(
v-if="insurance.insuranceKey === photoId" v-if="insurance.insuranceKey === photoId"
v-model="showModal", v-model="showModal",
@@ -36,11 +37,13 @@
v-model="basic[photoId][field.key]" v-model="basic[photoId][field.key]"
:confirm-upload="confirmChangePhoto" :confirm-upload="confirmChangePhoto"
) )
.flex.h-10.relative(v-else-if="field.type === 'select'") .flex.h-10.relative(
.flex(@click="openModalCategories") v-else-if="field.type === 'select'",
@click="openModalCategories"
)
q-field.items-center.cursor-pointer( q-field.items-center.cursor-pointer(
standout, standout,
:disable="!isEdit", :readonly="!isEdit",
:outlined="isEdit", :outlined="isEdit",
) {{selectCategory(basic[insurance.insuranceKey][field.key])}} ) {{selectCategory(basic[insurance.insuranceKey][field.key])}}
base-modal( base-modal(
@@ -52,9 +55,11 @@
base-category-selection( base-category-selection(
:benefit-data="benefitData", :benefit-data="benefitData",
:close-modal-categories="closeModalCategories", :close-modal-categories="closeModalCategories",
:save-categories="saveCategories" :save-categories="saveCategories",
:show-modal="showModalCategories",
@search="filterDataBenefit"
) )
.flex.font-medium.text-smm.absolute.top-10( .flex.font-medium.text-smm.absolute.top-11(
v-if="basic?.benefit[insurance?.discount]", v-if="basic?.benefit[insurance?.discount]",
:style="{color: 'var(--font-grey-color)'}" :style="{color: 'var(--font-grey-color)'}"
) )
@@ -67,18 +72,24 @@
v-model="basic[insurance.insuranceKey][field.key]", v-model="basic[insurance.insuranceKey][field.key]",
@update:model-value="checkChangeInput", @update:model-value="checkChangeInput",
:mask="field?.inputMask", :mask="field?.inputMask",
:disabled="!isEdit", :readonly="!isEdit",
:standout="!isEdit", :standout="!isEdit",
:outlined="isEdit", :outlined="isEdit",
:type="field.type", :type="field.type",
:width="278", :width="278",
text-color="black" text-color="black"
) )
q-icon.my-auto.text-lg.label-field(
size="18px",
name="app:icon-copy",
v-if="checkCopiedFields(field.key)",
@click="copyValue(basic[insurance.insuranceKey][field.key])"
)
</template> </template>
<script> <script>
import { baseInsuranceForm } from "@/pages/newMedicalCard/utils/medicalConfig"; import { baseInsuranceForm } from "@/pages/newMedicalCard/utils/medicalConfig";
import { mapActions, mapGetters, mapState } from "vuex"; import { mapGetters, mapState } from "vuex";
import MedicalFormWrapper from "@/pages/newMedicalCard/components/MedicalFormWrapper.vue"; import MedicalFormWrapper from "@/pages/newMedicalCard/components/MedicalFormWrapper.vue";
import BaseAvatar from "@/components/base/BaseAvatar.vue"; import BaseAvatar from "@/components/base/BaseAvatar.vue";
import { fetchWrapper } from "@/shared/fetchWrapper"; import { fetchWrapper } from "@/shared/fetchWrapper";
@@ -106,6 +117,7 @@ export default {
showModal: false, showModal: false,
showModalCategories: false, showModalCategories: false,
photoId: "", photoId: "",
copiedFields: ["series", "number"],
}; };
}, },
computed: { computed: {
@@ -118,11 +130,24 @@ export default {
basic: (state) => state.medical.basicData, basic: (state) => state.medical.basicData,
benefitData: (state) => state.medical.benefitData, benefitData: (state) => state.medical.benefitData,
}), }),
...mapActions({
fetchBenefitData: "getBenefitData",
}),
}, },
methods: { methods: {
filterDataBenefit(text) {
if (text.length > 1) {
localStorage.setItem("searchBenefit", text);
this.$store.dispatch("getBenefitDataSearch");
} else {
this.$store.dispatch("getBenefitData");
localStorage.removeItem("searchBenefit", text);
}
},
checkCopiedFields(key) {
return !this.isEdit && this.copiedFields.some((elem) => elem === key);
},
copyValue(text) {
navigator.clipboard.writeText(text);
},
selectCategory(str) { selectCategory(str) {
return str && str.length > 30 return str && str.length > 30
? str.substr(0, 30) + "..." ? str.substr(0, 30) + "..."
@@ -134,6 +159,7 @@ export default {
this.showModalCategories = false; this.showModalCategories = false;
this.basic.benefit.id = obj.id; this.basic.benefit.id = obj.id;
this.basic.benefit.name = obj.name; this.basic.benefit.name = obj.name;
this.basic.benefit.discount = obj.discount;
this.isCheckChange = true; this.isCheckChange = true;
}, },
changeModal(id) { changeModal(id) {
@@ -290,7 +316,7 @@ export default {
showModalCategories: { showModalCategories: {
immediate: true, immediate: true,
handler(newVal) { handler(newVal) {
if (newVal) this.fetchBenefitData; if (newVal) this.$store.dispatch("getBenefitData");
}, },
}, },
}, },
@@ -314,9 +340,6 @@ export default {
.replace-photo .replace-photo
color: var(--btn-blue-color) color: var(--btn-blue-color)
.input
color: purple
.form-wrap .form-wrap
display: grid display: grid
grid-template-columns: repeat(3, 1fr) grid-template-columns: repeat(3, 1fr)

View File

@@ -250,13 +250,13 @@ export const baseInsuranceForm = [
key: "series", key: "series",
label: "Серия", label: "Серия",
type: "text", type: "text",
inputMask: "######", inputMask: "####",
}, },
{ {
key: "number", key: "number",
label: "Номер", label: "Номер",
type: "text", type: "text",
inputMask: "##########", inputMask: "####-####-####",
}, },
{ {
key: "photo", key: "photo",
@@ -273,13 +273,13 @@ export const baseInsuranceForm = [
key: "series", key: "series",
label: "Серия", label: "Серия",
type: "text", type: "text",
inputMask: "######", inputMask: "####",
}, },
{ {
key: "number", key: "number",
label: "Номер", label: "Номер",
type: "text", type: "text",
inputMask: "##########", inputMask: "####-####-####",
}, },
{ {
key: "photo", key: "photo",

View File

@@ -47,6 +47,7 @@ const state = () => ({
}, },
benefit: { benefit: {
id: null, id: null,
discount: null,
name: null, name: null,
photo: null, photo: null,
}, },
@@ -129,6 +130,7 @@ const getters = {
benefit: { benefit: {
name: person?.benefit?.name, name: person?.benefit?.name,
id: person?.benefit?.id, id: person?.benefit?.id,
discount: person?.benefit?.discount,
photo: person?.photo_benefit photo: person?.photo_benefit
? { ? {
photo: rootState.getUrl + person?.photo_benefit, photo: rootState.getUrl + person?.photo_benefit,
@@ -212,6 +214,14 @@ const actions = {
commit("setBenefitData", res.results); commit("setBenefitData", res.results);
}); });
}, },
getBenefitDataSearch({ commit }) {
fetchWrapper
.get(`general/benefit/?name=${localStorage.getItem("searchBenefit")}`)
.then((res) => {
commit("setBenefitData", res.results);
});
},
getMedicalCardData({ commit }) { getMedicalCardData({ commit }) {
fetchWrapper fetchWrapper
.get( .get(