fix: user type and store
This commit is contained in:
parent
8b0c0a33ac
commit
cf215ba717
2 changed files with 53 additions and 4 deletions
|
|
@ -12,8 +12,11 @@ import {
|
||||||
UserOption,
|
UserOption,
|
||||||
} from './types';
|
} from './types';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import useBranchStore from '../branch';
|
||||||
import { Branch } from '../branch/types';
|
import { Branch } from '../branch/types';
|
||||||
|
|
||||||
|
const branchStore = useBranchStore()
|
||||||
|
|
||||||
const useUserStore = defineStore('api-user', () => {
|
const useUserStore = defineStore('api-user', () => {
|
||||||
const userOption = ref<UserOption>({
|
const userOption = ref<UserOption>({
|
||||||
hqOpts: [],
|
hqOpts: [],
|
||||||
|
|
@ -56,8 +59,50 @@ const useUserStore = defineStore('api-user', () => {
|
||||||
{ label: 'สถานที่อบรมแรงงานกัมพูชา-บ้านแหลม จ.จันทบุร' },
|
{ label: 'สถานที่อบรมแรงงานกัมพูชา-บ้านแหลม จ.จันทบุร' },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = ref<Pagination<User[]>>();
|
const data = ref<Pagination<User[]>>();
|
||||||
|
|
||||||
|
function calculateAge(birthDate: Date | null): string {
|
||||||
|
if (!birthDate) return '';
|
||||||
|
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 result = `${years} ปี`
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchHqOption() {
|
||||||
|
if (userOption.value.hqOpts.length === 0) {
|
||||||
|
const res = await branchStore.fetchList({ pageSize: 999, filter: 'head' });
|
||||||
|
if (res) {
|
||||||
|
res.result.map((item) => {
|
||||||
|
userOption.value.hqOpts.push({
|
||||||
|
label: item.code,
|
||||||
|
value: item.id,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function fetchBrOption(id: string) {
|
||||||
|
const res = await branchStore.fetchById(id, {
|
||||||
|
includeSubBranch: true,
|
||||||
|
});
|
||||||
|
if (res && res?.branch) {
|
||||||
|
res.branch.map((item) => {
|
||||||
|
userOption.value.brOpts.push({
|
||||||
|
label: item.code,
|
||||||
|
value: item.id,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchRoleOption() {
|
async function fetchRoleOption() {
|
||||||
const res = await api.get<RoleData[]>('/keycloak/role');
|
const res = await api.get<RoleData[]>('/keycloak/role');
|
||||||
res.data.map((item) => {
|
res.data.map((item) => {
|
||||||
|
|
@ -429,6 +474,10 @@ const useUserStore = defineStore('api-user', () => {
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
userOption,
|
userOption,
|
||||||
|
calculateAge,
|
||||||
|
|
||||||
|
fetchHqOption,
|
||||||
|
fetchBrOption,
|
||||||
fetchRoleOption,
|
fetchRoleOption,
|
||||||
|
|
||||||
fetchList,
|
fetchList,
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,15 @@ export type User = {
|
||||||
trainingPlace: string | null;
|
trainingPlace: string | null;
|
||||||
importNationality: string | null;
|
importNationality: string | null;
|
||||||
sourceNationality: string | null;
|
sourceNationality: string | null;
|
||||||
licenseExpireDate: string | null;
|
licenseExpireDate: Date | null;
|
||||||
licenseIssueDate: string | null;
|
licenseIssueDate: Date | null;
|
||||||
licenseNo: string | null;
|
licenseNo: string | null;
|
||||||
discountCondition: string | null;
|
discountCondition: string | null;
|
||||||
gender: string;
|
gender: string;
|
||||||
userRole: string;
|
userRole: string;
|
||||||
userType: string;
|
userType: string;
|
||||||
retireDate: string | null;
|
retireDate: Date | null;
|
||||||
startDate: string | null;
|
startDate: Date | null;
|
||||||
registrationNo: string | null;
|
registrationNo: string | null;
|
||||||
telephoneNo: string;
|
telephoneNo: string;
|
||||||
email: string;
|
email: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue