feat(material): modify handlers and service of material
This commit is contained in:
No files matched your search
@@ -0,0 +1,80 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
// Services
|
||||
import { postSourceMaterial, putSourceMaterial, removeSourceMaterial } from '~/services/material.service'
|
||||
|
||||
const recId = ref<number>(0)
|
||||
const recAction = ref<string>('')
|
||||
const recItem = ref<any>(null)
|
||||
const isFormEntryDialogOpen = ref(false)
|
||||
const isRecordConfirmationOpen = ref(false)
|
||||
|
||||
function onResetState() {
|
||||
recId.value = 0
|
||||
recAction.value = ''
|
||||
recItem.value = null
|
||||
}
|
||||
|
||||
export async function handleActionSave(values: any, refresh: () => void, reset: () => void) {
|
||||
let isSuccess = false
|
||||
try {
|
||||
const result = await postSourceMaterial(values)
|
||||
if (result.success) {
|
||||
isFormEntryDialogOpen.value = false
|
||||
isSuccess = true
|
||||
if (refresh) refresh()
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error saving form:', error)
|
||||
isSuccess = false
|
||||
} finally {
|
||||
if (isSuccess) {
|
||||
setTimeout(() => {
|
||||
reset()
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleActionEdit(id: number | string, values: any, refresh: () => void, reset: () => void) {
|
||||
let isSuccess = false
|
||||
try {
|
||||
const result = await putSourceMaterial(id, values)
|
||||
if (result.success) {
|
||||
isFormEntryDialogOpen.value = false
|
||||
isSuccess = true
|
||||
if (refresh) refresh()
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error editing form:', error)
|
||||
isSuccess = false
|
||||
} finally {
|
||||
if (isSuccess) {
|
||||
setTimeout(() => {
|
||||
reset()
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleActionRemove(id: number | string, refresh: () => void) {
|
||||
try {
|
||||
const result = await removeSourceMaterial(id)
|
||||
if (result.success) {
|
||||
if (refresh) refresh()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting record:', error)
|
||||
} finally {
|
||||
onResetState()
|
||||
}
|
||||
}
|
||||
|
||||
export function handleCancelForm(reset: () => void) {
|
||||
isFormEntryDialogOpen.value = false
|
||||
setTimeout(() => {
|
||||
reset()
|
||||
}, 500)
|
||||
}
|
||||
|
||||
export { recId, recAction, recItem, isFormEntryDialogOpen, isRecordConfirmationOpen }
|
||||
Reference in New Issue
Block a user