2024-04-10 18:05:05 +07:00
|
|
|
<script setup lang="ts">
|
2024-04-17 11:53:12 +07:00
|
|
|
import { ref, onMounted } from "vue";
|
2024-04-11 11:01:02 +07:00
|
|
|
import { useQuasar } from "quasar";
|
2024-04-17 11:53:12 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
2024-04-11 11:01:02 +07:00
|
|
|
|
2024-04-17 13:43:45 +07:00
|
|
|
import type { ItemsMenu } from "@/modules/15_development/interface/index/Main";
|
2024-04-17 18:06:15 +07:00
|
|
|
import type { DataStrategic } from "@/modules/15_development/interface/response/Strategic";
|
|
|
|
|
|
2024-04-11 11:01:02 +07:00
|
|
|
import DialogHeader from "@/components/DialogHeader.vue";
|
|
|
|
|
|
|
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
|
|
|
|
|
|
const $q = useQuasar();
|
2024-04-17 13:43:45 +07:00
|
|
|
const {
|
|
|
|
|
showLoader,
|
|
|
|
|
hideLoader,
|
|
|
|
|
dialogConfirm,
|
|
|
|
|
dialogRemove,
|
|
|
|
|
messageError,
|
|
|
|
|
success,
|
|
|
|
|
} = useCounterMixin();
|
2024-04-11 11:01:02 +07:00
|
|
|
|
2024-04-17 13:43:45 +07:00
|
|
|
const ListMenu = ref<ItemsMenu[]>([
|
2024-04-11 11:01:02 +07:00
|
|
|
{
|
|
|
|
|
label: "เพิ่ม",
|
|
|
|
|
icon: "add",
|
2024-04-17 13:43:45 +07:00
|
|
|
value: "ADD",
|
2024-04-11 11:01:02 +07:00
|
|
|
color: "primary",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "แก้ไข",
|
|
|
|
|
icon: "edit",
|
2024-04-17 13:43:45 +07:00
|
|
|
value: "EDIT",
|
2024-04-11 11:01:02 +07:00
|
|
|
color: "edit",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "ลบ",
|
|
|
|
|
icon: "delete",
|
2024-04-17 13:43:45 +07:00
|
|
|
value: "DEL",
|
2024-04-11 11:01:02 +07:00
|
|
|
color: "red",
|
|
|
|
|
},
|
|
|
|
|
]);
|
2024-04-10 18:05:05 +07:00
|
|
|
|
2024-04-17 18:06:15 +07:00
|
|
|
const nodes = ref<any[]>([]);
|
2024-04-10 18:05:05 +07:00
|
|
|
const filter = ref<string>("");
|
2024-04-17 18:06:15 +07:00
|
|
|
const expanded = ref<Array<string>>([]);
|
2024-04-10 18:05:05 +07:00
|
|
|
const nodeId = ref<string>("");
|
|
|
|
|
|
2024-04-17 11:53:12 +07:00
|
|
|
function fetchDataTree() {
|
|
|
|
|
showLoader();
|
|
|
|
|
http
|
|
|
|
|
.get(config.API.devStrategy)
|
|
|
|
|
.then((res) => {
|
2024-04-17 18:06:15 +07:00
|
|
|
const data: DataStrategic[] = res.data.result;
|
2024-04-17 11:53:12 +07:00
|
|
|
nodes.value = data;
|
|
|
|
|
})
|
2024-04-17 15:07:21 +07:00
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
2024-04-17 11:53:12 +07:00
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 18:06:15 +07:00
|
|
|
function onClickAction(type: string, data: DataStrategic | null = null) {
|
2024-04-11 11:01:02 +07:00
|
|
|
switch (type) {
|
|
|
|
|
case "ADD":
|
|
|
|
|
onClickOpenDialog(false, data);
|
|
|
|
|
break;
|
|
|
|
|
case "EDIT":
|
|
|
|
|
onClickOpenDialog(true, data);
|
|
|
|
|
break;
|
|
|
|
|
case "DEL":
|
2024-04-17 18:06:15 +07:00
|
|
|
data && onDelete(data);
|
2024-04-11 11:01:02 +07:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const modalDialog = ref<boolean>(false);
|
2024-04-17 13:43:45 +07:00
|
|
|
const isStatusEdit = ref<boolean>(false);
|
2024-04-11 11:01:02 +07:00
|
|
|
const strategicName = ref<string>("");
|
2024-04-17 13:43:45 +07:00
|
|
|
const levelnode = ref<number>(0);
|
2024-04-11 11:01:02 +07:00
|
|
|
const titleDialog = ref<string>("");
|
2024-04-17 18:06:15 +07:00
|
|
|
function onClickOpenDialog(
|
|
|
|
|
status: boolean = false,
|
|
|
|
|
data: DataStrategic | null = null
|
|
|
|
|
) {
|
2024-04-17 13:43:45 +07:00
|
|
|
isStatusEdit.value = status;
|
2024-04-11 11:01:02 +07:00
|
|
|
if (status) {
|
2024-04-17 18:06:15 +07:00
|
|
|
if (data) {
|
|
|
|
|
nodeId.value = data.id;
|
|
|
|
|
strategicName.value = data.name;
|
|
|
|
|
levelnode.value = data.level;
|
|
|
|
|
titleDialog.value =
|
|
|
|
|
data.level === 1
|
2024-04-18 09:43:48 +07:00
|
|
|
? "ยุทธศาสตร์/แผน"
|
2024-04-17 18:06:15 +07:00
|
|
|
: data.level === 2
|
2024-04-18 09:43:48 +07:00
|
|
|
? "ยุทธศาสตร์ที่"
|
2024-04-17 18:06:15 +07:00
|
|
|
: data.level === 3
|
|
|
|
|
? "ยุทธศาสตร์ย่อย"
|
|
|
|
|
: data.level === 4
|
|
|
|
|
? "กลยุทธ์ที่/เป้าประสงค์ที่"
|
|
|
|
|
: "";
|
|
|
|
|
}
|
2024-04-11 11:01:02 +07:00
|
|
|
} else {
|
|
|
|
|
if (data) {
|
|
|
|
|
titleDialog.value =
|
2024-04-17 14:30:23 +07:00
|
|
|
data.level === 1
|
2024-04-18 09:43:48 +07:00
|
|
|
? "ยุทธศาสตร์ที่"
|
2024-04-17 14:30:23 +07:00
|
|
|
: data.level === 2
|
2024-04-11 11:01:02 +07:00
|
|
|
? "ยุทธศาสตร์ย่อย"
|
2024-04-17 14:30:23 +07:00
|
|
|
: data.level === 3
|
2024-04-11 11:01:02 +07:00
|
|
|
? "กลยุทธ์ที่/เป้าประสงค์ที่"
|
|
|
|
|
: "";
|
2024-04-17 14:30:23 +07:00
|
|
|
levelnode.value = data.level;
|
2024-04-17 13:43:45 +07:00
|
|
|
nodeId.value = data.id;
|
2024-04-11 11:01:02 +07:00
|
|
|
} else {
|
2024-04-17 14:30:23 +07:00
|
|
|
levelnode.value = 0;
|
2024-04-18 09:43:48 +07:00
|
|
|
titleDialog.value = "ยุทธศาสตร์/แผน";
|
2024-04-11 11:01:02 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
modalDialog.value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeDialog() {
|
|
|
|
|
modalDialog.value = false;
|
|
|
|
|
strategicName.value = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onSubmit() {
|
2024-04-17 13:43:45 +07:00
|
|
|
dialogConfirm($q, async () => {
|
|
|
|
|
const formData = {
|
|
|
|
|
idnode: levelnode.value === 0 ? "0" : nodeId.value,
|
|
|
|
|
levelnode: levelnode.value,
|
|
|
|
|
name: strategicName.value,
|
|
|
|
|
};
|
|
|
|
|
try {
|
|
|
|
|
// const url = isStatusEdit.value
|
|
|
|
|
// ? config.API.devStrategy;
|
|
|
|
|
// : config.API.devStrategy;
|
|
|
|
|
const method = isStatusEdit.value ? "patch" : "post";
|
|
|
|
|
await http[method](config.API.devStrategy, formData);
|
|
|
|
|
fetchDataTree();
|
|
|
|
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
|
|
|
|
} catch (err) {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
} finally {
|
|
|
|
|
hideLoader();
|
|
|
|
|
closeDialog();
|
|
|
|
|
}
|
2024-04-11 11:01:02 +07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 18:06:15 +07:00
|
|
|
function onDelete(data: DataStrategic) {
|
2024-04-17 13:43:45 +07:00
|
|
|
dialogRemove($q, () => {
|
|
|
|
|
showLoader();
|
|
|
|
|
const formData = {
|
|
|
|
|
idnode: data.id,
|
2024-04-17 14:30:23 +07:00
|
|
|
levelnode: data.level,
|
2024-04-17 13:43:45 +07:00
|
|
|
};
|
|
|
|
|
http
|
|
|
|
|
.delete(config.API.devStrategy, { data: formData })
|
|
|
|
|
.then(() => {
|
|
|
|
|
fetchDataTree();
|
|
|
|
|
success($q, "ลบข้อมูลสำเร็จ");
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-04-11 11:01:02 +07:00
|
|
|
}
|
2024-04-17 11:53:12 +07:00
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
fetchDataTree();
|
|
|
|
|
});
|
2024-04-10 18:05:05 +07:00
|
|
|
</script>
|
|
|
|
|
<template>
|
|
|
|
|
<div class="toptitle text-dark col-12 row items-center">ยุทธศาสตร์</div>
|
|
|
|
|
<q-card flat bordered class="q-pa-md">
|
|
|
|
|
<div class="row q-col-gutter-sm q-pl-sm">
|
|
|
|
|
<q-toolbar class="text-primary">
|
2024-04-11 11:01:02 +07:00
|
|
|
<q-btn
|
|
|
|
|
dense
|
|
|
|
|
flat
|
|
|
|
|
round
|
|
|
|
|
color="primary"
|
|
|
|
|
icon="add"
|
|
|
|
|
@click.stop="onClickAction('ADD')"
|
|
|
|
|
>
|
2024-04-10 18:05:05 +07:00
|
|
|
<q-tooltip>เพิ่มยุทธศาสตร์</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
|
|
|
|
|
<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-toolbar>
|
|
|
|
|
</div>
|
|
|
|
|
<q-tree
|
|
|
|
|
class="q-pa-sm q-gutter-sm"
|
|
|
|
|
dense
|
|
|
|
|
:nodes="nodes"
|
2024-04-17 14:30:23 +07:00
|
|
|
node-key="id"
|
|
|
|
|
label-key="id"
|
2024-04-10 18:05:05 +07:00
|
|
|
:filter="filter"
|
2024-04-17 18:06:15 +07:00
|
|
|
no-results-label="ไม่พบข้อมูลที่ค้นหา"
|
|
|
|
|
no-nodes-label="ไม่มีข้อมูล"
|
2024-04-10 18:05:05 +07:00
|
|
|
v-model:expanded="expanded"
|
|
|
|
|
>
|
|
|
|
|
<template v-slot:default-header="prop">
|
|
|
|
|
<q-item
|
|
|
|
|
clickable
|
2024-04-11 11:01:02 +07:00
|
|
|
@click.stop
|
2024-04-17 14:30:23 +07:00
|
|
|
:active="nodeId == prop.node.name"
|
2024-04-10 18:05:05 +07:00
|
|
|
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">
|
2024-04-17 14:30:23 +07:00
|
|
|
{{ prop.node.name }}
|
2024-04-10 18:05:05 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-11 11:01:02 +07:00
|
|
|
<q-btn
|
|
|
|
|
flat
|
|
|
|
|
dense
|
|
|
|
|
icon="mdi-dots-vertical"
|
|
|
|
|
class="q-ml-xs"
|
|
|
|
|
color="grey-13"
|
|
|
|
|
size="12px"
|
|
|
|
|
round
|
|
|
|
|
>
|
|
|
|
|
<q-menu>
|
|
|
|
|
<q-list
|
|
|
|
|
dense
|
2024-04-17 14:30:23 +07:00
|
|
|
v-for="(item, index) in prop.node.level !== 4
|
2024-04-11 11:01:02 +07:00
|
|
|
? ListMenu
|
|
|
|
|
: ListMenu.slice(1, 4)"
|
|
|
|
|
:key="index"
|
|
|
|
|
style="min-width: 100px"
|
|
|
|
|
>
|
|
|
|
|
<q-item
|
|
|
|
|
clickable
|
|
|
|
|
v-close-popup
|
2024-04-17 13:43:45 +07:00
|
|
|
@click.stop="onClickAction(item.value, prop.node)"
|
2024-04-11 11:01:02 +07:00
|
|
|
>
|
|
|
|
|
<q-item-section avatar style="min-width: 20px">
|
|
|
|
|
<q-icon size="17px" :color="item.color" :name="item.icon" />
|
|
|
|
|
</q-item-section>
|
|
|
|
|
|
2024-04-17 13:43:45 +07:00
|
|
|
<div v-if="item.value === 'ADD'">
|
2024-04-17 14:30:23 +07:00
|
|
|
<q-item-section v-if="prop.node.level === 1">
|
2024-04-18 09:43:48 +07:00
|
|
|
{{ `${item.label}ยุทธศาสตร์ที่` }}
|
2024-04-11 11:01:02 +07:00
|
|
|
</q-item-section>
|
2024-04-17 14:30:23 +07:00
|
|
|
<q-item-section v-if="prop.node.level === 2">
|
2024-04-11 11:01:02 +07:00
|
|
|
{{ `${item.label}ยุทธศาสตร์ย่อย` }}
|
|
|
|
|
</q-item-section>
|
2024-04-17 14:30:23 +07:00
|
|
|
<q-item-section v-if="prop.node.level === 3">
|
2024-04-11 11:01:02 +07:00
|
|
|
{{ `${item.label}กลยุทธ์ที่/เป้าประสงค์` }}
|
|
|
|
|
</q-item-section>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-04-17 13:43:45 +07:00
|
|
|
<div v-else-if="item.value === 'EDIT'">
|
2024-04-17 14:30:23 +07:00
|
|
|
<q-item-section v-if="prop.node.level === 1">
|
2024-04-18 09:43:48 +07:00
|
|
|
{{ `${item.label}ยุทธศาสตร์/แผน` }}
|
2024-04-11 11:01:02 +07:00
|
|
|
</q-item-section>
|
2024-04-17 14:30:23 +07:00
|
|
|
<q-item-section v-if="prop.node.level === 2">
|
2024-04-18 09:43:48 +07:00
|
|
|
{{ `${item.label}ยุทธศาสตร์ที่` }}
|
2024-04-11 11:01:02 +07:00
|
|
|
</q-item-section>
|
2024-04-17 14:30:23 +07:00
|
|
|
<q-item-section v-if="prop.node.level === 3">
|
2024-04-11 11:01:02 +07:00
|
|
|
{{ `${item.label}ยุทธศาสตร์ย่อย` }}
|
|
|
|
|
</q-item-section>
|
2024-04-17 14:30:23 +07:00
|
|
|
<q-item-section v-if="prop.node.level === 4">
|
2024-04-11 11:01:02 +07:00
|
|
|
{{ `${item.label}กลยุทธ์ที่/เป้าประสงค์` }}
|
|
|
|
|
</q-item-section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-else>
|
|
|
|
|
<q-item-section>{{ item.label }}</q-item-section>
|
|
|
|
|
</div>
|
|
|
|
|
</q-item>
|
|
|
|
|
</q-list>
|
|
|
|
|
</q-menu>
|
|
|
|
|
</q-btn>
|
2024-04-10 18:05:05 +07:00
|
|
|
</q-item>
|
|
|
|
|
</template>
|
|
|
|
|
</q-tree>
|
|
|
|
|
</q-card>
|
2024-04-11 11:01:02 +07:00
|
|
|
|
|
|
|
|
<q-dialog v-model="modalDialog" persistent>
|
|
|
|
|
<q-card style="width: 700px; max-width: 80vw">
|
|
|
|
|
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
|
|
|
|
<DialogHeader
|
|
|
|
|
:tittle="`${
|
2024-04-17 13:43:45 +07:00
|
|
|
isStatusEdit ? `แก้ไข${titleDialog}` : `เพิ่ม${titleDialog}`
|
2024-04-11 11:01:02 +07:00
|
|
|
}`"
|
|
|
|
|
:close="closeDialog"
|
|
|
|
|
/>
|
|
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
|
|
<q-card-section class="q-pt-none">
|
|
|
|
|
<div class="row q-pa-md">
|
|
|
|
|
<div class="col">
|
|
|
|
|
<q-input
|
|
|
|
|
dense
|
|
|
|
|
outlined
|
|
|
|
|
v-model="strategicName"
|
2024-04-18 09:43:48 +07:00
|
|
|
:label="`ชื่อ${titleDialog}`"
|
2024-04-11 11:01:02 +07:00
|
|
|
hide-bottom-space
|
|
|
|
|
lazy-rules
|
|
|
|
|
:rules="[
|
|
|
|
|
(val:string) =>
|
2024-04-18 09:43:48 +07:00
|
|
|
!!val || `${'กรุณากรอกชื่อ'}${titleDialog}`,
|
2024-04-11 11:01:02 +07:00
|
|
|
|
|
|
|
|
]"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</q-card-section>
|
|
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
|
|
<q-card-actions align="right" class="bg-white text-teal">
|
|
|
|
|
<q-btn
|
|
|
|
|
dense
|
|
|
|
|
unelevated
|
|
|
|
|
label="บันทึก"
|
|
|
|
|
id="onSubmit"
|
|
|
|
|
type="submit"
|
|
|
|
|
color="public"
|
|
|
|
|
class="q-px-md"
|
|
|
|
|
>
|
|
|
|
|
<q-tooltip>บันทึกข้อมูล</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
</q-card-actions>
|
|
|
|
|
</q-form>
|
|
|
|
|
</q-card>
|
|
|
|
|
</q-dialog>
|
2024-04-10 18:05:05 +07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|