diff --git a/src/modules/14_KPI/components/indicatorByPlan/IndicatorByPlan.vue b/src/modules/14_KPI/components/indicatorByPlan/IndicatorByPlan.vue index 91968d13c..132b65e0b 100644 --- a/src/modules/14_KPI/components/indicatorByPlan/IndicatorByPlan.vue +++ b/src/modules/14_KPI/components/indicatorByPlan/IndicatorByPlan.vue @@ -20,8 +20,7 @@ const { } = mixin; const planData = reactive({ - year: 0, //ปีงบประมาณ - round: "", //รอบการประเมิน(เมษา->APR, ตุลา->OCT) + kpiPeriodId: "", //รอบการประเมิน(เมษา->APR, ตุลา->OCT) including: "", //รหัสตัวชี้วัด includingName: "", //ชื่อตัวชี้วัด target: "", //ค่าเป้าหมาย @@ -44,12 +43,10 @@ const planData = reactive({ const filter = ref(""); const filterAgency = ref(""); const route = useRoute(); -const id = ref(route.params.id); +const id = ref(route.params.id.toString()); +const year = ref(0); -const roundOp = ref([ - { id: "APR", name: "เมษายน" }, - { id: "OCT", name: "ตุลาคม" }, -]); +const roundOp = ref([]); const notFound = ref("ไม่พบข้อมูลที่ค้นหา"); const noData = ref("ไม่มีข้อมูล"); const expandedPlan = ref>([]); @@ -68,6 +65,41 @@ async function onSubmit() { ); } +const inputRef = ref(null); +function fetchRoundOption(isId: number | null = null) { + showLoader(); + http + .get( + config.API.kpiPeriod + + `?page=${1}&pageSize=${10}&keyword=${""}&year=${year.value}` + ) + .then((res) => { + const data = res.data.result.data; + const list = data.map((e: any) => ({ + id: e.id, + name: + e.durationKPI === "OCT" + ? "รอบตุลาคม" + : e.durationKPI === "APR" + ? "รอบเมษายน" + : "", + })); + roundOp.value = list; + console.log(isId); + + if (isId) { + planData.kpiPeriodId = ""; + inputRef.value.resetValidation(); + } + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + function fetchTree() { showLoader(); http @@ -126,9 +158,10 @@ async function fetchDataById(id: any) { .get(config.API.kpiPlanById(id)) .then(async (res) => { const data = res.data.result; + year.value = data.year; // planData.value = data; - planData.year = data.year; - planData.round = data.round; + // planData.year = data.year; + planData.kpiPeriodId = data.kpiPeriodId; planData.including = data.including; planData.includingName = data.includingName; planData.target = data.target; @@ -146,6 +179,7 @@ async function fetchDataById(id: any) { planData.orgRevisionId = data.orgRevisionId; planData.strategy = data.strategy; planData.strategyId = data.strategyId; + fetchRoundOption(); }) .catch((err) => { messageError($q, err); @@ -159,6 +193,7 @@ function updateSelected(data: any) { planData.strategyId = data.id; planData.strategy = data.level; } + function updateSelectedAgency(data: any) { if (planData.node === data.orgLevel && planData.nodeId === data.orgTreeId) { planData.node = null; @@ -184,11 +219,12 @@ async function addData() { }); } -async function editData(id: any) { +async function editData(id: string) { await http .put(config.API.kpiPlanById(id), planData) .then(() => { success($q, "บันทึกข้อมูลสำเร็จ"); + fetchDataById(id); }) .catch((err) => { messageError($q, err); @@ -219,12 +255,12 @@ onMounted(async () => {