/**
* =============================================================================
* menu1_3.html - 무료 맞춤 컨설팅 & 견적서 신청서 (#btn_sendmail)
* -----------------------------------------------------------------------------
* #btn_sendmail 버튼을 누르면 입력 내용을 모아 ajax/api_mail.php 로 발송합니다.
* (menu1_1.js / menu1_2.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 = $('#btn_sendmail').closest('form');
const $btn = $('#btn_sendmail');
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.name) {
return alert('담당자 성함 / 직책을 입력해 주세요.');
}
if (!data.phone) {
return alert('연락처를 입력해 주세요.');
}
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) {
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.start}`.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() || ''),
name: $.trim($('#qa_name').val() || ''),
phone: $.trim($('#qa_phone').val() || ''),
email: $.trim($('#qa_email').val() || ''),
type: $.trim($('#qa_option option:selected').text() || ''),
start: $.trim($('#qa_workday option:selected').text() || ''),
siteUrl: $.trim($('#qa_url').val() || ''),
etc: $.trim($('#qa_etc').val() || '')
};
}
function buildMessage(data) {
return [
'■ 구분 : 독립형 쇼핑몰 견적 문의',
'',
`■ 기업/브랜드명 : ${data.company}`,
`■ 담당자 : ${data.name}`,
`■ 연락처 : ${data.phone}`,
`■ 이메일 : ${data.email}`,
`■ 구축 유형 : ${data.type || '-'}`,
`■ 착수 시기 : ${data.start || '-'}`,
`■ 운영 사이트 URL : ${data.siteUrl || '-'}`,
'',
'■ 주요 요구사항 및 문의 내용',
data.etc || '(내용 없음)',
'',
'─────────────────────────────',
`접수일시 : ${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('목록 조회 중 통신 오류가 발생했습니다.')
});
}
});
$(document).ready(function () {
// 1. Smooth Scrolling for navigation anchors
$('a[href^="#"]').on('click', function (e) {
var target = $(this.getAttribute('href'));
if (target.length) {
e.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top - 80
}, 600);
}
});
// 2. Animated Number Counters
var countersStarted = false;
function checkCounters() {
if (!countersStarted && $('#hero').length) {
$('.counter').each(function () {
var $this = $(this);
var target = parseFloat($this.attr('data-target'));
var isFloat = target % 1 !== 0;
$({ countNum: 0 }).animate({ countNum: target }, {
duration: 2000,
easing: 'swing',
step: function () {
if (isFloat) {
$this.text(this.countNum.toFixed(2));
} else {
$this.text(Math.floor(this.countNum));
}
},
complete: function () {
$this.text(target);
}
});
});
countersStarted = true;
}
}
checkCounters();
// 3. Dynamic Live Dashboard Simulation
setInterval(function () {
var randomOffset = Math.floor(Math.random() * 300) - 150;
var baseTps = 14820;
var currentTps = (baseTps + randomOffset).toLocaleString();
$('#liveTps').text(currentTps);
// Randomize mock bar graphs height slightly for lively look
$('#dashboardBars > div').each(function () {
var currentH = parseInt($(this).css('height'));
var jitter = Math.floor(Math.random() * 14) - 7;
var newH = Math.min(Math.max(currentH + jitter, 30), 95);
$(this).css('height', newH + '%');
});
}, 2500);
// 4. Form Submission Handling with Validation
$('#consultForm').on('submit', function (e) {
e.preventDefault();
var company = $('#companyName').val().trim();
var contact = $('#contactName').val().trim();
var phone = $('#phone').val().trim();
var email = $('#email').val().trim();
var details = $('#projectDetails').val().trim();
var agree = $('#privacyAgree').is(':checked');
if (!company || !contact || !phone || !email || !details || !agree) {
// Highlight empty fields
$('#consultForm input, #consultForm textarea').each(function () {
if ($(this).prop('required') && !$(this).val().trim()) {
$(this).addClass('border-danger');
} else {
$(this).removeClass('border-danger');
}
});
if (!agree) {
$('#privacyAgree').addClass('border-danger');
}
return;
}
// Simulating async submission
var $submitBtn = $(this).find('button[type="submit"]');
var originalBtnText = $submitBtn.html();
$submitBtn.prop('disabled', true).html('견적 요청 접수 중...');
setTimeout(function () {
$('#consultForm').slideUp(300);
$('#formSuccessAlert').removeClass('d-none').hide().fadeIn(400);
// Reset form fields
$('#consultForm')[0].reset();
$submitBtn.prop('disabled', false).html(originalBtnText);
}, 1200);
});
// Clear validation error style on user input
$('#consultForm input, #consultForm textarea').on('input change', function () {
$(this).removeClass('border-danger');
});
// 5. Navbar background opacity on scroll
$(window).on('scroll', function () {
if ($(this).scrollTop() > 50) {
$('#mainNavbar').addClass('shadow-lg').css('background-color', 'rgba(11, 19, 43, 0.98)');
} else {
$('#mainNavbar').removeClass('shadow-lg').css('background-color', 'rgba(11, 19, 43, 0.95)');
}
});
});