106 lines
3.2 KiB
JavaScript
Executable File
106 lines
3.2 KiB
JavaScript
Executable File
// @/composables/useFormBuilder.js
|
|
import { useNuxtApp } from "#app";
|
|
|
|
export function useElpService(props, emit) {
|
|
const { $moment } = useNuxtApp(); // فرض میکنیم $moment در Nuxt plugin ثبت شده
|
|
const { $http: httpService } = useNuxtApp();
|
|
const toast = useToast();
|
|
///-----------------------------------------------------
|
|
///--- یک فیلد را بروزرسانی می کند
|
|
///-----------------------------------------------------
|
|
async function uepUpdateField(doc_id, payload, key = "sanad") {
|
|
if (!doc_id) {
|
|
return;
|
|
}
|
|
|
|
let url = elpApi.base.update_field;
|
|
url = url.replace("{{type_name}}", key);
|
|
url = url.replace("{{doc_id}}", doc_id);
|
|
return await httpService
|
|
.postRequest(url, payload)
|
|
.then(() => {
|
|
toast.add({
|
|
title: "موفق",
|
|
description: "عملیات با موفقیت انجام شد.",
|
|
icon: "i-lucide-calendar-days",
|
|
});
|
|
return true;
|
|
})
|
|
.catch(() => {
|
|
toast.add({
|
|
title: "خطا",
|
|
description: "خطا در انجام دوباره تلاش کنید",
|
|
color: "red",
|
|
});
|
|
return undefined;
|
|
});
|
|
}
|
|
|
|
///-----------------------------------------------------
|
|
///--- با توجه به یک فیلد، مقدار محاسبه شده ای بر میگردند مثلا : بیشترین مقدار یا مجموع یا ...
|
|
///-----------------------------------------------------
|
|
async function uepGetComputeField(
|
|
key = "mnsanad",
|
|
property_key = "meet_no",
|
|
compute_key = "max",
|
|
filters = {}
|
|
) {
|
|
let payload = {
|
|
compute_key,
|
|
property_key,
|
|
filters,
|
|
};
|
|
|
|
let url = elpApi.base.compute_field;
|
|
url = url.replace("{{type_name}}", key);
|
|
|
|
return await httpService
|
|
.postRequest(url, payload)
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch(() => {
|
|
toast.add({
|
|
title: "خطا",
|
|
description: "خطا در انجام عملیات، دوباره تلاش کنید",
|
|
color: "red",
|
|
});
|
|
return undefined;
|
|
});
|
|
}
|
|
|
|
///-----------------------------------------------------
|
|
///--- با توجه به یک فیلد، مقدار محاسبه شده ای بر میگردند مثلا : بیشترین مقدار یا مجموع یا ...
|
|
///-----------------------------------------------------
|
|
async function uepGetConflictDoc(
|
|
doc_id,
|
|
key = "qaconflict"
|
|
) {
|
|
let url = elpApi.conflict.get;
|
|
url = url.replace("{{type_name}}", key);
|
|
url = url.replace("{{doc_id}}", doc_id);
|
|
|
|
return await httpService
|
|
.getRequest(url)
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch(() => {
|
|
toast.add({
|
|
title: "خطا",
|
|
description: "خطا در انجام عملیات، دوباره تلاش کنید",
|
|
color: "red",
|
|
});
|
|
return undefined;
|
|
});
|
|
}
|
|
|
|
///-----------------------------------------------------
|
|
///-----------------------------------------------------
|
|
return {
|
|
uepUpdateField,
|
|
uepGetComputeField,
|
|
uepGetConflictDoc,
|
|
};
|
|
}
|