348 lines
11 KiB
Vue
348 lines
11 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted, watch } from "vue";
|
|
import { useRouter } from "vue-router";
|
|
import { useQuasar, type QTableProps } from "quasar";
|
|
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
import { useDataStore } from "@/stores/data";
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
import type {
|
|
DataOptions,
|
|
Scholarship,
|
|
} from "@/modules/09_scholarship/interface/index/Main";
|
|
|
|
const mixin = useCounterMixin();
|
|
const { showLoader, hideLoader, messageError } = mixin;
|
|
const router = useRouter();
|
|
|
|
const $q = useQuasar();
|
|
const dataStore = useDataStore();
|
|
const profilId = ref<string>("");
|
|
const currentPage = ref<number>(1);
|
|
const page = ref<number>(1);
|
|
const rowsPerPage = ref<number>(10);
|
|
|
|
const rows = ref<Scholarship[]>([]);
|
|
const year = ref<number>(0);
|
|
const type = ref<string>("DOMESTICE");
|
|
const scholarshipTypeOp = ref<DataOptions[]>([
|
|
{ id: "DOMESTICE", name: "การศึกษาในประเทศ" },
|
|
{
|
|
id: "NOABROAD",
|
|
name: "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)",
|
|
},
|
|
{
|
|
id: "ABROAD",
|
|
name: "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)",
|
|
},
|
|
{
|
|
id: "EXECUTIVE",
|
|
name: " ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรประเภทนักบริหาร)",
|
|
},
|
|
{
|
|
id: "STUDY",
|
|
name: "ทุนการศึกษา ณ ต่างประเทศ",
|
|
},
|
|
{
|
|
id: "TRAINING",
|
|
name: "ทุนฝึกอบรม ณ ต่างประเทศ",
|
|
},
|
|
]);
|
|
|
|
/**
|
|
* ตั้งค่า pagination
|
|
*/
|
|
const pagination = ref({
|
|
sortBy: "lastUpdatedAt",
|
|
descending: true,
|
|
page: page.value,
|
|
rowsPerPage: rowsPerPage.value,
|
|
});
|
|
|
|
const columns = ref<QTableProps["columns"]>([
|
|
{
|
|
name: "scholarshipYear",
|
|
align: "left",
|
|
label: "ปีงบประมาณที่ได้รับทุน ",
|
|
sortable: true,
|
|
field: "scholarshipYear",
|
|
headerStyle: "font-size: 14px ;width:20%",
|
|
style: "font-size: 14px",
|
|
},
|
|
{
|
|
name: "scholarshipType",
|
|
align: "left",
|
|
label: "ประเภททุน",
|
|
sortable: true,
|
|
field: "scholarshipType",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
},
|
|
]);
|
|
const visibleColumns = ref<string[]>(["scholarshipYear", "scholarshipType"]);
|
|
|
|
/** ดึงข้อมูล */
|
|
async function getData() {
|
|
showLoader();
|
|
await http
|
|
.get(
|
|
config.API.developmentScholarship +
|
|
`/user/${profilId.value}?year=${year.value}&type=${type.value}`
|
|
)
|
|
.then(async (res) => {
|
|
rows.value = res.data.result;
|
|
})
|
|
.catch((e) => {
|
|
messageError($q, e);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
function onEdit(id: string) {
|
|
router.push(`/scholarship/${id}`);
|
|
}
|
|
|
|
// watch(
|
|
// () => currentPage.value,
|
|
// () => {
|
|
// rowsPerPage.value = pagination.value.rowsPerPage;
|
|
// getData();
|
|
// }
|
|
// );
|
|
|
|
// watch(
|
|
// () => pagination.value.rowsPerPage,
|
|
// () => {
|
|
// rowsPerPage.value = pagination.value.rowsPerPage;
|
|
// currentPage.value = 1;
|
|
// getData();
|
|
// }
|
|
// );
|
|
|
|
async function getProfileId() {
|
|
if (dataStore.profileId) {
|
|
profilId.value = dataStore.profileId;
|
|
} else {
|
|
showLoader();
|
|
try {
|
|
const res = await http.get(config.API.profilePosition());
|
|
dataStore.profileId = res.data.result.profileId;
|
|
profilId.value = dataStore.profileId;
|
|
} catch (e) {
|
|
messageError($q, e);
|
|
} finally {
|
|
hideLoader();
|
|
}
|
|
}
|
|
|
|
await getData();
|
|
}
|
|
|
|
function convertType(val: string) {
|
|
switch (val) {
|
|
case "DOMESTICE":
|
|
return "การศึกษาในประเทศ";
|
|
case "NOABROAD":
|
|
return "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)";
|
|
case "ABROAD":
|
|
return "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)";
|
|
case "EXECUTIVE":
|
|
return "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)";
|
|
case "STUDY":
|
|
return "ทุนการศึกษา ณ ต่างประเทศ";
|
|
case "TRAINING":
|
|
return "ทุนฝึกอบรม ณ ต่างประเทศ";
|
|
}
|
|
}
|
|
|
|
onMounted(async () => {
|
|
await getProfileId();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="col-12 row justify-center">
|
|
<div class="col-xs-12 col-sm-12 col-md-11">
|
|
<div class="toptitle text-white col-12 row items-center">
|
|
<q-btn
|
|
icon="mdi-arrow-left"
|
|
unelevated
|
|
round
|
|
dense
|
|
flat
|
|
color="primary"
|
|
class="q-mr-sm"
|
|
@click="router.push(`/`)"
|
|
/>
|
|
รายการทุนการศึกษา/ฝึกอบรม
|
|
</div>
|
|
<div class="col-12">
|
|
<q-card bordered class="q-pa-md">
|
|
<div class="items-center col-12 row q-col-gutter-sm q-mb-sm">
|
|
<datepicker
|
|
class="col-xs-12 col-md-1"
|
|
v-model="year"
|
|
:locale="'th'"
|
|
autoApply
|
|
year-picker
|
|
:enableTimePicker="false"
|
|
@update:model-value="getData()"
|
|
>
|
|
<template #year="{ year }">{{ year + 543 }}</template>
|
|
<template #year-overlay-value="{ value }">{{
|
|
parseInt(value + 543)
|
|
}}</template>
|
|
<template #trigger>
|
|
<q-input
|
|
dense
|
|
lazy-rules
|
|
outlined
|
|
:model-value="year === 0 ? 'ทั้งหมด' : Number(year) + 543"
|
|
:label="`${'ปีงบประมาณ'}`"
|
|
>
|
|
<template v-if="year" v-slot:append>
|
|
<q-icon
|
|
name="cancel"
|
|
@click.stop.prevent="(year = 0), getData()"
|
|
class="cursor-pointer"
|
|
/>
|
|
</template>
|
|
<template v-slot:prepend>
|
|
<q-icon
|
|
name="event"
|
|
class="cursor-pointer"
|
|
style="color: var(--q-primary)"
|
|
>
|
|
</q-icon>
|
|
</template>
|
|
</q-input>
|
|
</template>
|
|
</datepicker>
|
|
<q-select
|
|
dense
|
|
outlined
|
|
v-model="type"
|
|
:options="scholarshipTypeOp"
|
|
emit-value
|
|
map-options
|
|
option-value="id"
|
|
option-label="name"
|
|
label="เลือกประเภททุน"
|
|
@update:model-value="getData()"
|
|
class="select_ellipsis col-xs-12 col-md-2"
|
|
/>
|
|
|
|
<q-space />
|
|
|
|
<q-select
|
|
v-model="visibleColumns"
|
|
multiple
|
|
outlined
|
|
dense
|
|
options-dense
|
|
:display-value="$q.lang.table.columns"
|
|
emit-value
|
|
map-options
|
|
:options="columns"
|
|
option-value="name"
|
|
class="col-xs-12 col-md-1"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<d-table
|
|
flat
|
|
bordered
|
|
dense
|
|
row-key="id"
|
|
:rows="rows"
|
|
:columns="columns"
|
|
:visible-columns="visibleColumns"
|
|
:rows-per-page-options="[10, 25, 50, 100]"
|
|
v-model:pagination="pagination"
|
|
>
|
|
<template v-slot:pagination="scope">
|
|
ทั้งหมด {{ rows.length }} รายการ
|
|
<q-pagination
|
|
v-model="pagination.page"
|
|
active-color="primary"
|
|
color="dark"
|
|
:max="scope.pagesNumber"
|
|
:max-pages="5"
|
|
size="sm"
|
|
boundary-links
|
|
direction-links
|
|
></q-pagination>
|
|
</template>
|
|
<template v-slot:header="props">
|
|
<q-tr :props="props">
|
|
<q-th
|
|
v-for="col in props.cols"
|
|
:key="col.name"
|
|
:props="props"
|
|
style="color: #000000; font-weight: 500"
|
|
>
|
|
<span class="text-weight-medium">{{ col.label }}</span>
|
|
</q-th>
|
|
</q-tr>
|
|
</template>
|
|
<template v-slot:body="props">
|
|
<q-tr :props="props" class="cursor-pointer">
|
|
<q-td
|
|
v-for="col in props.cols"
|
|
:key="col.name"
|
|
:props="props"
|
|
@click="onEdit(props.row.id)"
|
|
>
|
|
<div v-if="col.name == 'scholarshipYear'">
|
|
{{ col.value ? col.value + 543 : "-" }}
|
|
</div>
|
|
<div v-else-if="col.name == 'scholarshipType'">
|
|
{{ col.value ? convertType(col.value) : "-" }}
|
|
</div>
|
|
<div v-else>
|
|
{{ col.value ? col.value : "-" }}
|
|
</div>
|
|
</q-td>
|
|
</q-tr>
|
|
</template>
|
|
|
|
<template #item="props">
|
|
<div class="q-pa-xs col-xs-12 col-sm-6 col-md-4 col-lg-3">
|
|
<q-card bordered flat>
|
|
<q-list @click="onEdit(props.row.id)">
|
|
<q-item
|
|
v-for="col in props.cols.filter((col:any) => col.name !== 'desc')"
|
|
:key="col.name"
|
|
>
|
|
<q-item-section>
|
|
<q-item-label caption>{{ col.label }}</q-item-label>
|
|
|
|
<q-item-label v-if="col.name === 'scholarshipYear'">
|
|
{{ col.value ? col.value + 543 : "-" }}
|
|
</q-item-label>
|
|
<q-item-label
|
|
v-else-if="col.name === 'scholarshipType'"
|
|
>
|
|
{{ col.value ? convertType(col.value) : "-" }}
|
|
</q-item-label>
|
|
|
|
<q-item-label v-else>{{ col.value }}</q-item-label>
|
|
</q-item-section>
|
|
</q-item>
|
|
</q-list>
|
|
</q-card>
|
|
</div>
|
|
</template>
|
|
</d-table>
|
|
</div>
|
|
</q-card>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
<style scoped lang="scss"></style>
|