refactor: add submitWorkHistory and submitHealthCheck
This commit is contained in:
parent
5e525e43da
commit
7a81991c79
4 changed files with 170 additions and 15 deletions
|
|
@ -473,7 +473,8 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEmployeeForm() {
|
function createEmployeeForm() {
|
||||||
employeeFormStore.resetFormDataEmployee();
|
employeeFormStore.resetFormDataEmployee(true);
|
||||||
|
employeeFormState.value.dialogType = 'create';
|
||||||
employeeFormState.value.dialogModal = true;
|
employeeFormState.value.dialogModal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1947,11 +1948,24 @@ watch(
|
||||||
:undo="() => employeeFormUndo(false)"
|
:undo="() => employeeFormUndo(false)"
|
||||||
:submit="
|
:submit="
|
||||||
async () => {
|
async () => {
|
||||||
await employeeFormStore.submitPersonal();
|
if (employeeFormState.currentTab === 'personalInfo') {
|
||||||
|
await employeeFormStore.submitPersonal();
|
||||||
|
}
|
||||||
|
if (employeeFormState.currentTab === 'healthCheck') {
|
||||||
|
await employeeFormStore.submitHealthCheck();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if (employeeFormState.currentTab === 'workHistory') {
|
||||||
|
console.log('ทำงาน');
|
||||||
|
|
||||||
|
await employeeFormStore.submitWorkHistory();
|
||||||
|
}
|
||||||
|
}
|
||||||
await fetchListEmployee();
|
await fetchListEmployee();
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
:close="
|
:close="() => {}"
|
||||||
|
:show="
|
||||||
() => {
|
() => {
|
||||||
employeeFormStore.resetFormDataEmployee(true);
|
employeeFormStore.resetFormDataEmployee(true);
|
||||||
}
|
}
|
||||||
|
|
@ -1967,7 +1981,6 @@ watch(
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<div class="q-mx-lg q-mt-lg">
|
<div class="q-mx-lg q-mt-lg">
|
||||||
{{ employeeFormState.statusSavePersonal }}
|
|
||||||
<ProfileBanner
|
<ProfileBanner
|
||||||
active
|
active
|
||||||
useToggle
|
useToggle
|
||||||
|
|
@ -2186,6 +2199,19 @@ watch(
|
||||||
v-model:insuranceCompanyOption="
|
v-model:insuranceCompanyOption="
|
||||||
optionStore.globalOption.insurancePlace
|
optionStore.globalOption.insurancePlace
|
||||||
"
|
"
|
||||||
|
@save="
|
||||||
|
(index) => {
|
||||||
|
employeeFormState.currentIndex = index;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@edit="
|
||||||
|
(index) => {
|
||||||
|
if (currentFromDataEmployee.employeeCheckup?.[index].statusSave) {
|
||||||
|
currentFromDataEmployee.employeeCheckup[index].statusSave =
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<FormEmployeeWorkHistory
|
<FormEmployeeWorkHistory
|
||||||
v-if="employeeFormState.currentTab === 'workHistory'"
|
v-if="employeeFormState.currentTab === 'workHistory'"
|
||||||
|
|
@ -2197,6 +2223,18 @@ watch(
|
||||||
v-model:position-name-option="optionStore.globalOption.position"
|
v-model:position-name-option="optionStore.globalOption.position"
|
||||||
v-model:job-type-option="optionStore.globalOption.businessType"
|
v-model:job-type-option="optionStore.globalOption.businessType"
|
||||||
v-model:workplace-option="optionStore.globalOption.area"
|
v-model:workplace-option="optionStore.globalOption.area"
|
||||||
|
@save="
|
||||||
|
(index) => {
|
||||||
|
employeeFormState.currentIndex = index;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@edit="
|
||||||
|
(index) => {
|
||||||
|
if (currentFromDataEmployee.employeeWork?.[index].statusSave) {
|
||||||
|
currentFromDataEmployee.employeeWork[index].statusSave = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<FormEmployeeOther
|
<FormEmployeeOther
|
||||||
v-if="employeeFormState.currentTab === 'other'"
|
v-if="employeeFormState.currentTab === 'other'"
|
||||||
|
|
@ -2266,7 +2304,7 @@ watch(
|
||||||
</template>
|
</template>
|
||||||
</ImageUploadDialog>
|
</ImageUploadDialog>
|
||||||
|
|
||||||
<!-- นายจ้างนิติ -->
|
<!-- ลูกจ้าง -->
|
||||||
<DrawerInfo
|
<DrawerInfo
|
||||||
v-model:drawer-open="employeeFormState.drawerModal"
|
v-model:drawer-open="employeeFormState.drawerModal"
|
||||||
:is-edit="employeeFormState.isEmployeeEdit"
|
:is-edit="employeeFormState.isEmployeeEdit"
|
||||||
|
|
@ -2287,10 +2325,22 @@ watch(
|
||||||
"
|
"
|
||||||
:submit="
|
:submit="
|
||||||
async () => {
|
async () => {
|
||||||
await employeeFormStore.submitPersonal();
|
if (employeeFormState.currentTab === 'personalInfo') {
|
||||||
|
await employeeFormStore.submitPersonal();
|
||||||
|
}
|
||||||
|
if (employeeFormState.currentTab === 'healthCheck') {
|
||||||
|
await employeeFormStore.submitHealthCheck();
|
||||||
|
}
|
||||||
|
await fetchListEmployee();
|
||||||
|
|
||||||
employeeFormState.isEmployeeEdit = false;
|
employeeFormState.isEmployeeEdit = false;
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
:close="
|
||||||
|
() => {
|
||||||
|
employeeFormStore.resetFormDataEmployee(true);
|
||||||
|
}
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<div class="full-height full-width column">
|
<div class="full-height full-width column">
|
||||||
<div class="q-mx-lg q-mt-lg">
|
<div class="q-mx-lg q-mt-lg">
|
||||||
|
|
@ -2472,6 +2522,21 @@ watch(
|
||||||
v-model:insuranceCompanyOption="
|
v-model:insuranceCompanyOption="
|
||||||
optionStore.globalOption.insurancePlace
|
optionStore.globalOption.insurancePlace
|
||||||
"
|
"
|
||||||
|
@save="
|
||||||
|
(index) => {
|
||||||
|
employeeFormState.currentIndex = index;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@edit="
|
||||||
|
(index) => {
|
||||||
|
if (
|
||||||
|
currentFromDataEmployee.employeeCheckup?.[index].statusSave
|
||||||
|
) {
|
||||||
|
currentFromDataEmployee.employeeCheckup[index].statusSave =
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<FormEmployeeWorkHistory
|
<FormEmployeeWorkHistory
|
||||||
v-if="employeeFormState.currentTab === 'workHistory'"
|
v-if="employeeFormState.currentTab === 'workHistory'"
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
||||||
drawerModal: boolean;
|
drawerModal: boolean;
|
||||||
currentEmployeeCode: string;
|
currentEmployeeCode: string;
|
||||||
currentEmployee: Employee | null;
|
currentEmployee: Employee | null;
|
||||||
|
currentIndex: number;
|
||||||
profileUrl: string;
|
profileUrl: string;
|
||||||
isEmployeeEdit: boolean;
|
isEmployeeEdit: boolean;
|
||||||
profileSubmit: boolean;
|
profileSubmit: boolean;
|
||||||
|
|
@ -265,6 +266,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
||||||
}
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
}>({
|
}>({
|
||||||
|
currentIndex: 0,
|
||||||
statusSavePersonal: false,
|
statusSavePersonal: false,
|
||||||
drawerModal: false,
|
drawerModal: false,
|
||||||
imageDialog: false,
|
imageDialog: false,
|
||||||
|
|
@ -385,6 +387,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
||||||
|
|
||||||
function resetFormDataEmployee(clean = false) {
|
function resetFormDataEmployee(clean = false) {
|
||||||
if (clean) {
|
if (clean) {
|
||||||
|
state.value.currentTab = 'personalInfo';
|
||||||
state.value.formDataEmployeeOwner = undefined;
|
state.value.formDataEmployeeOwner = undefined;
|
||||||
resetEmployeeData = structuredClone(defaultFormData);
|
resetEmployeeData = structuredClone(defaultFormData);
|
||||||
state.value.statusSavePersonal = false;
|
state.value.statusSavePersonal = false;
|
||||||
|
|
@ -393,6 +396,77 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
||||||
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
currentFromDataEmployee.value = structuredClone(resetEmployeeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function submitWorkHistory() {
|
||||||
|
if (!currentFromDataEmployee.value.employeeWork) return;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!currentFromDataEmployee.value.employeeWork[state.value.currentIndex].id
|
||||||
|
) {
|
||||||
|
const res = await employeeStore.createEmployeeWork(
|
||||||
|
currentFromDataEmployee.value?.id || '',
|
||||||
|
currentFromDataEmployee.value.employeeWork[state.value.currentIndex],
|
||||||
|
);
|
||||||
|
if (res) {
|
||||||
|
currentFromDataEmployee.value.employeeWork[
|
||||||
|
state.value.currentIndex
|
||||||
|
].id = res.id;
|
||||||
|
currentFromDataEmployee.value.employeeWork[
|
||||||
|
state.value.currentIndex
|
||||||
|
].statusSave = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const res = await employeeStore.editByIdEmployeeWork(
|
||||||
|
currentFromDataEmployee.value?.id || '',
|
||||||
|
currentFromDataEmployee.value.employeeWork[state.value.currentIndex],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
currentFromDataEmployee.value.employeeWork[
|
||||||
|
state.value.currentIndex
|
||||||
|
].statusSave = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitHealthCheck() {
|
||||||
|
if (!currentFromDataEmployee.value.employeeCheckup) return;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex]
|
||||||
|
.id
|
||||||
|
) {
|
||||||
|
const res = await employeeStore.createEmployeeCheckup(
|
||||||
|
state.value.currentEmployee?.id || '',
|
||||||
|
currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
currentFromDataEmployee.value.employeeCheckup[
|
||||||
|
state.value.currentIndex
|
||||||
|
].id = res.id;
|
||||||
|
|
||||||
|
currentFromDataEmployee.value.employeeCheckup[
|
||||||
|
state.value.currentIndex
|
||||||
|
].statusSave = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const res = await employeeStore.editByIdEmployeeCheckup(
|
||||||
|
state.value.currentEmployee?.id || '',
|
||||||
|
currentFromDataEmployee.value.employeeCheckup[state.value.currentIndex],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
currentFromDataEmployee.value.employeeCheckup[
|
||||||
|
state.value.currentIndex
|
||||||
|
].statusSave = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await assignFormDataEmployee(currentFromDataEmployee.value.id);
|
||||||
|
}
|
||||||
|
|
||||||
async function submitPersonal() {
|
async function submitPersonal() {
|
||||||
if (state.value.dialogType === 'create') {
|
if (state.value.dialogType === 'create') {
|
||||||
const res = await employeeStore.create({
|
const res = await employeeStore.create({
|
||||||
|
|
@ -403,8 +477,10 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
||||||
employeeCheckup: [],
|
employeeCheckup: [],
|
||||||
employeeOtherInfo: undefined,
|
employeeOtherInfo: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
await assignFormDataEmployee(res.id);
|
await assignFormDataEmployee(res.id);
|
||||||
|
currentFromDataEmployee.value.id = res.id;
|
||||||
state.value.statusSavePersonal = true;
|
state.value.statusSavePersonal = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -462,9 +538,20 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
||||||
provinceId: province?.id,
|
provinceId: province?.id,
|
||||||
districtId: district?.id,
|
districtId: district?.id,
|
||||||
subDistrictId: subDistrict?.id,
|
subDistrictId: subDistrict?.id,
|
||||||
employeeCheckup: structuredClone(playlond.employeeCheckup),
|
employeeCheckup: structuredClone(
|
||||||
employeeOtherInfo: structuredClone(playlond.employeeOtherInfo),
|
playlond.employeeCheckup?.length === 0
|
||||||
employeeWork: structuredClone(playlond.employeeWork),
|
? defaultFormData.employeeCheckup
|
||||||
|
: playlond.employeeCheckup?.map((item) => ({
|
||||||
|
...item,
|
||||||
|
statusSave: true,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
employeeOtherInfo: structuredClone(playlond.employeeOtherInfo || {}),
|
||||||
|
employeeWork: structuredClone(
|
||||||
|
playlond.employeeWork?.length === 0
|
||||||
|
? defaultFormData.employeeWork
|
||||||
|
: playlond.employeeWork,
|
||||||
|
),
|
||||||
image: null,
|
image: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -518,7 +605,9 @@ export const useEmployeeForm = defineStore('form-employee', () => {
|
||||||
currentFromDataEmployee,
|
currentFromDataEmployee,
|
||||||
resetEmployeeData,
|
resetEmployeeData,
|
||||||
|
|
||||||
|
submitWorkHistory,
|
||||||
submitPersonal,
|
submitPersonal,
|
||||||
|
submitHealthCheck,
|
||||||
|
|
||||||
resetFormDataEmployee,
|
resetFormDataEmployee,
|
||||||
assignFormDataEmployee,
|
assignFormDataEmployee,
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
transactionId?: string;
|
transactionId?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { code, image, ...payload } = data;
|
const { id, code, image, ...payload } = data;
|
||||||
const res = await api.post<
|
const res = await api.post<
|
||||||
Employee & { profileImageUrl: string; profileImageUploadUrl: string }
|
Employee & { profileImageUrl: string; profileImageUploadUrl: string }
|
||||||
>('/employee', payload, {
|
>('/employee', payload, {
|
||||||
|
|
@ -196,9 +196,9 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
transactionId?: string;
|
transactionId?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { ...payload } = data;
|
const { id, statusSave, ...payload } = data;
|
||||||
const res = await api.put<EmployeeCheckupCreate>(
|
const res = await api.put<EmployeeCheckupCreate>(
|
||||||
`/employee/${employeeId}/checkup}`,
|
`/employee/${employeeId}/checkup/${id}`,
|
||||||
{ ...payload },
|
{ ...payload },
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -269,7 +269,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function editById(
|
async function editById(
|
||||||
id: string,
|
employeeId: string,
|
||||||
data: Partial<EmployeeCreate>,
|
data: Partial<EmployeeCreate>,
|
||||||
flow?: {
|
flow?: {
|
||||||
sessionId?: string;
|
sessionId?: string;
|
||||||
|
|
@ -277,10 +277,10 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
transactionId?: string;
|
transactionId?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { code, image, ...payload } = data;
|
const { id, code, image, ...payload } = data;
|
||||||
const res = await api.put<
|
const res = await api.put<
|
||||||
Employee & { imageUrl: string; profileImageUploadUrl: string }
|
Employee & { imageUrl: string; profileImageUploadUrl: string }
|
||||||
>(`/employee/${id}`, payload, {
|
>(`/employee/${employeeId}`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Session-Id': flow?.sessionId,
|
'X-Session-Id': flow?.sessionId,
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ export type Employee = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EmployeeCreate = {
|
export type EmployeeCreate = {
|
||||||
|
id?: string;
|
||||||
code: string;
|
code: string;
|
||||||
image: File | null;
|
image: File | null;
|
||||||
customerBranchId: string;
|
customerBranchId: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue