hrms-mgt/src/modules/14_KPI/components/competency/01ListCompetency.vue

249 lines
6.6 KiB
Vue
Raw Normal View History

2024-04-05 14:08:20 +07:00
<script setup lang="ts">
2024-04-19 14:38:05 +07:00
import { ref, onMounted, reactive } from "vue";
2024-04-05 14:08:20 +07:00
import type { QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
2024-04-19 15:50:01 +07:00
import type { DataOption } from "@/modules/14_KPI/interface/index/Main";
import type { FormQueryCapacity } from "@/modules/14_KPI/interface/request/Main";
import type { ResDataCapacity } from "@/modules/14_KPI/interface/response/Main";
2024-04-11 17:51:03 +07:00
import { useKPIDataStore } from "@/modules/14_KPI/store/KPIStore";
2024-04-05 14:08:20 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-04-11 17:51:03 +07:00
const store = useKPIDataStore();
const router = useRouter();
2024-04-19 14:38:05 +07:00
const $q = useQuasar();
const mixin = useCounterMixin();
const { dialogRemove, messageError, showLoader, hideLoader, success } = mixin;
2024-04-05 14:08:20 +07:00
const competencyTypeOp = ref<DataOption[]>([
{
id: "HEAD",
name: "สมรรถนะหลัก",
2024-04-05 14:08:20 +07:00
},
{
id: "GROUP",
name: "สมรรถนะประจำกลุ่มงาน",
2024-04-05 14:08:20 +07:00
},
{
id: "EXECUTIVE",
name: "สมรรถนะประจำผู้บริหารกรุงเทพมหานคร",
2024-04-05 14:08:20 +07:00
},
{
id: "DIRECTOR",
name: "สมรรถนะเฉพาะสำหรับตำแหน่ง ผอ.เขต ผช.ผอ.เขต และหัวหน้าฝ่ายในสังกัด สนง.เขต",
2024-04-05 14:08:20 +07:00
},
{
id: "INSPECTOR",
name: "สมรรถนะเฉพาะสำหรับตำแหน่งผู้ตรวจราชการ กทม. และผู้ตรวจราชการ",
2024-04-05 14:08:20 +07:00
},
]);
2024-04-05 14:42:55 +07:00
const columns = ref<QTableProps["columns"]>([
2024-04-05 14:08:20 +07:00
{
2024-04-19 14:38:05 +07:00
name: "name",
2024-04-05 14:08:20 +07:00
align: "left",
label: "ชื่อสมรรถนะ",
sortable: true,
2024-04-19 14:38:05 +07:00
field: "name",
2024-04-05 14:08:20 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
2024-04-19 14:38:05 +07:00
const visibleColumns = ref<string[]>(["name"]);
2024-04-05 14:08:20 +07:00
2024-04-19 15:50:01 +07:00
const rows = ref<ResDataCapacity[]>([]);
const formQuery = reactive<FormQueryCapacity>({
2024-04-19 14:38:05 +07:00
page: 1,
pageSize: 10,
keyword: "",
});
const totalList = ref<number>(1); //จำนวนข้อมูลรายการ
2024-04-05 14:08:20 +07:00
/** ดึงข้อมูล */
2024-04-19 14:38:05 +07:00
async function fetchList() {
showLoader();
await http
.get(
config.API.kpiCapacity +
`?page=${formQuery.page}&pageSize=${formQuery.pageSize}&keyword=${formQuery.keyword}&type=${store.competencyType}`
)
.then(async (res) => {
2024-04-19 15:50:01 +07:00
const data: ResDataCapacity[] = res.data.result.data;
2024-04-19 14:38:05 +07:00
totalList.value = Math.ceil(res.data.result.total / formQuery.pageSize);
rows.value = data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
2024-04-05 14:08:20 +07:00
}
2024-04-19 14:38:05 +07:00
async function onViewDetail(id: string) {
router.push(`/KPI-competency/${id}`);
2024-04-05 14:08:20 +07:00
}
2024-04-19 14:38:05 +07:00
function deleteData(id: string) {
dialogRemove($q, () => {
http
.delete(config.API.kpiCapacity + `/${id}`)
.then(() => {
fetchList();
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
2024-04-05 14:08:20 +07:00
}
/** เปลี่ยนเป็นหน้าเพิ่มข้อมูล */
function onAdd() {
router.push(`/KPI-competency/add`);
2024-04-05 14:08:20 +07:00
}
2024-04-19 14:38:05 +07:00
function fetchNewList() {
formQuery.page = 1;
fetchList();
}
onMounted(() => {
fetchList();
2024-04-05 14:08:20 +07:00
});
</script>
<template>
<q-toolbar style="padding: 0">
<q-select
2024-04-11 17:51:03 +07:00
v-model="store.competencyType"
outlined
label="ประเภทสมรรถนะ"
dense
option-label="name"
option-value="id"
:options="competencyTypeOp"
style="min-width: 200px"
emit-value
map-options
2024-04-19 14:38:05 +07:00
@update:model-value="fetchNewList"
2024-04-05 14:08:20 +07:00
/>
<q-btn flat round color="primary" icon="add" @click="onAdd()">
2024-04-05 14:08:20 +07:00
<q-tooltip> เพมขอม </q-tooltip>
</q-btn>
<q-space />
<div class="row q-gutter-sm">
2024-04-19 14:38:05 +07:00
<q-input
outlined
dense
v-model="formQuery.keyword"
label="ค้นหา"
@keyup.enter="fetchNewList()"
>
<template v-slot:append>
<q-icon v-if="formQuery.keyword == ''" name="search" />
<q-icon
v-if="formQuery.keyword !== ''"
name="clear"
class="cursor-pointer"
@click="(formQuery.keyword = ''), fetchNewList()"
/>
</template>
</q-input>
2024-04-05 14:08:20 +07:00
<q-select
v-model="visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
2024-04-05 14:42:55 +07:00
:options="columns"
2024-04-05 14:08:20 +07:00
option-value="name"
options-cover
style="min-width: 150px"
/>
</div>
</q-toolbar>
<d-table
ref="table"
2024-04-05 14:42:55 +07:00
:columns="columns"
2024-04-05 14:08:20 +07:00
:rows="rows"
row-key="id"
flat
bordered
:paging="true"
dense
class="custom-header-table"
:visible-columns="visibleColumns"
>
<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">
<q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.id">
{{ col.value }}
</q-td>
<q-td auto-width>
2024-04-19 14:38:05 +07:00
<q-btn
2024-04-05 14:08:20 +07:00
color="edit"
flat
dense
round
size="12px"
icon="edit"
clickable
2024-04-19 14:38:05 +07:00
@click.stop="onViewDetail(props.row.id)"
v-close-popup
2024-04-05 14:08:20 +07:00
>
2024-04-19 14:38:05 +07:00
<q-tooltip>แกไข</q-tooltip>
</q-btn>
2024-04-05 14:08:20 +07:00
<q-btn
color="red"
flat
dense
round
size="12px"
icon="mdi-delete"
clickable
2024-04-19 14:38:05 +07:00
@click.stop="deleteData(props.row.id)"
2024-04-05 14:08:20 +07:00
v-close-popup
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
2024-04-19 14:38:05 +07:00
<template v-slot:pagination="scope">
<q-pagination
v-model="formQuery.page"
active-color="primary"
color="dark"
:max="Number(totalList)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetchList"
></q-pagination>
</template>
2024-04-05 14:08:20 +07:00
</d-table>
</template>