ต่อ 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

@ -67,7 +67,7 @@
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="educationLevel"
v-model="educationLevelId"
:rules="[(val) => !!val || `${'กรุณาเลือกวุฒิที่ได้รับ'}`]"
:label="`${'วุฒิที่ได้รับ'}`"
@update:modelValue="clickEditRow"
@ -221,14 +221,13 @@ 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 educationLevel = ref<string>()
const qualification = ref<string>()
const qualificationId = ref<string>()
const educationLevelId = ref<string>()
const educationLevelOptions = ref<DataOption[]>([])
const major = ref<string>()
const scores = ref<number | null>()
@ -246,45 +245,26 @@ const editRow = ref<boolean>(false) //เช็คมีการแก้ไข
const statusCode = ref<number>()
const checkValidate = ref<boolean>(false) //validate data
const modalConsend = ref<boolean>(false)
const rows = ref<RequestItemsObject[]>([])
const candidateId = ref<string>('2223ba53-2fb2-470b-8dc1-27e5471b0331')
const emit = defineEmits(['update:loader', 'update:statusEdit'])
const rows = ref<RequestItemsObject[]>([
{
id: '1',
qualificationId: 'ปริญญาตรี',
qualification: 'ปริญญาตรี',
major: 'คอมพิวเตอร์',
scores: 3.99,
name: 'มหาลัยเอ',
duration: [new Date('1995-04-15'), new Date('1999-02-25')]
},
{
id: '2',
qualificationId: 'ปริญญาเอก',
qualification: 'ปริญญาเอก',
major: 'คอมพิวเตอร์',
scores: 3.54,
name: 'มหาลัยบี',
duration: [new Date('2020-06-30'), new Date('2023-10-14')]
}
])
const filter = ref<string>('') //search data table
const visibleColumns = ref<String[]>([])
examData.education.columns.length == 0
? (visibleColumns.value = ['qualification', 'major', 'scores', 'name', 'duration'])
? (visibleColumns.value = ['educationLevel', 'major', 'scores', 'name', 'duration'])
: (visibleColumns.value = examData.education.columns)
const columns = ref<Columns>([
{
name: 'qualification',
name: 'educationLevel',
align: 'left',
label: 'วุฒิที่ได้รับ',
sortable: true,
field: 'qualification',
field: 'educationLevel',
headerStyle: 'font-size: 14px',
style: 'font-size: 14px'
},
@ -340,11 +320,28 @@ watch(edit, (count: boolean, prevCount: boolean) => {
onMounted(async () => {
await fetchData()
// await fetchQualification()
await fetcheducationLevel()
})
const fetchData = () => {
educationLevel.value = 'e4e6a4f8-39c6-467f-bd84-7650d105fc4c'
const fetchData = async () => {
loader.value = true
await http
.get(config.API.candidateEducation(candidateId.value))
.then((res) => {
const data = res.data.result
rows.value = []
data.map((r: any) => {
rows.value.push({
...r,
educationLevelId: r.educationLevel.id,
educationLevel: r.educationLevel.name,
duration: [r.durationStart, r.durationEnd]
})
})
})
.catch((e: any) => {})
.finally(() => {
loader.value = false
})
}
const fetcheducationLevel = async () => {
@ -365,28 +362,6 @@ const fetcheducationLevel = async () => {
})
}
const fetchQualification = async () => {
// loader.value = true;
// await http
// .get(config.API.educationQualification)
// .then((res) => {
// const data = res.data.result
// let option: DataOption[] = []
// data.map((r: any) => {
// option.push({ id: r.id.toString(), name: r.name.toString() })
// })
// qualificationOptions.value = option
// })
// .catch((e: any) => {})
// .finally(() => {
// // loader.value = false;
// })
}
// const fetchData = async () => {
// editRow.value = false
// }
/**
* กดดอมลกอนหน
*/
@ -394,8 +369,8 @@ const clickPrevious = () => {
// edit.value = false
rowIndex.value -= 1
const row = rows.value[rowIndex.value]
qualification.value = row.qualification
qualificationId.value = row.qualificationId
educationLevel.value = row.educationLevel
educationLevelId.value = row.educationLevelId
major.value = row.major
scores.value = row.scores
name.value = row.name
@ -411,8 +386,8 @@ const clickNext = () => {
// edit.value = false
rowIndex.value += 1
const row = rows.value[rowIndex.value]
qualification.value = row.qualification
qualificationId.value = row.qualificationId
educationLevel.value = row.educationLevel
educationLevelId.value = row.educationLevelId
major.value = row.major
scores.value = row.scores
name.value = row.name
@ -460,9 +435,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.candidateEducation(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
}
}
/**
@ -488,52 +482,60 @@ 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.candidateEducation(candidateId.value), {
educationLevelId: educationLevelId.value,
major: major.value,
scores: scores.value,
name: name.value,
durationStart: dateToISO(new Date(duration.value[0])),
durationEnd: dateToISO(new Date(duration.value[1]))
})
.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()
})
}
/**
* นทกแกไขขอม
*/
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.candidateEducation(id.value), {
educationLevelId: educationLevelId.value,
major: major.value,
scores: scores.value,
name: name.value,
durationStart: dateToISO(new Date(duration.value[0])),
durationEnd: dateToISO(new Date(duration.value[1]))
})
.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
edit.value = false
modal.value = false
await fetchData()
})
}
const checkClose = async () => {
@ -550,6 +552,7 @@ const checkClose = async () => {
*/
const clickClose = async () => {
modal.value = false
editRow.value = false
next.value = false
previous.value = false
}
@ -561,11 +564,11 @@ 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
qualification.value = props.row.qualification
qualificationId.value = props.row.qualificationId
educationLevel.value = props.row.educationLevel
educationLevelId.value = props.row.educationLevelId
major.value = props.row.major
scores.value = props.row.scores
name.value = props.row.name
@ -586,8 +589,8 @@ const addRow = () => {
modalEdit.value = false
modal.value = true
// edit.value = true
qualification.value = ''
qualificationId.value = ''
educationLevel.value = ''
educationLevelId.value = ''
major.value = ''
scores.value = null
name.value = ''