WIP rework medical card data
This commit is contained in:
@@ -68,7 +68,7 @@ export default {
|
||||
name: "Гордеев Николай Степанович",
|
||||
},
|
||||
showPopup: false,
|
||||
userData: JSON.parse(localStorage.getItem("userData")),
|
||||
userData: {},
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -101,6 +101,7 @@ export default {
|
||||
},
|
||||
async mounted() {
|
||||
this.userData = await fetchWrapper.get("users/me");
|
||||
this.$store.dispatch("setUserData", this.userData);
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -124,8 +124,10 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
openMedicalCard(id) {
|
||||
localStorage.setItem("medicalId", id);
|
||||
this.$router.push("medical-card");
|
||||
this.getMedicalCardData({
|
||||
personId: id,
|
||||
successCallback: (id) => this.$router.push("medical-card/" + id),
|
||||
});
|
||||
},
|
||||
hidePreview() {
|
||||
this.internalPreview = false;
|
||||
@@ -141,7 +143,7 @@ export default {
|
||||
});
|
||||
},
|
||||
...mapActions({
|
||||
getMedicalCardData: "getMedicalCardData",
|
||||
getMedicalCardData: "getMedicalCardDataByPersonId",
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -48,8 +48,7 @@ export default {
|
||||
medical: (state) => state.medical.medicalCard,
|
||||
}),
|
||||
created() {
|
||||
if (!localStorage.getItem("medicalId")) this.$router.push("/calendar");
|
||||
this.$store.dispatch("getMedicalCardData");
|
||||
this.$store.dispatch("getMedicalDataById", this.$route.params.id);
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -40,7 +40,7 @@ export default createRouter({
|
||||
{ path: "clients", component: TheUser },
|
||||
{ path: "medcards", component: TheMedcards },
|
||||
{ path: "settings", component: TheSettings },
|
||||
{ path: "medical-card", component: TheMedicalCard },
|
||||
{ path: "medical-card/:id", component: TheMedicalCard },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -29,4 +29,16 @@ export default createStore({
|
||||
return data;
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
setUserData({ commit }, props) {
|
||||
commit("setUserData", props);
|
||||
},
|
||||
},
|
||||
|
||||
mutations: {
|
||||
setUserData(state, props) {
|
||||
state.userData = { ...props };
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -450,29 +450,44 @@ const actions = {
|
||||
commit("setBenefitData", res.results);
|
||||
});
|
||||
},
|
||||
createMedicalCard(id) {
|
||||
createMedicalCard(ctx, id) {
|
||||
fetchWrapper.post("medical_cards", {
|
||||
person_id: id,
|
||||
number: String(Math.floor(1 + Math.random() * (100000000 + 1 - 1))),
|
||||
});
|
||||
return this.getMedicalCardData(id);
|
||||
return this.getMedicalCardDataByPersonId(ctx, id);
|
||||
},
|
||||
getMedicalCardData({ commit }) {
|
||||
fetchWrapper
|
||||
.get(`medical_cards/person/${localStorage.getItem("medicalId")}`)
|
||||
.then((data) => {
|
||||
if (!data) {
|
||||
return this.createMedicalCard(localStorage.getItem("medicalId"));
|
||||
}
|
||||
commit("setMedicalCard", data);
|
||||
commit("setBasicData");
|
||||
commit("setContactsData");
|
||||
commit("setDocumentsData");
|
||||
commit("setAllergiesData");
|
||||
commit("setConfidantData");
|
||||
commit("setHealthStateData");
|
||||
commit("setEventsPersonData", data?.person?.id);
|
||||
});
|
||||
getMedicalCardDataByPersonId({ commit }, { personId, successCallback }) {
|
||||
fetchWrapper.get(`medical_cards/person/${personId}`).then((data) => {
|
||||
if (!data) {
|
||||
return this.createMedicalCard({ commit }, personId);
|
||||
}
|
||||
commit("setMedicalCard", data);
|
||||
commit("setBasicData");
|
||||
commit("setContactsData");
|
||||
commit("setDocumentsData");
|
||||
commit("setAllergiesData");
|
||||
commit("setConfidantData");
|
||||
commit("setHealthStateData");
|
||||
commit("setEventsPersonData", personId);
|
||||
successCallback?.(data?.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() {
|
||||
return fetchWrapper
|
||||
|
||||
Reference in New Issue
Block a user