var COUPON = function(){ var $coupon_add_form; var header_ctl; var $content; var $coupon_issue_list = ''; var is_modify = false; var type_group_code_list = []; var apply_type_category_list = []; var select_group_name = ''; var select_group_code = ''; var current_base_url = ''; var current_page = 1; var prev_search_get_issue_list_type_and_text = ''; var old_data = { apply_sale_percent : '', apply_sale_price : '', apply_sale_type : 'price', apply_sale_type_minimum_price : '', apply_sale_type_max_price : '', apply_type : '', apply_type_category_list : '', indeterminate_category_list : '', apply_type_product_list : '', apply_excluded_product_list : '', code : '', create_date : '', currency : '', end_date : '', is_limit : '', is_overlap : '', is_unlimited_date : '', limit_count : '', is_duplication : '', is_alarm : true, duration_type : 'none', menu_type : '', name : '', start_date : '', type : 'targeted', type_coupon_code : '', type_coupon_create_count : '', type_group_code : '', type_is_mult_coupon : '', type_target : 'all', unit_code : '', member_limit_count : '', is_delivery : '', use_guest : '', auto_data : '', }; var group_count = 0; var category_count = 0; var $group_name = ''; var $product_search_input; var $product_search_btn; var $product_search_list; // var $product_except_search_btn; var product_list = []; var product_list_data = []; var excluded_product_list = []; var excluded_product_list_data = []; var $product_add_btn; var $product_more_btn; var $product_apply_list; var $excluded_product_list; var $issue_search_btn; var $issue_search_type; var $issue_search_input; var page = 1; var init = function(){ $content = $('#content'); }; var is_submit = false; var is_issue_list_loading = false; var is_coupon_setting_open = false; //쿠폰 리스트 페이지 기본설정 var listInit = function(base_url){ current_base_url = base_url; var $coupon_list_table = $('#coupon_list_table'); $content.find('._check_list:checked').prop('checked', false); $content.find('._check_list').change(function(){ var check_list = $content.find('._check_list:checked'); var check_list_length = check_list.length; $content.find('._check_list_count').text(check_list_length); var _flag, _coupon_type; if(check_list_length === 1){ check_list.each(function(){ _flag = $(this).attr('data-issue-flag'); _coupon_type = $(this).attr('data-coupon-type'); if(_coupon_type === 'auto'){ if(_flag === 'Y'){ $content.find('._issue_flag_btn').text(getLocalizeString('설명_발행중지', '', '발행중지')); }else{ $content.find('._issue_flag_btn').text(getLocalizeString('설명_발행재개', '', '발행재개')); } } }); $content.find('._edit_btn').show(); $content.find('._issue_list_btn').show(); $content.find('#_copy_coupon_info_list_btn').show(); if(_coupon_type === 'auto'){ $content.find('._issue_flag_btn').show(); }else{ $content.find('._issue_flag_btn').hide(); } }else{ $content.find('._edit_btn').hide(); $content.find('._issue_list_btn').hide(); $content.find('._issue_flag_btn').hide(); $content.find('#_copy_coupon_info_list_btn').hide(); } // 전체 체크박스 업데이트 const isItemsChecked = Boolean(check_list_length); $content.find('._all_check').prop('checked', isItemsChecked); if(!isItemsChecked){ hideDeleteBtn(); } }); //체크박스 전체체크 설정 및 삭제버튼 표시 이벤트 설정 $content.find('input[type=\'checkbox\']').off('click.coupon_list_table').on('click.coupon_list_table', function(){ if($(this).hasClass('_all_check')){ $content.find('input[type=\'checkbox\']').prop('checked', $(this).prop('checked')); } if($coupon_list_table.find('input[type=\'checkbox\']:checked').length > 0){ var check_list = $content.find('._check_list:checked'); $content.find('._check_list_count').text(check_list.length); var _flag, _coupon_type; if(check_list.length === 1){ check_list.each(function(){ _flag = $(this).attr('data-issue-flag'); _coupon_type = $(this).attr('data-coupon-type'); if(_coupon_type === 'auto'){ if(_flag === 'Y'){ $content.find('._issue_flag_btn').text(getLocalizeString('설명_발행중지', '', '발행중지')); }else{ $content.find('._issue_flag_btn').text(getLocalizeString('설명_발행재개', '', '발행재개')); } } }); $content.find('._edit_btn').show(); $content.find('._issue_list_btn').show(); $content.find('#_copy_coupon_info_list_btn').show(); $content.find('._create_coupon_pack_link_btn').hide(); if(_coupon_type === 'AUTO'){ $content.find('._issue_flag_btn').show(); }else{ $content.find('._issue_flag_btn').hide(); } }else{ $content.find('._edit_btn').hide(); $content.find('._issue_list_btn').hide(); $content.find('._issue_flag_btn').hide(); $content.find('#_copy_coupon_info_list_btn').hide(); $content.find('._create_coupon_pack_link_btn').show(); } showDeleteBtn(); }else{ hideDeleteBtn(); } }); $content.find('._issue_fla_btn').off('click._issue_fla_btn').on('click._issue_fla_btn', function(){ updateCouponIssueFlag($(this).data('code'), $(this).data('flag')); }); $content.find('._delete_btn').off('click._delete_btn').on('click._delete_btn', function(){ deleteCoupon($(this).data('code')); }); $content.find('._edit_btn').off('click._edit_btn').on('click._edit_btn', function(){ var code; $content.find('._check_list:checked').each(function(){ code = $(this).val(); }); window.location.href = current_base_url + '&mode=add&code=' + code; }); $content.find('#_copy_coupon_info_list_btn').off('click.#_copy_coupon_info_list_btn').on('click.#_copy_coupon_info_list_btn', function(){ let code; $content.find('._check_list:checked').each(function(){ code = $(this).val(); }); window.location.href = current_base_url + '&mode=add©_coupon_code=' + code; }); $content.find('._copy_coupon_info_btn').off('click._copy_coupon_info_btn').on('click._copy_coupon_info_btn', function(){ window.location.href = current_base_url + '&mode=add©_coupon_code=' + $(this).data('code'); }); $content.find('._issue_list_btn').off('click._issue_list_btn').on('click._issue_list_btn', function(){ var code; $content.find('._check_list:checked').each(function(){ code = $(this).val(); }); if(code != ''){ openIssueDialog(code); } }); $content.find('._issue_flag_btn').off('click._issue_flag_btn').on('click._issue_flag_btn', function(){ var _flag; if($content.find('._check_list:checked').length === 1){ $content.find('._check_list:checked').each(function(){ _flag = $(this).attr('data-issue-flag'); //발행중 -> 발행중지처리 | 발행중지 -> 발행중 처리 if(_flag === 'Y'){ _flag = 'N'; }else{ _flag = 'Y'; } }); }else{ return false; } var code; $content.find('._check_list:checked').each(function(){ code = $(this).val(); }); updateCouponIssueFlag(code, _flag); }); $content.find('._coupon_search').off('keyup._coupon_search').on('keyup._coupon_search', function(e){ if(e.keyCode == 13){ startKeywordSearch(); } }); $content.find('._coupon_search_btn').off('click._coupon_search_btn').on('click._coupon_search_btn', function(e){ startKeywordSearch(); }); $content.find('._issue_btn').off('click._issue_btn').on('click._issue_btn', function(){ var code = $(this).data('code'); if(code != ''){ openIssueDialog(code); } }); $content.find('._modify_btn').off('click._modify_btn').on('click._modify_btn', function(){ window.location.href = current_base_url + '&mode=add&code=' + $(this).data('code'); }); $content.find('._create_coupon_pack_link_btn').off('click._create_coupon_pack_link_btn').on('click._create_coupon_pack_link_btn', function(){ let coupon_urls = []; let selected_count = $content.find('._check_list:checked').length; if (selected_count > 10) { alert('쿠폰팩 링크는 최대 10개까지의 다운로드 쿠폰만 포함할 수 있어요.'); return; } // 종료된 쿠폰 체크 let has_completed_coupon = false; $content.find('._check_list:checked').each(function(){ let $row = $(this).closest('tr'); let status_text = $row.find('td:nth-child(3) span').text(); // 상태 텍스트 가져오기 if(status_text === '종료' || status_text === '종료(!)') { has_completed_coupon = true; return false; // each 루프 중단 } }); if(has_completed_coupon) { alert('이미 종료된 쿠폰은 쿠폰팩 링크에 포함할 수 없어요.'); return; } let valid_url_count = 0; $content.find('._check_list:checked').each(function(){ // 체크박스에서 직접 쿠폰 URL 데이터 추출 let coupon_url = $(this).data('coupon-url'); if(coupon_url) { coupon_urls.push(coupon_url); valid_url_count++; } }); if(selected_count > 0 && selected_count !== valid_url_count) { alert("고객 다운로드 형식의 쿠폰만 링크로 만들 수 있어요. 선택한 쿠폰형식을 다시 확인해주세요."); return; } if(valid_url_count > 0) { // 사이트 URL + 쿠폰팩 파라미터 생성 let base_url = window.location.origin; let coupon_pack_url = base_url + '/?coupon_pack=' + coupon_urls.join('|'); // 클립보드에 복사 (Clipboard.js 활용) let tempElement = $('