start commit for admin system

This commit is contained in:
Warunee Tamkoo 2024-05-29 17:58:57 +07:00
commit badb676529
300 changed files with 58634 additions and 0 deletions

View file

@ -0,0 +1,447 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import { useQuasar } from "quasar";
import type {
DataOption,
FormPositionSelect,
ListMenu,
RowDetailPositions,
} from "@/modules/01_metadata/interface/request/position/index";
import type { QTableProps } from "quasar";
import DialogAddPosition from "@/modules/01_metadata/components/position/DialogAddPosition.vue";
const editPosition = ref<boolean>(false);
const modalAddPosition = ref<boolean>(false);
const levelOpsMain = ref<DataOption[]>([]);
const dataLevel = ref<any>();
const levelOps = ref<DataOption[]>([]);
const isSpecial = ref<boolean>(false);
const formPositionSelect = reactive<FormPositionSelect>({
positionId: "",
posTypeId: "",
positionName: "",
positionField: "",
positionType: "",
positionLevel: "",
positionExecutive: "",
positionExecutiveField: "",
positionArea: "",
isSpecial: false,
});
const rows = ref<RowDetailPositions[]>([]);
const listMenu = ref<ListMenu[]>([
{
label: "คัดลอก",
icon: "mdi-content-copy",
type: "copy",
color: "blue-6",
},
{
label: "ลบ",
icon: "delete",
type: "remove",
color: "red",
},
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionName",
align: "left",
label: "ตำแหน่งในสายงาน",
sortable: true,
field: "positionName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionField",
align: "left",
label: "สายงาน",
sortable: true,
field: "positionField",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posTypeName",
align: "left",
label: "ประเภทตำเเหน่ง",
sortable: true,
field: "posTypeName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posLevelName",
align: "left",
label: "ระดับตำแหน่ง",
sortable: true,
field: "posLevelName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posExecutiveName",
align: "left",
label: "ตำแหน่งทางการบริหาร",
sortable: true,
field: "posExecutiveName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionExecutiveField",
align: "left",
label: "ด้านทางการบริหาร",
sortable: true,
field: "positionExecutiveField",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionArea",
align: "left",
label: "ด้าน/สาขา",
sortable: true,
field: "positionArea",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const visibleColumns = ref<string[]>([
"no",
"positionName",
"positionField",
"posTypeName",
"posLevelName",
"posExecutiveName",
"positionExecutiveField",
"positionArea",
]);
const $q = useQuasar();
const rowsPositionSelect = ref<RowDetailPositions[]>([]);
const mixin = useCounterMixin();
const {
dialogConfirm,
showLoader,
hideLoader,
messageError,
success,
dialogRemove,
} = mixin;
/** input ค้นหา */
const searchRef = ref<any>(null);
const search = ref<string>("");
const type = ref<string>("positionName");
const isReadonly = ref<boolean>(false); //
const optionFilter = ref<DataOption[]>([
{ id: "positionName", name: "ตำแหน่งในสายงาน" },
{ id: "positionField", name: "สายงาน" },
{ id: "positionType", name: "ประเภทตำแหน่ง" },
{ id: "positionLevel", name: "ระดับตำแหน่ง" },
{ id: "positionExecutive", name: "ตำแหน่งทางการบริหาร" },
{ id: "positionExecutiveField", name: "ด้านทางการบริหาร" },
{ id: "positionArea", name: "ด้าน/สาขา" },
]);
/**
* ดลอกขอม
* @param data อมลตำแหน
*/
function copyDetiail(data: RowDetailPositions) {
formPositionSelect.positionId = data.id;
formPositionSelect.posTypeId = data.posTypeId;
formPositionSelect.positionName = data.positionName;
formPositionSelect.positionField = data.positionField;
formPositionSelect.positionType = data.posTypeId;
formPositionSelect.positionLevel = data.posLevelId;
formPositionSelect.positionExecutive = data.posExecutiveId;
formPositionSelect.positionExecutiveField = data.positionExecutiveField;
formPositionSelect.positionArea = data.positionArea;
modalAddPosition.value = true;
}
/**
* แกไขขอม
* @param data อมลตำแหน
*/
function editDetiail(data: RowDetailPositions) {
console.log(data);
formPositionSelect.positionId = data.id;
formPositionSelect.posTypeId = data.posTypeId;
formPositionSelect.positionName = data.positionName;
formPositionSelect.positionField = data.positionField;
formPositionSelect.positionType = data.posTypeId;
formPositionSelect.positionLevel = data.posLevelId;
formPositionSelect.positionExecutive = data.posExecutiveId;
formPositionSelect.positionExecutiveField = data.positionExecutiveField;
formPositionSelect.positionArea = data.positionArea;
formPositionSelect.isSpecial = data.isSpecial;
modalAddPosition.value = true;
editPosition.value = true;
}
/**
* งค css ออกไปตามเงอนไข
* @param val true/false
*/
function inputEdit(val: boolean) {
return {
"full-width cursor-pointer inputgreen ": val,
"full-width cursor-pointer inputgreen": !val,
};
}
async function searchInput() {
showLoader();
await http
.get(
config.API.orgPosPosition + `?keyword=${search.value}&type=${type.value}`
)
.then((res) => {
rowsPositionSelect.value = res.data.result;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
function addPosition(data: RowDetailPositions) {
const isIdExist = rows.value.some((item: any) => item.id === data.id);
if (!isIdExist) {
rows.value = [data, ...rows.value];
}
}
function deletePos(id: string) {
dialogRemove($q, () => {
showLoader();
http
.delete(config.API.orgPosPositionById(id))
.then(() => {
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
searchInput();
hideLoader();
});
});
}
function popupAdd() {
modalAddPosition.value = true;
}
async function fetchData() {
search.value = "";
showLoader();
await http
.get(config.API.orgPosPosition + `?keyword=&type=ALL`)
.then((res) => {
rowsPositionSelect.value = res.data.result;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
onMounted(() => {
fetchData();
});
</script>
<template>
<div class="row col-12 q-mb-sm">
<div class="col-md-2">
<q-btn
id="addComplaints"
for="addComplaints"
size="12px"
flat
round
color="primary"
icon="mdi-plus"
@click="popupAdd()"
><q-tooltip>เพมตำเเหน </q-tooltip></q-btn
>
</div>
<div class="row col-md-10 q-col-gutter-sm">
<div class="col-md-4">
<q-select
label="ค้นหาจาก"
v-model="type"
:options="optionFilter"
emit-value
dense
map-options
outlined
option-label="name"
option-value="id"
/>
</div>
<div class="col-md-6">
<q-input
ref="searchRef"
:class="inputEdit(isReadonly)"
v-model="search"
outlined
dense
lazy-rules
label="คำค้น"
hide-bottom-space
>
<template v-slot:append>
<q-icon
v-if="search"
name="cancel"
@click="fetchData()"
class="cursor-pointer"
></q-icon>
</template>
</q-input>
</div>
<div class="row col-md-2">
<q-btn
color="primary"
icon="search"
label="ค้นหา"
class="full-width"
@click="searchInput()"
/>
</div>
</div>
</div>
<div class="full-width q-mt-sm">
<d-table
ref="table"
:columns="columns"
:rows="rowsPositionSelect"
row-key="id"
flat
bordered
:paging="true"
dense
class="custom-header-table"
: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"
style="color: #000000; font-weight: 500"
>
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th auto-width></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="addPosition(props.row)"
>
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else-if="col.name === 'posLevelName'">
{{
props.row.posLevelName
? props.row.isSpecial == true
? `${props.row.posLevelName} (ฉ)`
: props.row.posLevelName
: "-"
}}
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
<q-td auto-width>
<q-btn
color="blue-6"
flat
dense
round
class="q-mr-xs"
size="12px"
icon="mdi-content-copy"
clickable
@click.stop="
() => {
copyDetiail(props.row);
}
"
>
<q-tooltip>ดลอกขอม</q-tooltip>
</q-btn>
<q-btn
color="edit"
flat
dense
round
size="12px"
icon="mdi-pencil"
clickable
@click.stop="editDetiail(props.row)"
v-close-popup
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
<q-btn
color="red"
flat
dense
round
size="12px"
icon="mdi-delete"
clickable
@click.stop="deletePos(props.row.id)"
v-close-popup
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
</d-table>
</div>
<DialogAddPosition
v-model:add-position="modalAddPosition"
v-model:form-data="formPositionSelect"
v-model:edit-check="editPosition"
:get-data="searchInput"
/>
</template>

View file

@ -0,0 +1,430 @@
<script setup lang="ts">
import { ref, onMounted } from "vue";
import type { QInput, QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import { useRouter } from "vue-router";
import { usePositionTypeDataStore } from "@/modules/01_metadata/stores/positionTypeStore";
import dialogHeader from "@/components/DialogHeader.vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
const store = usePositionTypeDataStore();
const router = useRouter();
const mixin = useCounterMixin();
const {
dialogRemove,
dialogConfirm,
success,
messageError,
showLoader,
hideLoader,
} = mixin;
const columns = [
{
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: "posTypeRank",
align: "left",
label: "ระดับตำแหน่ง",
sortable: true,
field: "posTypeRank",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "createdAt",
align: "left",
label: "วันที่สร้าง",
sortable: true,
field: "createdAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "lastUpdatedAt",
align: "left",
label: "วันที่แก้ไข",
sortable: true,
field: "lastUpdatedAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "lastUpdateFullName",
align: "left",
label: "ผู้ดำเนินการ",
sortable: true,
field: "lastUpdateFullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
] as const satisfies QTableProps["columns"];
const $q = useQuasar();
const editId = ref<string>("");
const filterKeyword = ref<string>("");
const dialog = ref<boolean>(false);
const posTypeName = ref<string>("");
const posTypeNameRef = ref<QInput | null>(null);
const posTypeRank = ref<number | null>(null);
const posTypeRankRef = ref<QInput | null>(null);
const dialogStatus = ref<string>("");
const visibleColumns = ref<string[]>(["posTypeName", "posTypeRank"]);
async function fetchData() {
showLoader();
await http
.get(config.API.orgPosType)
.then(async (res) => {
store.save(res.data.result);
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function addData() {
await http
.post(config.API.orgPosType, {
posTypeName: posTypeName.value,
posTypeRank: posTypeRank.value,
})
.then(() => {
fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function editData(id: string) {
await http
.put(config.API.orgPosTypeId(id), {
posTypeName: posTypeName.value,
posTypeRank: posTypeRank.value,
})
.then(() => {
fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function deleteData(id: string) {
await http
.delete(config.API.orgPosTypeId(id))
.then(() => {
fetchData();
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
onMounted(async () => {
fetchData();
});
function closeDialog() {
dialog.value = false;
}
function onclickDetail(id: string) {
router.push(`/master-data/position/level/${id}`);
}
function validateForm() {
posTypeNameRef.value?.validate();
posTypeRankRef.value?.validate();
onSubmit();
}
async function onSubmit() {
if (posTypeName.value.length > 0 && posTypeRank.value !== null) {
dialogConfirm(
$q,
async () => {
dialogStatus.value === "create" ? addData() : editData(editId.value);
closeDialog();
posTypeName.value = "";
posTypeRank.value = null;
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
}
}
</script>
<template>
<q-toolbar style="padding: 0">
<q-btn
flat
round
color="primary"
icon="add"
@click.stop="
() => {
dialogStatus = 'create';
dialog = true;
}
"
>
<q-tooltip> เพมขอม </q-tooltip>
</q-btn>
<q-space />
<div class="row q-gutter-sm">
<q-input outlined dense v-model="filterKeyword" label="ค้นหา"></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"
/>
</div>
</q-toolbar>
<d-table
ref="table"
:columns="columns"
:rows="store.row"
:filter="filterKeyword"
row-key="name"
flat
bordered
:paging="true"
dense
class="custom-header-table"
: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"
@click.stop="onclickDetail(props.row.id)"
>
<q-td v-for="col in props.cols" :key="col.id">
{{ col.value }}
</q-td>
<q-td auto-width>
<q-btn
color="edit"
flat
dense
round
class="q-mr-xs"
size="12px"
icon="edit"
clickable
@click.stop="
() => {
dialogStatus = 'edit';
dialog = true;
editId = props.row.id;
posTypeName = props.row.posTypeName;
posTypeRank = props.row.posTypeRank;
}
"
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
<q-btn
color="red"
flat
dense
round
size="12px"
icon="mdi-delete"
clickable
@click.stop="
dialogRemove($q, async () => await deleteData(props.row.id))
"
v-close-popup
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
</d-table>
<q-dialog v-model="dialog" class="dialog" persistent>
<q-card style="min-width: 350px">
<form @submit.prevent="validateForm">
<q-card-section class="flex justify-between" style="padding: 0">
<dialog-header
:tittle="dialogStatus === 'edit' ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
:close="closeDialog"
/>
</q-card-section>
<q-separator color="grey-4" />
<q-card-section class="q-pa-none">
<div class="col-12 q-ma-md">
<q-input
ref="posTypeNameRef"
outlined
v-model="posTypeName"
label="ประเภทตำแหน่ง"
dense
lazy-rules
borderless
:rules="[(val) => val.length > 0 || 'กรุณากรอกประเภทตำแหน่ง']"
hide-bottom-space
/>
</div>
<div class="col-12 q-ma-md">
<q-input
ref="posTypeRankRef"
outlined
v-model="posTypeRank"
label="ระดับตำแหน่ง"
dense
lazy-rules
borderless
min="1"
:rules="[(val) => val != undefined || 'กรุณากรอกระดับตำแหน่ง']"
hide-bottom-space
mask="############"
/>
</div>
</q-card-section>
<q-card-actions align="right">
<q-btn
id="onSubmit"
type="submit"
dense
unelevated
label="บันทึก"
color="public"
class="q-px-md"
>
<q-tooltip>นทกขอม</q-tooltip>
</q-btn>
</q-card-actions>
</form>
</q-card>
</q-dialog>
</template>
<style scoped lang="scss">
.border_custom {
border-radius: 6px !important;
border: 1px solid #e1e1e1;
}
$toggle-background-color-on: #06884d;
$toggle-background-color-off: darkgray;
$toggle-control-color: white;
$toggle-width: 40px;
$toggle-height: 25px;
$toggle-gutter: 3px;
$toggle-radius: 50%;
$toggle-control-speed: 0.15s;
$toggle-control-ease: ease-in;
// These are our computed variables
// change at your own risk.
$toggle-radius: $toggle-height / 2;
$toggle-control-size: $toggle-height - ($toggle-gutter * 2);
.toggle-control {
display: block;
position: relative;
padding-left: $toggle-width;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
user-select: none;
input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
input:checked ~ .control {
background-color: $toggle-background-color-on;
&:after {
left: $toggle-width - $toggle-control-size - $toggle-gutter;
}
}
.control {
position: absolute;
top: -7px;
left: -15px;
height: $toggle-height;
width: $toggle-width;
border-radius: $toggle-radius;
background-color: $toggle-background-color-off;
transition: background-color $toggle-control-speed $toggle-control-ease;
&:after {
content: "";
position: absolute;
left: $toggle-gutter;
top: $toggle-gutter;
width: $toggle-control-size;
height: $toggle-control-size;
border-radius: $toggle-radius;
background: $toggle-control-color;
transition: left $toggle-control-speed $toggle-control-ease;
}
}
}
</style>

View file

@ -0,0 +1,30 @@
<script setup lang="ts">
import { ref } from "vue";
import { useRouter } from "vue-router";
import ListLevelDetail from "@/modules/01_metadata/components/position/05ListLevelDetail.vue";
const router = useRouter();
const posName = ref<string>("");
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
<q-btn
icon="mdi-arrow-left"
unelevated
round
dense
flat
color="primary"
class="q-mr-sm"
@click="router.go(-1)"
/>
รายการระดบตำแหนงของ {{ posName }}
</div>
<q-card flat bordered>
<ListLevelDetail v-model:posName="posName" />
</q-card>
</template>
<style scoped></style>

View file

@ -0,0 +1,242 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import type { QTableProps } from "quasar";
import { useQuasar } from "quasar";
import type {
RowListForm,
ListMenu,
} from "@/modules/01_metadata/interface/request/position";
import http from "@/plugins/http";
import config from "@/app.config";
import DialogAdd from "@/modules/01_metadata/components/position/DialogAddExecutive.vue";
import { useCounterMixin } from "@/stores/mixin";
const $q = useQuasar();
const mixin = useCounterMixin();
const {
dialogConfirm,
showLoader,
hideLoader,
messageError,
success,
dialogRemove,
} = mixin;
const dataEdit = ref<any>();
const isEdit = ref<boolean>(false);
const modalAdd = ref<boolean>(false);
const filterKeyword = ref<string>("");
const rows = ref<RowListForm[]>([]);
const listMenu = ref<ListMenu[]>([
{
label: "แก้ไข",
icon: "mdi-pencil",
type: "copy",
color: "teal-6",
},
{
label: "ลบ",
icon: "delete",
type: "remove",
color: "red",
},
]);
const visibleColumns = ref<string[]>([
"no",
"posExecutiveName",
"posExecutivePriority",
]);
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posExecutiveName",
align: "left",
label: "ชื่อตำแหน่งทางการบริหาร",
sortable: true,
field: "posExecutiveName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posExecutivePriority",
align: "left",
label: "ลำดับความสำคัญ",
sortable: true,
field: "posExecutivePriority",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
function getData() {
showLoader();
http
.get(config.API.orgPosExecutive)
.then((res) => {
const dataList = res.data.result;
rows.value = dataList;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
function popUpAdd() {
modalAdd.value = true;
}
function editPopUp(data: RowListForm[]) {
dataEdit.value = data;
modalAdd.value = true;
isEdit.value = true;
}
function deletePos(id: string) {
dialogRemove($q, () => {
showLoader();
http
.delete(config.API.orgPosExecutiveById(id))
.then(() => {
success($q, "ลบข้อมูลสำเร็จ");
getData();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
}
onMounted(() => {
getData();
});
</script>
<template>
<div class="row col-12 q-col-gutter-x-sm">
<div class="col-2">
<q-btn
size="12px"
flat
round
color="primary"
icon="mdi-plus"
@click="popUpAdd()"
>
<q-tooltip>เพมตำแหนงทางการบรหาร</q-tooltip>
</q-btn>
</div>
<q-space />
<q-input outlined dense v-model="filterKeyword" label="ค้นหา"></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"
/>
</div>
<div class="col-12 q-mt-sm">
<d-table
ref="table"
:columns="columns"
:rows="rows"
row-key="id"
flat
bordered
:paging="true"
dense
class="custom-header-table"
: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"
style="color: #000000; font-weight: 500"
>
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th auto-width></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">
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
<q-td auto-width>
<q-btn
color="edit"
flat
dense
round
class="q-mr-xs"
size="12px"
icon="edit"
clickable
@click.stop="
() => {
editPopUp(props.row);
}
"
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
<q-btn
color="red"
flat
dense
round
size="12px"
icon="mdi-delete"
clickable
@click.stop="deletePos(props.row.id)"
v-close-popup
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
</d-table>
</div>
<DialogAdd
v-model:executive="modalAdd"
v-model:form-data="dataEdit"
v-model:edit="isEdit"
:get-data="getData"
/>
</template>

View file

@ -0,0 +1,543 @@
<script setup lang="ts">
import { ref, onMounted } from "vue";
import type { QInput, QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import { useRoute } from "vue-router";
import { usePositionDataStore } from "@/modules/01_metadata/stores/positionListStore";
import { useMainOptionDataStore } from "@/modules/01_metadata/stores/main";
import { usePositionTypeDataStore } from "@/modules/01_metadata/stores/positionTypeStore";
import dialogHeader from "@/components/DialogHeader.vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
const store = usePositionDataStore();
const storeOption = useMainOptionDataStore();
const storeName = usePositionTypeDataStore();
const mixin = useCounterMixin();
const posName = defineModel<string>("posName", {
required: true,
});
const {
dialogRemove,
dialogConfirm,
showLoader,
hideLoader,
messageError,
success,
} = mixin;
const $q = useQuasar();
const columns = [
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px; width:0px",
style: "font-size: 14px",
},
{
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: "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: "posLevelRank",
align: "left",
label: "ระดับของระดับตำแหน่ง",
sortable: true,
field: "posLevelRank",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "posLevelAuthority",
align: "left",
label: "ผู้มีอำนาจสั่งบรรจุ",
sortable: true,
field: "posLevelAuthority",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "createdAt",
align: "center",
label: "วันที่สร้าง",
sortable: true,
field: "createdAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "lastUpdatedAt",
align: "center",
label: "วันที่แก้ไข",
sortable: true,
field: "lastUpdatedAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "lastUpdateFullName",
align: "left",
label: "ผู้ดำเนินการ",
sortable: true,
field: "lastUpdateFullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
] as const satisfies QTableProps["columns"];
const route = useRoute();
const id = ref<string>(route.params.id.toString());
const filterKeyword = ref<string>("");
const dialog = ref<boolean>(false);
const dialogStatus = ref<string>("");
const editId = ref<string>("");
const posLevelName = ref<string>("");
const posLevelRank = ref<number>();
const posLevelAuthority = ref<string>("");
const posLevelNameRef = ref<QInput | null>(null);
const posLevelRankRef = ref<QInput | null>(null);
const posTypeIdRef = ref<QInput | null>(null);
const posLevelAuthorityRef = ref<QInput | null>(null);
const visibleColumns = ref<string[]>([
"no",
"posTypeName",
"posLevelName",
"posLevelRank",
"posLevelAuthority",
]);
async function fetchData() {
showLoader();
await http
.get(config.API.orgPosTypeId(id.value))
.then(async (res) => {
posName.value = res.data.result.posTypeName;
store.save(res.data.result.posLevels);
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function addData() {
await http
.post(config.API.orgPosLevel, {
posLevelName: posLevelName.value,
posLevelRank: posLevelRank.value,
posLevelAuthority:
posLevelAuthority.value == "" ? "" : posLevelAuthority.value,
posTypeId: id.value,
})
.then(() => {
fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function editData(editId: string) {
await http
.put(config.API.orgPosLevelId(editId), {
posLevelName: posLevelName.value,
posLevelRank: posLevelRank.value,
posLevelAuthority:
posLevelAuthority.value == "" ? "" : posLevelAuthority.value,
posTypeId: id.value,
})
.then(() => {
fetchData();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function deleteData(id: string) {
await http
.delete(config.API.orgPosLevelId(id))
.then(() => {
fetchData();
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
function closeDialog() {
dialog.value = false;
}
function validateForm() {
posLevelNameRef.value?.validate();
posLevelRankRef.value?.validate();
posTypeIdRef.value?.validate();
posLevelAuthorityRef.value?.validate();
onSubmit();
}
async function onSubmit() {
if (
posLevelName.value.length > 0 &&
posLevelAuthority.value.length > 0 &&
posLevelRank.value !== undefined &&
posLevelRank.value > 0
) {
dialogConfirm(
$q,
async () => {
dialogStatus.value === "create" ? addData() : editData(editId.value);
closeDialog();
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
}
}
onMounted(async () => {
fetchData();
});
</script>
<template>
<div class="q-pa-md">
<q-toolbar style="padding: 0">
<q-btn
flat
round
color="primary"
icon="add"
@click.stop="
() => {
dialogStatus = 'create';
dialog = true;
posLevelName = '';
posLevelRank = undefined;
posLevelAuthority = '';
}
"
>
<q-tooltip> เพมขอม </q-tooltip>
</q-btn>
<q-space />
<div class="row q-gutter-sm">
<q-input outlined dense v-model="filterKeyword" label="ค้นหา"></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"
/>
</div>
</q-toolbar>
<d-table
ref="table"
:columns="columns"
:rows="store.row"
:filter="filterKeyword"
row-key="name"
flat
bordered
:paging="true"
dense
class="custom-header-table"
: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-bold">{{ 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, index) in props.cols" :key="col.id">
<div v-if="col.name === 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-if="col.name === 'posTypeName'">
{{ posName }}
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
<q-td auto-width>
<q-btn
color="edit"
flat
dense
round
class="q-mr-xs"
size="12px"
icon="edit"
clickable
@click.stop="
() => {
dialogStatus = 'edit';
editId = props.row.id;
posLevelName = props.row.posLevelName;
posLevelRank = props.row.posLevelRank;
if (props.row.posLevelAuthority === 'หัวหน้าหน่วยงาน') {
posLevelAuthority = 'HEAD';
} else if (props.row.posLevelAuthority === 'ปลัด') {
posLevelAuthority = 'DEPUTY';
} else {
posLevelAuthority = 'GOVERNOR';
}
dialog = true;
}
"
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
<q-btn
color="red"
flat
dense
round
size="12px"
icon="mdi-delete"
clickable
@click.stop="
dialogRemove($q, async () => await deleteData(props.row.id))
"
v-close-popup
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
</d-table>
<q-dialog v-model="dialog" class="dialog" persistent>
<q-card style="width: 350px">
<form @submit.prevent="validateForm">
<q-card-section class="flex justify-between" style="padding: 0">
<dialog-header
:tittle="dialogStatus == 'edit' ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
:close="closeDialog"
/>
</q-card-section>
<q-separator color="grey-4" />
<q-card-section class="row q-gutter-y-md">
<div class="col-12">
<q-input
outlined
ref="posLevelNameRef"
v-model="posLevelName"
label="ชื่อระดับตำแหน่ง"
dense
lazy-rules
borderless
bg-color="white"
hide-bottom-space
:rules="[(val) => val.length > 0 || 'กรุณากรอกระดับตำแหน่ง']"
/>
</div>
<div class="col-12">
<q-input
ref="posLevelRankRef"
outlined
v-model="posLevelRank"
label="ระดับ"
dense
lazy-rules
borderless
min="1"
bg-color="white"
:rules="[(val) => val > 0 || 'กรุณากรอกระดับ']"
hide-bottom-space
mask="############"
/>
</div>
<div class="col-12">
<q-select
ref="posLevelAuthorityRef"
outlined
v-model="posLevelAuthority"
emit-value
map-options
:options="storeOption.posLevelAuthorityOption"
option-value="id"
label="ผู้มีอำนาจสั่งบรรจุ"
dense
lazy-rules
:rules="[(val) => !!val || 'กรุณาเลือกผู้มีอำนาจสั่งบรรจุ']"
borderless
bg-color="white"
hide-bottom-space
/>
</div>
<div class="col-12">
<q-select
ref="posTypeIdRef"
v-model="posName"
label="ประเภทตำแหน่ง"
outlined
dense
bg-color="white"
options-cover
hide-bottom-space
readonly
/>
</div>
</q-card-section>
<q-card-actions align="right">
<q-btn
id="onSubmit"
type="submit"
dense
unelevated
label="บันทึก"
color="public"
class="q-px-md"
>
<q-tooltip>นทกขอม</q-tooltip>
</q-btn>
</q-card-actions>
</form>
</q-card>
</q-dialog>
</div>
</template>
<style scoped lang="scss">
.border_custom {
border-radius: 6px !important;
border: 1px solid #e1e1e1;
}
$toggle-background-color-on: #06884d;
$toggle-background-color-off: darkgray;
$toggle-control-color: white;
$toggle-width: 40px;
$toggle-height: 25px;
$toggle-gutter: 3px;
$toggle-radius: 50%;
$toggle-control-speed: 0.15s;
$toggle-control-ease: ease-in;
// These are our computed variables
// change at your own risk.
$toggle-radius: $toggle-height / 2;
$toggle-control-size: $toggle-height - ($toggle-gutter * 2);
.toggle-control {
display: block;
position: relative;
padding-left: $toggle-width;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
user-select: none;
input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
input:checked ~ .control {
background-color: $toggle-background-color-on;
&:after {
left: $toggle-width - $toggle-control-size - $toggle-gutter;
}
}
.control {
position: absolute;
top: -7px;
left: -15px;
height: $toggle-height;
width: $toggle-width;
border-radius: $toggle-radius;
background-color: $toggle-background-color-off;
transition: background-color $toggle-control-speed $toggle-control-ease;
&:after {
content: "";
position: absolute;
left: $toggle-gutter;
top: $toggle-gutter;
width: $toggle-control-size;
height: $toggle-control-size;
border-radius: $toggle-radius;
background: $toggle-control-color;
transition: left $toggle-control-speed $toggle-control-ease;
}
}
}
</style>

View file

@ -0,0 +1,214 @@
<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import type { QTableProps } from "quasar";
import DialogHeader from "@/components/DialogHeader.vue";
import type {
FormExecutiveRef,
RowListForm,
} from "@/modules/01_metadata/interface/request/position/index";
import { useCounterMixin } from "@/stores/mixin";
// import { bo } from "@fullcalendar/core/internal-common";
const { dialogConfirm, showLoader, success, hideLoader, messageError } =
useCounterMixin();
const formExecutive = reactive<RowListForm>({
id: "",
posExecutiveName: "",
posExecutivePriority: null,
});
const $q = useQuasar();
const isReadonly = ref<boolean>(false); //
const modal = defineModel<boolean>("executive", { required: true });
const formData = defineModel<any>("formData", { required: true });
const isEdit = defineModel<any>("edit", { required: true });
const posExecutiveNameRef = ref<Object | null>(null);
const posExecutivePriorityRef = ref<Object | null>(null);
const objectExecutiveRef: FormExecutiveRef = {
posExecutiveName: posExecutiveNameRef,
posExecutivePriority: posExecutivePriorityRef,
};
const props = defineProps({
getData: Function,
});
/** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */
function validateFormExecutive() {
const hasError = [];
for (const key in objectExecutiveRef) {
if (Object.prototype.hasOwnProperty.call(objectExecutiveRef, key)) {
const property = objectExecutiveRef[key];
if (property.value && typeof property.value.validate === "function") {
const isValid = property.value.validate();
hasError.push(isValid);
}
}
}
if (hasError.every((result) => result === true)) {
if (isEdit.value == false) {
onSubmit();
} else {
putSubmit();
}
}
}
/** ฟังชั่น บันทึก */
function onSubmit() {
dialogConfirm(
$q,
async () => {
showLoader();
const body = {
posExecutiveName: formExecutive.posExecutiveName,
posExecutivePriority: formExecutive.posExecutivePriority, //
};
await http
.post(config.API.orgPosExecutive, body)
.then(() => {
success($q, "เพิ่มข้อมูลสำเร็จ");
clearForm();
modal.value = false;
props.getData?.();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการเพิ่มตำแหน่ง",
"ต้องการยืนยันการเพิ่มตำแหน่งนี้ใช่หรือไม่?"
);
}
/** ฟังชั่น บันทึก */
function putSubmit() {
dialogConfirm(
$q,
async () => {
showLoader();
const body = {
posExecutiveName: formExecutive.posExecutiveName,
posExecutivePriority: formExecutive.posExecutivePriority, //
};
await http
.put(config.API.orgPosExecutive + `/${formExecutive.id}`, body)
.then(() => {
success($q, "เพิ่มข้อมูลสำเร็จ");
clearForm();
modal.value = false;
props.getData?.();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการเพิ่มตำแหน่ง",
"ต้องการยืนยันการเพิ่มตำแหน่งนี้ใช่หรือไม่?"
);
}
async function clearForm() {
formExecutive.id = "";
formExecutive.posExecutiveName = "";
formExecutive.posExecutivePriority = null;
isEdit.value = false;
}
/**
* งค css ออกไปตามเงอนไข
* @param val true/false
*/
function inputEdit(val: boolean) {
return {
"full-width cursor-pointer inputgreen ": val,
"full-width cursor-pointer inputgreen": !val,
};
}
function close() {
clearForm();
modal.value = false;
}
watch(
() => modal.value,
() => {
if (modal.value == true) {
const dataList = formData.value;
formExecutive.id = "";
formExecutive.posExecutiveName = "";
formExecutive.posExecutivePriority = null;
if (isEdit.value == true) {
formExecutive.id = dataList.id;
formExecutive.posExecutiveName = dataList.posExecutiveName;
formExecutive.posExecutivePriority = dataList.posExecutivePriority;
}
}
}
);
</script>
<template>
<q-dialog v-model="modal" persistent>
<q-card style="min-width: 50vw">
<form @submit.prevent="validateFormExecutive">
<DialogHeader
:tittle="
isEdit ? `แก้ไขตำแหน่งทางการบริหาร` : 'เพิ่มตำแหน่งทางการบริหาร'
"
:close="close"
/>
<q-separator />
<q-card-section>
<div class="row q-col-gutter-sm col-12">
<div class="col-6">
<q-input
ref="posExecutiveNameRef"
v-model="formExecutive.posExecutiveName"
:class="inputEdit(isReadonly)"
dense
outlined
for="#posExecutiveName"
label="ชื่อตำแหน่งทางการบริหาร"
lazy-rules
hide-bottom-space
:rules="[
(val) => !!val || `${'กรุณากรอกชื่อตำแหน่งทางการบริหาร'}`,
]"
/>
</div>
<div class="col-6">
<q-input
ref="posExecutivePriorityRef"
v-model="formExecutive.posExecutivePriority"
:class="inputEdit(isReadonly)"
dense
outlined
type="number"
for="#posExecutivePriority"
label="ลำดับความสำคัญ"
lazy-rules
hide-bottom-space
:rules="[(val) => !!val || `${'กรุณากรอกลำดับความสำคัญ'}`]"
/>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<q-btn type="submit" :label="`บันทึก`" color="public" />
</q-card-actions>
</form>
</q-card>
</q-dialog>
</template>

View file

@ -0,0 +1,404 @@
<script setup lang="ts">
import { ref, reactive, watch, defineProps } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import type { QTableProps } from "quasar";
import DialogHeader from "@/components/DialogHeader.vue";
import type {
DataOption,
FormPositionSelectDialog,
FormPositionSelectRef,
OptionType,
OptionLevel,
OptionExecutive,
} from "@/modules/01_metadata/interface/request/position/index";
import { useCounterMixin } from "@/stores/mixin";
const executiveOpsMain = ref<DataOption[]>([]);
const levelOps = ref<DataOption[]>([]);
const levelOpsMain = ref<DataOption[]>([]);
const typeOps = ref<DataOption[]>([]);
const typeOpsMain = ref<DataOption[]>([]);
const dataLevel = ref<any>();
const executiveOps = ref<DataOption[]>([]);
const formPositionSelect = reactive<FormPositionSelectDialog>({
positionId: "",
positionName: "",
positionField: "",
positionType: "",
positionLevel: "",
positionExecutive: "",
positionExecutiveField: "",
positionArea: "",
});
const $q = useQuasar();
const isSpecial = ref<boolean>(false);
const props = defineProps({
getData: Function,
});
const { dialogConfirm, showLoader, success, hideLoader, messageError } =
useCounterMixin();
const isReadonly = ref<boolean>(false); //
const modal = defineModel<boolean>("addPosition", { required: true });
const formData = defineModel<any>("formData", { required: true });
const editCheck = defineModel<boolean>("editCheck", { required: true });
const positionNameRef = ref<Object | null>(null);
const positionFieldRef = ref<Object | null>(null);
const positionTypeRef = ref<Object | null>(null);
const positionLevelRef = ref<Object | null>(null);
const positionExecutiveRef = ref<Object | null>(null);
const positionExecutiveFieldRef = ref<Object | null>(null);
const positionAreaRef = ref<Object | null>(null);
const objectPositionSelectRef: FormPositionSelectRef = {
positionName: positionNameRef,
positionField: positionFieldRef,
positionType: positionTypeRef,
positionLevel: positionLevelRef,
positionExecutive: positionExecutiveRef,
positionExecutiveField: positionExecutiveFieldRef,
positionArea: positionAreaRef,
};
/** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */
function validateFormPositionEdit() {
const hasError = [];
for (const key in objectPositionSelectRef) {
if (Object.prototype.hasOwnProperty.call(objectPositionSelectRef, key)) {
const property = objectPositionSelectRef[key];
if (property.value && typeof property.value.validate === "function") {
const isValid = property.value.validate();
hasError.push(isValid);
}
}
}
if (hasError.every((result) => result === true)) {
if (editCheck.value == true) {
saveSelectEdit();
} else {
onSubmitSelectEdit();
}
}
}
/** ฟังชั่น บันทึก */
function saveSelectEdit() {
console.log(formPositionSelect.positionExecutive);
console.log(formPositionSelect.positionArea);
dialogConfirm(
$q,
async () => {
showLoader();
const body = {
posDictName: formPositionSelect.positionName,
posDictField: formPositionSelect.positionField, //
posTypeId: formPositionSelect.positionType, //*
posLevelId: formPositionSelect.positionLevel, //*
posExecutiveId: formPositionSelect.positionExecutive, //
posDictExecutiveField: formPositionSelect.positionExecutiveField, //
posDictArea: formPositionSelect.positionArea, ///
isSpecial: isSpecial.value,
};
await http
.put(config.API.orgPosPositionById(formPositionSelect.positionId), body)
.then(() => {
success($q, "เพิ่มข้อมูลสำเร็จ");
clearFormPositionSelect();
modal.value = false;
editCheck.value = false;
props.getData?.();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการเพิ่มตำแหน่ง",
"ต้องการยืนยันการเพิ่มตำแหน่งนี้ใช่หรือไม่?"
);
}
/** ฟังชั่น บันทึก */
function onSubmitSelectEdit() {
dialogConfirm(
$q,
async () => {
showLoader();
const body = {
posDictName: formPositionSelect.positionName,
posDictField: formPositionSelect.positionField, //
posTypeId: formPositionSelect.positionType, //*
posLevelId: formPositionSelect.positionLevel, //*
posExecutiveId: formPositionSelect.positionExecutive,
posDictExecutiveField: formPositionSelect.positionExecutiveField, //
posDictArea: formPositionSelect.positionArea, ///
isSpecial: isSpecial.value,
};
await http
.post(config.API.orgPosPosition, body)
.then(() => {
success($q, "เพิ่มข้อมูลสำเร็จ");
clearFormPositionSelect();
modal.value = false;
editCheck.value = false;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการเพิ่มตำแหน่ง",
"ต้องการยืนยันการเพิ่มตำแหน่งนี้ใช่หรือไม่?"
);
}
async function clearFormPositionSelect() {
formPositionSelect.positionId = "";
formPositionSelect.positionName = "";
formPositionSelect.positionField = "";
formPositionSelect.positionType = "";
formPositionSelect.positionLevel = "";
formPositionSelect.positionExecutive = "";
formPositionSelect.positionExecutiveField = "";
formPositionSelect.positionArea = "";
}
/**
* งค css ออกไปตามเงอนไข
* @param val true/false
*/
function inputEdit(val: boolean) {
return {
"full-width cursor-pointer inputgreen ": val,
"full-width cursor-pointer inputgreen": !val,
};
}
/** function เรียกรายการประเภทตำแหน่ง */
async function fetchType() {
showLoader();
await http
.get(config.API.orgPosType)
.then((res) => {
const data = res.data.result;
dataLevel.value = data;
typeOpsMain.value = data.map((e: OptionType) => ({
id: e.id,
name: e.posTypeName,
}));
typeOps.value = typeOpsMain.value;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/** function เรียกรายการตำแหน่งทางการบริหาร */
async function fetchExecutive() {
showLoader();
await http
.get(config.API.orgPosExecutive)
.then((res) => {
executiveOpsMain.value = res.data.result.map((e: OptionExecutive) => ({
id: e.id,
name: e.posExecutiveName,
}));
executiveOps.value = executiveOpsMain.value;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
watch(
() => modal.value,
() => {
if (modal.value == true) {
fetchType();
fetchExecutive();
if (formData.value) {
const dataList = formData.value;
setTimeout(() => {
updateSelectType(dataList.posTypeId);
}, 1000);
formPositionSelect.positionId = dataList.positionId;
formPositionSelect.positionName = dataList.positionName;
formPositionSelect.positionField = dataList.positionField;
formPositionSelect.positionType = dataList.positionType;
formPositionSelect.positionLevel = dataList.positionLevel;
formPositionSelect.positionExecutive = dataList.positionExecutive;
formPositionSelect.positionExecutiveField =
dataList.positionExecutiveField;
formPositionSelect.positionArea = dataList.positionArea;
isSpecial.value = dataList.isSpecial;
}
}
}
);
function updateSelectType(val: string) {
const listLevel = dataLevel.value.find((e: any) => e.id === val);
levelOpsMain.value = listLevel.posLevels.map((e: OptionLevel) => ({
id: e.id,
name: e.posLevelName,
}));
levelOps.value = levelOpsMain.value;
}
function close() {
modal.value = false;
editCheck.value = false;
}
</script>
<template>
<q-dialog v-model="modal" persistent>
<q-card style="min-width: 50vw">
<form @submit.prevent="validateFormPositionEdit">
<DialogHeader
:tittle="`${editCheck ? 'แก้ไขข้อมูลตำแหน่ง' : 'เพิ่มข้อมูลตำแหน่ง'}`"
:close="close"
/>
<q-separator />
<q-card-section>
<div class="row q-col-gutter-sm col-12">
<div class="col-12">
<q-input
ref="positionNameRef"
v-model="formPositionSelect.positionName"
:class="inputEdit(isReadonly)"
dense
outlined
for="#positionName"
label="ตำแหน่งในสายงาน"
lazy-rules
hide-bottom-space
:rules="[(val) => !!val || `${'กรุณากรอกตำแหน่งในสายงาน'}`]"
/>
</div>
<div class="col-6">
<q-input
ref="positionAreaRef"
v-model="formPositionSelect.positionArea"
:class="inputEdit(isReadonly)"
dense
outlined
for="#positionArea"
label="ด้าน/สาขา"
lazy-rules
hide-bottom-space
/>
</div>
<div class="col-6">
<q-input
ref="positionFieldRef"
v-model="formPositionSelect.positionField"
:class="inputEdit(isReadonly)"
dense
outlined
for="#positionField"
label="สายงาน"
lazy-rules
hide-bottom-space
:rules="[(val) => !!val || `${'กรุณากรอกสายงาน'}`]"
/>
</div>
<div class="col-6">
<q-select
ref="positionTypeRef"
:class="inputEdit(isReadonly)"
label="ประเภทตำแหน่ง"
v-model="formPositionSelect.positionType"
:options="typeOps"
emit-value
dense
@update:model-value="updateSelectType"
map-options
outlined
option-label="name"
option-value="id"
lazy-rules
hide-bottom-space
:rules="[(val) => !!val || `${'กรุณาเลือกประเภทตำแหน่ง'}`]"
/>
</div>
<div class="col-6">
<q-select
ref="positionLevelRef"
:class="inputEdit(isReadonly)"
label="ระดับตำแหน่ง"
v-model="formPositionSelect.positionLevel"
:disable="formPositionSelect.positionType === ''"
:options="levelOps"
emit-value
dense
map-options
outlined
option-label="name"
option-value="id"
lazy-rules
hide-bottom-space
:rules="[(val) => !!val || `${'กรุณาเลือกระดับตำแหน่ง'}`]"
/>
</div>
<div class="col-6">
<q-select
ref="positionExecutiveRef"
:class="inputEdit(isReadonly)"
label="ตำแหน่งทางการบริหาร"
v-model="formPositionSelect.positionExecutive"
:options="executiveOps"
emit-value
dense
map-options
outlined
option-label="name"
option-value="id"
lazy-rules
hide-bottom-space
clearable
/>
</div>
<div class="col-6">
<q-input
ref="positionExecutiveFieldRef"
v-model="formPositionSelect.positionExecutiveField"
:class="inputEdit(isReadonly)"
dense
outlined
for="#positionExecutiveField"
label="ด้านทางการบริหาร"
lazy-rules
hide-bottom-space
/>
</div>
<div class="col-6 self-center">
<q-checkbox
size="md"
v-model="isSpecial"
label="เฉพาะสายงานที่กำหนด"
/>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<q-btn type="submit" :label="`บันทึก`" color="public" />
</q-card-actions>
</form>
</q-card>
</q-dialog>
</template>