676 lines
22 KiB
Vue
676 lines
22 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted, reactive, watch } from "vue";
|
|
import { useQuasar, type QTableProps } from "quasar";
|
|
import { useRouter } from "vue-router";
|
|
import genReportXLSX from "@/plugins/genreportxlsx";
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
|
|
import DialogHeader from "@/components/DialogHeader.vue";
|
|
|
|
/**importType*/
|
|
import type {
|
|
DataOption,
|
|
NewPagination,
|
|
} from "@/modules/15_development/interface/index/Main";
|
|
import type {
|
|
FormQueryListProject,
|
|
FormProject,
|
|
} from "@/modules/15_development/interface/request/Main";
|
|
import type {
|
|
ResListProject,
|
|
DataTree,
|
|
} from "@/modules/15_development/interface/response/Main";
|
|
|
|
/** importStore*/
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
/** use*/
|
|
const $q = useQuasar();
|
|
const router = useRouter();
|
|
const { showLoader, hideLoader, messageError, dialogMessageNotify } =
|
|
useCounterMixin();
|
|
|
|
const node = ref<any>([]);
|
|
const expanded = ref<string[]>([]);
|
|
const filter = ref<string>("");
|
|
const filterMain = ref<string>("");
|
|
const splitterModel = ref<number>(60);
|
|
const modal = ref<boolean>(false);
|
|
const projectName = ref<string>("");
|
|
const orgName = ref<string>("");
|
|
const year = ref<number>(0);
|
|
/** หัวตาราง */
|
|
const rows = ref<ResListProject[]>([]); // ข้อมูลรายการ
|
|
const columns = ref<QTableProps["columns"]>([
|
|
{
|
|
name: "year",
|
|
align: "left",
|
|
label: "ปีงบประมาณ ",
|
|
sortable: true,
|
|
field: "year",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px ; width:10%",
|
|
format: (val) => val + 543,
|
|
},
|
|
{
|
|
name: "projectName",
|
|
align: "left",
|
|
label: "ชื่อโครงการ/กิจกรรม/หลักสูตร",
|
|
sortable: true,
|
|
field: "projectName",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px;width:45% ",
|
|
},
|
|
|
|
{
|
|
name: "org",
|
|
align: "left",
|
|
label: "หน่วยงานที่รับผิดชอบ",
|
|
sortable: true,
|
|
field: "org",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px ; width:45% ",
|
|
},
|
|
]);
|
|
const visibleColumns = ref<string[]>(["year", "projectName", "org"]);
|
|
|
|
const statusOpt = ref<DataOption[]>([
|
|
{ id: "ONGOING", name: "กำลังดำเนินการ" },
|
|
{ id: "FINISH", name: "เสร็จสิ้นโครงการ" },
|
|
]);
|
|
|
|
const formProject = reactive<FormProject>({
|
|
year: null,
|
|
projectName: "",
|
|
node: null,
|
|
nodeId: null,
|
|
orgRevisionId: null,
|
|
});
|
|
/** formQuery*/
|
|
const formQuery = reactive<FormQueryListProject>({
|
|
year: new Date().getFullYear(),
|
|
page: 1,
|
|
pageSize: 10,
|
|
org: "1",
|
|
keyword: "",
|
|
status: "ONGOING",
|
|
node: null,
|
|
nodeId: null,
|
|
});
|
|
const totalList = ref<number>(1); //จำนวนข้อมูลรายการ
|
|
|
|
/** funciton fetch รายการโครงการ*/
|
|
function fetchListProject() {
|
|
showLoader();
|
|
http
|
|
.get(
|
|
config.API.developmentMain +
|
|
`?page=${formQuery.page}&pageSize=${formQuery.pageSize}&keyword=${formQuery.keyword}&year=${formQuery.year}&status=${formQuery.status}&node=${formQuery.node}&nodeId=${formQuery.nodeId}`
|
|
)
|
|
.then((res) => {
|
|
const data = res.data.result.data;
|
|
totalList.value = Math.ceil(res.data.result.total / formQuery.pageSize);
|
|
rows.value = data;
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* funciotn redirect to page เพิ่มหริอแก้ไข รายการโครงการ
|
|
* @param status สถานะแก่ไข
|
|
* @param id รายการโครงการ
|
|
*/
|
|
function onClickAddOrView(status: boolean = false, id: string = "") {
|
|
status ? router.push(`/development/${id}`) : router.push("/development/add");
|
|
}
|
|
|
|
/** function เปิด Dialog เพิ่มโครงการ/หลักสูตรการฝึกอบรม*/
|
|
function onAdd() {
|
|
modal.value = true;
|
|
}
|
|
|
|
/** function fetchข้อมูลหน้าแรกใหม่*/
|
|
function fetchListProjectNew() {
|
|
formQuery.page = 1;
|
|
fetchListProject();
|
|
}
|
|
|
|
/** function Download รายการโครงการ*/
|
|
function onDownload() {
|
|
showLoader();
|
|
http
|
|
.get(config.API.developmentReportMain())
|
|
.then((res) => {
|
|
const dataList = res.data.result;
|
|
genReportXLSX(
|
|
dataList,
|
|
"รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด"
|
|
);
|
|
})
|
|
.catch((e) => {
|
|
messageError($q, e);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/** function ปิด Dialog เพิ่มโครงการ/หลักสูตรการฝึกอบรม*/
|
|
function closeDialog() {
|
|
modal.value = false;
|
|
year.value = 0;
|
|
orgName.value = "";
|
|
projectName.value = "";
|
|
}
|
|
|
|
/** dialog submit */
|
|
function onSubmit() {
|
|
if (formProject.nodeId) {
|
|
http
|
|
.post(config.API.developmentMain, formProject)
|
|
.then((res) => {
|
|
closeDialog();
|
|
router.push(`/development/${res.data.result}`);
|
|
})
|
|
.catch((e) => {
|
|
messageError($q, e);
|
|
})
|
|
.finally(() => {});
|
|
} else {
|
|
dialogMessageNotify($q, "กรุณาเลือกหน่วยงานที่รับผิดชอบ");
|
|
}
|
|
}
|
|
|
|
/** function fetch หา Id หน่วยงานที่ Active*/
|
|
function fetchActive() {
|
|
showLoader();
|
|
http
|
|
.get(config.API.activeOrganization)
|
|
.then((res) => {
|
|
const data = res.data.result;
|
|
fetchTree(data.activeId);
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* function fetch โครงสร้างปจุบัน
|
|
* @param id โครงสร้างปจุบัน
|
|
*/
|
|
function fetchTree(id: string) {
|
|
showLoader();
|
|
http
|
|
.get(config.API.orgByid(id.toString()))
|
|
.then((res) => {
|
|
const data = res.data.result;
|
|
node.value = data;
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/** function เลือกหน่วยงานที่รับผิดชอบ*/
|
|
function updateSelected(data: DataTree) {
|
|
formProject.node = data.orgLevel;
|
|
formProject.nodeId = data.orgTreeId;
|
|
formProject.orgRevisionId = data.orgRevisionId;
|
|
}
|
|
|
|
/** function เลือกหน่วยงานที่จะค้นหาโครงการ */
|
|
function updateSelectedTreeMain(data: DataTree) {
|
|
if (formQuery.node === data.orgLevel && formQuery.nodeId === data.orgTreeId) {
|
|
formQuery.node = null;
|
|
formQuery.nodeId = null;
|
|
} else {
|
|
formQuery.node = data.orgLevel;
|
|
formQuery.nodeId = data.orgTreeId;
|
|
}
|
|
fetchListProjectNew(); // fetch โครงการ
|
|
}
|
|
|
|
/**
|
|
* function updatePagination
|
|
* @param newPagination ข้อมูล Pagination ใหม่
|
|
*/
|
|
function updatePagination(newPagination: NewPagination) {
|
|
formQuery.page = 1;
|
|
formQuery.pageSize = newPagination.rowsPerPage;
|
|
}
|
|
|
|
/** callbackFunction ทำเมื่อมีการอัปเดท pageSize*/
|
|
watch(
|
|
() => formQuery.pageSize,
|
|
() => {
|
|
fetchListProject();
|
|
}
|
|
);
|
|
|
|
onMounted(() => {
|
|
fetchActive();
|
|
fetchListProject();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="toptitle text-dark col-12 row items-center">
|
|
รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด
|
|
</div>
|
|
<q-card bordered class="col-12 row caedNone">
|
|
<div class="col-xs-12 col-sm-3 row">
|
|
<div class="col-12 row no-wrap">
|
|
<div class="col-12 q-py-sm q-px-sm">
|
|
<div class="q-gutter-sm">
|
|
<q-input dense outlined v-model="filterMain" label="ค้นหา">
|
|
<template v-slot:append>
|
|
<q-icon
|
|
v-if="filterMain !== ''"
|
|
name="clear"
|
|
class="cursor-pointer"
|
|
@click="filterMain = ''"
|
|
/>
|
|
<q-icon v-else name="search" color="grey-5" />
|
|
</template>
|
|
</q-input>
|
|
|
|
<q-tree
|
|
class="tree-container"
|
|
dense
|
|
:nodes="node"
|
|
node-key="orgTreeName"
|
|
label-key="labelName"
|
|
v-model:expanded="expanded"
|
|
:filter="filterMain"
|
|
no-results-label="ไม่พบข้อมูลที่ค้นหา"
|
|
no-nodes-label="ไม่มีข้อมูล"
|
|
v-model:selected="formQuery.nodeId"
|
|
>
|
|
<template v-slot:default-header="prop">
|
|
<q-item
|
|
clickable
|
|
@click.stop="updateSelectedTreeMain(prop.node)"
|
|
:active="formQuery.nodeId === prop.node.orgTreeId"
|
|
active-class="my-list-link text-primary text-weight-medium"
|
|
class="row col-12 items-center text-dark q-py-xs q-pl-sm rounded-borders my-list"
|
|
>
|
|
<div>
|
|
<div class="text-weight-medium">
|
|
{{ prop.node.orgTreeName }}
|
|
</div>
|
|
<div class="text-weight-light text-grey-8">
|
|
{{ prop.node.orgCode == null ? null : prop.node.orgCode }}
|
|
{{
|
|
prop.node.orgTreeShortName == null
|
|
? null
|
|
: prop.node.orgTreeShortName
|
|
}}
|
|
</div>
|
|
</div>
|
|
</q-item>
|
|
</template>
|
|
</q-tree>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 row">
|
|
<q-separator :vertical="!$q.screen.lt.md" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-xs-12 col-sm-9 q-pa-md row">
|
|
<div class="col-12">
|
|
<q-toolbar style="padding: 0">
|
|
<div class="row q-gutter-sm">
|
|
<datepicker
|
|
menu-class-name="modalfix"
|
|
v-model="formQuery.year"
|
|
:locale="'th'"
|
|
autoApply
|
|
year-picker
|
|
:enableTimePicker="false"
|
|
style="width: 150px"
|
|
@update:model-value="fetchListProjectNew"
|
|
>
|
|
<template #year="{ year }">{{ year + 543 }}</template>
|
|
<template #year-overlay-value="{ value }">{{
|
|
parseInt(value + 543)
|
|
}}</template>
|
|
<template #trigger>
|
|
<q-input
|
|
dense
|
|
lazy-rules
|
|
outlined
|
|
:model-value="
|
|
formQuery.year === 0
|
|
? 'ทั้งหมด'
|
|
: Number(formQuery.year) + 543
|
|
"
|
|
:label="`${'ปีงบประมาณ'}`"
|
|
>
|
|
<template v-if="formQuery.year" v-slot:append>
|
|
<q-icon
|
|
name="cancel"
|
|
@click.stop.prevent="
|
|
(formQuery.year = 0), fetchListProjectNew()
|
|
"
|
|
class="cursor-pointer"
|
|
/>
|
|
</template>
|
|
<template v-slot:prepend>
|
|
<q-icon
|
|
name="event"
|
|
class="cursor-pointer"
|
|
style="color: var(--q-primary)"
|
|
>
|
|
</q-icon>
|
|
</template>
|
|
</q-input>
|
|
</template>
|
|
</datepicker>
|
|
<q-select
|
|
dense
|
|
outlined
|
|
v-model="formQuery.status"
|
|
:options="statusOpt"
|
|
label="สถานะโครงการ"
|
|
option-label="name"
|
|
option-value="id"
|
|
emit-value
|
|
map-options
|
|
@update:model-value="fetchListProjectNew"
|
|
/>
|
|
<q-toolbar-title>
|
|
<q-btn
|
|
flat
|
|
round
|
|
dense
|
|
icon="add"
|
|
color="primary"
|
|
@click="onAdd()"
|
|
>
|
|
<q-tooltip>เพิ่ม</q-tooltip>
|
|
</q-btn>
|
|
</q-toolbar-title>
|
|
</div>
|
|
<q-space />
|
|
<div class="row q-gutter-sm">
|
|
<div>
|
|
<q-btn
|
|
flat
|
|
round
|
|
dense
|
|
icon="mdi-arrow-down-bold-circle-outline"
|
|
color="blue"
|
|
@click="onDownload"
|
|
>
|
|
<q-tooltip>ดาวน์โหลด</q-tooltip>
|
|
</q-btn>
|
|
</div>
|
|
<div>
|
|
<q-input
|
|
standout
|
|
dense
|
|
v-model="formQuery.keyword"
|
|
ref="filterRef"
|
|
outlined
|
|
placeholder="ค้นหา"
|
|
@keyup.enter="fetchListProjectNew"
|
|
>
|
|
<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 = ''),
|
|
fetchListProject(),
|
|
(formQuery.page = 1)
|
|
"
|
|
/>
|
|
</template>
|
|
</q-input>
|
|
</div>
|
|
<div>
|
|
<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>
|
|
</div>
|
|
</q-toolbar>
|
|
|
|
<div class="col-12">
|
|
<d-table
|
|
for="table"
|
|
ref="table"
|
|
:columns="columns"
|
|
:rows="rows"
|
|
row-key="id"
|
|
flat
|
|
bordered
|
|
dense
|
|
class="custom-header-table"
|
|
:rows-per-page-options="[10, 25, 50, 100]"
|
|
:visible-columns="visibleColumns"
|
|
@update:pagination="updatePagination"
|
|
>
|
|
<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-tr>
|
|
</template>
|
|
<template v-slot:body="props">
|
|
<q-tr :props="props" class="cursor-pointer">
|
|
<q-td
|
|
v-for="col in props.cols"
|
|
:key="col.name"
|
|
:props="props"
|
|
@click="onClickAddOrView(true, props.row.id)"
|
|
>
|
|
<div class="table_ellipsis">
|
|
{{ col.value ? col.value : "-" }}
|
|
</div>
|
|
</q-td>
|
|
</q-tr>
|
|
</template>
|
|
<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="fetchListProject"
|
|
></q-pagination>
|
|
</template>
|
|
</d-table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</q-card>
|
|
|
|
<q-dialog persistent v-model="modal">
|
|
<q-card flat bordered style="min-width: 60vw">
|
|
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
|
<DialogHeader
|
|
tittle="เพิ่มโครงการ/หลักสูตรการฝึกอบรม"
|
|
:close="closeDialog"
|
|
/>
|
|
<q-separator />
|
|
<q-card-sectio class="q-pa-none">
|
|
<q-splitter v-model="splitterModel" disable>
|
|
<template v-slot:before>
|
|
<q-scroll-area visible style="height: 60vh">
|
|
<div class="q-pa-md">
|
|
<q-input dense outlined v-model="filter" label="ค้นหา">
|
|
<template v-slot:append>
|
|
<q-icon
|
|
v-if="filter !== ''"
|
|
name="clear"
|
|
class="cursor-pointer"
|
|
@click="filter = ''"
|
|
/>
|
|
<q-icon v-else name="search" color="grey-5" />
|
|
</template>
|
|
</q-input>
|
|
</div>
|
|
<q-tree
|
|
dense
|
|
:nodes="node"
|
|
node-key="orgTreeName"
|
|
label-key="labelName"
|
|
v-model:expanded="expanded"
|
|
:filter="filter"
|
|
no-results-label="ไม่พบข้อมูลที่ค้นหา"
|
|
no-nodes-label="ไม่มีข้อมูล"
|
|
>
|
|
<template v-slot:default-header="prop">
|
|
<q-item
|
|
clickable
|
|
@click.stop="updateSelected(prop.node)"
|
|
:active="formProject.nodeId === prop.node.orgTreeId"
|
|
active-class="my-list-link text-primary text-weight-medium"
|
|
class="row col-12 items-center text-dark q-py-xs q-pl-sm rounded-borders my-list"
|
|
>
|
|
<div>
|
|
<div class="text-weight-medium">
|
|
{{ prop.node.orgTreeName }}
|
|
</div>
|
|
<div class="text-weight-light text-grey-8">
|
|
{{
|
|
prop.node.orgCode == null ? null : prop.node.orgCode
|
|
}}
|
|
{{
|
|
prop.node.orgTreeShortName == null
|
|
? null
|
|
: prop.node.orgTreeShortName
|
|
}}
|
|
</div>
|
|
</div>
|
|
</q-item>
|
|
</template>
|
|
</q-tree>
|
|
</q-scroll-area>
|
|
</template>
|
|
|
|
<template v-slot:after>
|
|
<div class="row q-col-gutter-sm q-pa-sm">
|
|
<div class="col-12">
|
|
<datepicker
|
|
menu-class-name="modalfix"
|
|
v-model="formProject.year"
|
|
:locale="'th'"
|
|
autoApply
|
|
year-picker
|
|
:enableTimePicker="false"
|
|
>
|
|
<template #year="{ year }">{{ year + 543 }}</template>
|
|
<template #year-overlay-value="{ value }">{{
|
|
parseInt(value + 543)
|
|
}}</template>
|
|
<template #trigger>
|
|
<q-input
|
|
dense
|
|
hide-bottom-space
|
|
:rules="[(val:string) => !!val || `${'กรุณาเลือกปีงบประมาณ'}`,]"
|
|
outlined
|
|
:model-value="
|
|
formProject.year === null
|
|
? null
|
|
: Number(formProject.year) + 543
|
|
"
|
|
:label="`${'ปีงบประมาณ'}`"
|
|
>
|
|
<template v-if="formProject.year" v-slot:append>
|
|
<q-icon
|
|
name="cancel"
|
|
@click.stop.prevent="formProject.year = null"
|
|
class="cursor-pointer"
|
|
/>
|
|
</template>
|
|
<template v-slot:prepend>
|
|
<q-icon
|
|
name="event"
|
|
class="cursor-pointer"
|
|
style="color: var(--q-primary)"
|
|
>
|
|
</q-icon>
|
|
</template>
|
|
</q-input>
|
|
</template>
|
|
</datepicker>
|
|
</div>
|
|
<div class="col-12">
|
|
<q-input
|
|
v-model="formProject.projectName"
|
|
label="ชื่อโครงการ/กิจกรรม/หลักสูตร"
|
|
dense
|
|
outlined
|
|
hide-bottom-space
|
|
type="textarea"
|
|
:rules="[(val:string) => !!val || `${'กรุณากรอกชื่อโครงการ/กิจกรรม/หลักสูตร'}`,]"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</q-splitter>
|
|
</q-card-sectio>
|
|
<q-separator />
|
|
<q-card-actions align="right">
|
|
<q-btn label="บันทึก" type="submit" color="public" dense></q-btn>
|
|
</q-card-actions>
|
|
</q-form>
|
|
</q-card>
|
|
</q-dialog>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
.table_ellipsis {
|
|
max-width: 400px;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
.tree-container {
|
|
overflow: auto;
|
|
height: 80vh;
|
|
border: 1px solid #e6e6e7;
|
|
border-radius: 10px;
|
|
}
|
|
|
|
.my-list-link {
|
|
color: rgb(118, 168, 222);
|
|
border-radius: 5px;
|
|
background: #a3d3fb48 !important;
|
|
font-weight: 600;
|
|
border: 1px solid rgba(175, 185, 196, 0.217);
|
|
}
|
|
</style>
|