fix: change calculate age function store
This commit is contained in:
parent
204a854a1c
commit
1c5acba093
4 changed files with 6 additions and 46 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, watch, computed } from 'vue';
|
import { ref, onMounted, watch, computed } from 'vue';
|
||||||
import useUtilsStore, { dialog, calculateAge } from 'src/stores/utils';
|
import useUtilsStore, { dialog } from 'src/stores/utils';
|
||||||
|
import { calculateAge } from 'src/utils/datetime';
|
||||||
import type { QTableProps } from 'quasar';
|
import type { QTableProps } from 'quasar';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@ import FormEmployeeWorkHistory from 'src/components/03_customer-management/FormE
|
||||||
import FormEmployeeOther from 'src/components/03_customer-management/FormEmployeeOther.vue';
|
import FormEmployeeOther from 'src/components/03_customer-management/FormEmployeeOther.vue';
|
||||||
import FormEmployeePassport from 'src/components/03_customer-management/FormEmployeePassport.vue';
|
import FormEmployeePassport from 'src/components/03_customer-management/FormEmployeePassport.vue';
|
||||||
import FormEmployeeVisa from 'src/components/03_customer-management/FormEmployeeVisa.vue';
|
import FormEmployeeVisa from 'src/components/03_customer-management/FormEmployeeVisa.vue';
|
||||||
import useUtilsStore, { dialog, calculateAge } from 'src/stores/utils';
|
import useUtilsStore, { dialog } from 'src/stores/utils';
|
||||||
|
import { calculateAge } from 'src/utils/datetime';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import useFlowStore from 'src/stores/flow';
|
import useFlowStore from 'src/stores/flow';
|
||||||
|
|
||||||
|
|
@ -2416,7 +2417,7 @@ watch([inputSearch, currentStatus], async () => {
|
||||||
<q-td
|
<q-td
|
||||||
v-if="fieldSelected.includes('formDialogInputAge')"
|
v-if="fieldSelected.includes('formDialogInputAge')"
|
||||||
>
|
>
|
||||||
{{ userStore.calculateAge(props.row.dateOfBirth) }}
|
{{ calculateAge(props.row.dateOfBirth) }}
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
||||||
<q-td
|
<q-td
|
||||||
|
|
@ -2597,9 +2598,7 @@ watch([inputSearch, currentStatus], async () => {
|
||||||
{
|
{
|
||||||
icon: 'mdi-clock-outline',
|
icon: 'mdi-clock-outline',
|
||||||
value: props.row.dateOfBirth
|
value: props.row.dateOfBirth
|
||||||
? userStore.calculateAge(
|
? calculateAge(props.row.dateOfBirth) ?? ''
|
||||||
props.row.dateOfBirth,
|
|
||||||
) ?? ''
|
|
||||||
: '',
|
: '',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -69,25 +69,6 @@ const useUserStore = defineStore('api-user', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = ref<Pagination<User[]>>();
|
const data = ref<Pagination<User[]>>();
|
||||||
const { locale } = useI18n();
|
|
||||||
|
|
||||||
function calculateAge(birthDate: Date | null | string) {
|
|
||||||
if (!birthDate) return null;
|
|
||||||
const birthDateTimeStamp = new Date(birthDate).getTime();
|
|
||||||
const now = new Date();
|
|
||||||
const diff = now.getTime() - birthDateTimeStamp;
|
|
||||||
|
|
||||||
const ageDate = new Date(diff);
|
|
||||||
const years = ageDate.getUTCFullYear() - 1970;
|
|
||||||
const months = ageDate.getUTCMonth();
|
|
||||||
const days = ageDate.getUTCDate() - 1;
|
|
||||||
|
|
||||||
if (locale.value === 'th-th') {
|
|
||||||
return `${years} ปี ${months !== 0 ? months + ' เดือน' : ''} ${days !== 0 ? days + ' วัน' : ''} `;
|
|
||||||
} else {
|
|
||||||
return `${years} years ${months !== 0 ? months + ' months' : ''} ${days !== 0 ? days + ' days' : ''} `;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchHqOption() {
|
async function fetchHqOption() {
|
||||||
if (userOption.value.hqOpts.length === 0) {
|
if (userOption.value.hqOpts.length === 0) {
|
||||||
|
|
@ -493,7 +474,6 @@ const useUserStore = defineStore('api-user', () => {
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
userOption,
|
userOption,
|
||||||
calculateAge,
|
|
||||||
|
|
||||||
fetchHqOption,
|
fetchHqOption,
|
||||||
fetchBrOption,
|
fetchBrOption,
|
||||||
|
|
|
||||||
|
|
@ -44,26 +44,6 @@ export function dialogWarningClose(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateAge(birthDate: Date | null | string) {
|
|
||||||
const { locale } = useI18n();
|
|
||||||
|
|
||||||
if (!birthDate) return null;
|
|
||||||
const birthDateTimeStamp = new Date(birthDate).getTime();
|
|
||||||
const now = new Date();
|
|
||||||
const diff = now.getTime() - birthDateTimeStamp;
|
|
||||||
|
|
||||||
const ageDate = new Date(diff);
|
|
||||||
const years = ageDate.getUTCFullYear() - 1970;
|
|
||||||
const months = ageDate.getUTCMonth();
|
|
||||||
const days = ageDate.getUTCDate() - 1;
|
|
||||||
|
|
||||||
if (locale.value === 'th-th') {
|
|
||||||
return `${years} ปี ${months !== 0 ? months + ' เดือน' : ''} ${days !== 0 ? days + ' วัน' : ''} `;
|
|
||||||
} else {
|
|
||||||
return `${years} years ${months !== 0 ? months + ' months' : ''} ${days !== 0 ? days + ' days' : ''} `;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function moveItemUp(items: unknown[], index: number) {
|
export function moveItemUp(items: unknown[], index: number) {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
const temp = items[index];
|
const temp = items[index];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue