File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
/**
*
* @author : 이호영
* @fileName : priceClclt.js
* @date : 2023.03.02
* @description : 알림톡 및 대체문자 금액 연산.js
* ===========================================================
* DATE AUTHOR NOTE
* ----------------------------------------------------------- *
* 2023.02.21 이호영 최초 생성
*
*
*
*/
// 발송 금액 '발송타입:00건' 초기 셋팅
var REP_PRICE_TXT = '<div class="info" id="repPriceTxt">'
+'$TYPETXT$ : <strong>$SU$</strong>건<span>/</span>'
// +'장문 :<strong>150</strong>건<span>/</span>'
// +'그림문자 :<strong>30</strong>건'
+'</div>'
// 카카오 mms sms 단가 셋팅
var KAKAO_AT_PRICE = '';
var SHORT_PRICE = '';
var LONG_PRICE = '';
$(document).ready(function(){
// 카카오 mms sms 단가 셋팅
KAKAO_AT_PRICE = $('#kakaoAtPrice').val();
SHORT_PRICE = $('#shortPrice').val();
LONG_PRICE = $('#longPrice').val();
///////////////////////////////////////// Mutation Observer
// 감시 대상 node 선택
// 변수X 수신자 목록
let target01 = document.getElementById('wrap01_body');
// 변수O 수신자 목록
let target02 = document.getElementById('wrap02');
// 대체 문자 단문 장문 텍스트 노드
let target03 = document.getElementById('afterDeny');
// 감시자의 설정
let option = {
subtree : true // 대상 노드의 자식 요소뿐만 아니라 후손 요소의 변화까지 감지
, childList : true // 대상 노드의 자식 요소(텍스트 포함)의 변화 감지
, attributes : true // 해당 노드의 attribute 속성
// , characterData: true // 대상 노드의 데이터 변화 감지
};
// wrap01 감시자 인스턴스 만들기
let observer_wrap01 = new MutationObserver((mutations) => {
// 노드가 변경 됐을 때의 작업
fn_priceClclt();
});
// wrap02 감시자 인스턴스 만들기
let observer_wrap02 = new MutationObserver((mutations) => {
// 노드가 변경 됐을 때의 작업
fn_priceClclt();
});
// wrap03 감시자 인스턴스 만들기
let observer_wrap03 = new MutationObserver((mutations) => {
// 노드가 변경 됐을 때의 작업
fn_priceClclt();
});
// 대상 노드에 감시자 전달
observer_wrap01.observe(target01, option);
observer_wrap02.observe(target02, option);
observer_wrap03.observe(target03, option);
///////////////////////////////////////// //Mutation Observer
});
/**
* @description 금액 계산 function
*/
function fn_priceClclt(phoneSu = 0){
console.log(":: at fn_priceClclt :: ");
// 미리보기 텍스트
var templateHtml = $('#smsTxtArea').val();
// var templateHtml = $('.template_text').html();
// 치환문자 여부 확인
var txtReplYn = $('#txtReplYn').val()
console.log('txtReplYn : ', txtReplYn);
// 수신 번호 개수
if(phoneSu == 0 && txtReplYn == 'Y')
phoneSu = $('.phoneArea').length;
if(phoneSu == 0 && txtReplYn == 'N')
phoneSu = tableL.getData().length;
// 대체문자 있는지 확인
var isSendFailChecked = $("#send_fail_check").is(":checked");
// 대체문자 하위에 장문 / 단문 select
var msgTypeText = $('.msg_com').text().trim();
if(typeof templateHtml == 'undefined') return false;
else if(isSendFailChecked && txtReplYn=='Y') fn_sendFailCheckedAndTxtRepl_Y(templateHtml, msgTypeText, phoneSu); // 대체문자 체크 & 치환문자 Y
else if(isSendFailChecked && txtReplYn=='N') fn_sendFailCheckedAndTxtRepl_N(msgTypeText, phoneSu); // 대체문자 체크 & 치환문자 N
else fn_sendFailUnChecked(phoneSu);
}
/**
*
* @param {*} phoneSu 수신자 수
* @description 금액 계산 function
* 대체 문자 X
* 카카오 금액 * 수신자 수 계산
*/
function fn_sendFailUnChecked(phoneSu){
// 카카오 금액 * 수신자 수
// fn_writePriceText() 첫 파라미터가 null이면 카카오 전송으로 인식
fn_writePriceText('', phoneSu);
// $('#totalPriceTxt').text((KAKAO_AT_PRICE * phoneSu).toFixed(1));
fn_priceText('알림톡', phoneSu);
}
/**
*
* @param {*} templateHtml 템플릿html
* @param {*} msgTypeText 발송 타입
* @param {*} phoneSu 수신자 수
* @description 금액 계산 function
* 대체 문자 O
* 치환 문자 O
*/
function fn_sendFailCheckedAndTxtRepl_Y(templateHtml, msgTypeText, phoneSu){
// 대체문자 하위에 html 그대로의 byte 계산이 단문일 경우에만 치환 후 장문이 있는지 확인
if(msgTypeText == '단문'){
msgTypeText = fn_transHtml(msgTypeText, templateHtml);
}
fn_writePriceText(msgTypeText, phoneSu);
fn_priceText(msgTypeText, phoneSu);
}
/**
*
* @param {*} msgTypeText 발송 타입
* @param {*} phoneSu 수신자 수
* @description 금액 계산 function
* 대체 문자 O
* 치환 문자 X
*/
function fn_sendFailCheckedAndTxtRepl_N(msgTypeText, phoneSu){
fn_priceText(msgTypeText, phoneSu);
fn_writePriceText(msgTypeText, phoneSu);
}
/**
*
* @param {*} msgTypeText 발송 타입
* @param {*} phoneSu 수신자 수
* @returns
* @description 발송 금액 계산 / 노출
*/
function fn_priceText(msgTypeText, phoneSu){
// $("#repPriceTxt").is(":visible") => 발송 금액 show hide 여부
if(phoneSu === 0){
$('#repPriceTxt').empty();
$('#repPriceTxt').hide();
return false;
}
// 텍스트 초기화
$('#repPriceTxt').show();
$('#repPriceTxt').empty();
var priceText = '$SENDTYPE$ :<strong>$SU$</strong>건';
priceText = priceText.replace('$SENDTYPE$', msgTypeText).replace('$SU$', phoneSu);
$('#repPriceTxt').append(priceText);
}
/**
* @description 발송금액 라인 text / 금액 초기화
*/
function priceInit(){
if($("#repPriceTxt").is(":visible")){
$('#repPriceTxt').empty();
$('#repPriceTxt').hide();
}
$('#totalPriceTxt').text(0.0);
}
/**
*
* @param {*} msgTypeText 발송 타입
* @param {*} phoneSu 수신자 수
* @description 발송 금액 '발송타입:00건' 노출
*/
function fn_writePriceText(msgTypeText, phoneSu){
var price;
msgTypeText = msgTypeText.trim();
if(msgTypeText == '단문') price = SHORT_PRICE * phoneSu;
else if(msgTypeText == '장문') price = LONG_PRICE * phoneSu;
else price = KAKAO_AT_PRICE * phoneSu; // 카카오
$('#totalPriceTxt').text(numberWithCommas((price).toFixed(1)));
}
/**
*
* @param {*} msgTypeText 발송 타입 : 단문
* @param {*} templateHtml 템플릿 html
* @returns msgTypeText : 단문 or 장문
* @description 치환 데이터 있는 경우 단문일 경우만 호출
* 치환 후 장문 데이터일경우 'returns 장문'으로 끝남
*/
function fn_transHtml(msgTypeText, templateHtml){
// 템플릿
templateHtml = templateHtml.trim().replace(/(<br>|<br\/>|<br \/>)/g, '\n');
// 치환 부분 '#{내용}'만 추출
var varList = $("#excelTemplateContent").val().match(/#\{([^}]+)\}/g);
// 템플릿을 반복할때마다 담는 temp 선언
var tempTemplateHtml;
// 치환 데이터 담는 변수 선언
var replaceStr;
// excelBody 부분 반복 시작
$('.excelBody').each(function(i, t){
tempTemplateHtml = templateHtml;
$(this).find('.transData').each(function(index, item){
// console.log('item text :: ', $(item).text().trim());
replaceStr = $(item).text().trim();
tempTemplateHtml = tempTemplateHtml.replace(varList[index], replaceStr);
});
// 치환 후 byte 계산
// 장문이면 break;
if(90 < conByteLeng(tempTemplateHtml))
{
msgTypeText = '장문';
return false;
}
});
return msgTypeText;
}