ทะเบียนประวัติ: ความสามารถพิเศษ clean code

This commit is contained in:
oat_dev 2024-03-21 14:46:19 +07:00
parent 8aa9e2be13
commit c2d386c026
4 changed files with 107 additions and 135 deletions

View file

@ -234,7 +234,6 @@ const educationData = reactive<RequestItemsObject>({
educationLevelId: "", educationLevelId: "",
positionPath: "", positionPath: "",
positionPathId: "", positionPathId: "",
isActive: true,
}); });
const keyword = ref<string>(""); const keyword = ref<string>("");
@ -770,7 +769,7 @@ onMounted(async () => {
year-picker year-picker
:enableTimePicker="false" :enableTimePicker="false"
@update:modelValue=" @update:modelValue="
(v) => (v:number) =>
(educationData.startDate = new Date( (educationData.startDate = new Date(
`${v}-01-01T00:00:02.010+07:00` `${v}-01-01T00:00:02.010+07:00`
)) ))
@ -813,7 +812,7 @@ onMounted(async () => {
year-picker year-picker
:enableTimePicker="false" :enableTimePicker="false"
@update:modelValue=" @update:modelValue="
(v) => (v:number) =>
(educationData.endDate = new Date( (educationData.endDate = new Date(
`${v}-01-01T00:00:02.010+07:00` `${v}-01-01T00:00:02.010+07:00`
)) ))
@ -858,7 +857,7 @@ onMounted(async () => {
:enableTimePicker="false" :enableTimePicker="false"
week-start="0" week-start="0"
@update:modelValue=" @update:modelValue="
(v) => (v: Date) =>
(educationData.startYear = parseInt( (educationData.startYear = parseInt(
v.toString().slice(11, 15) v.toString().slice(11, 15)
)) ))
@ -901,7 +900,7 @@ onMounted(async () => {
:enableTimePicker="false" :enableTimePicker="false"
week-start="0" week-start="0"
@update:modelValue=" @update:modelValue="
(v) => (v: Date) =>
(educationData.endYear = parseInt( (educationData.endYear = parseInt(
v.toString().slice(11, 15) v.toString().slice(11, 15)
)) ))

View file

@ -76,34 +76,22 @@ const historyRows = ref<ResponseObject[]>([]);
const route = useRoute(); const route = useRoute();
const id = ref<string>(route.params.id.toString()); const id = ref<string>(route.params.id.toString());
const editId = ref<string>(""); const editId = ref<string>("");
const keyword = ref<string>("");
const formFilter = reactive({ const historyKeyword = ref<string>("");
page: 1,
pageSize: 10,
keyword: "",
});
const specialSkill = reactive<RequestItemsObject>({ const specialSkill = reactive<RequestItemsObject>({
field: "", field: "",
detail: "", detail: "",
remark: "", remark: "",
reference: "", reference: "",
profileId: id.value,
dateStart: null,
dateEnd: null,
}); });
const pagination = ref({ const pagination = ref({
page: formFilter.page,
rowsPerPage: formFilter.pageSize,
});
const historyFormFilter = reactive({
page: 1, page: 1,
pageSize: 10, rowsPerPage: 10,
keyword: "",
});
const historyPagination = ref({
page: historyFormFilter.page,
rowsPerPage: historyFormFilter.pageSize,
}); });
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
@ -127,10 +115,6 @@ function closeHistoryDialog() {
historyDialog.value = false; historyDialog.value = false;
} }
function validateForm() {
onSubmit();
}
async function onSubmit() { async function onSubmit() {
dialogConfirm( dialogConfirm(
$q, $q,
@ -166,7 +150,6 @@ async function fetchData(id: string) {
.get(config.API.profileNewAbilityByProfileId(id)) .get(config.API.profileNewAbilityByProfileId(id))
.then(async (res) => { .then(async (res) => {
rows.value = res.data.result; rows.value = res.data.result;
console.log(rows.value);
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -194,12 +177,7 @@ async function fetchHistoryData(id: string) {
async function addData() { async function addData() {
await http await http
.post(config.API.profileNewAbility, { .post(config.API.profileNewAbility, {
profileId: id.value, ...specialSkill,
isActive: true,
remark: specialSkill.remark,
field: specialSkill.field,
reference: specialSkill.reference,
detail: specialSkill.detail,
dateStart: null, dateStart: null,
dateEnd: null, dateEnd: null,
}) })
@ -218,13 +196,10 @@ async function addData() {
async function editData(idData: string) { async function editData(idData: string) {
await http await http
.patch(config.API.profileNewAbilityByAbilityId(idData), { .patch(config.API.profileNewAbilityByAbilityId(idData), {
isActive: true, ...specialSkill,
remark: specialSkill.remark,
field: specialSkill.field,
reference: specialSkill.reference,
detail: specialSkill.detail,
dateStart: null, dateStart: null,
dateEnd: null, dateEnd: null,
profileId: undefined,
}) })
.then(() => { .then(() => {
fetchData(id.value); fetchData(id.value);
@ -239,17 +214,20 @@ async function editData(idData: string) {
} }
async function deleteData(idData: string) { async function deleteData(idData: string) {
await http dialogRemove($q, () =>
.delete(config.API.profileNewAbilityByAbilityId(idData)) http
.then(() => { .delete(config.API.profileNewAbilityByAbilityId(idData))
fetchData(id.value); .then(() => {
}) fetchData(id.value);
.catch((err) => { success($q, "ลบข้อมูลสำเร็จ");
messageError($q, err); })
}) .catch((err) => {
.finally(() => { messageError($q, err);
hideLoader(); })
}); .finally(() => {
hideLoader();
})
);
} }
onMounted(async () => { onMounted(async () => {
@ -268,13 +246,7 @@ onMounted(async () => {
<q-tooltip>เพ</q-tooltip> <q-tooltip>เพ</q-tooltip>
</q-btn> </q-btn>
<q-space /> <q-space />
<q-input <q-input dense outlined v-model="keyword" label="ค้นหา" class="q-mr-sm">
dense
outlined
v-model="formFilter.keyword"
label="ค้นหา"
class="q-mr-sm"
>
<template v-slot:append> <template v-slot:append>
<q-icon name="search" /> <q-icon name="search" />
</template> </template>
@ -338,7 +310,7 @@ onMounted(async () => {
:columns="columns" :columns="columns"
:rows="rows" :rows="rows"
:paging="true" :paging="true"
:filter="formFilter.keyword" :filter="keyword"
v-model:pagination="pagination" v-model:pagination="pagination"
:rows-per-page-options="[20, 50, 100]" :rows-per-page-options="[20, 50, 100]"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
@ -396,9 +368,7 @@ onMounted(async () => {
size="14px" size="14px"
icon="mdi-delete" icon="mdi-delete"
clickable clickable
@click.stop=" @click.stop="deleteData(props.row.id)"
dialogRemove($q, async () => await deleteData(props.row.id))
"
v-close-popup v-close-popup
> >
<q-tooltip>ลบขอม</q-tooltip> <q-tooltip>ลบขอม</q-tooltip>
@ -461,9 +431,12 @@ onMounted(async () => {
<q-dialog v-model="dialog" class="dialog" persistent> <q-dialog v-model="dialog" class="dialog" persistent>
<q-card style="min-width: 40%" class="bg-white"> <q-card style="min-width: 40%" class="bg-white">
<q-form @submit.prevent greedy @validation-success="validateForm"> <q-form @submit.prevent greedy @validation-success="onSubmit()">
<q-card-section class="flex justify-between" style="padding: 0"> <q-card-section class="flex justify-between" style="padding: 0">
<dialog-header tittle="เพิ่มความสามารถพิเศษ" :close="closeDialog" /> <dialog-header
:tittle="dialogStatus == 'edit' ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
:close="closeDialog"
/>
</q-card-section> </q-card-section>
<q-separator color="grey-4" /> <q-separator color="grey-4" />
<q-card-section class="col q-gutter-sm q-pr-md"> <q-card-section class="col q-gutter-sm q-pr-md">
@ -527,80 +500,78 @@ onMounted(async () => {
<q-dialog v-model="historyDialog" class="dialog" persistent> <q-dialog v-model="historyDialog" class="dialog" persistent>
<q-card style="min-width: 70%" class="bg-white"> <q-card style="min-width: 70%" class="bg-white">
<q-form @submit.prevent greedy @validation-success="validateForm"> <q-card-section class="flex justify-between" style="padding: 0">
<q-card-section class="flex justify-between" style="padding: 0"> <dialog-header
<dialog-header tittle="ประวัติแก้ไขความสามารถพิเศษ"
tittle="ประวัติแก้ไขความสามารถพิเศษ" :close="closeHistoryDialog"
:close="closeHistoryDialog" />
/> </q-card-section>
</q-card-section> <q-separator color="grey-4" />
<q-separator color="grey-4" /> <q-card-section>
<q-card-section> <q-toolbar style="padding: 0px" class="text-primary q-mb-sm">
<q-toolbar style="padding: 0px" class="text-primary q-mb-sm"> <q-space />
<q-space /> <q-input
<q-input
dense
outlined
bg-color="white"
v-model="historyFormFilter.keyword"
label="ค้นหา"
class="q-mr-sm"
>
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
<q-select
v-model="historyVisibleColumns"
multiple
outlined
dense
bg-color="white"
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="columns"
option-value="name"
options-cover
style="min-width: 150px"
/>
</q-toolbar>
<d-table
ref="table"
:columns="columns"
:rows="historyRows"
row-key="name"
flat
bordered
:paging="true"
dense dense
:filter="historyFormFilter.keyword" outlined
v-model:pagination="historyPagination" bg-color="white"
:rows-per-page-options="[20, 50, 100]" v-model="historyKeyword"
class="custom-header-table" label="ค้นหา"
:visible-columns="historyVisibleColumns" class="q-mr-sm"
> >
<template v-slot:header="props"> <template v-slot:append>
<q-tr :props="props"> <q-icon name="search" />
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th auto-width />
</q-tr>
</template> </template>
<template v-slot:body="props" v-if="mode === 'table'"> </q-input>
<q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.id"> <q-select
<div>{{ col.value ? col.value : "-" }}</div> v-model="historyVisibleColumns"
</q-td> multiple
<q-td auto-width> </q-td> outlined
</q-tr> dense
</template> bg-color="white"
</d-table> options-dense
</q-card-section> :display-value="$q.lang.table.columns"
</q-form> emit-value
map-options
:options="columns"
option-value="name"
options-cover
style="min-width: 150px"
/>
</q-toolbar>
<d-table
ref="table"
:columns="columns"
:rows="historyRows"
row-key="name"
flat
bordered
:paging="true"
dense
:filter="historyKeyword"
v-model:pagination="pagination"
:rows-per-page-options="[20, 50, 100]"
class="custom-header-table"
:visible-columns="historyVisibleColumns"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th auto-width />
</q-tr>
</template>
<template v-slot:body="props" v-if="mode === 'table'">
<q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.id">
<div>{{ col.value ? col.value : "-" }}</div>
</q-td>
<q-td auto-width> </q-td>
</q-tr>
</template>
</d-table>
</q-card-section>
</q-card> </q-card>
</q-dialog> </q-dialog>
</template> </template>

View file

@ -20,7 +20,6 @@ interface RequestItemsObject {
educationLevelId: string, educationLevelId: string,
positionPath: string, positionPath: string,
positionPathId: string, positionPathId: string,
isActive: boolean,
isDate: boolean isDate: boolean
} }

View file

@ -3,6 +3,9 @@ interface RequestItemsObject {
detail: string; detail: string;
remark: string; remark: string;
reference: string; reference: string;
dateStart: Date | null,
dateEnd: Date | null ,
profileId: string,
} }
export type { RequestItemsObject }; export type { RequestItemsObject };