refactor code
This commit is contained in:
parent
d2c352de17
commit
92fc21033d
50 changed files with 652 additions and 2170 deletions
|
|
@ -11,7 +11,6 @@
|
|||
v-model:editvisible="edit"
|
||||
:add="clickAdd"
|
||||
:edit="clickEdit"
|
||||
:cancel="clickCancel"
|
||||
:addData="false"
|
||||
:editData="status == 'register' || status == 'rejectRegister'"
|
||||
name="ประวัติการศีกษา"
|
||||
|
|
@ -48,7 +47,6 @@
|
|||
</template>
|
||||
</Table>
|
||||
</q-form>
|
||||
<!-- popup Edit window-->
|
||||
<q-dialog v-model="modal" persistent>
|
||||
<q-card style="width: 600px">
|
||||
<q-form ref="myForm">
|
||||
|
|
@ -166,7 +164,6 @@
|
|||
</q-card-section>
|
||||
<q-separator />
|
||||
<DialogFooter
|
||||
:cancel="clickCancel"
|
||||
:edit="clickEdit"
|
||||
:save="clickSave"
|
||||
:validate="validateData"
|
||||
|
|
@ -184,11 +181,14 @@
|
|||
</template>
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from 'vue'
|
||||
import type { PropType } from 'vue'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { useCounterMixin } from '@/stores/mixin'
|
||||
import { useDataStore } from '@/stores/data'
|
||||
import http from '@/plugins/http'
|
||||
import config from '@/app.config'
|
||||
import { useExamDataStore } from '@/modules/01_exam/store'
|
||||
import { useRoute } from 'vue-router'
|
||||
import type {
|
||||
RequestItemsObject,
|
||||
Columns,
|
||||
|
|
@ -199,9 +199,12 @@ import type { ResponseObject } from '@/modules/01_exam/interface/response/Educat
|
|||
import Table from '@/components/Table.vue'
|
||||
import DialogHeader from '@/components/DialogHeader.vue'
|
||||
import DialogFooter from '@/components/DialogFooter.vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
const props = defineProps({
|
||||
educationLevelOptions: {
|
||||
type: Array as PropType<DataOption[]>,
|
||||
required: true
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
required: true
|
||||
|
|
@ -210,14 +213,14 @@ const props = defineProps({
|
|||
|
||||
const $q = useQuasar()
|
||||
const mixin = useCounterMixin() //เรียกฟังก์ชันกลาง
|
||||
const { dateThaiRange, modalDelete, modalConfirm, dateToISO, success } = mixin
|
||||
const { dateThaiRange, modalDelete, modalConfirm, dateToISO, success, messageError } = mixin
|
||||
const store = useExamDataStore()
|
||||
const { examData, changeExamColumns } = store
|
||||
const loader = ref<boolean>(false)
|
||||
const dataStore = useDataStore()
|
||||
const { loaderPage } = dataStore
|
||||
const id = ref<string>('')
|
||||
const educationLevel = ref<string>()
|
||||
const educationLevelId = ref<string>()
|
||||
const educationLevelOptions = ref<DataOption[]>([])
|
||||
const major = ref<string>()
|
||||
const scores = ref<number | null>()
|
||||
const name = ref<string>()
|
||||
|
|
@ -298,11 +301,10 @@ watch(visibleColumns, async (count: String[], prevCount: String[]) => {
|
|||
|
||||
onMounted(async () => {
|
||||
await fetchData()
|
||||
await fetcheducationLevel()
|
||||
})
|
||||
|
||||
const fetchData = async () => {
|
||||
loader.value = true
|
||||
loaderPage(true)
|
||||
await http
|
||||
.get(config.API.candidateEducation(examId.value, positionId.value))
|
||||
.then((res) => {
|
||||
|
|
@ -317,34 +319,18 @@ const fetchData = async () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
loader.value = false
|
||||
.catch((e) => {
|
||||
// messageError($q, e)
|
||||
})
|
||||
}
|
||||
|
||||
const fetcheducationLevel = async () => {
|
||||
loader.value = true
|
||||
await http
|
||||
.get(config.API.educationLevel)
|
||||
.then((res) => {
|
||||
const data = res.data.result
|
||||
let option: DataOption[] = []
|
||||
data.map((r: DataOption) => {
|
||||
option.push({ id: r.id.toString(), name: r.name.toString() })
|
||||
})
|
||||
educationLevelOptions.value = option
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
loader.value = false
|
||||
loaderPage(false)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* กดดูข้อมูลก่อนหน้า
|
||||
*/
|
||||
const clickPrevious = () => {
|
||||
const clickPrevious = async () => {
|
||||
rowIndex.value -= 1
|
||||
const row = rows.value[rowIndex.value]
|
||||
educationLevel.value = row.educationLevel
|
||||
|
|
@ -354,13 +340,13 @@ const clickPrevious = () => {
|
|||
name.value = row.name
|
||||
duration.value = row.duration
|
||||
id.value = row.id
|
||||
checkRowPage()
|
||||
await checkRowPage()
|
||||
}
|
||||
|
||||
/**
|
||||
* กดดูข้อมูลต่อไป
|
||||
*/
|
||||
const clickNext = () => {
|
||||
const clickNext = async () => {
|
||||
rowIndex.value += 1
|
||||
const row = rows.value[rowIndex.value]
|
||||
educationLevel.value = row.educationLevel
|
||||
|
|
@ -370,7 +356,7 @@ const clickNext = () => {
|
|||
name.value = row.name
|
||||
duration.value = row.duration
|
||||
id.value = row.id
|
||||
checkRowPage()
|
||||
await checkRowPage()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -392,7 +378,6 @@ const checkRowPage = () => {
|
|||
* กดปุ่มแก้ไขใน dialog
|
||||
*/
|
||||
const clickEdit = () => {
|
||||
// edit.value = true
|
||||
next.value = false
|
||||
previous.value = false
|
||||
}
|
||||
|
|
@ -400,8 +385,8 @@ const clickEdit = () => {
|
|||
/**
|
||||
* กดปุ่มเพิ่มด้านบน table
|
||||
*/
|
||||
const clickAdd = () => {
|
||||
addRow()
|
||||
const clickAdd = async () => {
|
||||
await addRow()
|
||||
}
|
||||
|
||||
const checkDelete = (row: RequestItemsObject) => {
|
||||
|
|
@ -414,26 +399,20 @@ const checkDelete = (row: RequestItemsObject) => {
|
|||
*/
|
||||
const clickDeleteRow = async () => {
|
||||
if (rawItem.value != null) {
|
||||
loader.value = true
|
||||
loaderPage(true)
|
||||
await http
|
||||
.delete(config.API.candidateEducation(rawItem.value.id, ''))
|
||||
.then(() => {
|
||||
success($q, 'ลบข้อมูลสำเร็จ')
|
||||
})
|
||||
.catch(() => {
|
||||
// modalError.value = true
|
||||
// modalErrorTittle.value = 'ไม่สามารถบันทึกข้อมูลร่างได้'
|
||||
// modalErrorDetail.value = e.response.data.message
|
||||
// statusCode.value = e.response.data.status
|
||||
.catch((e) => {
|
||||
messageError($q, e)
|
||||
})
|
||||
.finally(async () => {
|
||||
loader.value = false
|
||||
await fetchData()
|
||||
// edit.value = false
|
||||
})
|
||||
} else {
|
||||
await fetchData()
|
||||
// edit.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -443,15 +422,11 @@ const clickDeleteRow = async () => {
|
|||
const clickSave = async () => {
|
||||
myForm.value.validate().then(async (result: boolean) => {
|
||||
if (result) {
|
||||
// if (store.consend == true) {
|
||||
if (modalEdit.value) {
|
||||
await editData()
|
||||
} else {
|
||||
await saveData()
|
||||
}
|
||||
// } else {
|
||||
// modalConsend.value = true
|
||||
// }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -460,7 +435,7 @@ const clickSave = async () => {
|
|||
* บันทึกเพิ่มข้อมูล
|
||||
*/
|
||||
const saveData = async () => {
|
||||
loader.value = true
|
||||
loaderPage(true)
|
||||
await http
|
||||
.post(config.API.candidateEducation(examId.value, positionId.value), {
|
||||
educationLevelId: educationLevelId.value,
|
||||
|
|
@ -473,15 +448,10 @@ const saveData = async () => {
|
|||
.then(() => {
|
||||
success($q, 'บันทึกข้อมูลสำเร็จ')
|
||||
})
|
||||
.catch(() => {
|
||||
// modalError.value = true
|
||||
// modalErrorTittle.value = 'ไม่สามารถบันทึกข้อมูลร่างได้'
|
||||
// modalErrorDetail.value = e.response.data.message
|
||||
// statusCode.value = e.response.data.status
|
||||
.catch((e) => {
|
||||
messageError($q, e)
|
||||
})
|
||||
.finally(async () => {
|
||||
loader.value = false
|
||||
// edit.value = false
|
||||
modal.value = false
|
||||
await fetchData()
|
||||
})
|
||||
|
|
@ -491,7 +461,7 @@ const saveData = async () => {
|
|||
* บันทึกแก้ไขข้อมูล
|
||||
*/
|
||||
const editData = async () => {
|
||||
loader.value = true
|
||||
loaderPage(true)
|
||||
await http
|
||||
.put(config.API.candidateEducation(id.value, ''), {
|
||||
educationLevelId: educationLevelId.value,
|
||||
|
|
@ -504,15 +474,10 @@ const editData = async () => {
|
|||
.then(() => {
|
||||
success($q, 'บันทึกข้อมูลสำเร็จ')
|
||||
})
|
||||
.catch(() => {
|
||||
// modalError.value = true
|
||||
// modalErrorTittle.value = 'ไม่สามารถบันทึกข้อมูลร่างได้'
|
||||
// modalErrorDetail.value = e.response.data.message
|
||||
// statusCode.value = e.response.data.status
|
||||
.catch((e) => {
|
||||
messageError($q, e)
|
||||
})
|
||||
.finally(async () => {
|
||||
loader.value = false
|
||||
// edit.value = false
|
||||
modal.value = false
|
||||
await fetchData()
|
||||
})
|
||||
|
|
@ -554,12 +519,8 @@ const selectData = (props: DataProps) => {
|
|||
name.value = props.row.name
|
||||
duration.value = props.row.duration
|
||||
id.value = props.row.id
|
||||
// if (edit.value == true) {
|
||||
next.value = false
|
||||
previous.value = false
|
||||
// } else {
|
||||
// checkRowPage()
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -576,13 +537,6 @@ const addRow = () => {
|
|||
duration.value = [new Date(), new Date()]
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันปุ่มยกเลิกการแก้ไขข้อมูล
|
||||
*/
|
||||
const clickCancel = async () => {
|
||||
// edit.value = false
|
||||
}
|
||||
|
||||
/**
|
||||
* เช็คว่ามีการแก้ไขข้อมูล
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue