hrms-mgt/src/modules/18_command/components/DialogCreateCommandORG.vue

562 lines
18 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { nextTick, ref, watch, computed } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import { useCommandMainStore } from "@/modules/18_command/store/Main";
/** importType*/
import type { QTableProps } from "quasar";
import type {
ListCommand,
DataOption,
} from "@/modules/18_command/interface/index/Main";
import DialogHeader from "@/components/DialogHeader.vue";
const storeCommand = useCommandMainStore();
const router = useRouter();
const $q = useQuasar();
const mixin = useCounterMixin();
const {
showLoader,
success,
messageError,
dialogConfirm,
hideLoader,
date2Thai,
} = mixin;
const modal = defineModel<boolean>("modal", { required: true });
const isOfficer = defineModel<boolean>("isOfficer");
const isStaff = defineModel<boolean>("isStaff");
const rootId = defineModel<string>("rootId");
const props = defineProps({
commandTypeCode: String, // ไอดีประเภทคำสั่ง
2024-10-21 10:50:01 +07:00
systemName: String, // ไอดีประเภทคำสั่ง
orgPublishDate: { type: Date || undefined, defult: undefined },
});
const commandOp = ref<ListCommand[]>([]); // ประเภทคำสั่ง
const commandType = ref<string>(""); //ประเภทคำสั่ง
const commandNo = ref<string>(""); //คำสั่งเลขที่
const commandYear = ref<number>(new Date().getFullYear());
const commandAffectDate = ref<Date | null>(null); //วันที่ลงนาม
const commandExcecuteDate = ref<Date | null>(null); //วันที่คำสั่งมีผล
2024-10-18 13:22:42 +07:00
const group = ref<string>("GROUP1.1"); //กลุ่ม
const isCheckOrgPublishDate = ref<boolean>(false); //เช็คค่าของวันที่คำสั่งมีผล
const groupDataOp = ref<DataOption[]>([
{
2024-10-18 13:22:42 +07:00
id: "GROUP1.1",
name: "กลุ่มที่ 1.1 : ปฏิบัติงาน ชำนาญงาน ปฏิบัติการ ชำนาญการ",
},
{
id: "GROUP1.2",
name: "กลุ่มที่ 1.2 : อาวุโส ชำนาญการพิเศษ อำนวยการต้น",
},
{
id: "GROUP2",
name: "กลุ่มที่ 2 : ทักษะพิเศษ เชี่ยวชาญ ทรงคุณวุฒิ อำนวยการสูง บริหารต้น บริหารสูง",
},
]);
const groupOp = ref<DataOption[]>(groupDataOp.value);
const dataMapToSend = computed(() => {
return selected.value.map((i: any) => ({
refId: i.id,
profileId: i.profileId,
prefix: i.prefix,
firstName: i.firstName,
lastName: i.lastName,
citizenId: i.citizenId,
}));
});
//Table
const rows = ref<any[]>([]);
const selected = ref<any[]>([]);
const columns = ref<QTableProps["columns"]>([
{
name: "posMasterNo",
align: "left",
label: "ตำแหน่งเลขที่",
sortable: false,
field: "posMasterNo",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionName",
align: "left",
label: "ตำแหน่งในสายงาน",
field: "positionName",
sortable: false,
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posType",
align: "left",
label: "ประเภทตำแหน่ง",
sortable: false,
field: "posType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posLevel",
align: "left",
label: "ระดับตำแหน่ง",
sortable: false,
field: "posLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionIsSelected",
align: "left",
label: "คนครอง",
sortable: false,
field: "positionIsSelected",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
/** ฟังก์ชันบันทึกและไปยังหน้าคำสั่ง*/
function onSubmit() {
dialogConfirm($q, async () => {
showLoader();
const body = {
commandTypeId: commandType.value,
commandAffectDate: commandAffectDate.value,
commandExcecuteDate: commandExcecuteDate.value,
commandYear: commandYear.value,
commandNo: commandNo.value,
persons: selected.value ? dataMapToSend.value : [],
};
await http
.post(config.API.command + `/person`, body)
.then(async (res) => {
const id = await res.data.result;
router.push(`/command/edit/${id}`);
modal.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
}
/**
* งกนป popup สรางคำส
* และกำหนดตวแปรใหเปนค Defult
*/
function closeModal() {
modal.value = false;
commandNo.value = "";
commandYear.value = new Date().getFullYear();
commandAffectDate.value = null;
commandExcecuteDate.value = null;
2024-10-18 13:22:42 +07:00
group.value = "GROUP1.1";
isCheckOrgPublishDate.value = false;
rows.value = [];
selected.value = [];
}
/** ฟังก์ชันดึงข้อมูลคำสั่ง */
async function fetchCommandType() {
const data = await storeCommand.getCommandTypes(); // ยิงไป get ที่ store
// filter เฉพาะ code ของคำสั่งที่เลือก
commandOp.value = await data.filter(
(v: ListCommand) => v.code == props.commandTypeCode
);
commandType.value = commandOp.value[0].id;
}
/**
* งกนตนหาขอมลของ Option ขอสถานะ
* @param val าทองการฟลเตอร
* @param update พเดทค
* @param refData ดาตาทองการฟลเตอร
*/
function filterOption(val: string, update: Function) {
update(() => {
group.value = val ? "" : group.value;
groupOp.value = groupDataOp.value.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
}
/**
* งกนเลอกกล
* @param val กลมทองการคนหา
*/
function updateGroup() {
getPerson();
}
/** ดึงข้อมูลคน */
function getPerson() {
const body = {
rootId: rootId.value ? rootId.value : "",
type: group.value,
};
showLoader();
http
.post(config.API.orgPosReport, body)
.then((res) => {
const data = res.data.result;
rows.value = data;
hideLoader();
})
.catch((e) => {
messageError($q, e);
hideLoader();
})
.finally(() => {});
}
watch(modal, async () => {
if (modal.value) {
fetchCommandType();
if (props.orgPublishDate) {
commandExcecuteDate.value = props.orgPublishDate;
isCheckOrgPublishDate.value = true;
}
await nextTick();
if (isOfficer.value) {
group.value = "GROUP1.2";
groupDataOp.value = groupDataOp.value.filter(
2024-10-18 13:22:42 +07:00
(item) => item.id !== "GROUP1.1"
);
}
getPerson();
}
});
</script>
<template>
<q-dialog v-model="modal" persistent>
<q-card style="min-width: 50vw">
<q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader :tittle="'สร้างคำสั่ง'" :close="closeModal" />
<q-separator />
<q-card-section style="max-height: 50vh" class="scroll">
<div class="row q-sm q-col-gutter-sm">
<div class="col-12">
<q-select
v-model="commandType"
:label="`${'ประเภทคำสั่ง'}`"
option-label="name"
:options="commandOp"
option-value="id"
dense
emit-value
map-options
lazy-rules
use-input
hide-bottom-space
outlined
readonly
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<!-- คำสงเลขท -->
<div class="col-6">
<q-input
class="inputgreen"
outlined
dense
hide-bottom-space
v-model="commandNo"
:label="`${'คำสั่งเลขที่'}`"
:rules="[(val:string) => !!val || `${'กรุณากรอกคำสั่งเลขที่'}`]"
/>
</div>
<label class="col-1 flex justify-center items-center text-bold"
>/</label
>
<!-- . -->
<div class="col-5">
<datepicker
menu-class-name="modalfix"
v-model="commandYear"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
class="inputgreen"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
outlined
hide-bottom-space
:model-value="
commandYear == null ? null : commandYear + 543
"
:label="`${'พ.ศ.'}`"
:rules="[(val:string) => !!val || `${'กรุณากรอก พ.ศ.'}`]"
>
<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-6">
<datepicker
clearable
menu-class-name="modalfix"
v-model="commandAffectDate"
:locale="'th'"
autoApply
:enableTimePicker="false"
class="inputgreen"
>
<template #year="{ year }">
{{ year + 543 }}
</template>
<template #year-overlay-value="{ value }">
{{ parseInt(value + 543) }}
</template>
<template #trigger>
<q-input
clearable
dense
outlined
hide-bottom-space
:model-value="
commandAffectDate == null
? null
: date2Thai(commandAffectDate)
"
:label="`${'วันที่ลงนาม'}`"
@clear="() => (commandAffectDate = null)"
>
<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-6">
<datepicker
clearable
menu-class-name="modalfix"
v-model="commandExcecuteDate"
:locale="'th'"
autoApply
:enableTimePicker="false"
:class="!isCheckOrgPublishDate ? 'inputgreen' : ''"
:readonly="isCheckOrgPublishDate"
>
<template #year="{ year }">
{{ year + 543 }}
</template>
<template #year-overlay-value="{ value }">
{{ parseInt(value + 543) }}
</template>
<template #trigger>
<q-input
:readonly="isCheckOrgPublishDate"
clearable
dense
outlined
hide-bottom-space
:class="!isCheckOrgPublishDate ? 'inputgreen' : ''"
:model-value="
commandExcecuteDate == null
? null
: date2Thai(commandExcecuteDate)
"
:label="`${'วันที่คำสั่งมีผล'}`"
@clear="() => (commandExcecuteDate = null)"
>
<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-select
v-model="group"
:label="`${'กลุ่ม'}`"
option-label="name"
:options="groupOp"
option-value="id"
class="inputgreen"
dense
:readonly="isStaff"
emit-value
map-options
use-input
outlined
@update:model-value="updateGroup"
@filter="(inputValue:any,doneFn:Function) => filterOption(inputValue, doneFn) "
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<!-- TABLE -->
<div class="col-12">
<d-table
ref="table"
:columns="columns"
:rows="rows"
:paging="true"
row-key="id"
flat
bordered
dense
:rows-per-page-options="[10, 25, 50, 100]"
selection="multiple"
v-model:selected="selected"
>
<template v-slot:header-selection="scope">
<q-checkbox
keep-color
color="primary"
dense
v-model="scope.selected"
/>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<q-td>
<q-checkbox
keep-color
color="primary"
dense
v-model="props.selected"
/>
</q-td>
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div v-if="col.name === 'posMasterNo'">
{{
props.row.isSit
? col.value + " " + "(นั่งทับตำแหน่ง)"
: col.value
}}
</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-if="col.name === 'positionIsSelected'">
{{
props.row.firstName
? `${props.row.prefix}${props.row.firstName} ${props.row.lastName}`
: "-"
}}
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>
</template>
<!-- <template v-slot:pagination="scope">
<q-pagination
v-model="reqMaster.page"
active-color="primary"
color="dark"
:max="totalPage"
:max-pages="5"
size="sm"
boundary-links
direction-links
></q-pagination>
</template> -->
</d-table>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right">
<q-btn
label="ส่งไปออกคำสั่ง"
:disable="
commandType == '' ||
selected.length === 0 ||
!commandNo ||
!commandYear
"
type="submit"
color="public"
>
<q-tooltip>นทกและไปยงหนาคำส</q-tooltip>
</q-btn>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
</template>
<style scoped></style>