WIP Изменила отправку документов
This commit is contained in:
@@ -19,10 +19,10 @@
|
||||
q-avatar(
|
||||
rounded,
|
||||
size="40px",
|
||||
v-if="docData[data.dataKey][field.key]?.photo"
|
||||
v-if="docData[data.dataKey]?.attachments?.photo"
|
||||
)
|
||||
img.h-10.w-10.object-cover(
|
||||
:src="docData[data.dataKey][field.key]?.photo",
|
||||
:src="docData[data.dataKey]?.attachments?.photo",
|
||||
:alt="docData[data.dataKey][field.label]"
|
||||
)
|
||||
q-badge.delete(
|
||||
@@ -114,6 +114,7 @@ export default {
|
||||
],
|
||||
initializationData: {
|
||||
passport: {
|
||||
category: "passport",
|
||||
id: null,
|
||||
series: null,
|
||||
number: null,
|
||||
@@ -124,11 +125,13 @@ export default {
|
||||
},
|
||||
insurance_number: {
|
||||
id: null,
|
||||
category: "insurance_number",
|
||||
number: null,
|
||||
attachments: null,
|
||||
},
|
||||
tax_identification_number: {
|
||||
id: null,
|
||||
category: "tax_identification_number",
|
||||
number: null,
|
||||
attachments: null,
|
||||
},
|
||||
@@ -143,7 +146,14 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
initialDocData() {
|
||||
return this.$store.state.medical?.documents;
|
||||
// const { passport, insurance_number, tax_identification_number } =
|
||||
// this.$store.state.medical.documents;
|
||||
// return {
|
||||
// passport: passport,
|
||||
// insurance_number: insurance_number,
|
||||
// tax_identification_number: tax_identification_number,
|
||||
// };
|
||||
return this.$store.state.medical.documents;
|
||||
},
|
||||
passportFields() {
|
||||
let excludedFields = ["attachments", "id", "category"];
|
||||
@@ -179,7 +189,15 @@ export default {
|
||||
return !this.isEdit && this.copiedFields.some((elem) => elem === key);
|
||||
},
|
||||
cancelEdit() {
|
||||
this.docData = JSON.parse(JSON.stringify(this.initialDocData));
|
||||
const { passport, insurance_number, tax_identification_number } =
|
||||
this.initialDocData;
|
||||
this.docData = {
|
||||
passport: JSON.parse(JSON.stringify(passport)),
|
||||
insurance_number: JSON.parse(JSON.stringify(insurance_number)),
|
||||
tax_identification_number: JSON.parse(
|
||||
JSON.stringify(tax_identification_number)
|
||||
),
|
||||
};
|
||||
this.isEdit = false;
|
||||
this.isCheckChange = false;
|
||||
this.$refs.documentForm.resetValidation();
|
||||
@@ -215,61 +233,34 @@ export default {
|
||||
} else {
|
||||
let request = [];
|
||||
Object.keys(this.docData).forEach((elem) => {
|
||||
let formData = new FormData();
|
||||
form
|
||||
.getValidationComponents()
|
||||
.filter(({ name }) => name?.split(":")?.[0] === elem)
|
||||
.forEach((el) => {
|
||||
const name = el?.name?.split(":")?.[1];
|
||||
if (name === "issued_at")
|
||||
formData.append(name, this.convertFormat(el.modelValue));
|
||||
else formData.append(name, el.modelValue ?? "");
|
||||
});
|
||||
this.checkChangePhoto(elem, "attachments", formData);
|
||||
if (formData.get("attachments")) {
|
||||
console.log(elem, "img", formData.get("attachments"));
|
||||
formData.delete("attachments");
|
||||
}
|
||||
if (formData.get("issued_by_org_code")) {
|
||||
this.checkChangePhoto(elem, "attachments");
|
||||
let newData = JSON.parse(JSON.stringify(this.docData[elem]));
|
||||
newData.attachments = {};
|
||||
if (!checkChangeData(this.initialDocData?.[elem], newData)) return;
|
||||
delete newData.id;
|
||||
if (newData?.issued_by_org_code) {
|
||||
console.log(
|
||||
"issued_by_org_code",
|
||||
formData.get("issued_by_org_code")
|
||||
"passport issued_by_org_code",
|
||||
newData.issued_by_org_code
|
||||
);
|
||||
formData.delete("issued_by_org_code");
|
||||
delete newData.issued_by_org_code;
|
||||
}
|
||||
if (
|
||||
!checkChangeData(
|
||||
this.initialDocData?.[elem],
|
||||
this.docData?.[elem]
|
||||
)
|
||||
)
|
||||
return;
|
||||
formData.append("category", elem);
|
||||
delete newData.attachments;
|
||||
if (!this.initialDocData?.[elem]?.id) {
|
||||
formData.append(
|
||||
"person_id",
|
||||
this.$store.state.medical?.basicData?.personalData?.id
|
||||
);
|
||||
// for (const key of formData.keys()) {
|
||||
// console.log(key, formData.get(key));
|
||||
// }
|
||||
request.push(this.createData("documents/", formData));
|
||||
} else {
|
||||
// for (const key of formData.keys()) {
|
||||
// console.log(key, formData.get(key));
|
||||
// }
|
||||
request.push(
|
||||
this.updateData(
|
||||
`documents/${this.initialDocData?.[elem]?.id}`,
|
||||
formData
|
||||
)
|
||||
);
|
||||
}
|
||||
newData.person_id =
|
||||
this.$store.state.medical?.basicData?.personalData?.id;
|
||||
console.log("create", newData);
|
||||
request.push(this.createData("documents/", newData));
|
||||
} else console.log("create", newData);
|
||||
request.push(
|
||||
this.updateData(
|
||||
`documents/${this.initialDocData?.[elem]?.id}`,
|
||||
newData
|
||||
)
|
||||
);
|
||||
});
|
||||
Promise.allSettled(request).then(() => {
|
||||
this.getMedicalCardData({
|
||||
personId: this.$store.state.medical?.basicData?.personalData?.id,
|
||||
});
|
||||
this.getMedicalCardData(this.$route.params.id);
|
||||
this.isEdit = false;
|
||||
this.isCheckChange = false;
|
||||
this.$refs.form?.resetValidation();
|
||||
@@ -277,21 +268,19 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
checkChangePhoto(updatedObjId, field, formData) {
|
||||
checkChangePhoto(updatedObjId, field) {
|
||||
if (this.docData[updatedObjId][field]?.file)
|
||||
formData.append(field, this.docData[updatedObjId][field]?.file[0]);
|
||||
},
|
||||
checkPhotoDeletion(updatedObjId, field) {
|
||||
return (
|
||||
!Object.keys(this.docData[updatedObjId][field]).length &&
|
||||
this.initialDocData[updatedObjId][field]?.photo
|
||||
);
|
||||
console.log(
|
||||
updatedObjId,
|
||||
field,
|
||||
this.docData[updatedObjId][field]?.file[0]
|
||||
);
|
||||
},
|
||||
async createData(url, body) {
|
||||
return await fetchWrapper.post(url, body, "formData");
|
||||
return await fetchWrapper.post(url, body);
|
||||
},
|
||||
async updateData(url, body) {
|
||||
return await fetchWrapper.patch(url, body, "formData");
|
||||
return await fetchWrapper.patch(url, body);
|
||||
},
|
||||
async deletePhoto(url) {
|
||||
return await fetchWrapper.del(url);
|
||||
@@ -303,7 +292,7 @@ export default {
|
||||
return date ? date.split(".").reverse().join("-") : "";
|
||||
},
|
||||
...mapActions({
|
||||
getMedicalCardData: "getMedicalCardDataByPersonId",
|
||||
getMedicalCardData: "getMedicalCardDataById",
|
||||
}),
|
||||
},
|
||||
watch: {
|
||||
@@ -312,7 +301,15 @@ export default {
|
||||
immediate: true,
|
||||
handler(value) {
|
||||
if (Object.keys(value).length) {
|
||||
this.docData = JSON.parse(JSON.stringify(value));
|
||||
const { passport, insurance_number, tax_identification_number } =
|
||||
value;
|
||||
this.docData = {
|
||||
passport: JSON.parse(JSON.stringify(passport)),
|
||||
insurance_number: JSON.parse(JSON.stringify(insurance_number)),
|
||||
tax_identification_number: JSON.parse(
|
||||
JSON.stringify(tax_identification_number)
|
||||
),
|
||||
};
|
||||
} else this.docData = this.initializationData;
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user