139 lines
3.6 KiB
JavaScript
139 lines
3.6 KiB
JavaScript
import { fetchWrapper } from "@/shared/fetchWrapper";
|
|
import { genderOptions } from "@/pages/newMedicalCard/utils/medicalConfig";
|
|
|
|
const state = () => ({
|
|
medicalCard: {},
|
|
basicData: {
|
|
personalData: {
|
|
last_name: null,
|
|
first_name: null,
|
|
patronymic: null,
|
|
gender: null,
|
|
birth_date: null,
|
|
photo: null,
|
|
},
|
|
registrationAddress: {
|
|
region: null,
|
|
city: null,
|
|
street: null,
|
|
house_number: null,
|
|
apartment_number: null,
|
|
},
|
|
residenceAddress: {
|
|
region: null,
|
|
city: null,
|
|
street: null,
|
|
house_number: null,
|
|
apartment_number: null,
|
|
},
|
|
},
|
|
avatar: "",
|
|
});
|
|
|
|
const getters = {
|
|
getBasicData(state, rootState) {
|
|
let registrationAddress =
|
|
state.medicalCard?.person?.address?.find((el) => el.registration_flg) ||
|
|
{};
|
|
let residenceAddress =
|
|
state?.medicalCard?.person?.address?.find((el) => el.residence_flg) || {};
|
|
let person = state.medicalCard.person;
|
|
return {
|
|
personalData: {
|
|
last_name: person?.last_name,
|
|
first_name: person?.first_name,
|
|
patronymic: person?.patronymic,
|
|
gender:
|
|
person?.gender &&
|
|
genderOptions.find((el) => el.id === person?.gender),
|
|
birth_date: person?.birth_date
|
|
? new Date(person?.birth_date)
|
|
: new Date(),
|
|
photo: person?.photo
|
|
? {
|
|
photo: rootState.getUrl + person.photo,
|
|
file: null,
|
|
}
|
|
: {},
|
|
id: person?.id,
|
|
},
|
|
registrationAddress: {
|
|
region: registrationAddress?.region,
|
|
city: registrationAddress?.city,
|
|
street: registrationAddress?.street,
|
|
house_number: registrationAddress?.house_number,
|
|
apartment_number: registrationAddress?.apartment_number,
|
|
id: registrationAddress?.id,
|
|
},
|
|
residenceAddress: {
|
|
region: residenceAddress?.region,
|
|
city: residenceAddress?.city,
|
|
street: residenceAddress?.street,
|
|
house_number: residenceAddress?.house_number,
|
|
apartment_number: residenceAddress?.apartment_number,
|
|
id: residenceAddress?.id,
|
|
},
|
|
insuranceDMS: {
|
|
series: person.insurance_policy.find((e) => e.title === "DMS")?.series,
|
|
number: person.insurance_policy.find((e) => e.title === "DMS")?.number,
|
|
},
|
|
insuranceOMS: {
|
|
series: person.insurance_policy.find((e) => e.title === "OMS")?.series,
|
|
number: person.insurance_policy.find((e) => e.title === "OMS")?.number,
|
|
},
|
|
};
|
|
},
|
|
getAvatar(state) {
|
|
let lastName = state?.medicalCard?.person?.last_name;
|
|
let firstName = state?.medicalCard?.person?.first_name;
|
|
return lastName?.[0] + firstName?.[0];
|
|
},
|
|
};
|
|
|
|
const actions = {
|
|
getMedicalCardData({ commit }) {
|
|
fetchWrapper
|
|
.get(
|
|
`medical_card/medical_history/${localStorage.getItem(
|
|
"medicalId"
|
|
)}/detail/`
|
|
)
|
|
.then((res) => {
|
|
commit("setMedicalCard", res);
|
|
commit("setBasicData");
|
|
});
|
|
},
|
|
returnInitData({ commit }) {
|
|
commit("setBasicData");
|
|
},
|
|
removeMedicalCardData({ commit, rootState }) {
|
|
fetchWrapper
|
|
.del(
|
|
`medical_card/medical_history/${localStorage.getItem(
|
|
"medicalId"
|
|
)}/delete/`
|
|
)
|
|
.then(() => {
|
|
rootState.routingHistory.back();
|
|
commit("setMedicalCard", {});
|
|
localStorage.removeItem("medicalId");
|
|
});
|
|
},
|
|
};
|
|
|
|
const mutations = {
|
|
setMedicalCard(state, card) {
|
|
state.medicalCard = card;
|
|
},
|
|
setBasicData(state) {
|
|
state.basicData = { ...this.getters.getBasicData };
|
|
},
|
|
};
|
|
|
|
export default {
|
|
state,
|
|
getters,
|
|
actions,
|
|
mutations,
|
|
};
|