ต่อ api ประวัติการศึกษา

This commit is contained in:
Kittapath 2023-03-24 20:47:01 +07:00
parent 8d2b93b6a3
commit 0760ae1981
9 changed files with 357 additions and 222 deletions

View file

@ -219,11 +219,11 @@ const props = defineProps({
const $q = useQuasar()
const mixin = useCounterMixin() //
const { dateThaiRange, modalDelete, modalConfirm } = mixin
const { dateThaiRange, modalDelete, modalConfirm, dateToISO, success } = mixin
const store = useExamDataStore()
const { examData, changeExamColumns } = store
const loader = ref<boolean>(false)
const id = ref<string>()
const id = ref<string>('')
const location = ref<string>()
const position = ref<string>()
const salary = ref<number | null>()
@ -241,27 +241,11 @@ const editRow = ref<boolean>(false) //เช็คมีการแก้ไข
const statusCode = ref<number>()
const checkValidate = ref<boolean>(false) //validate data
const modalConsend = ref<boolean>(false)
const candidateId = ref<string>('2223ba53-2fb2-470b-8dc1-27e5471b0331')
const emit = defineEmits(['update:loader', 'update:statusEdit'])
const rows = ref<RequestItemsObject[]>([
{
id: '1',
location: 'แอดวานซ์ อินโฟร์ เซอร์วิส',
position: 'Direct Sales Staff',
salary: 30000,
duration: [new Date('1995-04-15'), new Date('1999-02-25')],
reason: 'ไล่ออก'
},
{
id: '2',
location: 'บริษัท ทรู คอร์ปอเรชั่น จำกัด (มหาชน)',
position: 'Direct Sales Staff',
salary: 40000,
duration: [new Date('2020-06-30'), new Date('2023-10-14')],
reason: '-'
}
])
const rows = ref<RequestItemsObject[]>([])
const filter = ref<string>('') //search data table
@ -332,11 +316,28 @@ watch(edit, (count: boolean, prevCount: boolean) => {
})
onMounted(async () => {
// await fetchData()
await fetchData()
})
const fetchData = async () => {
editRow.value = false
loader.value = true
await http
.get(config.API.candidateCareer(candidateId.value))
.then((res) => {
const data = res.data.result
rows.value = []
data.map((r: any) => {
rows.value.push({
...r,
location: r.name,
duration: [r.durationStart, r.durationEnd]
})
})
})
.catch((e: any) => {})
.finally(() => {
loader.value = false
})
}
/**
@ -410,9 +411,28 @@ const checkDelete = (row: RequestItemsObject) => {
/**
* ลบขอมลใน table
*/
function clickDeleteRow() {
rows.value = rows.value.filter((val: any) => val.id != rawItem.value?.id)
edit.value = false
const clickDeleteRow = async () => {
if (rawItem.value != null) {
loader.value = true
await http
.delete(config.API.candidateCareer(rawItem.value.id))
.then(() => {
success($q, 'ลบข้อมูลสำเร็จ')
})
.catch((e) => {
// modalError.value = true
// modalErrorTittle.value = ''
// modalErrorDetail.value = e.response.data.message
statusCode.value = e.response.data.status
})
.finally(async () => {
await fetchData()
edit.value = false
})
} else {
await fetchData()
edit.value = false
}
}
/**
@ -440,24 +460,29 @@ const clickSave = async () => {
const saveData = async () => {
edit.value = false
modal.value = false
// loader.value = true;
// await http
// .post(config.API.xxxxxxxxxxxxxxx, {
// xxx: "xxx",
// })
// .then((res) => {
// success($q, "");
// })
// .catch((e) => {
// modalError.value = true;
// modalErrorTittle.value = "";
// modalErrorDetail.value = e.response.data.message;
// statusCode.value = e.response.data.status;
// })
// .finally(async () => {
// modal.value = false;
// await fetchData();
// });
loader.value = true
await http
.post(config.API.candidateCareer(candidateId.value), {
name: location.value,
position: position.value,
salary: salary.value,
durationStart: dateToISO(new Date(duration.value[0])),
durationEnd: dateToISO(new Date(duration.value[1])),
reason: reason.value
})
.then((res) => {
success($q, 'บันทึกข้อมูลสำเร็จ')
})
.catch((e) => {
// modalError.value = true
// modalErrorTittle.value = ''
// modalErrorDetail.value = e.response.data.message
statusCode.value = e.response.data.status
})
.finally(async () => {
modal.value = false
await fetchData()
})
}
/**
@ -466,24 +491,29 @@ const saveData = async () => {
const editData = async () => {
edit.value = false
modal.value = false
// loader.value = true;
// await http
// .post(config.API.xxxxxxxxxxxxxxx(id.value), {
// xxx: "xxx",
// })
// .then((res) => {
// success($q, "");
// })
// .catch((e) => {
// modalError.value = true;
// modalErrorTittle.value = "";
// modalErrorDetail.value = e.response.data.message;
// statusCode.value = e.response.data.status;
// })
// .finally(async () => {
// edit.value = false;
// await fetchData();
// });
loader.value = true
await http
.put(config.API.candidateCareer(id.value), {
name: location.value,
position: position.value,
salary: salary.value,
durationStart: dateToISO(new Date(duration.value[0])),
durationEnd: dateToISO(new Date(duration.value[1])),
reason: reason.value
})
.then((res) => {
success($q, 'บันทึกข้อมูลสำเร็จ')
})
.catch((e) => {
// modalError.value = true
// modalErrorTittle.value = ''
// modalErrorDetail.value = e.response.data.message
statusCode.value = e.response.data.status
})
.finally(async () => {
edit.value = false
await fetchData()
})
}
const checkClose = async () => {
@ -500,6 +530,7 @@ const checkClose = async () => {
*/
const clickClose = async () => {
modal.value = false
editRow.value = false
next.value = false
previous.value = false
}
@ -511,7 +542,7 @@ const clickClose = async () => {
const selectData = (props: DataProps) => {
modalEdit.value = true
modal.value = true
// edit.value = false
editRow.value = false
rawItem.value = props.row
rowIndex.value = props.rowIndex
location.value = props.row.location