/** * ============================================================================= * menu1_2.html - 프로젝트 상담 및 견적 신청서 (#send_mail) * ----------------------------------------------------------------------------- * #send_mail 버튼을 누르면 입력 내용을 모아 ajax/api_mail.php 로 발송합니다. * (menu1_1.js 와 동일한 방식) * ============================================================================= */ $(document).ready(function () { 'use strict'; // ========================= // Config & Selectors // ========================= const API_BASE_URL = `${typeof hostURL !== 'undefined' ? hostURL : ''}/ajax/api.php`; const API_MAIL_URL = `${typeof hostURL !== 'undefined' ? hostURL : ''}/ajax/api_mail.php`; const API_CONTENT_URL = `${typeof hostURL !== 'undefined' ? hostURL : ''}/ajax/api_content.php`; const MAIL_TO = 'itfor21@naver.com'; // 문의 메일 수신 주소 (필요 시 변경) const SUBJECT_PREFIX = '[MyPR123:기업형홈피]'; const $form = $('#send_mail').closest('form'); const $btn = $('#send_mail'); const $btnHtml = $btn.html(); let sending = false; // 중복 발송 방지 if (!$form.length) { return; } //loadPosts(); // ========================= // Event Binding // ========================= $btn.on('click', onSubmitForm); $form.on('submit', onSubmitForm); // Enter 입력 대비(중복 발송은 sending 플래그로 차단) // ========================= // Handlers // ========================= function onSubmitForm(e) { e.preventDefault(); // 실제 전송은 ajax 로 처리 if (sending) { return; } const data = collectData(); if (!data.company) { return alert('회사명을 입력해 주세요.'); } if (!data.user) { return alert('담당자 성함 및 직함을 입력해 주세요.'); } if (!data.phone) { return alert('연락처를 입력해 주세요.'); } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) { return alert('이메일 주소를 정확히 입력해 주세요.'); } if (!$('#privacyCheck').prop('checked')) { return alert('개인정보 수집 및 상담 목적의 이용에 동의해 주세요.'); } setLoading(true); $.ajax({ url: API_MAIL_URL, type: 'POST', dataType: 'json', data: { to: MAIL_TO, subject: `${SUBJECT_PREFIX} ${data.company} ${data.phone} ${data.type} ${data.size}`.substring(0, 200), message: buildMessage(data), replyTo: data.email, html: false } }).done(function (res) { if (res && res.success) { alert('상담 신청이 정상적으로 접수되었습니다.\n영업일 기준 24시간 이내에 연락드리겠습니다.'); $form[0].reset(); } else { alert((res && res.message) ? res.message : '메일 발송에 실패했습니다.'); } }).fail(function (xhr) { const res = xhr.responseJSON; alert((res && res.message) ? res.message : '메일 발송 중 오류가 발생했습니다. 잠시 후 다시 시도해 주세요.'); }).always(function () { setLoading(false); }); } // ========================= // Helpers // ========================= function collectData() { return { company: $.trim($('#qa_subject').val() || ''), user: $.trim($('#qa_user').val() || ''), phone: $.trim($('#wa_phone').val() || ''), email: $.trim($('#qa_email').val() || ''), type: $.trim($('#qa_option option:selected').text() || ''), size: $.trim($('#qa_size option:selected').text() || ''), reference: $.trim($('#qa_etc').val() || ''), content: $.trim($('#qa_content').val() || '') }; } function buildMessage(data) { return [ '■ 구분 : 기업형 홈페이지 견적 문의', '', `■ 회사명 : ${data.company}`, `■ 담당자 : ${data.user}`, `■ 연락처 : ${data.phone}`, `■ 이메일 : ${data.email}`, `■ 제작 희망 유형 : ${data.type || '-'}`, `■ 예상 패키지 : ${data.size || '-'}`, `■ 참고 레퍼런스 : ${data.reference || '-'}`, `■ 개인정보 수집 동의 : 동의함`, '', '■ 프로젝트 개요 및 문의사항', data.content || '(내용 없음)', '', '─────────────────────────────', `접수일시 : ${new Date().toLocaleString('ko-KR')}` ].join('\n'); } function setLoading(loading) { sending = loading; $btn.prop('disabled', loading); $btn.html(loading ? ' 발송 중...' : $btnHtml); } // ========================= // List & Detail Logic // ========================= function loadPosts(searchType, searchKeyword, category) { const params = { action: 'detail', board_name: $('#board_name').val(), post_name: $('#post_name').val(), last:'0' }; if (searchKeyword) { params.search_type = searchType || 'title'; params.search_keyword = searchKeyword; } if (category && category !== 'all') { params.category = category; } $.ajax({ url: API_CONTENT_URL, method: 'GET', data: params, dataType: 'json', success(res) { if (!res.success) { alert(res.message || '목록 조회에 실패했습니다.'); return; } $('#my_content').html(res.data.content || ''); }, error: () => alert('목록 조회 중 통신 오류가 발생했습니다.') }); } });