Merge branch 'develop'

This commit is contained in:
Warunee Tamkoo 2025-03-15 19:02:21 +07:00
commit e0b55cab72
3 changed files with 30 additions and 4 deletions

View file

@ -34,6 +34,7 @@ const {
dialogConfirm, dialogConfirm,
dialogMessageNotify, dialogMessageNotify,
onSearchDataTable, onSearchDataTable,
convertDatetimeToAPI,
} = useCounterMixin(); } = useCounterMixin();
const { const {
getSchedule, getSchedule,
@ -64,6 +65,7 @@ const formDataschedule = ref<ScheduleCreate>({
name: "", name: "",
time: "", time: "",
schedule: "", schedule: "",
startAt: new Date(),
}); });
/** /**
@ -203,10 +205,16 @@ function onSubmit() {
dialogConfirm($q, async () => { dialogConfirm($q, async () => {
showLoader(); showLoader();
if (typeOnSubmit.value === "create") { if (typeOnSubmit.value === "create") {
await createSchedule(formDataschedule.value); await createSchedule({
...formDataschedule.value,
startAt: convertDatetimeToAPI(formDataschedule.value.startAt as Date),
});
} }
if (typeOnSubmit.value === "edit") { if (typeOnSubmit.value === "edit") {
await editSchedule(idEditSchedule.value, formDataschedule.value); await editSchedule(idEditSchedule.value, {
...formDataschedule.value,
startAt: convertDatetimeToAPI(formDataschedule.value.startAt as Date),
});
} }
getSchedule(); getSchedule();
hideLoader(); hideLoader();
@ -476,7 +484,7 @@ onMounted(async () => {
if (formDataschedule.startAt !== undefined) { if (formDataschedule.startAt !== undefined) {
formDataschedule.startAt = new Date( formDataschedule.startAt = new Date(
formDataschedule.startAt formDataschedule.startAt as Date
).toISOString(); ).toISOString();
} }
convertFormToCron(); convertFormToCron();

View file

@ -7,7 +7,7 @@ interface ScheduleCreate {
type: string; type: string;
date: string[]; date: string[];
schedule: string; schedule: string;
startAt?: string; startAt?: Date|null|string;
enabled?: boolean; enabled?: boolean;
} }

View file

@ -3,6 +3,7 @@ import "moment/dist/locale/th";
import moment from "moment"; import moment from "moment";
import CustomComponent from "@/components/CustomDialog.vue"; import CustomComponent from "@/components/CustomDialog.vue";
import { Loading, QSpinnerCube } from "quasar"; import { Loading, QSpinnerCube } from "quasar";
import { format, utcToZonedTime } from "date-fns-tz";
moment.locale("th"); moment.locale("th");
@ -1078,6 +1079,20 @@ export const useCounterMixin = defineStore("mixin", () => {
}); });
} }
// กรณีมีเฉพาะ date
function convertDateToAPI(date: Date | null) {
return date
? format(utcToZonedTime(date, "Asia/Bangkok"), "yyyy-MM-dd")
: null;
}
// กรณี datetime
function convertDatetimeToAPI(date: Date | null) {
return date
? format(utcToZonedTime(date, "Asia/Bangkok"), "yyyy-MM-dd HH:mm:ss")
: null;
}
return { return {
calAge, calAge,
date2Thai, date2Thai,
@ -1121,5 +1136,8 @@ export const useCounterMixin = defineStore("mixin", () => {
findPosMasterNoOld, findPosMasterNoOld,
onSearchDataTable, onSearchDataTable,
convertDateToAPI,
convertDatetimeToAPI,
}; };
}); });