hrms-mgt/src/modules/11_discipline/components/4_Order/Step01.vue
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 cfc073e30c ปรับ interfeac
2023-10-19 15:39:18 +07:00

329 lines
11 KiB
Vue

<script setup lang="ts">
import { ref, reactive } from "vue";
import { useQuasar } from "quasar";
import type { DataOption } from "@/modules/11_discipline/interface/index/Main";
import type {
FormData,
MyObjectRef,
} from "@/modules/11_discipline/interface/request/order";
// importStroe
import { useCounterMixin } from "@/stores/mixin";
const mixin = useCounterMixin();
const { date2Thai, dialogConfirm } = mixin;
const $q = useQuasar();
const props = defineProps({
next: {
type: Function,
default: () => console.log("not function"),
},
previous: {
type: Function,
default: () => console.log("not function"),
},
});
const next = () => props.next();
// Options ต่างๆ
const orderTypeOptions = ref<DataOption[]>([
{ id: "0", name: "ประเภทคำสั่ง 1" },
{ id: "1", name: "ประเภทคำสั่ง 2" },
{ id: "2", name: "ประเภทคำสั่ง 3" },
]);
const orderByOptions = ref<DataOption[]>([
{ id: "0", name: "คำสั่งโดย 1" },
{ id: "1", name: "คำสั่งโดย 2" },
{ id: "2", name: "คำสั่งโดย 3" },
]);
const listInvestigationOptions = ref<DataOption[]>([
{ id: "0", name: "รายการสอบสวนความผิดทางวินัย 1" },
{ id: "1", name: "รายการสอบสวนความผิดทางวินัย 2" },
{ id: "2", name: "รายการสอบสวนความผิดทางวินัย 3" },
]);
// ตัวแปรทั้งหมด
const formData = reactive<FormData>({
orderType: "",
orderBy: "",
listInvestigation: "",
authority: "",
orderNumber: "",
dateYear: 0,
date: null,
authorityPosition: "",
subject: "",
mistakeDetail: "",
});
// validateForm
const orderTypeRef = ref<Object | null>(null);
const orderByRef = ref<Object | null>(null);
const listInvestigationRef = ref<Object | null>(null);
const authorityRef = ref<Object | null>(null);
const orderNumberRef = ref<Object | null>(null);
const dateYearRef = ref<Object | null>(null);
const dateRef = ref<Object | null>(null);
const authorityPositionRef = ref<Object | null>(null);
const subjectRef = ref<Object | null>(null);
const mistakeDetailRef = ref<Object | null>(null);
const myObjectRef: MyObjectRef = {
orderType: orderTypeRef,
orderBy: orderByRef,
listInvestigation: listInvestigationRef,
authority: authorityRef,
orderNumber: orderNumberRef,
dateYear: dateYearRef,
date: dateRef,
authorityPosition: authorityPositionRef,
subject: subjectRef,
mistakeDetail: mistakeDetailRef,
};
function validateForm() {
const hasError = [];
for (const key in myObjectRef) {
if (Object.prototype.hasOwnProperty.call(myObjectRef, key)) {
const property = myObjectRef[key];
if (property.value && typeof property.value.validate === "function") {
const isValid = property.value.validate();
hasError.push(isValid);
}
}
}
if (hasError.every((result) => result === true)) {
onSubmit();
} else {
console.log("ไม่ผ่าน ");
}
}
function onSubmit() {
console.log(formData);
dialogConfirm(
$q,
async () => {
next();
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่"
);
}
</script>
<template>
<form @submit.prevent.stop="validateForm">
<div class="col-12 row q-pa-lg">
<div class="col-xs-12 col-sm-12 q-col-gutter-x-lg row q-col-gutter-y-xs">
<div class="col-xs-12 col-sm-6">
ประเภทคำส
<q-select
for="orderType"
ref="orderTypeRef"
dense
outlined
v-model="formData.orderType"
:options="orderTypeOptions"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกประเภทคำสั่ง'}`]"
lazy-rules
use-input
/>
</div>
<div class="col-xs-12 col-sm-6">
คำสงโดย
<q-select
for="orderBy"
ref="orderByRef"
dense
outlined
v-model="formData.orderBy"
:options="orderByOptions"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกคำสั่งโดย'}`]"
lazy-rules
use-input
/>
</div>
<div class="col-xs-12 col-sm-6">
เลอกรายการสอบสวนความผดทางว
<q-select
for="listInvestigation"
ref="listInvestigationRef"
dense
outlined
v-model="formData.listInvestigation"
:options="listInvestigationOptions"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[
(val) => !!val || `${'กรุณาเลือกรายการสอบสวนความผิดทางวินัย'}`,
]"
lazy-rules
use-input
/>
</div>
<div class="col-xs-12 col-sm-6">
อำนาจลงนาม
<q-input
for="authority"
ref="authorityRef"
dense
outlined
v-model="formData.authority"
placeholder="กรอกผู้มีอำนาจลงนาม"
:rules="[(val) => !!val || `${'กรุณากรอกผู้มีอำนาจลงนาม'}`]"
lazy-rules
/>
</div>
<div class="row col-xs-7 col-sm-3">
<div class="col-6">
คำสงท
<q-input
for="orderNumber"
ref="orderNumberRef"
outlined
dense
v-model="formData.orderNumber"
hide-bottom-space
:rules="[(val) => !!val || `${'กรุณากรอรคำสั่งที่'}`]"
lazy-rules
>
</q-input>
</div>
<label class="col-1 flex justify-center items-center text-bold"
>/</label
>
<div class="col-5">
พศ
<datepicker
v-model="formData.dateYear"
:locale="'th'"
autoApply
year-picker
:enableTimePicker="false"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
ref="dateYearRef"
:model-value="
formData.dateYear ? formData.dateYear + 543 : null
"
:rules="[(val) => !!val || `${'กรุณากรอก พ.ศ.'}`]"
dense
outlined
>
</q-input>
</template>
</datepicker>
</div>
</div>
<div class="col-xs-5 col-sm-3">
นทผลคำส
<datepicker
menu-class-name="modalfix"
v-model="formData.date"
:locale="'th'"
autoApply
borderless
:enableTimePicker="false"
week-start="0"
>
<template #year="{ year }">
{{ year + 543 }}
</template>
<template #year-overlay-value="{ value }">
{{ parseInt(value + 543) }}
</template>
<template #trigger>
<q-input
for="date"
ref="dateRef"
outlined
dense
class="full-width datepicker"
:model-value="
formData.date != null ? date2Thai(formData.date) : null
"
:rules="[(val) => !!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-xs-12 col-sm-6">
ตำแหนงผอำนาจลงนาม
<q-input
for="authorityPosition"
ref="authorityPositionRef"
dense
outlined
v-model="formData.authorityPosition"
placeholder="กรอกตำแหน่งผู้มีอำนาจลงนาม"
:rules="[(val) => !!val || `${'กรุณากรอกตำแหน่งผู้มีอำนาจลงนาม'}`]"
lazy-rules
/>
</div>
<div class="col-xs-12 col-sm-6">
คำสงเรอง
<q-input
for="subject"
ref="subjectRef"
dense
outlined
v-model="formData.subject"
placeholder="กรอกคำสั่งเรื่อง"
:rules="[(val) => !!val || `${'กรุณากรอกคำสั่งเรื่อง'}`]"
lazy-rules
/>
</div>
<div class="col-xs-12 col-sm-12">
รายละเอยดการกระทำความผ
<q-input
for="mistakeDetail"
ref="mistakeDetailRef"
dense
outlined
v-model="formData.mistakeDetail"
placeholder="กรอกรายละเอียดการกระทำความผิด"
:rules="[(val) => !!val || `${'กรุณากรอกคำสั่งเรื่อง'}`]"
lazy-rules
type="textarea"
rows="5"
/>
</div>
</div>
</div>
<q-card-actions align="right">
<q-btn
for="submit"
flat
round
unelevated
color="secondary"
icon="mdi-content-save-outline"
type="submit"
/>
</q-card-actions>
</form>
</template>
<style scoped></style>