This commit is contained in:
setthawutttty 2024-01-30 15:11:57 +07:00
parent db968d9dd5
commit f9febc19dd

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref,watch } from "vue"; import { ref, watch, computed } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
@ -13,14 +13,26 @@ const props = defineProps({
close: Function, close: Function,
}); });
const store = useOrganizational() const store = useOrganizational();
const $q = useQuasar(); const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { dialogConfirm, date2Thai,showLoader,hideLoader,messageError,success } = mixin; const {
dialogConfirm,
date2Thai,
showLoader,
hideLoader,
messageError,
success,
} = mixin;
const minDate = computed(() => {
const date = new Date();
date.setDate(date.getDate() + 1);
return date;
});
const dateTimeRef = ref<Object | null>(null); const dateTimeRef = ref<Object | null>(null);
const dateTime = ref<Date|null>(); const dateTime = ref<Date | null>();
/** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */ /** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */
const objectRef: FormDateTimeRef = { const objectRef: FormDateTimeRef = {
@ -48,37 +60,39 @@ function validateForm() {
/** ฟังชั่น บันทึก */ /** ฟังชั่น บันทึก */
function onSubmit() { function onSubmit() {
dialogConfirm($q, () => { dialogConfirm($q, () => {
showLoader();
showLoader()
http http
.put(config.API.orgSetDateTime(store.draftId as string),{ .put(config.API.orgSetDateTime(store.draftId as string), {
orgPublishDate:dateTime.value, orgPublishDate: dateTime.value,
}) })
.then((res)=>{ .then((res) => {
props.close?.() props.close?.();
success($q, "บันทึกข้อมูลสำเร็จ"); success($q, "บันทึกข้อมูลสำเร็จ");
}) })
.catch((e)=>{ .catch((e) => {
messageError($q,e) messageError($q, e);
}) })
.finally(()=>{ .finally(() => {
hideLoader() hideLoader();
}) });
}); });
} }
watch(()=>props.modal,()=>{ watch(
if(props.modal === true){ () => props.modal,
dateTime.value = null () => {
if (props.modal === true) {
dateTime.value = null;
}
} }
}) );
</script> </script>
<template> <template>
<template> <template>
<q-dialog v-model="props.modal" persistent> <q-dialog v-model="props.modal" persistent>
<q-card style="min-width: 10vw"> <q-card style="min-width: 10vw">
<form @submit.prevent="validateForm"> <form @submit.prevent="validateForm">
<DialogHeader :tittle="`วันที่เผยแพร่`" :close="props.close" /> <DialogHeader :tittle="`ตั้งเวลาเผยแพร่`" :close="props.close" />
<q-separator /> <q-separator />
<q-card-section> <q-card-section>
@ -92,6 +106,7 @@ watch(()=>props.modal,()=>{
borderless borderless
:enableTimePicker="false" :enableTimePicker="false"
week-start="0" week-start="0"
:min-date="minDate"
> >
<template #year="{ year }"> <template #year="{ year }">
{{ year + 543 }} {{ year + 543 }}
@ -109,9 +124,9 @@ watch(()=>props.modal,()=>{
:model-value=" :model-value="
dateTime != null ? date2Thai(dateTime) : null dateTime != null ? date2Thai(dateTime) : null
" "
label="วันเวลาเผยแพร่" label="วันที่เผยแพร่"
:rules="[ :rules="[
(val) => !!val || `${'กรุณาเลือกวันเวลาเผยแพร่'}`, (val) => !!val || `${'กรุณาเลือกวันที่เผยแพร่'}`,
]" ]"
lazy-rules lazy-rules
> >