2024-09-11 15:59:04 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, watch } from "vue";
|
|
|
|
|
import { useQuasar } from "quasar";
|
|
|
|
|
|
|
|
|
|
import { useRouter } from "vue-router";
|
2024-09-30 16:18:46 +07:00
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
|
import { useCommandListStore } from "@/modules/18_command/store/ListStore";
|
2024-09-11 15:59:04 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
|
|
|
|
|
2024-09-12 17:11:00 +07:00
|
|
|
import type { FormCommand } from "@/modules/18_command/interface/request/Main";
|
|
|
|
|
import type { DataCommandType } from "@/modules/18_command/interface/response/Main";
|
2024-09-11 15:59:04 +07:00
|
|
|
|
|
|
|
|
import DialogHeader from "@/components/DialogHeader.vue";
|
|
|
|
|
|
|
|
|
|
const $q = useQuasar();
|
|
|
|
|
const router = useRouter();
|
2024-09-30 16:18:46 +07:00
|
|
|
const store = useCommandListStore();
|
2024-09-12 17:11:00 +07:00
|
|
|
const { dialogConfirm, showLoader, hideLoader, messageError, success } =
|
2024-09-11 15:59:04 +07:00
|
|
|
useCounterMixin();
|
|
|
|
|
|
2024-09-30 16:18:46 +07:00
|
|
|
/** props*/
|
|
|
|
|
const modal = defineModel<boolean>("modal", { required: true }); //เปิด,ปิด Popup
|
|
|
|
|
const isCopy = defineModel<boolean>("isCopy", { required: true }); //สถานะทำสำเนา
|
|
|
|
|
const commandId = defineModel<string>("commandId", { default: "" }); // id ประเภทคำสั่งที่คำสำเนา
|
2024-09-11 15:59:04 +07:00
|
|
|
|
2024-09-30 16:18:46 +07:00
|
|
|
const commandType = ref<string>(""); //ประเภทคำสั่ง
|
|
|
|
|
const commandNo = ref<string>(""); //คำสั่งเลขที่
|
|
|
|
|
const commandYear = ref<number>(new Date().getFullYear()); //ปี
|
2024-09-11 15:59:04 +07:00
|
|
|
|
2024-09-30 16:18:46 +07:00
|
|
|
const listCommand = ref<DataCommandType[]>([]); //ข้อมูลรายการประเภทคำสั่ง
|
|
|
|
|
const commandOp = ref<DataCommandType[]>([]); //ตัวเลือกประเภทคำสั่ง
|
2024-09-11 15:59:04 +07:00
|
|
|
|
2024-09-30 16:18:46 +07:00
|
|
|
/** ฟังก์ชันดึงข้อมูลปรเภทคำสั่ง*/
|
2024-09-11 15:59:04 +07:00
|
|
|
async function fetchCommandType() {
|
2024-09-30 16:18:46 +07:00
|
|
|
const data = await store.fetchCommandType();
|
|
|
|
|
if (data) {
|
|
|
|
|
listCommand.value = data;
|
|
|
|
|
commandOp.value = data;
|
|
|
|
|
}
|
2024-09-11 15:59:04 +07:00
|
|
|
}
|
|
|
|
|
|
2024-09-30 16:18:46 +07:00
|
|
|
/** ฟังก์ชันยืนยันการบันทึกข้อมูล */
|
2024-09-11 15:59:04 +07:00
|
|
|
function onSubmit() {
|
|
|
|
|
dialogConfirm($q, () => {
|
2024-09-12 17:11:00 +07:00
|
|
|
showLoader();
|
|
|
|
|
const body: FormCommand = {
|
|
|
|
|
commandYear: commandYear.value,
|
|
|
|
|
commandNo: commandNo.value,
|
|
|
|
|
commandTypeId: !isCopy.value ? commandType.value : undefined,
|
|
|
|
|
};
|
|
|
|
|
const path = !isCopy.value
|
|
|
|
|
? config.API.command
|
|
|
|
|
: config.API.commandAction(commandId.value, "copy");
|
|
|
|
|
|
|
|
|
|
http[!isCopy.value ? "post" : "put"](path, body)
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
const id = await res.data.result;
|
|
|
|
|
router.push(`/command/edit/${id}`);
|
|
|
|
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
|
|
|
|
onClose();
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
2024-09-11 15:59:04 +07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 16:18:46 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังก์ชันค้นหาข้อมูลรายการประเภทคำสั่ง
|
|
|
|
|
* @param val คำที่ค้องการค้นหา
|
|
|
|
|
* @param update function จาก quasar
|
|
|
|
|
*/
|
|
|
|
|
function filterSelector(val: string, update: Function) {
|
|
|
|
|
update(() => {
|
|
|
|
|
commandOp.value = listCommand.value.filter(
|
|
|
|
|
(v: any) => v.name.indexOf(val) > -1
|
|
|
|
|
);
|
|
|
|
|
});
|
2024-09-11 15:59:04 +07:00
|
|
|
}
|
|
|
|
|
|
2024-09-30 16:18:46 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังก์ชันปิด Popup
|
|
|
|
|
* และกำหนด commandNo commandYear เป็นค่า Defult
|
|
|
|
|
* */
|
2024-09-11 15:59:04 +07:00
|
|
|
function onClose() {
|
|
|
|
|
modal.value = false;
|
|
|
|
|
commandNo.value = "";
|
2024-12-02 17:02:54 +07:00
|
|
|
commandType.value = "";
|
2024-09-12 17:11:00 +07:00
|
|
|
commandYear.value = new Date().getFullYear();
|
2024-09-11 15:59:04 +07:00
|
|
|
}
|
|
|
|
|
|
2024-09-30 16:18:46 +07:00
|
|
|
/**
|
|
|
|
|
* ดูการเปลี่ยนแปลงของ modal
|
|
|
|
|
* เมื่อ modal เป็น True และ isCopy เป็น False จะเรียก ฟังก์ชัน fetchCommandType เพื่อดึงข้อมูลปรเภทคำสั่ง
|
|
|
|
|
*/
|
2024-09-11 15:59:04 +07:00
|
|
|
watch(modal, () => {
|
2024-09-30 16:18:46 +07:00
|
|
|
//เช็คค่าของ modal และ isCopy
|
2024-09-11 15:59:04 +07:00
|
|
|
if (modal.value && !isCopy.value) {
|
|
|
|
|
fetchCommandType();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<q-dialog v-model="modal" persistent>
|
|
|
|
|
<q-card style="max-width: 35%">
|
|
|
|
|
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
|
|
|
|
<DialogHeader
|
|
|
|
|
:tittle="isCopy ? 'ทำสำเนาคำสั่ง' : 'เพิ่มคำสั่ง'"
|
|
|
|
|
:close="onClose"
|
|
|
|
|
/>
|
|
|
|
|
<q-separator />
|
|
|
|
|
<q-card-section>
|
|
|
|
|
<div class="row q-col-gutter-sm">
|
|
|
|
|
<div class="col-12" v-if="!isCopy">
|
|
|
|
|
<q-select
|
|
|
|
|
class="inputgreen"
|
|
|
|
|
v-model="commandType"
|
|
|
|
|
:label="`${'ประเภทคำสั่ง'}`"
|
|
|
|
|
dense
|
|
|
|
|
emit-value
|
|
|
|
|
map-options
|
|
|
|
|
option-label="name"
|
|
|
|
|
:options="commandOp"
|
|
|
|
|
option-value="id"
|
|
|
|
|
lazy-rules
|
|
|
|
|
use-input
|
2024-12-02 17:02:54 +07:00
|
|
|
hide-selected
|
|
|
|
|
fill-input
|
2024-09-11 15:59:04 +07:00
|
|
|
hide-bottom-space
|
|
|
|
|
outlined
|
2024-09-24 17:16:27 +07:00
|
|
|
:rules="[(val:string) => !!val || `${'กรุณาเลือกประเภทคำสั่ง'}`]"
|
2024-12-02 17:02:54 +07:00
|
|
|
@filter="(inputValue:string,
|
2024-09-30 16:18:46 +07:00
|
|
|
doneFn:Function) => filterSelector(inputValue, doneFn) "
|
2024-09-11 15:59:04 +07:00
|
|
|
>
|
|
|
|
|
<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"
|
|
|
|
|
hide-bottom-space
|
|
|
|
|
:label="`${'คำสั่งเลขที่'}`"
|
|
|
|
|
lazy-rules
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<label class="col-1 flex justify-center items-center text-bold"
|
|
|
|
|
>/</label
|
|
|
|
|
>
|
|
|
|
|
<div class="col-5">
|
2024-09-12 17:11:00 +07:00
|
|
|
<datepicker
|
|
|
|
|
menu-class-name="modalfix"
|
2024-09-11 15:59:04 +07:00
|
|
|
v-model="commandYear"
|
2024-09-12 17:11:00 +07:00
|
|
|
: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
|
|
|
|
|
"
|
2025-10-09 17:02:11 +07:00
|
|
|
label="ปี พ.ศ."
|
|
|
|
|
:rules="[(val:string) => !!val || 'กรุณากรอกปี พ.ศ.']"
|
2024-09-12 17:11:00 +07:00
|
|
|
>
|
|
|
|
|
<template v-slot:prepend>
|
|
|
|
|
<q-icon
|
|
|
|
|
name="event"
|
|
|
|
|
class="cursor-pointer"
|
|
|
|
|
style="color: var(--q-primary)"
|
|
|
|
|
>
|
|
|
|
|
</q-icon>
|
|
|
|
|
</template>
|
|
|
|
|
</q-input>
|
|
|
|
|
</template>
|
|
|
|
|
</datepicker>
|
2024-09-11 15:59:04 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</q-card-section>
|
|
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
|
|
<q-card-actions align="right">
|
|
|
|
|
<q-btn label="บันทึก" color="public" type="submit" />
|
|
|
|
|
</q-card-actions>
|
|
|
|
|
</q-form>
|
|
|
|
|
</q-card>
|
|
|
|
|
</q-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|