WIP rework medical card data

This commit is contained in:
andrusyakka
2023-08-15 20:27:33 +03:00
parent cc4ea131f9
commit 6c85c5dcf1
6 changed files with 55 additions and 26 deletions

View File

@@ -8,7 +8,7 @@
) )
header-inputs header-inputs
.flex.ml-auto.items-center.gap-x-4 .flex.ml-auto.items-center.gap-x-4
q-btn( q-btn(
flat, flat,
dense, dense,
@@ -68,7 +68,7 @@ export default {
name: "Гордеев Николай Степанович", name: "Гордеев Николай Степанович",
}, },
showPopup: false, showPopup: false,
userData: JSON.parse(localStorage.getItem("userData")), userData: {},
}; };
}, },
computed: { computed: {
@@ -101,6 +101,7 @@ export default {
}, },
async mounted() { async mounted() {
this.userData = await fetchWrapper.get("users/me"); this.userData = await fetchWrapper.get("users/me");
this.$store.dispatch("setUserData", this.userData);
}, },
}; };
</script> </script>

View File

@@ -124,8 +124,10 @@ export default {
}, },
methods: { methods: {
openMedicalCard(id) { openMedicalCard(id) {
localStorage.setItem("medicalId", id); this.getMedicalCardData({
this.$router.push("medical-card"); personId: id,
successCallback: (id) => this.$router.push("medical-card/" + id),
});
}, },
hidePreview() { hidePreview() {
this.internalPreview = false; this.internalPreview = false;
@@ -141,7 +143,7 @@ export default {
}); });
}, },
...mapActions({ ...mapActions({
getMedicalCardData: "getMedicalCardData", getMedicalCardData: "getMedicalCardDataByPersonId",
}), }),
}, },
}; };

View File

@@ -48,8 +48,7 @@ export default {
medical: (state) => state.medical.medicalCard, medical: (state) => state.medical.medicalCard,
}), }),
created() { created() {
if (!localStorage.getItem("medicalId")) this.$router.push("/calendar"); this.$store.dispatch("getMedicalDataById", this.$route.params.id);
this.$store.dispatch("getMedicalCardData");
}, },
}; };
</script> </script>

View File

@@ -40,7 +40,7 @@ export default createRouter({
{ path: "clients", component: TheUser }, { path: "clients", component: TheUser },
{ path: "medcards", component: TheMedcards }, { path: "medcards", component: TheMedcards },
{ path: "settings", component: TheSettings }, { path: "settings", component: TheSettings },
{ path: "medical-card", component: TheMedicalCard }, { path: "medical-card/:id", component: TheMedicalCard },
], ],
}, },
], ],

View File

@@ -29,4 +29,16 @@ export default createStore({
return data; return data;
}, },
}, },
actions: {
setUserData({ commit }, props) {
commit("setUserData", props);
},
},
mutations: {
setUserData(state, props) {
state.userData = { ...props };
},
},
}); });

View File

@@ -450,29 +450,44 @@ const actions = {
commit("setBenefitData", res.results); commit("setBenefitData", res.results);
}); });
}, },
createMedicalCard(id) { createMedicalCard(ctx, id) {
fetchWrapper.post("medical_cards", { fetchWrapper.post("medical_cards", {
person_id: id, person_id: id,
number: String(Math.floor(1 + Math.random() * (100000000 + 1 - 1))), number: String(Math.floor(1 + Math.random() * (100000000 + 1 - 1))),
}); });
return this.getMedicalCardData(id); return this.getMedicalCardDataByPersonId(ctx, id);
}, },
getMedicalCardData({ commit }) { getMedicalCardDataByPersonId({ commit }, { personId, successCallback }) {
fetchWrapper fetchWrapper.get(`medical_cards/person/${personId}`).then((data) => {
.get(`medical_cards/person/${localStorage.getItem("medicalId")}`) if (!data) {
.then((data) => { return this.createMedicalCard({ commit }, personId);
if (!data) { }
return this.createMedicalCard(localStorage.getItem("medicalId")); commit("setMedicalCard", data);
} commit("setBasicData");
commit("setMedicalCard", data); commit("setContactsData");
commit("setBasicData"); commit("setDocumentsData");
commit("setContactsData"); commit("setAllergiesData");
commit("setDocumentsData"); commit("setConfidantData");
commit("setAllergiesData"); commit("setHealthStateData");
commit("setConfidantData"); commit("setEventsPersonData", personId);
commit("setHealthStateData"); successCallback?.(data?.id);
commit("setEventsPersonData", data?.person?.id); });
}); },
getMedicalDataById({ commit }, id) {
fetchWrapper.get(`medical_cards/${id}`).then((data) => {
if (!data) {
return;
}
commit("setMedicalCard", data);
commit("setBasicData");
commit("setContactsData");
commit("setDocumentsData");
commit("setAllergiesData");
commit("setConfidantData");
commit("setHealthStateData");
commit("setEventsPersonData", data?.person?.id);
});
}, },
getPersonsFiltredList() { getPersonsFiltredList() {
return fetchWrapper return fetchWrapper