diff --git a/src/pages/01_branch-management/MainPage.vue b/src/pages/01_branch-management/MainPage.vue index e9ed3dee..b77305d0 100644 --- a/src/pages/01_branch-management/MainPage.vue +++ b/src/pages/01_branch-management/MainPage.vue @@ -23,8 +23,6 @@ import { BranchCreate, } from 'src/stores/branch/types'; -const test = ref(); - const profileFile = ref(undefined); const inputFile = document.createElement('input'); inputFile.type = 'file'; @@ -71,7 +69,6 @@ const formDataContact = ref({ const formType = ref<'edit' | 'create' | 'delete'>('create'); const typeBranch = ref<'headOffice' | 'subBranch'>('headOffice'); -const branchContact = ref(); const inputCode = ref(''); const formData = ref({ taxNo: '', diff --git a/src/pages/02_personnel-management/MainPage.vue b/src/pages/02_personnel-management/MainPage.vue index f634033e..3b5a3aae 100644 --- a/src/pages/02_personnel-management/MainPage.vue +++ b/src/pages/02_personnel-management/MainPage.vue @@ -2,13 +2,11 @@ import { ref, onMounted, watch } from 'vue'; import { api } from 'src/boot/axios'; import { storeToRefs } from 'pinia'; -import { dialog } from 'src/stores/utils'; import useUserStore from 'stores/user'; import useBranchStore from 'src/stores/branch'; import { UserCreate, UserTypeStats, UserOption } from 'src/stores/user/types'; import { BranchUserStats } from 'src/stores/branch/types'; -// import { dateFormat } from 'src/utils/datetime'; import PersonCard from 'components/home/PersonCard.vue'; import AppBox from 'components/app/AppBox.vue'; @@ -17,6 +15,7 @@ import SelectorList from 'components/SelectorList.vue'; import AddButton from 'components/AddButton.vue'; import TooltipComponent from 'components/TooltipComponent.vue'; import FormDialog from 'src/components/FormDialog.vue'; +import { dateFormat } from 'src/utils/datetime'; const userStore = useUserStore(); const branchStore = useBranchStore(); @@ -158,7 +157,7 @@ async function fetchBrOption(id: string) { const res = await branchStore.fetchById(id, { includeSubBranch: true, }); - if (res.branch) { + if (res && res?.branch) { res.branch.map((item) => { userOption.value.brOpts.push({ label: item.code, @@ -173,52 +172,31 @@ async function openDialog(id?: string) { modal.value = true; if (id && userData.value) { const foundUser = userData.value.result.find((user) => user.id === id); + if (foundUser) { - formData.value.provinceId = foundUser.provinceId; - formData.value.districtId = foundUser.districtId; - formData.value.subDistrictId = foundUser.subDistrictId; - formData.value.telephoneNo = foundUser.telephoneNo; - formData.value.email = foundUser.email; - formData.value.zipCode = foundUser.zipCode; - formData.value.gender = foundUser.gender; - formData.value.addressEN = foundUser.addressEN; - formData.value.address = foundUser.address; - formData.value.trainingPlace = foundUser.trainingPlace; - formData.value.importNationality = foundUser.importNationality; - formData.value.sourceNationality = foundUser.sourceNationality; - formData.value.licenseExpireDate = foundUser.licenseExpireDate - ? new Date(foundUser.licenseExpireDate) - : null; - formData.value.licenseIssueDate = foundUser.licenseIssueDate - ? new Date(foundUser.licenseIssueDate) - : null; - formData.value.licenseNo = foundUser.licenseNo; - formData.value.discountCondition = foundUser.discountCondition; - formData.value.retireDate = foundUser.retireDate - ? new Date(foundUser.retireDate) - : null; - formData.value.startDate = foundUser.startDate - ? new Date(foundUser.startDate) - : null; - formData.value.registrationNo = foundUser.registrationNo; - formData.value.lastNameEN = foundUser.lastNameEN; - formData.value.lastName = foundUser.lastName; - formData.value.firstNameEN = foundUser.firstNameEN; - formData.value.firstName = foundUser.firstName; - formData.value.userRole = foundUser.userRole; - formData.value.userType = foundUser.userType; - formData.value.keycloakId = foundUser.keycloakId; - formData.value.profileImage = new File([], foundUser.profileImageUrl); - formData.value.birthDate = foundUser.birthDate - ? new Date(foundUser.birthDate) - : null; - formData.value.responsibleArea = foundUser.responsibleArea; + formData.value = { + ...foundUser, + licenseExpireDate: + (foundUser.licenseExpireDate && + new Date(foundUser.licenseExpireDate)) || + null, + licenseIssueDate: + (foundUser.licenseIssueDate && + new Date(foundUser.licenseIssueDate)) || + null, + retireDate: + (foundUser.retireDate && new Date(foundUser.retireDate)) || null, + startDate: + (foundUser.startDate && new Date(foundUser.startDate)) || null, + birthDate: + (foundUser.birthDate && new Date(foundUser.birthDate)) || null, + }; + userId.value = foundUser.id; hqId.value = foundUser.branch[0].headOfficeId as string; brId.value = foundUser.branch[0].id; code.value = foundUser.code; isEdit.value = true; - console.log(hqId.value); } } } @@ -626,7 +604,7 @@ watch( dense outlined label="วันที่เริ่มงาน" - v-model="formData.startDate" + :model-value="dateFormat(formData.startDate)" >