2024-09-30 13:30:45 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, watch } 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";
|
|
|
|
|
|
|
|
|
|
import type { ListCommand } 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 props = defineProps({
|
|
|
|
|
commandTypeCode: String, // ไอดีประเภทคำสั่ง
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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-08 10:35:55 +07:00
|
|
|
/** ฟังก์ชันบันทึกและไปยังหน้าคำสั่ง*/
|
2024-09-30 13:30:45 +07:00
|
|
|
function onSubmit() {
|
2024-10-08 10:35:55 +07:00
|
|
|
dialogConfirm($q, async () => {
|
|
|
|
|
showLoader();
|
|
|
|
|
const body = {
|
|
|
|
|
commandYear: commandYear.value,
|
|
|
|
|
commandNo: commandNo.value,
|
|
|
|
|
commandTypeId: commandType.value,
|
|
|
|
|
commandAffectDate: commandAffectDate.value,
|
|
|
|
|
commandExcecuteDate: commandExcecuteDate.value,
|
|
|
|
|
persons: [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-09-30 13:30:45 +07:00
|
|
|
}
|
|
|
|
|
|
2024-10-08 10:35:55 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังก์ชันปิด popup สร้างคำสั่ง
|
|
|
|
|
* และกำหนดตัวแปรให้เป็นค่า Defult
|
|
|
|
|
*/
|
2024-09-30 13:30:45 +07:00
|
|
|
function closeModal() {
|
|
|
|
|
modal.value = false;
|
|
|
|
|
commandNo.value = "";
|
|
|
|
|
commandYear.value = new Date().getFullYear();
|
|
|
|
|
commandAffectDate.value = null;
|
|
|
|
|
commandExcecuteDate.value = null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 10:35:55 +07:00
|
|
|
/** ฟังก์ชันดึงข้อมูลคำสั่ง */
|
2024-09-30 13:30:45 +07:00
|
|
|
async function fetchCommandType() {
|
|
|
|
|
const data = await storeCommand.getCommandTypes(); // ยิงไป get ที่ store
|
|
|
|
|
// filter เฉพาะ code ของคำสั่งที่เลือก
|
|
|
|
|
commandOp.value = await data.filter(
|
2024-10-08 10:35:55 +07:00
|
|
|
(v: ListCommand) => v.code == props.commandTypeCode
|
2024-09-30 13:30:45 +07:00
|
|
|
);
|
|
|
|
|
commandType.value = commandOp.value[0].id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(modal, () => {
|
|
|
|
|
if (modal.value) {
|
|
|
|
|
fetchCommandType();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</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
|
|
|
|
|
v-model="commandNo"
|
|
|
|
|
:label="`${'คำสั่งเลขที่'}`"
|
|
|
|
|
/>
|
|
|
|
|
</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="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
|
|
|
|
|
class="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>
|
|
|
|
|
</q-card-section>
|
|
|
|
|
|
|
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
|
|
<q-card-actions align="right">
|
|
|
|
|
<q-btn
|
|
|
|
|
label="บันทึกและไปยังหน้าคำสั่ง"
|
|
|
|
|
:disable="commandType == ''"
|
|
|
|
|
type="submit"
|
|
|
|
|
color="public"
|
|
|
|
|
>
|
|
|
|
|
<q-tooltip>บันทึกและไปยังหน้าคำสั่ง</q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
</q-card-actions>
|
|
|
|
|
</q-form>
|
|
|
|
|
</q-card>
|
|
|
|
|
</q-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|