fix CurrentPage ===> รายการตัวชี้วัดตามตำแหน่ง

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-07-15 12:13:19 +07:00
parent 6db8040e90
commit e8eec83e17
2 changed files with 97 additions and 97 deletions

View file

@ -7,6 +7,7 @@ import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { checkPermission } from "@/utils/permissions";
import { updateCurrentPage } from "@/utils/function";
import type { FormListMainByRole } from "@/modules/01_masterdata/interface/request/Main";
import type {
@ -16,6 +17,7 @@ import type {
IndicatorType,
IndicatorTotal,
} from "@/modules/01_masterdata/interface/index/Main";
import type { DataKPIPosition } from "@/modules/01_masterdata/interface/response/Main";
import DialogHistory from "@/modules/01_masterdata/components/Indicators/DialogHistory.vue";
import Summary from "@/modules/01_masterdata/components/Indicators/Summary.vue";
@ -28,7 +30,7 @@ const { showLoader, hideLoader, dialogRemove, success, messageError } =
/** use*/
const dataHistory = ref<KpiRoleData[]>([]);
const modalHistory = ref<boolean>(false);
const total = ref<number>();
const total = ref<number>(0);
const positionOp = ref<DataOption[]>([{ id: "", name: "ทั้งหมด" }]);
const positionMainOp = ref<DataOption[]>([{ id: "", name: "ทั้งหมด" }]);
@ -103,7 +105,6 @@ const roundOp = ref<DataOption[]>([
]);
async function fetchList() {
showLoader();
rows.value = [];
await http
.post(config.API.kpiRoleMainList + `/search-edit`, {
@ -124,9 +125,6 @@ async function fetchList() {
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
@ -141,13 +139,18 @@ function onClickView(id: string = "") {
}
function onClickDelete(id: number) {
dialogRemove($q, () => {
dialogRemove($q, async () => {
showLoader();
http
await http
.delete(config.API.kpiRoleMainList + `/${id}`)
.then(() => {
.then(async () => {
formFilter.page = await updateCurrentPage(
formFilter.page,
maxPage.value,
rows.value.length
);
await fetchList();
success($q, "ลบข้อมูลสำเร็จ");
fetchList();
})
.catch((err) => {
messageError($q, err);
@ -158,9 +161,14 @@ function onClickDelete(id: number) {
});
}
function updatePage(val: number) {
formFilter.page = val;
fetchList();
async function updatePage(val: number) {
showLoader();
try {
formFilter.page = val;
await fetchList();
} finally {
hideLoader();
}
}
function updatePageSize(newPagination: NewPagination) {
@ -170,8 +178,13 @@ function updatePageSize(newPagination: NewPagination) {
watch(
() => formFilter.pageSize,
() => {
fetchList();
async () => {
showLoader();
try {
await fetchList();
} finally {
hideLoader();
}
}
);
@ -181,17 +194,16 @@ watch(
* @param update พเดทค
* @param refData ดาตาทองการฟลเตอร
*/
function filterOption(val: any, update: Function) {
function filterOption(val: string, update: Function) {
update(() => {
positionOp.value = positionMainOp.value.filter(
(v: any) => v.name.indexOf(val) > -1
(v: DataOption) => v.name.indexOf(val) > -1
);
});
}
/** ดึงข้อมูลตำแหน่ง */
async function getOptions() {
// showLoader();
await http
.get(config.API.orgSalaryPosition)
.then(async (res) => {
@ -199,14 +211,14 @@ async function getOptions() {
const uniqueNames = new Set();
const filteredData = dataOp
.filter((item: any) => {
.filter((item: DataKPIPosition) => {
if (!uniqueNames.has(item.positionName)) {
uniqueNames.add(item.positionName);
return true;
}
return false;
})
.map((item: any) => ({
.map((item: DataKPIPosition) => ({
id: item.positionName,
name: item.positionName,
}));
@ -216,9 +228,6 @@ async function getOptions() {
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
// hideLoader();
});
}
@ -227,13 +236,14 @@ async function getOptions() {
* @param id
*/
function onClickHistory(id: string) {
dataHistory.value = [];
modalHistory.value = true;
showLoader();
http
.get(config.API.kpiRoleMainList + `/history/${id}`)
.then((res) => {
const data = res.data.result;
dataHistory.value = data;
modalHistory.value = true;
})
.catch((e) => {
messageError($q, e);
@ -244,7 +254,6 @@ function onClickHistory(id: string) {
}
async function getTotal() {
// showLoader();
await http
.post(config.API.indicatorSummary)
.then(async (res) => {
@ -258,17 +267,16 @@ async function getTotal() {
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
// hideLoader();
});
}
onMounted(async () => {
showLoader();
await Promise.all([getTotal(), getOptions(), fetchList()]).finally(() => {
try {
await Promise.all([getTotal(), getOptions(), fetchList()]);
} finally {
hideLoader();
});
}
});
</script>