hrms-mgt/src/modules/14_KPI/components/competency/02ListLinkPosition.vue

289 lines
7.4 KiB
Vue
Raw Normal View History

2024-04-10 17:40:14 +07:00
<script setup lang="ts">
import { ref, onMounted } from "vue";
import type { QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
2024-04-19 11:36:48 +07:00
import dialogHeader from "@/components/DialogHeader.vue";
2024-04-10 17:40:14 +07:00
import type { DataOption } from "@/modules/14_KPI/interface/index/Main";
2024-04-19 11:36:48 +07:00
import type { ResponseObject } from "@/modules/14_KPI/interface/response/KpiGroup";
2024-04-10 17:40:14 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
const modal = ref<boolean>(false);
2024-04-19 11:36:48 +07:00
const rows = ref<ResponseObject[]>([]);
2024-04-10 17:40:14 +07:00
const groupName = ref<string>("");
const editStatus = ref<boolean>(false);
2024-04-19 11:36:48 +07:00
const editId = ref<string>("");
2024-04-10 17:40:14 +07:00
const competencyTypeOp = ref<DataOption[]>([
{
id: "ID1",
name: "สมรรถนะหลัก",
},
{
id: "ID2",
name: "สมรรถนะประจำกลุ่มงาน",
},
{
id: "ID3",
name: "สมรรถนะประจำผู้บริหารกรุงเทพมหานคร",
},
{
id: "ID4",
name: "สมรรถนะเฉพาะสำหรับตำแหน่ง ผอ.เขต ผช.ผอ.เขต และหัวหน้าฝ่ายในสังกัด สนง.เขต",
},
{
id: "ID5",
name: "สมรรถนะเฉพาะสำหรับตำแหน่งผู้ตรวจราชการ กทม. และผู้ตรวจราชการ",
},
]);
const columns = ref<QTableProps["columns"]>([
{
2024-04-19 11:36:48 +07:00
name: "nameGroupKPI",
2024-04-10 17:40:14 +07:00
align: "left",
label: "รายการกลุ่มงาน",
sortable: true,
2024-04-19 11:36:48 +07:00
field: "nameGroupKPI",
2024-04-10 17:40:14 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
const $q = useQuasar();
const mixin = useCounterMixin();
2024-04-19 11:36:48 +07:00
const {
dialogRemove,
dialogConfirm,
showLoader,
hideLoader,
messageError,
success,
} = mixin;
2024-04-10 17:40:14 +07:00
const filterKeyword = ref<string>("");
2024-04-19 11:36:48 +07:00
const visibleColumns = ref<string[]>(["nameGroupKPI"]);
2024-04-10 17:40:14 +07:00
/** ดึงข้อมูล */
2024-04-19 11:36:48 +07:00
async function fetchData() {
showLoader();
await http
.get(config.API.kpiGroup)
.then(async (res) => {
rows.value = res.data.result.data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function addData() {
await http
.post(config.API.kpiGroup, {
nameGroupKPI: groupName.value,
})
.then(() => {
fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
2024-04-10 17:40:14 +07:00
}
async function editData(id: string) {
2024-04-19 11:36:48 +07:00
await http
.put(config.API.kpiGroupById(id), {
nameGroupKPI: groupName.value,
})
.then(() => {
fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
2024-04-10 17:40:14 +07:00
}
async function deleteData(id: string) {
2024-04-19 11:36:48 +07:00
await http
.delete(config.API.kpiGroupById(id))
.then(() => {
fetchData();
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
2024-04-10 17:40:14 +07:00
}
/** เปลี่ยนเป็นหน้าเพิ่มข้อมูล */
function onAdd() {
modal.value = true;
}
2024-04-19 11:36:48 +07:00
function closeDialog() {
2024-04-10 17:40:14 +07:00
modal.value = false;
editStatus.value = false;
2024-04-19 11:36:48 +07:00
groupName.value = "";
2024-04-10 17:40:14 +07:00
}
function onEdit(data: any) {
modal.value = true;
editStatus.value = true;
2024-04-19 11:36:48 +07:00
groupName.value = data.nameGroupKPI;
editId.value = data.id;
2024-04-10 17:40:14 +07:00
}
2024-04-19 11:36:48 +07:00
async function onSubmit() {
dialogConfirm(
$q,
async () => {
editStatus.value ? editData(editId.value) : addData();
closeDialog();
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
2024-04-10 17:40:14 +07:00
}
onMounted(async () => {
2024-04-19 11:36:48 +07:00
fetchData();
2024-04-10 17:40:14 +07:00
});
</script>
2024-04-05 14:08:20 +07:00
<template>
2024-04-10 17:40:14 +07:00
<q-toolbar style="padding: 0">
<q-btn flat round color="primary" icon="add" @click="onAdd()">
<q-tooltip> เพมขอม </q-tooltip>
</q-btn>
<q-space />
<div class="row q-gutter-sm">
<q-input outlined dense v-model="filterKeyword" label="ค้นหา"></q-input>
<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"
options-cover
style="min-width: 150px"
/>
</div>
</q-toolbar>
<d-table
ref="table"
:columns="columns"
:rows="rows"
:filter="filterKeyword"
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">
2024-04-19 11:36:48 +07:00
<q-td v-for="col in props.cols" :key="col.id">
2024-04-10 17:40:14 +07:00
{{ col.value }}
</q-td>
<q-td auto-width>
2024-04-19 11:36:48 +07:00
<q-btn
2024-04-10 17:40:14 +07:00
color="edit"
flat
dense
round
class="q-mr-xs"
size="12px"
icon="edit"
clickable
2024-04-19 11:36:48 +07:00
@click="onEdit(props.row)"
2024-04-10 17:40:14 +07:00
>
<q-tooltip>แกไขขอม</q-tooltip>
2024-04-19 11:36:48 +07:00
</q-btn>
2024-04-10 17:40:14 +07:00
<q-btn
color="red"
flat
dense
round
size="12px"
icon="mdi-delete"
clickable
@click.stop="
dialogRemove($q, async () => await deleteData(props.row.id))
"
v-close-popup
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
</d-table>
<q-dialog v-model="modal" persistent>
<q-card flat bordered style="min-width: 50vh">
<q-form greedy @submit.prevent @validation-success="onSubmit">
2024-04-19 11:36:48 +07:00
<dialog-header
2024-04-10 17:40:14 +07:00
:tittle="editStatus ? 'แก้ไขกลุ่มงาน' : 'เพิ่มกลุ่มงาน'"
2024-04-19 11:36:48 +07:00
:close="closeDialog"
2024-04-10 17:40:14 +07:00
/>
<q-separator />
<q-card-section>
<q-input
label="กลุ่มงาน"
v-model="groupName"
outlined
dense
class="inputgreen"
:rules="[(val:string) => !!val || `${'กรุณากรอกกลุ่มงาน'}`,]"
hide-bottom-space
/>
</q-card-section>
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<q-btn
type="submit"
for="#submitForm"
unelevated
dense
class="q-px-md items-center"
color="public"
label="บันทึก"
/>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
2024-04-05 14:08:20 +07:00
</template>