355 lines
9.5 KiB
Vue
355 lines
9.5 KiB
Vue
<script setup lang="ts">
|
|
import { ref, reactive, onMounted } from "vue";
|
|
import { useRoute } from "vue-router";
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
import axios from "axios";
|
|
import type { QTableProps } from "quasar";
|
|
import { useQuasar } from "quasar";
|
|
const mixin = useCounterMixin();
|
|
const route = useRoute();
|
|
const $q = useQuasar();
|
|
const id = ref<string>(route.params.id ? route.params.id.toString() : "");
|
|
const {
|
|
success,
|
|
messageError,
|
|
showLoader,
|
|
hideLoader,
|
|
dialogConfirm,
|
|
dialogRemove,
|
|
date2Thai,
|
|
} = mixin;
|
|
const columns = ref<QTableProps["columns"]>([
|
|
{
|
|
name: "idcard",
|
|
align: "left",
|
|
label: "เลขประจำตัวประชาชน",
|
|
sortable: true,
|
|
field: "idcard",
|
|
headerStyle: "font-size: 14px; width: 50px;",
|
|
style: "font-size: 14px",
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
{
|
|
name: "fullName",
|
|
align: "left",
|
|
label: "ชื่อ - นามสกุล",
|
|
sortable: true,
|
|
field: "FullName",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
{
|
|
name: "position",
|
|
align: "left",
|
|
label: "ตำแหน่ง",
|
|
sortable: true,
|
|
field: "position",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
{
|
|
name: "posTypeName",
|
|
align: "left",
|
|
label: "ประเภทตำแหน่ง",
|
|
sortable: true,
|
|
field: "posTypeName",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
{
|
|
name: "posLevelName",
|
|
align: "left",
|
|
label: "ระดับตำแหน่ง",
|
|
sortable: true,
|
|
field: "posLevelName",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
{
|
|
name: "posExecutive",
|
|
align: "left",
|
|
label: "ตำแหน่งทางการบริหาร",
|
|
sortable: true,
|
|
field: "posExecutive",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
{
|
|
name: "org",
|
|
align: "left",
|
|
label: "หน่วยงานที่สังกัด",
|
|
sortable: true,
|
|
field: "org",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
{
|
|
name: "refCommandNo",
|
|
align: "left",
|
|
label: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ",
|
|
sortable: true,
|
|
field: "refCommandNo",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
{
|
|
name: "refCommandDate",
|
|
align: "left",
|
|
label: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่",
|
|
sortable: true,
|
|
field: "refCommandDate",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
format: (v) => date2Thai(v),
|
|
sort: (a: string, b: string) =>
|
|
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
|
|
},
|
|
]);
|
|
|
|
const fileList = ref<File[]>([]);
|
|
const visibleColumns = ref<string[]>([
|
|
"idcard",
|
|
"fullName",
|
|
"position",
|
|
"posTypeName",
|
|
"posLevelName",
|
|
"posExecutive",
|
|
"org",
|
|
"refCommandNo",
|
|
"refCommandDate",
|
|
]);
|
|
const files = ref<any>([]);
|
|
const pagination = ref({
|
|
page: 1,
|
|
rowsPerPage: 10,
|
|
});
|
|
const keyword = ref<string>("");
|
|
const row = [
|
|
{
|
|
idcard: "1234567890121",
|
|
prefix: "นาง",
|
|
firstName: "ณัฐนิชา",
|
|
lastName: "เป็งกำปอง",
|
|
position: "นักวิชาการสถิติ",
|
|
posTypeName: "วิชาการ",
|
|
posLevelName: "ชำนาญการ",
|
|
posExecutive: "นักบริหาร",
|
|
org: "สาขาสถิติ",
|
|
refCommandNo: "25/2566",
|
|
refCommandDate: new Date(),
|
|
},
|
|
{
|
|
idcard: "2222222222222",
|
|
prefix: "นาย",
|
|
firstName: "สมศักดิ์",
|
|
lastName: "กำแหง",
|
|
position: "นักการไฟฟ้า",
|
|
posTypeName: "วิชาการ",
|
|
posLevelName: "สูง",
|
|
posExecutive: "นักการช่าง",
|
|
org: "อิเล็กทรอนิกส์",
|
|
refCommandNo: "12/2565",
|
|
refCommandDate: new Date(),
|
|
},
|
|
];
|
|
|
|
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("พัฒนาบุคลาการ", "บันทึกผล", 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, files.value);
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
});
|
|
},
|
|
"ยืนยันการอัปโหลดไฟล์",
|
|
"ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่ ?"
|
|
);
|
|
}
|
|
|
|
async function getData() {
|
|
showLoader();
|
|
await http
|
|
.get(config.API.file("พัฒนาบุคลาการ", "บันทึกผล", 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", files.value);
|
|
showLoader();
|
|
await axios
|
|
.put(uploadUrl, file, {
|
|
headers: {
|
|
"Content-Type": file.type,
|
|
},
|
|
})
|
|
.then((res) => {
|
|
success($q, "อัปโหลดไฟล์สำเร็จ");
|
|
getData();
|
|
})
|
|
.catch((e) => {
|
|
messageError($q, e);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
files.value = null;
|
|
});
|
|
}
|
|
|
|
onMounted(() => {
|
|
// getData();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<q-toolbar style="padding: 0px" class="text-primary q-mb-xs">
|
|
<q-file
|
|
v-model="files"
|
|
dense
|
|
label="อัปโหลดไฟล์"
|
|
outlined
|
|
accept=".xlsx"
|
|
hide-bottom-space
|
|
clearable
|
|
class="col-xs-12 col-sm-4"
|
|
>
|
|
<template v-slot:prepend>
|
|
<q-icon name="attach_file" color="blue" />
|
|
</template>
|
|
</q-file>
|
|
<q-btn
|
|
v-if="files"
|
|
size="md"
|
|
icon="mdi-upload"
|
|
round
|
|
flat
|
|
color="blue"
|
|
@click="clickUpload(files)"
|
|
>
|
|
<q-tooltip>อัปโหลดไฟล์</q-tooltip>
|
|
</q-btn>
|
|
<q-space />
|
|
<q-input dense outlined v-model="keyword" label="ค้นหา" class="q-mr-sm">
|
|
<template v-slot:append>
|
|
<q-icon name="search" />
|
|
</template>
|
|
</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"
|
|
class="q-mr-sm"
|
|
/>
|
|
</q-toolbar>
|
|
<d-table
|
|
ref="table"
|
|
row-key="id"
|
|
flat
|
|
bordered
|
|
dense
|
|
:columns="columns"
|
|
:rows="row"
|
|
:paging="true"
|
|
:filter="keyword"
|
|
v-model:pagination="pagination"
|
|
:rows-per-page-options="[20, 50, 100]"
|
|
: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">
|
|
<div v-if="col.name === 'fullName'">
|
|
{{
|
|
props.row.prefix +
|
|
" " +
|
|
props.row.firstName +
|
|
" " +
|
|
props.row.lastName
|
|
}}
|
|
</div>
|
|
<div v-else>{{ col.value ? col.value : "-" }}</div>
|
|
</q-td>
|
|
<q-td auto-width>
|
|
<q-btn
|
|
color="primary"
|
|
flat
|
|
dense
|
|
round
|
|
class="q-mr-xs"
|
|
size="14px"
|
|
icon="mdi-pencil-outline"
|
|
clickable
|
|
>
|
|
<q-tooltip>แก้ไขข้อมูล</q-tooltip>
|
|
</q-btn>
|
|
<q-btn color="info" flat dense round size="14px" icon="mdi-history">
|
|
<q-tooltip>ประวัติบันทึกผล</q-tooltip>
|
|
</q-btn>
|
|
</q-td>
|
|
</q-tr>
|
|
</template>
|
|
</d-table>
|
|
</template>
|
|
|
|
<style scoped></style>
|