diff --git a/front/src/main/resources/templates/info/user/user.html b/front/src/main/resources/templates/info/user/user.html index b0f3084c..781f2718 100644 --- a/front/src/main/resources/templates/info/user/user.html +++ b/front/src/main/resources/templates/info/user/user.html @@ -61,6 +61,7 @@
-
@@ -150,7 +150,6 @@
-
-
@@ -363,66 +362,73 @@ // selectboxInstance1.setValue($('input[name=regionMainCode]').val()); }, confirmPopup() { + //유효성 검사 + const form = document.getElementById('reqForm'); + kri.form.errorInit(form); + const selects = ['tel1', 'phone1', 'regionSubCode', 'regionDetailCode']; + selects.forEach(id => { + const sel = document.getElementById(id); + if (sel && sel.value) form[id].value = sel.value; + }); + + const errors = []; + if (!form.ownerName.value) errors.push({field: 'ownerName', message: '이름을 입력해 주세요.'}); + if (!form.ownerAge.value) errors.push({field: 'ownerAge', message: '연령을 입력해 주세요.'}); + if (form.ownerAge.value < 0 || form.ownerAge.value > 120) errors.push({field: 'ownerAge', message: '연령은 0세이상 120세 이하이어야 합니다.'}); + if (form.tel1.value || form.tel2.value || form.tel3.value) { + if (!form.tel1.value || !form.tel2.value || !form.tel3.value) { + errors.push({ field: 'tel1', message: '가구 연락처를 모두 입력해 주세요.' }); + } else { + const telRegex = /^(0[2-7][0-9]?)$/; // 지역번호 (예: 02, 031, 032 등) + if (!telRegex.test(form.tel1.value)) errors.push({ field: 'tel1', message: '가구 연락처를 입력해주세요' }); // 유효한 지역번호를 선택해 주세요. + if (form.tel2.value.length < 3 || form.tel2.value.length > 4) errors.push({ field: 'tel2', message: '가구 연락처를 입력해주세요.' });// 가구 연락처 중간 자리수는 3~4자리여야 합니다. + if (form.tel3.value.length !== 4) errors.push({ field: 'tel3', message: '가구 연락처를 입력해주세요.' }); // 가구 연락처 마지막 자리수는 4자리여야 합니다. + } + } + if (form.phone1.value || form.phone2.value || form.phone3.value) { + if (form.tel2.value.length === 3) errors.push({ field: 'tel1', message: '핸드폰 번호를 입력해 주세요.' }); + if (form.tel2.value.length < 3 || form.tel2.value.length > 4) errors.push({ field: 'tel2', message: '핸드폰 번호를 입력해 주세요.' }); + if (form.tel3.value.length !== 4) errors.push({ field: 'tel3', message: '핸드폰 번호를 입력해 주세요.' }); + } + if (!form.phone1.value ||!form.phone2.value || !form.phone3.value) errors.push({field: 'phone1', message: '휴대폰 번호를 입력해 주세요.'}); + if (form.phone1.value.length < 2 || form.phone2.value.length < 3 || form.phone2.value.length > 4 || form.phone3.value.length < 3 || form.phone3.value.length > 4) errors.push({field: 'phone1', message: '휴대폰 번호를 입력해 주세요.'}); + if (!form.regionSubCode.value) errors.push({field: 'regionSubCode', message: '지역을 선택해 주세요.'}); + if (!form.regionDetailCode.value) errors.push({field: 'regionDetailCode', message: '세부 지역를 선택해 주세요.'}); + if (!form.address.value) errors.push({field: 'address', message: '전체 주소를 입력해 주세요.'}); + + kri.form.error(errors); + if (errors.length > 0) return; + // 이름 변경 여부 처리 const currentName = document.querySelector('input[name="ownerName"]').value.trim(); const isNameChanged = currentName !== ENV.initialOwnerName; - - formControl.updateUserInfo(isNameChanged); + if(isNameChanged){ + ENV.module.confirmPopup.open(); + }else { + formControl.updateUserInfo(); + } }, confirmPopupOk() { ENV.module.confirmPopup.close(); - - setTimeout(() => { - ajaxUtil._alert('개인정보 변경이 완료되었습니다.', null, () => { - location.href = '/info'; - }); - }, 500); + formControl.updateUserInfo(); }, - updateUserInfo(showPopupIfValidNameChanged = false) { - + updateUserInfo() { const f = document.reqForm; - // // TODO 어쩔수 없이 이렇게 하는데..... 콤포넌트값 핸들링 방법 UX에서 지정하면 수정해야함. - // const tel1Element = document.getElementById('tel1Id'); - // const phone1IdElement = document.getElementById('phone1Id'); - // const regionMainCodeIdElement = document.getElementById('regionMainCodeId'); - // const regionSubCodeIdElement = document.getElementById('regionSubCodeId'); - // if (tel1Element && tel1Element.value) { - // f.tel1.value = tel1Element.value; - // } - // if (phone1IdElement && phone1IdElement.value) { - // f.phone1.value = phone1IdElement.value; - // } - // if (regionMainCodeIdElement && regionMainCodeIdElement.value) { - // f.regionMainCode.value = regionMainCodeIdElement.value; - // } - // if (regionSubCodeIdElement && regionSubCodeIdElement.value) { - // f.regionSubCode.value = regionSubCodeIdElement.value; - // } - f.regionSubCode.value = ENV.select.regionSelect.getParentValue(); f.regionDetailCode.value = ENV.select.regionSelect.getChildValue(); f.tel1.value = ENV.select.selectTel.getValue(); f.phone1.value = ENV.select.selectPhone.getValue(); - - - const obj = $(f).serializeObject(); - console.log(obj) ajaxUtil._ajaxAsync( ENV.httpUrl.user, - obj, + $(f).serializeObject(), function (rstData, status) { if (rstData.code === 'SUCCESS') { // 유효성 검사를 모두 통과한 후 - if (showPopupIfValidNameChanged) { - // 이름이 바뀐 경우만 팝업 - ENV.module.confirmPopup.open(); - } else { - ajaxUtil._alert('개인정보 변경이 완료되었습니다.', null, () => { - location.href = '/info'; - }); - } + ajaxUtil._alert('개인정보 변경이 완료되었습니다.', null, () => { + location.href = '/info'; + }); } else if (rstData.code === 'ERROR') { ajaxUtil._alert('잠시 뒤에 다시 시도해 주세요.', null); }