Merge branch 'ASTRA-48' into 'master'
WIP Частично сделана отправка данных See merge request andrusyakka/urban-couscous!318
This commit is contained in:
@@ -52,6 +52,9 @@ import BaseInput from "@/components/base/BaseInput.vue";
|
||||
import BaseAvatar from "@/components/base/BaseAvatar.vue";
|
||||
import BaseModal from "@/components/base/BaseModal.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 {
|
||||
name: "DocumentsForm",
|
||||
components: {
|
||||
@@ -108,8 +111,7 @@ export default {
|
||||
this.isEdit = true;
|
||||
},
|
||||
checkChangeDocData() {
|
||||
this.isCheckChange =
|
||||
JSON.stringify(this.docData) !== JSON.stringify(this.initialDocData);
|
||||
this.isCheckChange = checkChangeData(this.initialDocData, this.docData);
|
||||
},
|
||||
openModal(id) {
|
||||
this.photoId = id;
|
||||
@@ -120,7 +122,102 @@ export default {
|
||||
this.isCheckChange = true;
|
||||
},
|
||||
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: {
|
||||
|
||||
@@ -363,7 +363,7 @@ export const documentForm = [
|
||||
{
|
||||
key: "tax_identification_number",
|
||||
label: "Номер ИНН",
|
||||
type: "number",
|
||||
type: "text",
|
||||
inputMask: "############",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -20,14 +20,10 @@ export function getObjectChangeField(objInit, objUpdate) {
|
||||
return resultObj;
|
||||
}
|
||||
|
||||
export function checkChangeData(dataInit, dataChange) {
|
||||
let initData = JSON.stringify(dataInit);
|
||||
let changeData = JSON.stringify(dataChange);
|
||||
return initData !== changeData;
|
||||
//Алексей, какого черта!?
|
||||
/*if (initData !== changeData) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}*/
|
||||
export function checkTypeofObject(obj) {
|
||||
return typeof obj === "object" && obj !== "null";
|
||||
}
|
||||
|
||||
export function checkChangeData(dataInit, dataChange) {
|
||||
return JSON.stringify(dataInit) !== JSON.stringify(dataChange);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user