WIP Частично сделана отправка данных

This commit is contained in:
Daria Golova
2023-04-18 18:26:38 +03:00
parent a6bfb742a7
commit 5f5507b50b
3 changed files with 107 additions and 14 deletions

View File

@@ -52,6 +52,9 @@ import BaseInput from "@/components/base/BaseInput.vue";
import BaseAvatar from "@/components/base/BaseAvatar.vue"; import BaseAvatar from "@/components/base/BaseAvatar.vue";
import BaseModal from "@/components/base/BaseModal.vue"; import BaseModal from "@/components/base/BaseModal.vue";
import BaseUploadPhoto from "@/components/base/BaseUploadPhoto.vue"; import BaseUploadPhoto from "@/components/base/BaseUploadPhoto.vue";
import { checkChangeData } from "@/shared/utils/changesObjects.js";
import { fetchWrapper } from "@/shared/fetchWrapper.js";
import * as moment from "moment/moment";
export default { export default {
name: "DocumentsForm", name: "DocumentsForm",
components: { components: {
@@ -108,8 +111,7 @@ export default {
this.isEdit = true; this.isEdit = true;
}, },
checkChangeDocData() { checkChangeDocData() {
this.isCheckChange = this.isCheckChange = checkChangeData(this.initialDocData, this.docData);
JSON.stringify(this.docData) !== JSON.stringify(this.initialDocData);
}, },
openModal(id) { openModal(id) {
this.photoId = id; this.photoId = id;
@@ -120,7 +122,102 @@ export default {
this.isCheckChange = true; this.isCheckChange = true;
}, },
saveChange() { saveChange() {
//console.log(this.docData); this.updateDocData();
},
updateDocData() {
let {
passport,
insurance_number: insurance,
tax_identification_number: tax,
} = this.docData;
let documentsFormData = new FormData();
let passportFormData = new FormData();
let request = [];
if (insurance?.insurance_number)
documentsFormData.append(
"insurance_number",
insurance?.insurance_number
);
if (tax?.tax_identification_number)
documentsFormData.append(
"tax_identification_number",
tax?.tax_identification_number
);
if (
insurance?.photo_insurance_number?.file &&
insurance?.photo_insurance_number?.photo !==
this.initialDocData.insurance_number?.photo_insurance_number.photo
)
documentsFormData.append(
"photo_insurance_number",
insurance?.photo_insurance_number?.file[0]
);
if (
tax?.photo_tax_identification_number?.file &&
tax?.photo_tax_identification_number.photo !==
this.initialDocData.tax_identification_number
?.photo_tax_identification_number.photo
)
documentsFormData.append(
"photo_tax_identification_number",
tax?.photo_tax_identification_number?.file[0]
);
Object.keys(passport).forEach((key) => {
if (key === "issued_by_date" && passport[key]) {
passportFormData.append(
"issued_by_date",
moment(passport.issued_by_date).format("YYYY-MM-DD")
);
return;
}
if (
key === "photo" &&
passport?.photo?.file &&
this.checkChangeField(
this.initialDocData?.passport?.photo,
passport?.photo,
"photo"
)
) {
passportFormData.append(key, passport[key]?.file[0]);
return;
}
if (
key !== "photo" &&
this.checkChangeField(this.initialDocData.passport, passport, key)
) {
passportFormData.append(key, passport[key]);
return;
}
});
if (!passport.id)
request.push(
this.sendData("general/identity_document/create/", passportFormData)
);
else
request.push(
this.sendData(
`general/identity_document/${passport.id}/update/`,
passportFormData
)
);
request.push(
this.sendData(
`general/person/${this.$store.state.medical?.basicData?.personalData?.id}/update/`,
documentsFormData
)
);
Promise.allSettled(request).then(() => {
this.$store.dispatch("getMedicalCardData");
this.isEdit = false;
this.isCheckChange = false;
});
},
checkChangeField(initObj, updatedObj, field) {
return initObj[field] !== updatedObj[field];
},
async sendData(url, body) {
return await fetchWrapper.post(url, body, "formData");
}, },
}, },
watch: { watch: {

View File

@@ -363,7 +363,7 @@ export const documentForm = [
{ {
key: "tax_identification_number", key: "tax_identification_number",
label: "Номер ИНН", label: "Номер ИНН",
type: "number", type: "text",
inputMask: "############", inputMask: "############",
}, },
{ {

View File

@@ -20,14 +20,10 @@ export function getObjectChangeField(objInit, objUpdate) {
return resultObj; return resultObj;
} }
export function checkChangeData(dataInit, dataChange) { export function checkTypeofObject(obj) {
let initData = JSON.stringify(dataInit); return typeof obj === "object" && obj !== "null";
let changeData = JSON.stringify(dataChange); }
return initData !== changeData;
//Алексей, какого черта!? export function checkChangeData(dataInit, dataChange) {
/*if (initData !== changeData) { return JSON.stringify(dataInit) !== JSON.stringify(dataChange);
return true;
} else {
return false;
}*/
} }