เพิ่มข้อความแจ้งเตือกรณีลืมลงเวลาออก

This commit is contained in:
Warunee Tamkoo 2026-05-08 18:15:54 +07:00
parent 9e69d33963
commit 89c20d53c2

View file

@ -1,12 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { import { ref, reactive, onMounted, watch, onBeforeUnmount, computed } from 'vue'
ref,
reactive,
onMounted,
watch,
onBeforeUnmount,
computed,
} from 'vue'
import { useQuasar } from 'quasar' import { useQuasar } from 'quasar'
import { format } from 'date-fns' import { format } from 'date-fns'
import Camera from 'simple-vue-camera' import Camera from 'simple-vue-camera'
@ -62,10 +55,40 @@ const msgCheckTime = ref<string>('') // ข้อความแจ้งเต
const isDisabledCheckTime = ref<boolean>(true) // const isDisabledCheckTime = ref<boolean>(true) //
const isErr = ref<boolean | null>(null) // const isErr = ref<boolean | null>(null) //
const endTimeAfternoon = ref<string>('12:00:00') // const endTimeAfternoon = ref<string>('12:00:00') //
const crossDayCheckoutWarning = ref<string>('')
const isLoadingCheckTime = ref<boolean>(false) // const isLoadingCheckTime = ref<boolean>(false) //
const disabledBtn = ref<boolean>(false) const disabledBtn = ref<boolean>(false)
function parseApiDateTime(value?: string | null) {
if (!value) return null
const normalizedValue = value.includes('T') ? value : value.replace(' ', 'T')
const parsedDate = new Date(normalizedValue)
return Number.isNaN(parsedDate.getTime()) ? null : parsedDate
}
function isSameCalendarDay(firstDate: Date, secondDate: Date) {
return (
firstDate.getFullYear() === secondDate.getFullYear() &&
firstDate.getMonth() === secondDate.getMonth() &&
firstDate.getDate() === secondDate.getDate()
)
}
function updateCrossDayCheckoutWarning(checkInTime?: string | null) {
crossDayCheckoutWarning.value = ''
const checkInDate = parseApiDateTime(checkInTime)
if (!checkInDate) return
if (!isSameCalendarDay(checkInDate, new Date())) {
crossDayCheckoutWarning.value = `คุณยังไม่ได้ลงเวลาออกของวันที่ ${date2Thai(
checkInDate
)} กรณาลงเวลาออกกอน งจะลงเวลาเขาของวนนได`
}
}
/** /**
* fetch เชคเวลาตองลงเวลาเขาหรอออกงาน * fetch เชคเวลาตองลงเวลาเขาหรอออกงาน
*/ */
@ -78,6 +101,7 @@ async function fetchCheckTime(load: any = true) {
statusCheckin.value = data.checkInId ? false : true statusCheckin.value = data.checkInId ? false : true
checkInId.value = data.checkInId ? data.checkInId : '' checkInId.value = data.checkInId ? data.checkInId : ''
updateCrossDayCheckoutWarning(data.checkInTime)
endTimeAfternoon.value = data.endTimeAfternoon endTimeAfternoon.value = data.endTimeAfternoon
isDisabledCheckTime.value = isDisabledCheckTime.value ? true : false isDisabledCheckTime.value = isDisabledCheckTime.value ? true : false
}) })
@ -425,11 +449,7 @@ async function onNativePhotoSelected(event: Event) {
if (!(await isValidCapturedImage(file))) { if (!(await isValidCapturedImage(file))) {
clearSelectedPhoto() clearSelectedPhoto()
messageError( messageError($q, '', 'ไม่สามารถอ่านไฟล์รูปภาพได้ กรุณาถ่ายรูปใหม่อีกครั้ง')
$q,
'',
'ไม่สามารถอ่านไฟล์รูปภาพได้ กรุณาถ่ายรูปใหม่อีกครั้ง'
)
return return
} }
@ -849,6 +869,7 @@ const mapRef = computed(() =>
) )
const timeChickin = ref<string>('') //, const timeChickin = ref<string>('') //,
const displayedCheckDate = ref<Date>(new Date())
/** function ยืนยันการลงเวลาเข้า - ออก*/ /** function ยืนยันการลงเวลาเข้า - ออก*/
async function confirm() { async function confirm() {
@ -870,11 +891,7 @@ async function confirm() {
} }
clearSelectedPhoto() clearSelectedPhoto()
disabledBtn.value = false disabledBtn.value = false
messageError( messageError($q, '', 'รูปภาพไม่สมบูรณ์ กรุณาถ่ายรูปใหม่อีกครั้งก่อนลงเวลา')
$q,
'',
'รูปภาพไม่สมบูรณ์ กรุณาถ่ายรูปใหม่อีกครั้งก่อนลงเวลา'
)
return return
} }
@ -895,6 +912,7 @@ async function confirm() {
.then(async (res) => { .then(async (res) => {
const data = await res.data.result const data = await res.data.result
const dateObject = new Date(data.date) const dateObject = new Date(data.date)
displayedCheckDate.value = dateObject
checkDate.value = data.date ? true : false checkDate.value = data.date ? true : false
const options: Intl.DateTimeFormatOptions = { const options: Intl.DateTimeFormatOptions = {
hour12: false, hour12: false,
@ -1197,6 +1215,16 @@ watch(
class="col-xs-12 col-md-11 q-pa-md q-col-gutter-md row q-pt-lg" class="col-xs-12 col-md-11 q-pa-md q-col-gutter-md row q-pt-lg"
v-if="!isDisabledCheckTime" v-if="!isDisabledCheckTime"
> >
<div v-if="crossDayCheckoutWarning" class="col-12">
<q-banner
rounded
class="bg-white text-orange-10 warning-banner"
>
<q-icon name="warning" color="warning" size="20px" />
{{ crossDayCheckoutWarning }}
</q-banner>
</div>
<div class="col-xs-12 col-sm-8 gt-xs"> <div class="col-xs-12 col-sm-8 gt-xs">
<div class="col-12"> <div class="col-12">
<MapCheck <MapCheck
@ -1231,9 +1259,7 @@ watch(
<Camera <Camera
:resolution="{ width: photoWidth, height: photoHeight }" :resolution="{ width: photoWidth, height: photoHeight }"
ref="camera" ref="camera"
:class="[ :class="['camera-preview']"
'camera-preview',
]"
:autoplay="false" :autoplay="false"
:playsinline="true" :playsinline="true"
:facingMode="'user'" :facingMode="'user'"
@ -1367,9 +1393,7 @@ watch(
height: photoHeight, height: photoHeight,
}" }"
ref="camera" ref="camera"
:class="[ :class="['camera-preview']"
'camera-preview',
]"
:autoplay="false" :autoplay="false"
:playsinline="true" :playsinline="true"
:facingMode="'user'" :facingMode="'user'"
@ -1817,7 +1841,7 @@ watch(
<div <div
class="col-12 text-subtitle1 text-center text-white text-weight-medium" class="col-12 text-subtitle1 text-center text-white text-weight-medium"
> >
{{ date2Thai(Thai) }} {{ date2Thai(displayedCheckDate) }}
</div> </div>
<div class="row col-12 justify-center q-pt-sm"> <div class="row col-12 justify-center q-pt-sm">
<!-- <div class="text-h3 text-white text-weight-bold"></div> --> <!-- <div class="text-h3 text-white text-weight-bold"></div> -->
@ -1947,6 +1971,11 @@ watch(
animation: bounce 2s infinite; animation: bounce 2s infinite;
} }
.warning-banner {
border: 1px solid #ffcc80;
border-left: 4px solid #fb8c00;
}
@keyframes bounce { @keyframes bounce {
0%, 0%,
100% { 100% {