ต่อAPI กลุ่มงาน
This commit is contained in:
parent
974f5d8270
commit
4dfd5a139b
3 changed files with 103 additions and 101 deletions
|
|
@ -3,21 +3,19 @@ import { ref, onMounted } from "vue";
|
|||
import type { QTableProps } from "quasar";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import { useQuasar } from "quasar";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import Header from "@/components/DialogHeader.vue";
|
||||
import dialogHeader from "@/components/DialogHeader.vue";
|
||||
import type { DataOption } from "@/modules/14_KPI/interface/index/Main";
|
||||
|
||||
import type { ResponseObject } from "@/modules/14_KPI/interface/response/KpiGroup";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
|
||||
const modal = ref<boolean>(false);
|
||||
const router = useRouter();
|
||||
const rows = ref<any>();
|
||||
const rows = ref<ResponseObject[]>([]);
|
||||
const groupName = ref<string>("");
|
||||
|
||||
const editStatus = ref<boolean>(false);
|
||||
|
||||
const editId = ref<string>("");
|
||||
const competencyTypeOp = ref<DataOption[]>([
|
||||
{
|
||||
id: "ID1",
|
||||
|
|
@ -42,11 +40,11 @@ const competencyTypeOp = ref<DataOption[]>([
|
|||
]);
|
||||
const columns = ref<QTableProps["columns"]>([
|
||||
{
|
||||
name: "groupName",
|
||||
name: "nameGroupKPI",
|
||||
align: "left",
|
||||
label: "รายการกลุ่มงาน",
|
||||
sortable: true,
|
||||
field: "groupName",
|
||||
field: "nameGroupKPI",
|
||||
headerStyle: "font-size: 14px",
|
||||
style: "font-size: 14px",
|
||||
sort: (a: string, b: string) =>
|
||||
|
|
@ -56,71 +54,81 @@ const columns = ref<QTableProps["columns"]>([
|
|||
|
||||
const $q = useQuasar();
|
||||
const mixin = useCounterMixin();
|
||||
const { dialogRemove, messageError, showLoader, hideLoader, success } = mixin;
|
||||
|
||||
const competencyType = ref<string>("ID1");
|
||||
const {
|
||||
dialogRemove,
|
||||
dialogConfirm,
|
||||
showLoader,
|
||||
hideLoader,
|
||||
messageError,
|
||||
success,
|
||||
} = mixin;
|
||||
const filterKeyword = ref<string>("");
|
||||
|
||||
const visibleColumns = ref<string[]>(["groupName"]);
|
||||
const visibleColumns = ref<string[]>(["nameGroupKPI"]);
|
||||
|
||||
/** ดึงข้อมูล */
|
||||
async function getData() {
|
||||
const data = [
|
||||
{
|
||||
id: "ID1",
|
||||
groupName: "กลุ่มงาน 1",
|
||||
},
|
||||
{
|
||||
id: "ID2",
|
||||
groupName: "กลุ่มงาน 2",
|
||||
},
|
||||
];
|
||||
rows.value = data;
|
||||
// showLoader();
|
||||
// await http
|
||||
// .get(config.API.orgPrefix)
|
||||
// .then(async (res) => {
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// messageError($q, err);
|
||||
// })
|
||||
// .finally(() => {
|
||||
// hideLoader();
|
||||
// });
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
async function editData(id: string) {
|
||||
console.log(id);
|
||||
// await http
|
||||
// .put(config.API.orgPrefixId(id), {
|
||||
// name: prefix.value,
|
||||
// })
|
||||
// .then(() => {
|
||||
// getData();
|
||||
// success($q, "บันทึกข้อมูลสำเร็จ");
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// messageError($q, err);
|
||||
// })
|
||||
// .finally(() => {
|
||||
// hideLoader();
|
||||
// });
|
||||
await http
|
||||
.put(config.API.kpiGroupById(id), {
|
||||
nameGroupKPI: groupName.value,
|
||||
})
|
||||
.then(() => {
|
||||
fetchData();
|
||||
success($q, "บันทึกข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
async function deleteData(id: string) {
|
||||
console.log(id);
|
||||
// await http
|
||||
// .delete(config.API.orgPrefixId(id))
|
||||
// .then(() => {
|
||||
// getData();
|
||||
// success($q, "ลบข้อมูลสำเร็จ");
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// messageError($q, err);
|
||||
// })
|
||||
// .finally(() => {
|
||||
// hideLoader();w
|
||||
// });
|
||||
await http
|
||||
.delete(config.API.kpiGroupById(id))
|
||||
.then(() => {
|
||||
fetchData();
|
||||
success($q, "ลบข้อมูลสำเร็จ");
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/** เปลี่ยนเป็นหน้าเพิ่มข้อมูล */
|
||||
|
|
@ -128,42 +136,38 @@ function onAdd() {
|
|||
modal.value = true;
|
||||
}
|
||||
|
||||
function close() {
|
||||
function closeDialog() {
|
||||
modal.value = false;
|
||||
editStatus.value = false;
|
||||
groupName.value = ''
|
||||
groupName.value = "";
|
||||
}
|
||||
|
||||
function onEdit(data: any) {
|
||||
modal.value = true;
|
||||
editStatus.value = true;
|
||||
groupName.value = data.groupName
|
||||
groupName.value = data.nameGroupKPI;
|
||||
editId.value = data.id;
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
console.log("save");
|
||||
close()
|
||||
async function onSubmit() {
|
||||
dialogConfirm(
|
||||
$q,
|
||||
async () => {
|
||||
editStatus.value ? editData(editId.value) : addData();
|
||||
closeDialog();
|
||||
},
|
||||
"ยืนยันการบันทึกข้อมูล",
|
||||
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
|
||||
);
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
getData();
|
||||
fetchData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<q-toolbar style="padding: 0">
|
||||
<!-- <q-select
|
||||
v-model="competencyType"
|
||||
outlined
|
||||
label="ประเภทสมรรถนะ"
|
||||
dense
|
||||
option-label="name"
|
||||
option-value="id"
|
||||
:options="competencyTypeOp"
|
||||
style="min-width: 200px"
|
||||
emit-value
|
||||
map-options
|
||||
/> -->
|
||||
<q-btn flat round color="primary" icon="add" @click="onAdd()">
|
||||
<q-tooltip> เพิ่มข้อมูล </q-tooltip>
|
||||
</q-btn>
|
||||
|
|
@ -210,15 +214,11 @@ onMounted(async () => {
|
|||
</template>
|
||||
<template v-slot:body="props">
|
||||
<q-tr :props="props" class="cursor-pointer">
|
||||
<q-td
|
||||
v-for="col in props.cols"
|
||||
:key="col.id"
|
||||
@click="onEdit(props.row)"
|
||||
>
|
||||
<q-td v-for="col in props.cols" :key="col.id">
|
||||
{{ col.value }}
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<!-- <q-btn
|
||||
<q-btn
|
||||
color="edit"
|
||||
flat
|
||||
dense
|
||||
|
|
@ -227,17 +227,10 @@ onMounted(async () => {
|
|||
size="12px"
|
||||
icon="edit"
|
||||
clickable
|
||||
@click.stop="
|
||||
() => {
|
||||
dialogStatus = 'edit';
|
||||
dialog = true;
|
||||
prefix = props.row.name;
|
||||
editId = props.row.id;
|
||||
}
|
||||
"
|
||||
@click="onEdit(props.row)"
|
||||
>
|
||||
<q-tooltip>แก้ไขข้อมูล</q-tooltip>
|
||||
</q-btn> -->
|
||||
</q-btn>
|
||||
<q-btn
|
||||
color="red"
|
||||
flat
|
||||
|
|
@ -261,9 +254,9 @@ onMounted(async () => {
|
|||
<q-dialog v-model="modal" persistent>
|
||||
<q-card flat bordered style="min-width: 50vh">
|
||||
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
||||
<Header
|
||||
<dialog-header
|
||||
:tittle="editStatus ? 'แก้ไขกลุ่มงาน' : 'เพิ่มกลุ่มงาน'"
|
||||
:close="close"
|
||||
:close="closeDialog"
|
||||
/>
|
||||
<q-separator />
|
||||
<q-card-section>
|
||||
|
|
|
|||
7
src/modules/14_KPI/interface/response/KpiGroup.ts
Normal file
7
src/modules/14_KPI/interface/response/KpiGroup.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
//ข้อมูล
|
||||
interface ResponseObject {
|
||||
nameGroupKPI: string,
|
||||
}
|
||||
|
||||
export type { ResponseObject };
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue