diff --git a/src/components/GanttChart/GanttChart.vue b/src/components/GanttChart/GanttChart.vue index b9db961b7b9d338000e809558ef518f827ccc3fb..95d50cbf8e84bab6742812f4f7b047e5e1b40dc6 100644 --- a/src/components/GanttChart/GanttChart.vue +++ b/src/components/GanttChart/GanttChart.vue @@ -6,7 +6,7 @@ <!-- ปุ่มจัดเรียงและเพิ่มระยะห่าง --> <div class="gantt-buttons"> - <MakequeueBtn @click="openAddQueueDialog" /> + <MakequeueBtn /> <SettingBtn class="mr-4" /> </div> </div> @@ -25,44 +25,24 @@ <!-- Rows: แสดงเครื่องจักรจาก Machine Store --> <div class="rows"> - <div - v-for="machine in machineStore.machines" - :key="machine.MachineID" - class="row" - :data-machine-id="machine.MachineID" - @dragover.prevent="onDragOver($event)" - @drop="onDrop($event, machine.MachineID)" - > + <div v-for="machine in machineStore.machines" :key="machine.MachineID" class="row" + :data-machine-id="machine.MachineID" @dragover.prevent="onDragOver($event)" + @drop="onDrop($event, machine.MachineID)"> <div class="machine-label"> {{ machine.name }} </div> <div class="row-timeline"> <!-- เส้นแนวตั้ง (Grid Lines) --> - <div - v-for="hour in hours" - :key="'line-' + hour" - class="vertical-line" - :style="getLineStyle(hour)" - ></div> + <div v-for="hour in hours" :key="'line-' + hour" class="vertical-line" :style="getLineStyle(hour)"></div> <!-- แสดง Queue ที่ตรงกับวันที่ (selectedDate), Page (pagenum), และ Machine --> - <div - v-for="item in filteredQueue(machine.MachineID)" - :key="item.QueueID" - class="order" - :class="{ faded: draggingQueue && draggingQueue.QueueID === item.QueueID }" - :style="getQueueStyle(item)" - > + <div v-for="item in filteredQueue(machine.MachineID)" :key="item.QueueID" class="order" + :class="{ faded: draggingQueue && draggingQueue.QueueID === item.QueueID }" :style="getQueueStyle(item)"> <!-- Handle สำหรับ Resize ด้านซ้าย --> <div class="resize-handle left" @mousedown="onResizeStart($event, item, 'left')"></div> <!-- ส่วนกลางของ Order ใช้สำหรับลาก และเปิด Dialog เมื่อคลิก --> - <div - class="order-content" - draggable="true" - @dragstart="onDragStart($event, item)" - @dragend="onDragEnd($event, item)" - @click.stop="openQueueDialog(item)" - > + <div class="order-content" draggable="true" @dragstart="onDragStart($event, item)" + @dragend="onDragEnd($event, item)" @click.stop="openQueueDialog(item)"> {{ item.label }} ({{ getTimeString(item.startTime) }} - {{ getTimeString(item.finishTime) }}) </div> <!-- Handle สำหรับ Resize ด้านขวา --> @@ -82,19 +62,10 @@ <!-- Pagination --> <div class="pagination-container"> <transition-group name="fade" tag="div" class="pagination"> - <button - v-for="p in pages" - :key="p" - :class="['page-btn', { active: p === currentPage }]" - @click="currentPage = p" - @contextmenu.prevent="onPageRightClick(p, $event)" - > + <button v-for="p in pages" :key="p" :class="['page-btn', { active: p === currentPage }]" + @click="currentPage = p" @contextmenu.prevent="onPageRightClick(p, $event)"> {{ p }} - <button - v-if="pageToShowDelete === p" - class="delete-btn" - @click.stop="deletePage(p)" - > + <button v-if="pageToShowDelete === p" class="delete-btn" @click.stop="deletePage(p)"> Delete </button> </button> @@ -107,21 +78,12 @@ <v-icon>mdi-plus</v-icon> </v-btn> </div> - <AddQueueDialog - :visible="showAddDialog" - :queueItem="selectedQueueItem" - :currentPage="currentPage" - @close="closeAddQueueDialog" - /> + <AddQueueDialog :visible="showAddDialog" :queueItem="selectedQueueItem" :currentPage="currentPage" + @close="closeAddQueueDialog" /> </div> - <OrderDialog - v-if="selectedQueueItem && !showAddDialog" - :queueId="selectedQueueItem.QueueID" - :color="getQueueColor(selectedQueueItem.QueueID)" - @close="closeQueueDialog" - @edit="openAddQueueDialogForEdit" - @delete="handleDelete" - /> + <OrderDialog v-if="selectedQueueItem && !showAddDialog" :queueId="selectedQueueItem.QueueID" + :color="getQueueColor(selectedQueueItem.QueueID)" @close="closeQueueDialog" @edit="openAddQueueDialogForEdit" + @delete="handleDelete" /> </div> </div> </template> @@ -203,8 +165,8 @@ const formattedQueues = computed(() => { const label = originalLabelMap[q.QueueID] ?? (q.QueueType?.QueueTypeID === 2 ? 'ผลิตเผื่อ' : - q.QueueType?.QueueTypeID === 3 ? 'เปลี่ยนขนาด' : - local?.label || q.order?.customer?.name || 'Unknown'); + q.QueueType?.QueueTypeID === 3 ? 'เปลี่ยนขนาด' : + local?.label || q.order?.customer?.name || 'Unknown'); const color = originalColorMap[q.QueueID] ?? getQueueColor(label); @@ -316,7 +278,7 @@ function filteredQueue(machineID: number) { } const colorMap: Record<string, string> = {}; - function getQueueColor(label: string): string { +function getQueueColor(label: string): string { if (label === "ผลิตเผื่อ") return "#FFC1C1"; if (label === "เปลี่ยนขนาด") return "#E1BEE7"; diff --git a/src/components/GanttChart/MakequeueBtn.vue b/src/components/GanttChart/MakequeueBtn.vue index 36474d62b6b8f794809f05dc059e1640bf85c96e..68a245213121f7dd15ab6ac64afe848bf8ae23a2 100644 --- a/src/components/GanttChart/MakequeueBtn.vue +++ b/src/components/GanttChart/MakequeueBtn.vue @@ -1,6 +1,6 @@ <template> <div> - <v-btn>Make a queue</v-btn> + <v-btn @click="handleClickRunSchedule">Make a queue</v-btn> </div> </template> @@ -8,7 +8,11 @@ import { defineEmits } from 'vue'; import { useQueueStore } from '@/stores/queue.js'; import LoadingDialog from '../LoadingDialog.vue'; +const queueStore = useQueueStore(); +const handleClickRunSchedule = () => { + queueStore.triggerRunSchedule(); +}; </script> diff --git a/src/components/GanttChart/StockConfig.vue b/src/components/GanttChart/StockConfig.vue index 217eeb61268c38759e9e072f714818f591ae59a6..bb05fb2361ca30cfba3e5e36eebe994aa77a8e8e 100644 --- a/src/components/GanttChart/StockConfig.vue +++ b/src/components/GanttChart/StockConfig.vue @@ -16,14 +16,8 @@ </tr> </thead> <transition-group tag="tbody" name="list"> - <tr - v-for="config in stockConfigStore.stockConfigs" - :key="config.StockConfigID" - draggable="true" - @dragstart="() => handleDragStart(config)" - @dragover="handleDragOver" - @drop="() => handleDrop(config)" - > + <tr v-for="config in stockConfigStore.stockConfigs" :key="config.StockConfigID" draggable="true" + @dragstart="() => handleDragStart(config)" @dragover="handleDragOver" @drop="() => handleDrop(config)"> <td class="drag-handle">☰</td> <td>{{ config.itemName }}</td> <td>{{ config.itemType }}</td> @@ -37,12 +31,8 @@ <!-- Toggle & Action Buttons --> <div class="action-section"> - <v-switch - color="primary" - v-model="isProductionSpare" - label="ไม่ทำการผลิตเผื่อ" - class="switch-toggle" - /> + <v-switch color="primary" v-model="stockConfigStore.isProductionSpare" + :label="stockConfigStore.productionSpareLabel" class="switch-toggle" @change="onSwitchChange" /> </div> </v-card> </template> @@ -93,15 +83,15 @@ async function handleDrop(targetConfig) { newConfigs.splice(targetIndex, 0, removed); const updatedPayload = { - configs: newConfigs.map((config, index) => ({ - id: config.StockConfigID, - priorityLevel: index + 1, - targetStockLevel: config.targetStockLevel, - status: config.status, - })), -}; + configs: newConfigs.map((config, index) => ({ + id: config.StockConfigID, + priorityLevel: index + 1, + targetStockLevel: config.targetStockLevel, + status: config.status, + })), + }; -await stockConfigStore.batchUpdateStockConfigs(updatedPayload); + await stockConfigStore.batchUpdateStockConfigs(updatedPayload); stockConfigStore.stockConfigs = newConfigs.map((c, idx) => ({ ...c, @@ -111,8 +101,10 @@ await stockConfigStore.batchUpdateStockConfigs(updatedPayload); draggedConfig.value = null; } -// Toggle สำหรับ "ไม่ทำการผลิตเผื่อ" -const isProductionSpare = ref(false); +function onSwitchChange(val) { + console.log('📌 เปลี่ยนค่า isProductionSpare เป็น:', stockConfigStore.isProductionSpare) +} + </script> <style scoped> @@ -175,5 +167,4 @@ const isProductionSpare = ref(false); align-items: center; margin-top: 15px; } - </style> diff --git a/src/services/queue.ts b/src/services/queue.ts index 28cdd75bd43205c510b90f7325fd4a75086e687e..18b0baddac7d87d816c97c99547830cd559803f2 100644 --- a/src/services/queue.ts +++ b/src/services/queue.ts @@ -1,41 +1,56 @@ -import http from './http'; -import type { Queue, QueuePostData } from '@/types/Queue'; +import axios from 'axios' +import http from './http' +import type { Queue, QueuePostData } from '@/types/Queue' /** * ดึงรายการ Queue ทั้งหมดจาก backend */ export async function listQueues(): Promise<Queue[]> { - const { data } = await http.get('/queues'); - return data; + const { data } = await http.get('/queues') + return data } /** * ดึงข้อมูล Queue รายการเดียวโดยใช้ QueueID */ export async function getQueue(id: number): Promise<Queue> { - const { data } = await http.get(`/queues/${id}`); - return data; + const { data } = await http.get(`/queues/${id}`) + return data } /** * สร้าง Queue ใหม่ (ใช้ QueuePostData เพื่อให้โครงสร้างถูกต้อง) */ export async function createQueue(payload: QueuePostData): Promise<Queue> { - const { data } = await http.post('/queues', payload); - return data; + const { data } = await http.post('/queues', payload) + return data } /** * อัปเดต Queue ตาม QueueID (ใช้ QueuePostData) */ export async function updateQueue(id: number, payload: QueuePostData): Promise<Queue> { - const { data } = await http.patch(`/queues/${id}`, payload); - return data; + const { data } = await http.patch(`/queues/${id}`, payload) + return data } /** * ลบ Queue ตาม QueueID */ export async function deleteQueue(id: number): Promise<void> { - await http.delete(`/queues/${id}`); + await http.delete(`/queues/${id}`) +} + +export async function runScheduleDirect(payload: { + produceBuffer: boolean + secondRound: boolean + startDate: string + pageID: number +}) { + const { data } = await axios.post('http://localhost:9000/run-schedule', payload, { + headers: { + 'Content-Type': 'application/json' + } + }) + return data } diff --git a/src/stores/queue.ts b/src/stores/queue.ts index f3b6e0ff40f5f255548a45e2c115d1ba959ea764..28b16f697a23175ce35ca62f47c6fe067e5d3a2b 100644 --- a/src/stores/queue.ts +++ b/src/stores/queue.ts @@ -1,107 +1,114 @@ -import { defineStore } from 'pinia'; -import { ref } from 'vue'; -import type { Queue, QueuePostData } from '@/types/Queue'; -import * as queueService from '@/services/queue'; +import { defineStore } from 'pinia' +import { ref } from 'vue' +import type { Queue, QueuePostData } from '@/types/Queue' +import * as queueService from '@/services/queue' +import { runScheduleDirect } from '@/services/queue' +import { refreshAllData } from './refresh/refreshAll' +import { useStockConfigStore } from './stockConfig' +import { useDateStore } from './dateStore' +import { usePageContextStore } from './pageContext' export const useQueueStore = defineStore('queue', () => { - const queues = ref<Queue[]>([]); - const loading = ref<boolean>(false); - const error = ref<string | null>(null); - + const queues = ref<Queue[]>([]) + const loading = ref<boolean>(false) + const error = ref<string | null>(null) + const stockConfigStore = useStockConfigStore() + const dateStore = useDateStore() + const pageContextStore = usePageContextStore() // **ดึงรายการ Queue ทั้งหมดจาก backend** async function fetchQueues() { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - console.log("📡 Fetching Queues from Backend..."); - const response = await queueService.listQueues(); - console.log("✅ Queues Response from Backend:", response); - queues.value = response; + console.log('📡 Fetching Queues from Backend...') + const response = await queueService.listQueues() + console.log('✅ Queues Response from Backend:', response) + queues.value = response } catch (e: any) { - console.error("❌ Error fetching queues:", e.response?.data || e.message); - error.value = e.message || "Unknown Error"; + console.error('❌ Error fetching queues:', e.response?.data || e.message) + error.value = e.message || 'Unknown Error' } finally { - loading.value = false; + loading.value = false } } // **ดึง Queue รายการเดียวจาก backend** async function getQueue(id: number): Promise<Queue> { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - console.log(`📡 Fetching Queue ID: ${id} from Backend...`); - const queue = await queueService.getQueue(id); - console.log("✅ Queue Data Received:", queue); - return queue; + console.log(`📡 Fetching Queue ID: ${id} from Backend...`) + const queue = await queueService.getQueue(id) + console.log('✅ Queue Data Received:', queue) + return queue } catch (e: any) { - console.error(`❌ Error fetching Queue ID ${id}:`, e.response?.data || e.message); - error.value = e.message || "Unknown Error"; - throw e; + console.error(`❌ Error fetching Queue ID ${id}:`, e.response?.data || e.message) + error.value = e.message || 'Unknown Error' + throw e } finally { - loading.value = false; + loading.value = false } } // **เพิ่ม Queue ลง Database (ใช้ QueuePostData)** async function addQueue(newQueue: QueuePostData) { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - console.log("➕ Adding Queue:", newQueue); - const createdQueue = await queueService.createQueue(newQueue); - queues.value.push(createdQueue); - console.log("✅ Queue Added:", createdQueue); + console.log('➕ Adding Queue:', newQueue) + const createdQueue = await queueService.createQueue(newQueue) + queues.value.push(createdQueue) + console.log('✅ Queue Added:', createdQueue) } catch (e: any) { - console.error("❌ Error adding queue:", e.response?.data || e.message); - error.value = e.message || "Unknown Error"; + console.error('❌ Error adding queue:', e.response?.data || e.message) + error.value = e.message || 'Unknown Error' } finally { - loading.value = false; + loading.value = false } } // **อัปเดต Queue (ใช้ QueuePostData)** async function updateQueue(id: number, updatedData: QueuePostData) { if (!id) { - console.error("❌ queueID is undefined! Cannot update."); - return; + console.error('❌ queueID is undefined! Cannot update.') + return } - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - console.log(`🛠 Updating Queue ID: ${id}...`); - const updatedQueue = await queueService.updateQueue(id, updatedData); - const index = queues.value.findIndex(q => q.QueueID === id); + console.log(`🛠 Updating Queue ID: ${id}...`) + const updatedQueue = await queueService.updateQueue(id, updatedData) + const index = queues.value.findIndex((q) => q.QueueID === id) if (index !== -1) { - queues.value[index] = updatedQueue; - console.log(`✅ Queue ID: ${id} Updated Successfully`, updatedQueue); + queues.value[index] = updatedQueue + console.log(`✅ Queue ID: ${id} Updated Successfully`, updatedQueue) } else { - console.warn(`⚠️ Queue ID: ${id} Not Found in Store!`); + console.warn(`⚠️ Queue ID: ${id} Not Found in Store!`) } } catch (e: any) { - console.error(`❌ Error updating Queue ID ${id}:`, e.response?.data || e.message); - error.value = e.message || "Unknown Error"; + console.error(`❌ Error updating Queue ID ${id}:`, e.response?.data || e.message) + error.value = e.message || 'Unknown Error' } finally { - loading.value = false; + loading.value = false } } // **ลบ Queue** async function deleteQueue(id: number) { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - console.log(`🗑 Deleting Queue ID: ${id}...`); - await queueService.deleteQueue(id); + console.log(`🗑 Deleting Queue ID: ${id}...`) + await queueService.deleteQueue(id) // ลบ Queue ออกจาก Store - queues.value = queues.value.filter(q => q.QueueID !== id); - console.log(`✅ Queue ID: ${id} Deleted Successfully`); + queues.value = queues.value.filter((q) => q.QueueID !== id) + console.log(`✅ Queue ID: ${id} Deleted Successfully`) } catch (e: any) { - console.error(`❌ Error deleting Queue ID ${id}:`, e.response?.data || e.message); - error.value = e.message || "Unknown Error"; + console.error(`❌ Error deleting Queue ID ${id}:`, e.response?.data || e.message) + error.value = e.message || 'Unknown Error' } finally { - loading.value = false; + loading.value = false } } @@ -115,10 +122,29 @@ export const useQueueStore = defineStore('queue', () => { MachineID: queue.machine?.MachineID ?? 0, // ใช้ MachineID จาก object PageID: queue.page?.PageID ?? 0, OrderID: queue.order?.OrderID ?? 0, - EmployeeIds: queue.employees.map(emp => emp.EmployeeID), // แปลง employees เป็นแค่ array ของ ID - }; + EmployeeIds: queue.employees.map((emp) => emp.EmployeeID) // แปลง employees เป็นแค่ array ของ ID + } + } + + const triggerRunSchedule = async () => { + const payload = { + produceBuffer: stockConfigStore.isProductionSpare, // ✅ ผูกกับ v-switch + secondRound: false, + startDate: dateStore.currentDate, + pageID: pageContextStore.currentPage + } + + console.log('📦 Payload ที่จะส่งไป:', payload) + + try { + const result = await runScheduleDirect(payload) + console.log('✅ Schedule run success:', result) + + await refreshAllData() + } catch (err) { + console.error('❌ Schedule run failed:', err) + } } - return { queues, @@ -130,5 +156,6 @@ export const useQueueStore = defineStore('queue', () => { addQueue, updateQueue, deleteQueue, - }; -}); + triggerRunSchedule + } +}) diff --git a/src/stores/refresh/refreshAll.ts b/src/stores/refresh/refreshAll.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ca1aac8213b745b1d8bdd06c272696bad98eac4 --- /dev/null +++ b/src/stores/refresh/refreshAll.ts @@ -0,0 +1,49 @@ +// 📁 src/stores/refresh/refreshAll.ts + +import { useMachineStore } from '@/stores/machine' +import { useMaterialStore } from '@/stores/material' +import { useOrderStore } from '@/stores/order' +import { useOrderPriorityStore } from '@/stores/orderPriority' +import { useQueueStore } from '@/stores/queue' +import { useStockConfigStore } from '@/stores/stockConfig' +import { useProductStore } from '@/stores/product' +import { useProductionTargetStore } from '@/stores/productionTarget' +import { useLoadingStore } from '@/stores/loading' // ✅ เพิ่ม loading store + +export async function refreshAllData() { + const loadingStore = useLoadingStore() // ✅ เรียก loading store + + try { + loadingStore.doLoad() // ✅ เริ่มโหลด + + // รอ 3 วินาที + await new Promise((resolve) => setTimeout(resolve, 3000)) + + // เรียกทุก store + const machineStore = useMachineStore() + const materialStore = useMaterialStore() + const orderStore = useOrderStore() + const orderPriorityStore = useOrderPriorityStore() + const queueStore = useQueueStore() + const stockConfigStore = useStockConfigStore() + const productStore = useProductStore() + const productionTargetStore = useProductionTargetStore() + + await Promise.all([ + machineStore.fetchMachines(), + materialStore.fetchMaterials(), + orderStore.fetchOrders(), + orderPriorityStore.fetchAll(), + queueStore.fetchQueues(), + stockConfigStore.fetchStockConfigs(), + productStore.fetchProducts(), + productionTargetStore.fetchProductionTargets() + ]) + + console.log('✅ Refreshed all data.') + } catch (err) { + console.error('❌ Error refreshing data:', err) + } finally { + loadingStore.finish() // ✅ จบโหลด + } +} diff --git a/src/stores/stockConfig.ts b/src/stores/stockConfig.ts index 0b545d12dd6398f54a1384785db779d588990efa..80ff67fbb681de44f2e70eac3b4b3b816357b992 100644 --- a/src/stores/stockConfig.ts +++ b/src/stores/stockConfig.ts @@ -1,111 +1,115 @@ -import { defineStore } from 'pinia'; -import { ref } from 'vue'; -import type { StockConfig } from '@/types/StockConfig'; -import * as stockConfigService from '@/services/stockConfig'; +import { defineStore } from 'pinia' +import { computed, ref, watch } from 'vue' +import type { StockConfig } from '@/types/StockConfig' +import * as stockConfigService from '@/services/stockConfig' import type { CreateStockConfigDto, UpdateStockConfigDto, - BatchUpdateManyStockConfigDto, -} from '@/types/StockConfigDto'; + BatchUpdateManyStockConfigDto +} from '@/types/StockConfigDto' export const useStockConfigStore = defineStore('stockConfig', () => { - const stockConfigs = ref<StockConfig[]>([]); - const loading = ref(false); - const error = ref<string | null>(null); + const stockConfigs = ref<StockConfig[]>([]) + const loading = ref(false) + const error = ref<string | null>(null) + const isProductionSpare = ref(false) async function fetchStockConfigs(pageId?: number) { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - const result = await stockConfigService.listStockConfigs(pageId); - console.log('📥 stockConfigService.listStockConfigs response:', result); - stockConfigs.value = result; + const result = await stockConfigService.listStockConfigs(pageId) + console.log('📥 stockConfigService.listStockConfigs response:', result) + stockConfigs.value = result } catch (e: any) { - error.value = e.message || 'Unknown Error'; - console.error('❌ fetchStockConfigs error:', e); + error.value = e.message || 'Unknown Error' + console.error('❌ fetchStockConfigs error:', e) } finally { - loading.value = false; + loading.value = false } } - async function fetchStockConfig(id: number): Promise<StockConfig | null> { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - return await stockConfigService.getStockConfig(id); + return await stockConfigService.getStockConfig(id) } catch (e: any) { - error.value = e.message || 'Unknown Error'; - return null; + error.value = e.message || 'Unknown Error' + return null } finally { - loading.value = false; + loading.value = false } } async function addStockConfig(payload: CreateStockConfigDto) { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - const res = await stockConfigService.createStockConfig(payload); - stockConfigs.value.push(res.stockConfig); + const res = await stockConfigService.createStockConfig(payload) + stockConfigs.value.push(res.stockConfig) } catch (e: any) { - error.value = e.message || 'Unknown Error'; + error.value = e.message || 'Unknown Error' } finally { - loading.value = false; + loading.value = false } } async function editStockConfig(id: number, payload: UpdateStockConfigDto) { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - const updated = await stockConfigService.updateStockConfig(id, payload); - const index = stockConfigs.value.findIndex((c) => c.StockConfigID === id); + const updated = await stockConfigService.updateStockConfig(id, payload) + const index = stockConfigs.value.findIndex((c) => c.StockConfigID === id) if (index !== -1) { - stockConfigs.value[index] = updated; + stockConfigs.value[index] = updated } } catch (e: any) { - error.value = e.message || 'Unknown Error'; + error.value = e.message || 'Unknown Error' } finally { - loading.value = false; + loading.value = false } } async function batchUpdateStockConfigs(payload: BatchUpdateManyStockConfigDto) { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - await stockConfigService.updateManyStockConfigs(payload); - await fetchStockConfigs(); // รีโหลดทั้งหมดเพื่อความชัวร์ + await stockConfigService.updateManyStockConfigs(payload) + await fetchStockConfigs() // รีโหลดทั้งหมดเพื่อความชัวร์ } catch (e: any) { - error.value = e.message || 'Unknown Error'; + error.value = e.message || 'Unknown Error' } finally { - loading.value = false; + loading.value = false } } async function removeStockConfig(id: number) { - loading.value = true; - error.value = null; + loading.value = true + error.value = null try { - await stockConfigService.deleteStockConfig(id); - stockConfigs.value = stockConfigs.value.filter((c) => c.StockConfigID !== id); + await stockConfigService.deleteStockConfig(id) + stockConfigs.value = stockConfigs.value.filter((c) => c.StockConfigID !== id) } catch (e: any) { - error.value = e.message || 'Unknown Error'; + error.value = e.message || 'Unknown Error' } finally { - loading.value = false; + loading.value = false } } - + const productionSpareLabel = computed(() => + isProductionSpare.value ? 'ทำการผลิตเผื่อ' : 'ไม่ทำการผลิตเผื่อ' + ) return { stockConfigs, loading, error, + isProductionSpare, + productionSpareLabel, fetchStockConfigs, fetchStockConfig, addStockConfig, editStockConfig, batchUpdateStockConfigs, - removeStockConfig, - }; -}); + removeStockConfig + } +})