API User Popup สมรรถนะในหน้าฟอร์มแบบประเมิน & อัปโหลดไฟล์

This commit is contained in:
STW_TTTY\stwtt 2024-04-22 15:46:21 +07:00
parent 95ac852446
commit 035a93c9f0
5 changed files with 364 additions and 72 deletions

10
src/api/KPI/api.kpi.ts Normal file
View file

@ -0,0 +1,10 @@
import env from "@/api/index";
const KpiCapacity = `${env.API_URI}/kpi/capacity`;
const KpiFile = `${env.API_URI}/salary/file`;
export default {
KpiCapacity,
file:KpiFile,
};

View file

@ -10,6 +10,7 @@ import evaluate from "./api/evaluate/api.evaluate";
import support from "./api/support/api.support"; import support from "./api/support/api.support";
import org from "./api/org/api.org"; import org from "./api/org/api.org";
import scholarship from "./api/scholarship/api.scholarship"; import scholarship from "./api/scholarship/api.scholarship";
import kpi from "./api/KPI/api.kpi";
const API = { const API = {
...testtest, ...testtest,
@ -21,6 +22,7 @@ const API = {
...support, ...support,
...org, ...org,
...scholarship, ...scholarship,
...kpi,
}; };
export default { export default {

View file

@ -1,3 +1,237 @@
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useCounterMixin } from "@/stores/mixin";
import axios from "axios";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useRoute } from "vue-router";
const $q = useQuasar();
const route = useRoute();
const id = ref<string>(route.params.id ? route.params.id.toString() : "");
const {
dialogConfirm,
showLoader,
hideLoader,
success,
messageError,
dialogRemove,
} = useCounterMixin();
interface ArrayFileList {
id: string;
pathName: string;
fileName: string;
}
const documentFile = ref<any>(null);
const fileList = ref<ArrayFileList[]>([]);
async function getData() {
showLoader();
await http
.get(config.API.file + `/KPI/ไฟล์เอกสาร/${id.value}`)
.then((res) => {
fileList.value = res.data;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
async function uploadFileDoc(uploadUrl: string, file: any) {
const Data = new FormData();
Data.append("file", documentFile.value);
showLoader();
await axios
.put(uploadUrl, file, {
headers: {
"Content-Type": file.type,
},
})
.then((res) => {
success($q, "อัปโหลดไฟล์สำเร็จ");
getData();
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
documentFile.value = null;
});
}
async function clickUpload(file: any) {
const fileName = { fileName: file.name };
dialogConfirm(
$q,
async () => {
const selectedFile = file;
const formdata = new FormData();
formdata.append("file", selectedFile);
await http
.post(config.API.file + `/KPI/ไฟล์เอกสาร/${id.value}`, {
replace: false,
fileList: fileName,
})
.then(async (res) => {
const foundKey: string | undefined = Object.keys(res.data).find(
(key) =>
res.data[key]?.fileName !== undefined &&
res.data[key]?.fileName !== ""
);
foundKey &&
uploadFileDoc(res.data[foundKey]?.uploadUrl, documentFile.value);
})
.catch((err) => {
messageError($q, err);
});
},
"ยืนยันการอัปโหลดไฟล์",
"ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่ ?"
);
}
/**
* ดาวนโหลดลงคไฟล
* @param fileName file name
*/
function downloadFile(fileName: string) {
showLoader();
http
.get(config.API.file + `/KPI/ไฟล์เอกสาร/${id.value}/${fileName}`)
.then((res) => {
const data = res.data.downloadUrl;
window.open(data, "_blank");
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
});
}
/**
* ลบไฟล
* @param fileName file name
*/
function deleteFile(fileName: string) {
dialogRemove($q, async () => {
showLoader();
http
.delete(config.API.file + `/KPI/ไฟล์เอกสาร/${id.value}/${fileName}`)
.then((res) => {
success($q, `ลบไฟล์สำเร็จ`);
setTimeout(() => {
getData();
hideLoader();
}, 1000);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
}
onMounted(() => {
getData();
});
</script>
<template> <template>
<div class="q-pa-md">4</div> <div class="q-pa-md">
<q-card bordered class="row col-12" style="border: 1px solid #d6dee1">
<div class="col-12 text-weight-medium bg-grey-1 q-py-sm q-px-md">
ปโหลดไฟลเอกสารหลกฐาน
</div>
<div class="col-12"><q-separator /></div>
<div class="row col-12 q-col-gutter-y-sm q-pa-sm">
<div class="col-12 row">
<q-file
for="inputFiles"
class="col-12"
outlined
dense
v-model="documentFile"
label="ไฟล์เอกสารหลักฐาน"
hide-bottom-space
accept=".pdf,.xlsx,.docx,.png,.jpg"
clearable
>
<template v-slot:prepend>
<q-icon name="attach_file" color="primary" />
</template>
<template v-slot:after>
<q-btn
size="14px"
v-if="documentFile"
flat
round
dense
color="add"
icon="mdi-upload"
@click="clickUpload(documentFile)"
><q-tooltip>ปโหลดไฟล</q-tooltip></q-btn
>
</template>
</q-file>
<!-- <div class="col-1 self-center" v-if="formData.documentFile"></div> -->
</div>
<div v-if="fileList.length > 0" class="col-xs-12 row">
<q-list class="full-width rounded-borders" bordered separator>
<q-item
clickable
v-ripple
v-for="data in fileList"
:key="data.id"
class="items-center"
>
<q-item-section>{{ data.fileName }}</q-item-section>
<q-space />
<div>
<q-btn
size="12px"
flat
round
dense
color="blue"
icon="mdi-download"
@click="downloadFile(data.fileName)"
><q-tooltip>ดาวนโหลดไฟล</q-tooltip></q-btn
>
<q-btn
size="12px"
flat
round
dense
color="red"
class="q-ml-sm"
icon="mdi-delete-outline"
@click="deleteFile(data.fileName)"
><q-tooltip>ลบไฟล</q-tooltip></q-btn
>
</div>
</q-item>
</q-list>
</div>
<div class="col-12" v-else>
<q-card class="q-pa-md" bordered> ไมรายการเอกสาร </q-card>
</div>
</div>
</q-card>
</div>
</template> </template>

View file

@ -1,9 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive } from "vue"; import { ref, reactive, onMounted, watch } from "vue";
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
import type { DataOptions } from "@/modules/08_KPI/interface/index/Main"; import type { DataOptions } from "@/modules/08_KPI/interface/index/Main";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
const { showLoader, hideLoader } = useCounterMixin();
const modal = defineModel<boolean>("modal", { required: true }); const modal = defineModel<boolean>("modal", { required: true });
const competencyType = defineModel<string>("competencyType", {
required: true,
});
const numpage = defineModel<number>("numpage", { required: true }); const numpage = defineModel<number>("numpage", { required: true });
const splitterModel = ref<number>(30); const splitterModel = ref<number>(30);
const search = ref<string>(""); const search = ref<string>("");
@ -13,18 +21,8 @@ const formula = ref<string>("");
const type = ref<string>(""); const type = ref<string>("");
const listCheck = ref<number | null>(); const listCheck = ref<number | null>();
const listTarget = ref<any>([ const listTarget = ref<any>([]);
{ const listTargetMain = ref<any>([]);
id: "ID1",
metricCode: "1กก",
indicatorName: "ตัวชี้วัด 1",
},
{
id: "ID2",
metricCode: "2กก",
indicatorName: "ตัวชี้วัด 2",
},
]);
const formDetail = reactive<any>({ const formDetail = reactive<any>({
type: "สมรรถนะหลัก", type: "สมรรถนะหลัก",
@ -33,11 +31,11 @@ const formDetail = reactive<any>({
criteria: "", criteria: "",
}); });
const formScore = reactive<any>({ const formScore = reactive<any>({
score1: "1", score1: "",
score2: "2", score2: "",
score3: "3", score3: "",
score4: "", score4: "",
score5: "5", score5: "",
}); });
const fieldDetailLabels = { const fieldDetailLabels = {
@ -57,48 +55,56 @@ const fieldLabels = {
const competencyTypeOp = ref<DataOptions[]>([ const competencyTypeOp = ref<DataOptions[]>([
{ {
id: "ID1", id: "HEAD",
name: "สมรรถนะหลัก", name: "สมรรถนะหลัก",
}, },
{ {
id: "ID2", id: "GROUP",
name: "สมรรถนะประจำกลุ่มงาน", name: "สมรรถนะประจำกลุ่มงาน",
}, },
{ {
id: "ID3", id: "EXECUTIVE",
name: "สมรรถนะประจำกลุ่มงาน",
},
{
id: "ID4",
name: "สมรรถนะประจำผู้บริหารกรุงเทพมหานคร", name: "สมรรถนะประจำผู้บริหารกรุงเทพมหานคร",
}, },
{ {
id: "ID5", id: "DIRECTOR",
name: "สมรรถนะเฉพาะสำหรับตำแหน่ง ผอ.เขต ผช.ผอ.เขต และหัวหน้าฝ่ายในสังกัด สนง.เขต", name: "สมรรถนะเฉพาะสำหรับตำแหน่ง ผอ.เขต ผช.ผอ.เขต และหัวหน้าฝ่ายในสังกัด สนง.เขต",
}, },
{ {
id: "ID6", id: "INSPECTOR",
name: "สมรรถนะเฉพาะสำหรับตำแหน่งผู้ตรวจราชการ กทม. และผู้ตรวจราชการ", name: "สมรรถนะเฉพาะสำหรับตำแหน่งผู้ตรวจราชการ กทม. และผู้ตรวจราชการ",
}, },
]); ]);
function clickList(index: number, data: any) { function clickList(index: number, data: any) {
listCheck.value = index; listCheck.value = index;
// dataList.value = data.map((i: any) => ({
// commandNo: i.commandNo, // formDetail.type = ???
// duty: i.duty, // formDetail.name = ???
// prefix: i.prefix, // formDetail.definition = ???
// firstName: i.firstName, // formDetail.criteria = ???
// lastName: i.lastName, formScore.score1 = data.capacityDetails[0].description;
// fullName:`${i.prefix}${i.firstName} ${i.lastName}` formScore.score2 = data.capacityDetails[1].description;
// })); formScore.score3 = data.capacityDetails[2].description;
formScore.score4 = data.capacityDetails[3].description;
formScore.score5 = data.capacityDetails[4].description;
} }
/** ปิด dialog */ /** ปิด dialog */
function closeDialog() { function closeDialog() {
modal.value = false; modal.value = false;
type.value = '' type.value = "";
search.value = '' search.value = "";
listCheck.value = null;
formScore.score1 = "";
formScore.score2 = "";
formScore.score3 = "";
formScore.score4 = "";
formScore.score5 = "";
formDetail.type = "";
formDetail.name = "";
formDetail.definition = "";
formDetail.criteria = "";
} }
/** เรียกใช้ class */ /** เรียกใช้ class */
@ -107,6 +113,43 @@ function getclass() {
} }
function onSubmit() {} function onSubmit() {}
function getData() {
showLoader();
http
.get(config.API.KpiCapacity + `?type=${type.value}`)
.then((res) => {
const data = res.data.result.data;
console.log(data);
listTarget.value = data;
listTargetMain.value = data;
formScore.score1 = data.capacityDetails[0].description;
formScore.score2 = data.capacityDetails[1].description;
formScore.score3 = data.capacityDetails[2].description;
formScore.score4 = data.capacityDetails[3].description;
formScore.score5 = data.capacityDetails[4].description;
})
.finally(() => {
hideLoader();
});
}
function filterTxt(val: any) {
console.log(val);
listTarget.value = listTargetMain.value.filter(
(v: any) => v.name.indexOf(val) > -1
);
console.log(listTarget.value.length);
}
watch(
() => modal.value,
() => {
if (modal.value == true) {
type.value = competencyType.value;
getData();
}
}
);
</script> </script>
<template> <template>
<q-dialog v-model="modal" persistent> <q-dialog v-model="modal" persistent>
@ -117,14 +160,17 @@ function onSubmit() {}
<q-card-section class="q-pa-none scroll" style="max-height: 80vh"> <q-card-section class="q-pa-none scroll" style="max-height: 80vh">
<div class="col-12 row"> <div class="col-12 row">
<div class="bg-grey-1 q-pa-md col-xs-12 col-sm-4 col-md-3 row lineRight"> <div
class="bg-grey-1 q-pa-md col-xs-12 col-sm-4 col-md-3 row lineRight"
>
<div class="col-12 q-col-gutter-sm fit"> <div class="col-12 q-col-gutter-sm fit">
<div class="col-12 "> <div class="col-12">
<q-select <q-select
v-model="type" v-model="type"
outlined outlined
label="ประเภทสมรรถนะ" label="ประเภทสมรรถนะ"
dense dense
readonly
bg-color="white" bg-color="white"
option-label="name" option-label="name"
option-value="id" option-value="id"
@ -134,7 +180,7 @@ function onSubmit() {}
map-options map-options
/> />
</div> </div>
<div class="col-12 "> <div class="col-12">
<q-input <q-input
v-model="search" v-model="search"
outlined outlined
@ -142,6 +188,7 @@ function onSubmit() {}
label="ค้นหา" label="ค้นหา"
bg-color="white" bg-color="white"
:class="getclass()" :class="getclass()"
@update:model-value="filterTxt"
> >
<template v-slot:append> <template v-slot:append>
<q-icon v-if="search == ''" name="search" /> <q-icon v-if="search == ''" name="search" />
@ -149,28 +196,23 @@ function onSubmit() {}
v-if="search !== ''" v-if="search !== ''"
name="clear" name="clear"
class="cursor-pointer" class="cursor-pointer"
@click="search = ''" @click="(search = ''), (listTarget = listTargetMain)"
/> />
</template> </template>
</q-input> </q-input>
</div> </div>
<div class="col-12 "> <div class="col-12">
<q-card bordered flat class="no-shadow bg-white col-12"> <q-card bordered flat class="no-shadow bg-white col-12">
<div class="row q-px-md q-py-sm items-center bg-grey-1"> <div class="row q-px-md q-py-sm items-center bg-grey-1">
<div class="col-4"> <div class="col-12">
<span>รหสตวช</span> <span>อสมรรถนะ</span>
</div>
<div class="col-4">
<span>อตวช</span>
</div> </div>
</div> </div>
<q-separator /> <q-separator />
<q-card-section class="q-pa-none"> <q-card-section class="q-pa-none">
<q-list <div v-if="listTarget.length > 0">
separator <q-list separator dense>
dense
>
<q-item <q-item
v-for="(item, index) in listTarget" v-for="(item, index) in listTarget"
:key="index" :key="index"
@ -178,20 +220,25 @@ function onSubmit() {}
v-ripple v-ripple
:active="listCheck === index" :active="listCheck === index"
active-class="my-menu-link" active-class="my-menu-link"
@click="clickList(index, item.id)" @click="clickList(index, item)"
> >
<q-item-section class="q-pa-none"> <q-item-section class="q-pa-none">
<div class="row items-center" style="height: 20px"> <div
<div class="col-4"> class="row items-center"
<span>{{ item.metricCode }}</span> style="height: 20px"
</div> >
<div class="col-4"> <div class="col-12">
<span>{{ item.indicatorName }}</span> <span>{{ item.name }}</span>
</div> </div>
</div> </div>
</q-item-section> </q-item-section>
</q-item> </q-item>
</q-list> </q-list>
</div>
<div v-else class="q-pa-md">
<span>ไมพบขอม</span>
</div>
</q-card-section> </q-card-section>
</q-card> </q-card>
</div> </div>
@ -228,7 +275,7 @@ function onSubmit() {}
</div> </div>
</q-card> </q-card>
</div> </div>
<div class="col-4 row "> <div class="col-4 row">
<q-card bordered class="col-12 row no-shadow"> <q-card bordered class="col-12 row no-shadow">
<div class="bg-grey-2 row q-py-sm text-weight-bold col-12"> <div class="bg-grey-2 row q-py-sm text-weight-bold col-12">
<div class="col-6 text-center">ระดบคะแนน</div> <div class="col-6 text-center">ระดบคะแนน</div>
@ -240,9 +287,7 @@ function onSubmit() {}
class="col-12" class="col-12"
> >
<div class="row col-12 q-py-sm"> <div class="row col-12 q-py-sm">
<div <div class="col-6 text-center text-body2">
class="col-6 text-center text-body2"
>
{{ fieldLabels[field as keyof typeof fieldLabels] }} {{ fieldLabels[field as keyof typeof fieldLabels] }}
</div> </div>
<div class="col-6 text-center"> <div class="col-6 text-center">
@ -281,17 +326,17 @@ function onSubmit() {}
background: #ebf9f7 !important; background: #ebf9f7 !important;
color: #1bb19ab8 !important; color: #1bb19ab8 !important;
} }
.no-shadow{ .no-shadow {
box-shadow:none !important; box-shadow: none !important;
} }
.lineRight{ .lineRight {
border-right: 1px solid #EDEDED !important; border-right: 1px solid #ededed !important;
} }
.lineTop{ .lineTop {
border-top: 1px solid #EDEDED !important; border-top: 1px solid #ededed !important;
} }
.card-box{ .card-box {
border: 1px solid #EDEDED !important; border: 1px solid #ededed !important;
border-radius: 8px; border-radius: 8px;
} }
</style> </style>

View file

@ -15,6 +15,7 @@ const filterKeyword = ref<string>("");
const modal = ref<boolean>(false); const modal = ref<boolean>(false);
const modalAssigned = ref<boolean>(false); const modalAssigned = ref<boolean>(false);
const competencyType = ref<string>('HEAD')
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"capacity", "capacity",
"level", "level",
@ -142,7 +143,7 @@ function onAdd() {
</q-card-section> </q-card-section>
</q-card> </q-card>
<Dialog v-model:modal="modal" :numpage="numpage"/> <Dialog v-model:modal="modal" :numpage="numpage" v-model:competency-type="competencyType"/>
</template> </template>
<style scoped> <style scoped>
.custom-table2 { .custom-table2 {