2024-03-25 18:01:33 +07:00
|
|
|
<script setup lang="ts">
|
2024-04-11 13:39:30 +07:00
|
|
|
import { reactive, ref, onMounted } from "vue";
|
2024-03-25 18:01:33 +07:00
|
|
|
import { useQuasar } from "quasar";
|
2024-04-11 08:33:35 +07:00
|
|
|
import { useRoute } from "vue-router";
|
2024-03-25 18:01:33 +07:00
|
|
|
|
2024-03-26 09:56:49 +07:00
|
|
|
import type { FormBasicinfo } from "@/modules/15_development/interface/request/Main";
|
|
|
|
|
|
2024-04-01 17:24:54 +07:00
|
|
|
import DialogSelectAgency from "@/modules/15_development/components/DialogSelectAgency.vue";
|
|
|
|
|
|
2024-03-25 18:01:33 +07:00
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2024-04-03 17:51:00 +07:00
|
|
|
import { useDevelopmentDataStore } from "@/modules/15_development/store/developmentStore";
|
2024-04-11 13:39:30 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
2024-03-25 18:01:33 +07:00
|
|
|
|
|
|
|
|
const $q = useQuasar();
|
2024-04-03 17:51:00 +07:00
|
|
|
const store = useDevelopmentDataStore();
|
2024-04-11 13:39:30 +07:00
|
|
|
const mixin = useCounterMixin();
|
2024-03-25 18:01:33 +07:00
|
|
|
|
2024-04-11 13:39:30 +07:00
|
|
|
const {
|
|
|
|
|
dialogRemove,
|
|
|
|
|
dialogConfirm,
|
|
|
|
|
showLoader,
|
|
|
|
|
hideLoader,
|
|
|
|
|
messageError,
|
|
|
|
|
success,
|
|
|
|
|
date2Thai,
|
|
|
|
|
} = mixin;
|
2024-04-11 08:33:35 +07:00
|
|
|
const route = useRoute();
|
|
|
|
|
const projectId = ref<string>(route.params.id.toLocaleString());
|
|
|
|
|
|
2024-03-26 09:56:49 +07:00
|
|
|
const formData = reactive<FormBasicinfo>({
|
2024-03-25 18:01:33 +07:00
|
|
|
year: new Date().getFullYear(),
|
|
|
|
|
projectName: "",
|
|
|
|
|
reason: "",
|
|
|
|
|
objective: "",
|
2024-04-18 12:21:10 +07:00
|
|
|
node: null,
|
|
|
|
|
nodeId: null,
|
|
|
|
|
orgRevisionId: null,
|
2024-03-25 18:01:33 +07:00
|
|
|
});
|
|
|
|
|
|
2024-04-18 12:21:10 +07:00
|
|
|
const orgName = ref<string>("");
|
|
|
|
|
const node = ref<any>([]);
|
|
|
|
|
const nodeId = ref<string>("");
|
|
|
|
|
const filter = ref<string>("");
|
|
|
|
|
const expanded = ref<any>([]);
|
2024-04-11 08:33:35 +07:00
|
|
|
|
2024-04-11 13:39:30 +07:00
|
|
|
async function fetchData(id: string) {
|
|
|
|
|
showLoader();
|
|
|
|
|
await http
|
2024-04-11 16:07:59 +07:00
|
|
|
.get(config.API.developmentMainTab("tab1", id))
|
2024-04-11 13:39:30 +07:00
|
|
|
.then(async (res) => {
|
|
|
|
|
const data = res.data.result;
|
|
|
|
|
formData.year = data.year;
|
|
|
|
|
formData.reason = data.reason;
|
|
|
|
|
formData.projectName = data.projectName;
|
|
|
|
|
formData.objective = data.objective;
|
2024-04-18 12:21:10 +07:00
|
|
|
formData.nodeId = data.nodeId;
|
|
|
|
|
|
|
|
|
|
const test = await searchAndReplace(node.value, formData?.nodeId);
|
|
|
|
|
console.log(test);
|
|
|
|
|
|
|
|
|
|
const parts = test.orgName.split("/");
|
|
|
|
|
for (let i = 0; i < parts.length; i++) {
|
|
|
|
|
const arrangedParts = parts[i];
|
|
|
|
|
expanded.value.push(arrangedParts);
|
|
|
|
|
}
|
|
|
|
|
updateSelected(test);
|
2024-04-11 13:39:30 +07:00
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function editData(id: string) {
|
|
|
|
|
await http
|
2024-04-18 12:21:10 +07:00
|
|
|
.put(config.API.developmentMainTab("tab1", id), formData)
|
2024-04-11 13:39:30 +07:00
|
|
|
.then(() => {
|
|
|
|
|
fetchData(id);
|
|
|
|
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 08:33:35 +07:00
|
|
|
function onSubmit() {
|
|
|
|
|
dialogConfirm($q, async () => {
|
|
|
|
|
showLoader();
|
2024-04-11 13:39:30 +07:00
|
|
|
editData(projectId.value);
|
2024-04-11 08:33:35 +07:00
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-11 13:39:30 +07:00
|
|
|
|
2024-04-18 12:21:10 +07:00
|
|
|
function fetchActive() {
|
|
|
|
|
showLoader();
|
|
|
|
|
http
|
|
|
|
|
.get(config.API.activeOrganization)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
const data = res.data.result;
|
|
|
|
|
fetchTree(data.activeId);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function fetchTree(id: string) {
|
|
|
|
|
showLoader();
|
|
|
|
|
http
|
|
|
|
|
.get(config.API.orgByid(id.toString()))
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
const data = res.data.result;
|
|
|
|
|
node.value = data;
|
|
|
|
|
fetchData(projectId.value);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateSelected(data: any) {
|
|
|
|
|
console.log(expanded.value);
|
|
|
|
|
|
|
|
|
|
nodeId.value = data.orgTreeId;
|
|
|
|
|
orgName.value = data.orgTreeName;
|
|
|
|
|
formData.node = data.orgLevel;
|
|
|
|
|
formData.nodeId = data.orgTreeId;
|
|
|
|
|
formData.orgRevisionId = data.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function searchAndReplace(orgTreeData: any, treeId: string | null) {
|
|
|
|
|
for (let orgTree of orgTreeData) {
|
|
|
|
|
if (orgTree.orgTreeId === treeId) {
|
|
|
|
|
return orgTree;
|
|
|
|
|
}
|
|
|
|
|
let foundOrg: any = searchAndReplace(orgTree.children, treeId);
|
|
|
|
|
if (foundOrg) {
|
|
|
|
|
return foundOrg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 13:39:30 +07:00
|
|
|
onMounted(async () => {
|
2024-04-18 12:21:10 +07:00
|
|
|
fetchActive();
|
|
|
|
|
// setTimeout(() => {
|
|
|
|
|
// fetchData(projectId.value);
|
|
|
|
|
// }, 500);
|
2024-04-11 13:39:30 +07:00
|
|
|
});
|
2024-03-25 18:01:33 +07:00
|
|
|
</script>
|
2024-04-11 08:33:35 +07:00
|
|
|
|
2024-03-25 18:01:33 +07:00
|
|
|
<template>
|
2024-04-11 08:33:35 +07:00
|
|
|
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
2024-04-18 12:21:10 +07:00
|
|
|
<q-card bordered class="col-12 row caedNone">
|
|
|
|
|
<div class="col-xs-12 col-sm-3 row">
|
|
|
|
|
<div class="col-12 row no-wrap bg-grey-1">
|
|
|
|
|
<div class="col-12 q-py-sm q-px-sm">
|
|
|
|
|
<q-card-section
|
|
|
|
|
class="q-pt-none q-pa-sm scroll"
|
|
|
|
|
style="max-height: 65vh"
|
2024-04-11 08:33:35 +07:00
|
|
|
>
|
2024-04-18 12:21:10 +07:00
|
|
|
<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>
|
|
|
|
|
<q-tree
|
|
|
|
|
dense
|
|
|
|
|
:nodes="node"
|
|
|
|
|
node-key="orgTreeName"
|
|
|
|
|
label-key="orgTreeName"
|
|
|
|
|
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="formData.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-card-section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="col-12 row">
|
|
|
|
|
<q-separator :vertical="!$q.screen.lt.md" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-11 08:33:35 +07:00
|
|
|
</div>
|
2024-04-18 12:21:10 +07:00
|
|
|
<div class="col-xs-12 col-sm-9 q-pa-md row">
|
|
|
|
|
<div class="col-12 row">
|
|
|
|
|
<div class="col-12">
|
|
|
|
|
<div class="row col-12 q-col-gutter-md q-pa-md">
|
|
|
|
|
<div class="col-xs-6 col-sm-2 col-md-2">
|
|
|
|
|
<datepicker
|
|
|
|
|
menu-class-name="modalfix"
|
|
|
|
|
v-model="formData.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
|
|
|
|
|
lazy-rules
|
|
|
|
|
outlined
|
|
|
|
|
class="inputgreen"
|
|
|
|
|
:model-value="Number(formData.year) + 543"
|
|
|
|
|
:label="`${'ปีงบประมาณ'}`"
|
|
|
|
|
>
|
|
|
|
|
<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-xs-10 col-sm-10 col-md-10">
|
|
|
|
|
<q-input
|
|
|
|
|
dense
|
|
|
|
|
outlined
|
|
|
|
|
class="inputgreen"
|
|
|
|
|
v-model="orgName"
|
|
|
|
|
inputgreen
|
|
|
|
|
label="ชื่อหน่วยงานที่รับผิดชอบ"
|
|
|
|
|
hide-bottom-space
|
|
|
|
|
lazy-rules
|
|
|
|
|
readonly
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-xs-12 col-sm-12 col-md-12">
|
|
|
|
|
<q-input
|
|
|
|
|
outlined
|
|
|
|
|
class="inputgreen"
|
|
|
|
|
dense
|
|
|
|
|
v-model="formData.projectName"
|
|
|
|
|
label="ชื่อโครงการ/กิจกรรม/หลักสูตร"
|
|
|
|
|
rows="6"
|
|
|
|
|
type="textarea"
|
|
|
|
|
hide-bottom-space
|
|
|
|
|
:rules="[
|
2024-03-25 18:01:33 +07:00
|
|
|
(val:string) =>
|
|
|
|
|
!!val || `${'กรุณากรอกชื่อโครงการ/กิจกรรม/หลักสูตร'}`,
|
|
|
|
|
]"
|
2024-04-18 12:21:10 +07:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-xs-12 col-sm-12 col-md-12">
|
|
|
|
|
<q-input
|
|
|
|
|
outlined
|
|
|
|
|
class="inputgreen"
|
|
|
|
|
dense
|
|
|
|
|
v-model="formData.reason"
|
|
|
|
|
label="หลักการและเหตุผล"
|
|
|
|
|
rows="6"
|
|
|
|
|
hide-bottom-space
|
|
|
|
|
type="textarea"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-xs-12 col-sm-12 col-md-12">
|
|
|
|
|
<q-input
|
|
|
|
|
outlined
|
|
|
|
|
class="inputgreen"
|
|
|
|
|
dense
|
|
|
|
|
v-model="formData.objective"
|
|
|
|
|
label="วัตถุประสงค์"
|
|
|
|
|
rows="6"
|
|
|
|
|
hide-bottom-space
|
|
|
|
|
type="textarea"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-11 08:33:35 +07:00
|
|
|
</div>
|
2024-04-18 12:21:10 +07:00
|
|
|
</q-card>
|
2024-03-25 18:01:33 +07:00
|
|
|
|
2024-04-11 08:33:35 +07:00
|
|
|
<q-separator />
|
2024-03-25 18:01:33 +07:00
|
|
|
<div class="text-right q-pa-sm">
|
|
|
|
|
<q-btn
|
|
|
|
|
dense
|
|
|
|
|
unelevated
|
|
|
|
|
label="บันทึก"
|
|
|
|
|
id="onSubmit"
|
|
|
|
|
type="submit"
|
|
|
|
|
color="public"
|
|
|
|
|
class="q-px-md"
|
|
|
|
|
>
|
|
|
|
|
<q-tooltip>บันทึกข้อมูล</q-tooltip>
|
|
|
|
|
</q-btn>
|
2024-04-11 08:33:35 +07:00
|
|
|
</div>
|
|
|
|
|
</q-form>
|
2024-04-01 17:24:54 +07:00
|
|
|
|
2024-04-18 12:21:10 +07:00
|
|
|
<!-- <DialogSelectAgency
|
2024-04-01 17:24:54 +07:00
|
|
|
v-model:modal="modalDialogSelect"
|
|
|
|
|
@update:updateAgency="updateAgency"
|
2024-04-18 12:21:10 +07:00
|
|
|
/> -->
|
2024-03-25 18:01:33 +07:00
|
|
|
</template>
|
|
|
|
|
|
2024-04-18 12:21:10 +07:00
|
|
|
<style scoped>
|
|
|
|
|
.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>
|