<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  :CouponPopupForm.html
 * @desc    : 쿠폰 등록 팝업 화면
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.05.17   bin2107     최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1500">
	<div class="panelStyle" style="height: 750px;">
		<div class="panelTitle">
			<h2 th:text="${'쿠폰 ' + (mode == 'N' ? '등록' : '수정')}">쿠폰등록</h2>
			<button type="button" class="close" onclick="uifnPopupClose('CouponCreatePopup')"><i class="fa fa-times"></i></button>
		</div>
		<div class="panelContent">
			<form id="CouponForm" name="CouponForm" action="#" th:action="@{'/marketing/coupon/save'}" >
				<input type="hidden" name="supplyCompList" id="supplyCompList"/>
				<input type="hidden" name="cpnId" id="cpnId" th:if="${cpnDetail}" th:value="${cpnDetail.cpnId}">
				<input type="hidden" name="mode" th:value="${mode}"/>
				<div class="tabs">
					<div class="tabsNav">
						<li class="on"><a href="#coupontab1">기본정보</a></li>
						<li><a href="#coupontab2">적용대상</a></li>
						<li><a href="#coupontab3">입점업체분담율</a></li>
					</div>
					<ul class="tabsCont">
						<li class="tab on" id="coupontab1">
							<div class="panelStyle">
								<table class="frmStyle">
									<colgroup>
										<col style="width:10%">
										<col style="width:45%;">
										<col style="width:10%">
										<col style="width:35%;">
									</colgroup>
									<tbody>
										<tr th:if="${cpnDetail}">
											<th>쿠폰번호</th>
											<td colspan="5">
												<span th:if="${cpnDetail}" th:text="${cpnDetail.cpnId}"></span>
											</td>
										</tr>
										<tr>
											<th>쿠폰명<em class="required" title="필수"></em></th>
											<td>
												<input type="text" name="cpnNm" id="cpnNm" required="required" data-valid-name="쿠폰명">
											</td>
											<th>쿠폰설명</th>
											<td>
												<input type="text" name="cpnDesc" id="cpnDesc" data-valid-name="쿠폰설명">
											</td>
										</tr>
										<tr>
											<th>쿠폰유형<em class="required" title="필수"></em></th>
											<td>
												<input type="hidden" id="cpnType" name="cpnType" required="required"  data-valid-name="쿠폰유형">
												<label class="rdoBtn" th:if="${cpnTypeList}" th:each="oneData, status : ${cpnTypeList}"> <input type="radio" name="rdoCpnType"  th:text="${oneData.cdNm}" th:value="${oneData.cd}"/></label>
											</td>
											<th>사이트<em class="required" title="필수"></em></th>
											<td>
												<select name="siteCd" id="siteCd" required="required" data-valid-name="사이트">
													<option th:if="${siteCdList}" th:each="oneData , status : ${siteCdList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
												</select>
											</td>
										</tr>
										<tr>
											<th>할인방식<em class="required" title="필수"></em></th>
											<td>
												<input type="hidden" name="dcWay" id="dcWay" required="required" data-valid-name="할인방식">
												<label class="rdoBtn" th:if="${dcWayList}" th:each="oneData, status : ${dcWayList}"> <input type="radio" name="rdoDcWay"  th:text="${oneData.cdNm}" th:value="${oneData.cd}"/></label>
											</td>
											<th>할인값(PC)<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" id="dcPval" name="dcPval" value="0" required="required" data-valid-name="할인값(PC)" data-valid-type="numeric" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);"><span id="dcPvalSpan">원</span>
												<button type="button" class="btn btn-default btn-lg" id="applySameValueBtn">동일적용</button>
											</td>
										</tr>
										<tr>
											<th>할인값(모바일웹)<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" id="dcMval" name="dcMval" value="0" required="required" data-valid-name="할인값(모바일웹)" data-valid-type="numeric" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);"><span id="dcMvalSpan">원</span>
											</td>
											<th>할인값(모바일앱)<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" id="dcAval" name="dcAval" value="0" required="required" data-valid-name="할인값(모바일앱)" data-valid-type="numeric" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);"><span id="dcAvalSpan">원</span>
											</td>
										</tr>
										<tr>
											<th class="buyLimitAmtArea">구매제한금액<em class="required" title="필수"></em></th>
											<td class="buyLimitAmtArea">
												<input type="text" id="buyLimitAmt" name="buyLimitAmt" class="w200" required="required" value="0" style="text-align: right;" data-valid-name="구매제한금액" data-valid-type="numeric">원
											</td>
											<th class="maxDcAmtArea">최대할인금액<em class="required" title="필수"></em></th>
											<td class="maxDcAmtArea">
												<input type="text" class="w200" id="maxDcAmt" name="maxDcAmt" value="0" required="required" data-valid-name="최대할인금액" data-valid-type="numeric" style="text-align: right;"><span id="maxDcAmtSpan">원</span>
											</td>
										</tr>
										<tr>
											<th class="downStdtArea">다운로드시작일시<em class="required" title="필수"></em></th>
											<td class="downStdtArea">
												<input type="hidden" name="downStdt" id="downStdt" required="required" data-valid-name="다운로드시작일시">
												<input type="text" class="schDate w100" name="downStDay" id="downStDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="downStHH" id="downStHH">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
												<select name="downStMM" id="downStMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											<th class="downEddtArea">다운로드종료일시<em class="required" title="필수"></em></th>
											<td class="downEddtArea">
												<input type="hidden" id="downEddt" name="downEddt" required="required" data-valid-name="다운로드종료일시">
												<input type="text" class="schDate w100" name="downEdDay" id="downEdDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="downEdHH" id="downEdHH" onclick="fnChangeEdHH(this);">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
													<option th:text="24시" th:value="24"></option>
												</select>
												<select name="downEdMM" id="downEdMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											</td>
										</tr>
										<tr>
											<th class="pdGbArea">기간/일수구분<em class="required" title="필수"></em></th>
											<td class="pdGbArea">
												<select name="pdGb" id="pdGb" onchange="pdGbChange(this)" required="required" data-valid-name="기간/일수구분">
													<option value="P">기간</option>
													<option value="D">일수</option>
												</select>
											</td>
											<th class="availDaysArea">유효기간일수<em class="required" title="필수"></em></th>
											<td class="availDaysArea">
												<input type="text" name="availDays" id="availDays" class="w200" data-valid-name="유효기간일수">
											</td>
										</tr>
										<tr>
											<th class="availDateTr">유효기간시작일시<em class="required" title="필수"></em></th>
											<td class="availDateTr">
												<input type="hidden" name="availStdt" id="availStdt" data-valid-name="유효기간시작일시">
												<input type="text" class="schDate w100" name="availStDay" id="availStDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="availStHH" id="availStHH">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
												<select name="availStMM" id="availStMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											<th class="availDateTr">유효기간종료일시<em class="required" title="필수"></em></th>
											<td class="availDateTr">
												<input type="hidden" id="availEddt" name="availEddt" data-valid-name="유효기간종료일시">
												<input type="text" class="schDate w100" name="availEdDay" id="availEdDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="availEdHH" id="availEdHH" onclick="fnChangeEdHH(this);">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
													<option th:text="24시" th:value="24"></option>
												</select>
												<select name="availEdMM" id="availEdMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											</td>
										</tr>
										<tr class="dcCdCheck1">
											<th>총발행제한수량<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" name="totPubLimitQty" id="totPubLimitQty" value="0" required="required" data-valid-name="총발행제한수량" data-valid-type="numeric" style="text-align: right;">개
												<label class="chkBox" id="chkBoxTotPubQty"><input type="checkbox" id="chkNoLimitTotPubLimitQty"/>제한없음</label>
											</td>
											<th>1인당발행제한수량<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" name="custPubLimitQty" id="custPubLimitQty" value="0" required="required" data-valid-name="1인당발행제한수량" data-valid-type="numeric" style="text-align: right;">개
												<label class="chkBox" id="chkBoxCustPubQty"><input type="checkbox" id="chkNoLimitCustPubLimitQty"/>제한없음</label>
											</td>
										</tr>
										<tr>
											<th class="dcCdCheck2">1회발행수량<em class="required" title="필수"></em></th>
											<td class="dcCdCheck2">
												<input type="text" class="w200" name="onePubQty" id="onePubQty" value="1" required="required" data-valid-name="1회발행수량" data-valid-type="numeric" style="text-align: right;">개
											</td>
											<th class="downAblArea">다운로드가능여부<em class="required" title="필수"></em></th>
											<td class="downAblArea">
												<select name="downAblYn" id="downAblYn" required="required" data-valid-name="다운로드가능여부">
													<option value="Y" selected="selected">Y</option>
<!--													<option value="N" >N</option>-->
												</select>
											</td>
										</tr>
										<tr>
											<th>쿠폰상태<em class="required" title="필수"></em></th>
											<td>
												<label class="rdoBtn" th:if="${cpnStatList}" th:each="oneData, status : ${cpnStatList}" >
													<input type="radio" id="disCpnStat" name="disCpnStat" th:value="${oneData.cd}" th:text="${oneData.cdNm}" data-valid-name="상태" disabled="disabled"/>
												</label>
												<input type="hidden" id="cpnStat" name="cpnStat"/>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
						</li>
						<li class="tab" id="coupontab2">
							<div class="panelStyle">
								<div class="inner-panelContent">
									<div class="panelContent">
										<div class="panelBar">
											<h4>적용 대상 상품 등록</h4>
										</div>
										<table class="frmStyle">
											<colgroup>
												<col style="width:15%;">
												<col style="width:85%;">
											</colgroup>
											<tbody>
											<tr>
												<th>적용범위<em class="required" title="필수"></em></th>
												<td>
													<input type="hidden" name="applyScope" id="applyScope" required="required" data-valid-name="적용범위">
													<label class="rdoBtn"> <input type="radio" name="rdoApplyScope" value="A"/>전체</label>
													<label class="rdoBtn"> <input type="radio" name="rdoApplyScope" value="I"/>개별</label>
												</td>
											</tr>
											<tr class="supplyTrArea">
												<th>공급처</th>
												<td>
													<div class="padding10 inner-tb-solid">
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnSupplyAdd">공급처 추가</button>
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnSupplyDel">선택삭제</button>
														<br/>
														<div id="supplyGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
													</div>
												</td>
											</tr>
											<tr class="brandTrArea">
												<th>브랜드</th>
												<td>
													<div class="padding10 inner-tb-solid">
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnBrandAdd">브랜드 추가</button>
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnBrandDel">선택삭제</button>
														<br/>
														<div id="brandGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
													</div>
												</td>
											</tr>
											<tr class="categoryTrArea">
												<th>카테고리</th>
												<td>
													<div class="padding10 inner-tb-solid">
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnCateAdd">카테고리 추가</button>
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnCateDel">선택삭제</button>
														<br/>
														<div id="cateGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
													</div>
												</td>
											</tr>
											<tr class="goodsTrArea">
												<th>적용상품</th>
												<td>
													<div class="padding10 inner-tb-solid">
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnGoodsAdd">상품 추가</button>
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnGoodsDel">선택삭제</button>
														<br/>
														<div id="goodsGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
													</div>
												</td>
											</tr>
											</tbody>
										</table>
									</div>
								</div>
								<div class="inner-panelContent exceptArea">
									<div class="panelContent">
										<div class="panelBar">
											<h4>적용 대상 상품 등록</h4>
										</div>
										<table class="frmStyle">
											<colgroup>
												<col style="width:15%;">
												<col style="width:85%;">
											</colgroup>
											<tbody>
											<tr>
												<th>제외상품</th>
												<td>
													<div class="padding10 inner-tb-solid">
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnExcepGoodsAdd">제외상품 추가</button>
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnExcepGoodsDel">선택삭제</button>
														<br/>
														<div id="excepGoodsGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
													</div>
												</td>
											</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</li>
						<li class="tab" id="coupontab3">
							<div class="panelStyle">
								<div class="inner-panelContent">
									<div class="panelContent">
										<div class="panelBar">
											<h4>업체 분담율</h4>
										</div>
										<table class="frmStyle">
											<colgroup>
												<col style="width:15%;">
												<col style="width:85%;">
											</colgroup>
											<tbody>
											<tr>
												<th>업체 분담율</th>
												<td>
													<div class="padding10 inner-tb-solid">
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnAddApplyBurden">업체추가</button>
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnDelApplyBurden">선택삭제</button>
														<br/>
														<div id="inComGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
													</div>
												</td>
											</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</li>
					</ul>
				</div>
				<div class="mdPopBtnB aR">
					<button type="button" class="btn btn-info btn-lg" onclick="fnPubCustListPopUp();" th:if="${mode == 'U'}">발급받은회원</button>
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnCouponSave" onclick="fnCouponCreate();" th:text="${mode == 'N' ? '등록' : '수정'}"></button>
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnChangeStatIng" style="display: none;">진행</button>
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnCouponStop" style="display: none;">중지</button>
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnCouponEnd" style="display: none;">종료</button>
				</div>
			</form>
		</div>
	</div>
</div>
<script th:inline="javascript">
	/*<![CDATA[*/
	var mode = [[${mode}]];
	var cpnDetail = [[${cpnDetail}]];
	var cpnDtlRefvalSupplyCompList = [[${cpnDtlRefvalSupplyCompList}]];
	var cpnDtlRefvalApplyGoodsList = [[${cpnDtlRefvalApplyGoodsList}]];
	var cpnDtlRefvalCateList = [[${cpnDtlRefvalCateList}]];
	var cpnDtlRefvalBrandList = [[${cpnDtlRefvalBrandList}]];
	var cpnDtlRefvalExceptGoodsList = [[${cpnDtlRefvalExceptGoodsList}]];
	var cpnDtlBurdenList = [[${cpnDtlBurdenList}]];

	var issueCnt = [[${issueCnt}]];

	// 공통코드 리스트
	var ibSupplyComList = gagajf.convertToArray([[${ibSupplyCompList}]]);
	var formalGbList = gagajf.convertToArray([[${formalGbList}]]);
	var cateGbList = gagajf.convertToArray([[${cateGbList}]]);
	var delYnList = { "Y":"Yes", "N":"No" };
	var selfBrandList = gagajf.convertToArray([[${selfBrandList}]]);
	var siteCdList = gagajf.convertToArray([[${siteCdList}]]);

	// ag-grid 입점업체분담율 컬럼
	var columnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "입점업체코드" , field:"supplyCompCd" , width:150, cellClass:"text-center"} ,
		{ headerName: "입점업체명"  , field: "supplyCompNm" , width: 120 , cellClass: 'text-center'},
		{ headerName: "쿠폰분담율(%)", field:"burdenRate" , width:150, cellClass: "text-center" , required: true
			,valueFormatter: function(params) {
				if(params.value && params.value > 0) {
					if(params.value > 100){
						mcxDialog.alert('할인율은 100이하로 설정해주세요.');
						params.data.burdenRate = '0';
						return '0';
					}
					return params.value.addComma();
				} else {
					return '0';
				}
			},
			cellEditorParams: { maxlength: 4, validType: 'numeric'}
		} ,
		{ headerName: "쿠폰번호"  , field: "cpnId" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 공급처 컬럼
	var supplyColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName : "공급업체코드" , field: "supplyCompCd" , width:150, cellClass: 'text-center'} ,
		{ headerName: "공급업체명" , field: "supplyCompNm" , width:150, cellClass: 'text-center'},
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 브랜드 컬럼
	var brandSelColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName : "브랜드ID" , field: "brandCd" , width: 120, cellClass : 'text-center'} ,
		{ headerName : "브랜드명" , field: "brandEnm" , width: 120, cellClass: 'text-center'} ,
		//{ headerName : "공급업체명", field: "supplyCompNm" , width: 150, cellClass: 'text-center' } ,
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 적용상품 컬럼
	var goodsSelColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "상품구분" , field: "goodsGb" , width: 100, cellClass: 'text-center'} ,
		{ headerName: "Product ID" , field: "goodsCd" , width: 120, cellClass: 'text-center'},
		{ headerName: "상품명"  , field: "goodsNm" , width: 250 , cellClass: 'text-center'} ,
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 카테고리 컬럼
	var cateSelColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "사이트" , field: "siteCd" , width: 100 , cellClass: 'text-center' ,
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(siteCdList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(siteCdList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(siteCdList, params.newValue); }
		},
		{ headerName: "카테고리구분" , field: "cateGb" , width: 100 , cellClass: 'text-center' ,
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(cateGbList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(cateGbList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(cateGbList, params.newValue); }
		},
		{ headerName: "카테고리코드" , field: "cateNo" , width: 100 , cellClass: 'text-center'} ,
		{ headerName: "카테고리명" , field: "cateNm" , width: 120 , cellClass: 'text-center'},
		{ headerName: "이월/정상구분" , field: "formalGb" , width: 120 , cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(formalGbList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(formalGbList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(formalGbList, params.newValue); }
		},
		{ headerName: "브랜드명" , field:"brandCd" , width:150, cellClass: "text-center", required: true ,
			editable: true, cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(selfBrandList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(selfBrandList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(selfBrandList, params.newValue); }
		},
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 제외상품 컬럼
	var excepGoodsColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "상품구분" , field: "goodsGb" , width: 100, cellClass: 'text-center'} ,
		{ headerName: "Product ID" , field: "goodsCd" , width: 120, cellClass: 'text-center'},
		{ headerName: "상품명"  , field: "goodsNm" , width: 250 , cellClass: 'text-center'} ,
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	var inComGridOptions = gagaAgGrid.getGridOptions(columnDefs);
	var cateGridOptions = gagaAgGrid.getGridOptions(cateSelColumnDefs);
	var goodsGridOptions = gagaAgGrid.getGridOptions(goodsSelColumnDefs);
	var brandGridOptions = gagaAgGrid.getGridOptions(brandSelColumnDefs);
	var supplyGridOptions = gagaAgGrid.getGridOptions(supplyColumnDefs);
	var excepGoodsGridOptions = gagaAgGrid.getGridOptions(excepGoodsColumnDefs);

	inComGridOptions.rowSelection = "multiple";
	goodsGridOptions.rowSelection = "multiple";
	supplyGridOptions.rowSelection = "multiple";
	excepGoodsGridOptions.rowSelection = "multiple";
	cateGridOptions.rowSelection = "multiple";
	brandGridOptions.rowSelection = "multiple";

	// 삭제버튼 클릭시
	// 1.공급업체
	$('#btnSupplyDel').on('click', function() {
		supplyGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(supplyGridOptions)});
	});
	// 2.브랜드
	$('#btnBrandDel').on('click', function() {
		brandGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(brandGridOptions)});
	});
	// 3.카테고리
	$('#btnCateDel').on('click', function() {
		cateGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(cateGridOptions)});
	});
	// 4.적용상품
	$('#btnGoodsDel').on('click', function() {
		goodsGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(goodsGridOptions)});
	});
	// 5.제외상품
	$('#btnExcepGoodsDel').on('click', function() {
		excepGoodsGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(excepGoodsGridOptions)});
	});

	// 업체분담율 추가 버튼 클릭시
	$('#CouponForm #btnAddApplyBurden').on('click', function() {
		cfnOpenCompanyListPopup("fnSetPopupApplyBurdenInfo" , "M" ,"","","N");
	});

	// 분담업체율 설정 / 업체 추가 콜백함수
	var fnSetPopupApplyBurdenInfo = function(result) {
		// 기존 리스트 데이터 for
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(inComGridOptions);		// 받아온 모든 데이터

			// 받아온 data for
			for(let j = 0 ; j < gridListValue.length ; j++) {
				// 동일한 data는 추가하지 않음
				if(gridListValue[j].supplyCompCd == result[i].supplyCompCd) {	addChk = false;	}		// 중복체크
			}

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(inComGridOptions, {"supplyCompCd" : result[i].supplyCompCd, "supplyCompNm" : result[i].supplyCompNm, "burdenRate"  : 100, "delYn" : result[i].delYn});
			}
		}
	};

	// 종료시간 클릭시
	var fnChangeEdHH = function (obj){
		var selectId = obj.id;
		var changeId = "";
		if(selectId == "downEdHH"){
			changeId = "downEdMM";
		}else if(selectId == "availEdHH"){
			changeId = "availEdMM";
		}else if(selectId == "buyEdHH"){
			changeId = "buyEdMM";
		}else{
			changeId = "custJoinEdMM";
		}
		if(obj.value == 24) {
			$("#CouponForm #"+changeId+" option").hide();
			$('#CouponForm #'+changeId+' option:first').show().prop("selected", true);
		} else {
			$("#CouponForm #"+changeId+" option").show();
		}
	};

	// 총발행 제한수량 -> 제한없음 처리
	$("#CouponForm #chkBoxTotPubQty").bind('click', function (){
		var chkBox= document.getElementById('chkNoLimitTotPubLimitQty').checked;

		var cpnStat = $('#CouponForm input:radio[name="disCpnStat"]:checked').val();
		if(cpnStat=='G232_10'){
			if(chkBox){ //true 체크가 되어있었는데 해제됐어 -> 값0 inputbox disabled 해제
				$("#CouponForm #totPubLimitQty").val(0);
				$("#CouponForm input[id=totPubLimitQty]").prop("disabled", true);
				$("#CouponForm input[id=totPubLimitQty]").prop("readonly", true);
			}else{	//false 체크가 안되어있었는데 체크됐어 -> 값0 inputbox disabled
				$("#CouponForm #totPubLimitQty").val(0);
				$("#CouponForm input[id=totPubLimitQty]").prop("disabled", false);
				$("#CouponForm input[id=totPubLimitQty]").prop("readonly", false);
			}
		}
	});

	// 1인당발행 제한수량 -> 제한없음 처리
	$("#CouponForm #chkBoxCustPubQty").bind('click', function (){
		var chkBox= document.getElementById('chkNoLimitCustPubLimitQty').checked;
		var cpnStat = $('#CouponForm input:radio[name="disCpnStat"]:checked').val();
		if(cpnStat=='G232_10'){
			if(chkBox){ //true 체크가 되어있었는데 해제됐어 -> 값0 inputbox disabled 해제
				$("#CouponForm #custPubLimitQty").val(0);
				$("#CouponForm input[id=custPubLimitQty]").prop("disabled", true);
				$("#CouponForm input[id=custPubLimitQty]").prop("readonly", true);
			}else{	//false 체크가 안되어있었는데 체크됐어 -> 값0 inputbox disabled
				$("#CouponForm #custPubLimitQty").val(0);
				$("#CouponForm input[id=custPubLimitQty]").prop("disabled", false);
				$("#CouponForm input[id=custPubLimitQty]").prop("readonly", false);
			}
		}
	});

	// 할인방식 할인율 일때, 할인값 체크
	var fnDcValOnkeyUp = function (obj){
		var inputName = $(obj).attr("name");
		var rdoDcWay = $('#CouponForm input:radio[name="rdoDcWay"]:checked').val();
		var dcVal = $("#CouponForm input[name="+inputName+"]").val();
		if(rdoDcWay == "G240_11"){
			if(dcVal > 100){
				mcxDialog.alert('할인율은 100을 넘을수 없습니다.');
				$("#CouponForm input[name="+inputName+"]").val('');
				$("#CouponForm input[name="+inputName+"]").focus();
				return;
			}
		}
	}

	// 할인값 동일적용
	$("#applySameValueBtn").bind('click change', function () {
		var cdPval = $("#CouponForm input[name=dcPval]").val();
		$("#CouponForm input[name=dcMval]").val(cdPval);
		$("#CouponForm input[name=dcAval]").val(cdPval);
	});

	function checkValidation2(){
		// 쿠폰명 체크
		var chkCpnNm = $('#CouponForm input[name=cpnNm]').val();
		if(gagajf.isNull(chkCpnNm)){
			mcxDialog.alert("쿠폰명을 입력해주세요.");
			$('#CouponForm input[name=cpnNm]').focus();
			return false;
		}

		// 할인금액, 할인율 체크
		var chkDcPval = $('#CouponForm input[name=dcPval]').val();
		var chkDcMval = $('#CouponForm input[name=dcMval]').val();
		var chkDcAval = $('#CouponForm input[name=dcAval]').val();
		if(gagajf.isNull(chkDcPval)){
			mcxDialog.alert("할인값(PC)을 입력해주세요.");
			$('#CouponForm input[name=dcPval]').focus();
			return false;
		}
		if(gagajf.isNull(chkDcMval)){
			mcxDialog.alert("할인값(모바일웹)을 입력해주세요.");
			$('#CouponForm input[name=dcMval]').focus();
			return false;
		}
		if(gagajf.isNull(chkDcAval)){
			mcxDialog.alert("할인값(모바일앱)을 입력해주세요.");
			$('#CouponForm input[name=dcAval]').focus();
			return false;
		}

		return true;
	}

	// 즉시할인쿠폰일때 데이터 validation 체크
	var checkValidation10 = function (){
		var stdt = $('#CouponForm #availStdt').val();
		var eddt = $('#CouponForm #availEddt').val();
		if(gagajf.isNull(stdt)){
			mcxDialog.alert("유효기간 시작일시를 입력해주세요.");
			return false;
		}
		if(gagajf.isNull(eddt)){
			mcxDialog.alert("유효기간 종료일시를 입력해주세요.");
			return false;
		}
		if(stdt>eddt){
			mcxDialog.alert("시작일시가 종료일시보다 클 수 없습니다.");
			return false;
		}

		return true;
	}

	var checkValidation20 = function (cpnType){
		// 할인율 validation 체크 (100을 넘길수없음)
		if($('#dcWay').val() == 'G240_11') {
			if($('#dcPval').val() > 100) {
				mcxDialog.alert('PC할인율은 100을 초과할수없습니다.');
				$('#dcPval').focus();
				return false;
			} else if( $('#dcMval').val() > 100) {
				mcxDialog.alert('모바일(웹)할인율은 100을 초과할수없습니다.');
				$('#dcMval').focus();
				return false;
			}  else if( $('#dcAval').val() > 100) {
				mcxDialog.alert('모바일(앱)할인율은 100을 초과할수없습니다.');
				$('#dcAval').focus();
				return false;
			}
		}

		var chkLimitCpnCnt = document.getElementById('chkNoLimitTotPubLimitQty').checked;
		if(!chkLimitCpnCnt){
			let cnt = $("#CouponForm").find("[name=totPubLimitQty]").val();
			if(cnt < 1){
				mcxDialog.alert("총발행 제한수량은 0보다 커야합니다.");
				return false;
			}
		}

		var chkCustLimitCpnCnt = document.getElementById('chkNoLimitCustPubLimitQty').checked;
		if(!chkCustLimitCpnCnt){
			let cnt = $("#CouponForm").find("[name=custPubLimitQty]").val();
			if(cnt < 1){
				mcxDialog.alert("1인당 발행 제한수량은 0보다 커야합니다.");
				return false;
			}
		}

		var chkIssueCnt = $("#CouponForm").find("[name=onePubQty]").val();
		if(chkIssueCnt < 1){
			mcxDialog.alert("1회발행 제한수량은 0보다 커야합니다.");
			return false;
		}

		return true;
	}

	// 쿠폰 등록
	function fnCouponCreate(){
		// 필수값들 셋팅
		setReqValue();

		// 데이터 validation 체크
		if(!checkValidation2()) {
			return false;
		}

		var chkCpnType = $("#CouponForm input[name=rdoCpnType]:checked").val();
		if(chkCpnType == 'G230_10'){	// 즉시할인쿠폰일때
			if(!checkValidation10()){
				return false;
			}
		}else{
			if(!checkValidation20(chkCpnType)){
				return false;
			}
		}
		var usableCustGbArr = [];
		var usableCustGradeArr = [];
		var payTypeArr = [];

		mcxDialog.confirm('저장하시겠습니까?' , {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function () {
				var data = {
					cpnId : $('#CouponForm input[name=cpnId]').val()
					,cpnNm : $('#CouponForm input[name=cpnNm]').val()
					,cpnDesc : $('#CouponForm input[name=cpnDesc]').val()
					,siteCd : $('#CouponForm select[name=siteCd]').val()
					,cpnType : $('input:radio[name="rdoCpnType"]:checked').val()
					,applyScope : $('input:radio[name="rdoApplyScope"]:checked').val()
					,dcWay : $('input:radio[name="rdoDcWay"]:checked').val()
					,dcPval : $('#CouponForm input[name=dcPval]').val().replaceAll(',','')
					,dcMval : $('#CouponForm input[name=dcMval]').val().replaceAll(',','')
					,dcAval : $('#CouponForm input[name=dcAval]').val().replaceAll(',','')
					,maxDcAmt : $('#CouponForm input[name=maxDcAmt]').val().replaceAll(',','')
					,pdGb : $('#CouponForm select[name=pdGb]').val()
					,availStdt : $('#CouponForm input[name=availStdt]').val()
					,availEddt : $('#CouponForm input[name=availEddt]').val()
					,availDays : $('#CouponForm input[name=availDays]').val()
					,custPubLimitQty : $('#CouponForm input[name=custPubLimitQty]').val().replaceAll(',','')
					,totPubLimitQty : $('#CouponForm input[name=totPubLimitQty]').val().replaceAll(',','')
					,onePubQty : $('#CouponForm input[name=onePubQty]').val().replaceAll(',','')
					,downStdt : $('#CouponForm input[name=downStdt]').val()
					,downEddt : $('#CouponForm input[name=downEddt]').val()
					,buyLimitAmt : $('#CouponForm input[name=buyLimitAmt]').val().replaceAll(',','')
					,cpnStat : $('input:radio[name="disCpnStat"]:checked').val()
					,endAlimYn : 'N'
					,firstOrdYn : 'N'
					,downAblYn : 'Y'
					,custJoinStdt : null
					,custJoinEddt : null
					,buyStdt : null
					,buyEddt : null
					,newCustYn : 'N'
					,dcCdGb : 'G233_00'
					,rdCpnNm : null
					,usableCustGbArr : usableCustGbArr
					,usableCustGradeArr : usableCustGradeArr
					,payTypeArr : payTypeArr
					,supplyCompList : gagaAgGrid.getAllRowData(supplyGridOptions)
					,brandList : gagaAgGrid.getAllRowData(brandGridOptions)
					,applyGoodsList : gagaAgGrid.getAllRowData(goodsGridOptions)
					,exceptGoodsList : gagaAgGrid.getAllRowData(excepGoodsGridOptions)
					,cateList : gagaAgGrid.getAllRowData(cateGridOptions)
					,burdenList : gagaAgGrid.getAllRowData(inComGridOptions)
					,mode : $('#CouponForm input[name=mode]').val()
					,limitedTimeCpnList : null
					,afChannelList : null
					,scmYn : 'Y'
				};
				var jsonData = JSON.stringify(data);
				console.log('jsonData::>>'+jsonData);
				gagajf.ajaxJsonSubmit($('#CouponForm').prop('action'), jsonData, fnCouponSaveCollback);
			}
		});
	}

	var fnCouponSaveCollback = function (result){
		uifnPopupClose('CouponRegForm');
		$('#btnSearch').trigger('click');
	}

	// 쿠폰 수정 시
	function fnCouponUpdate(){
		mcxDialog.confirm('수정하시겠습니까?' , {
			cancelBtnText:"취소",
			sureBtnText:"확인",
			sureBtnClick: function () {
				gagajf.removeCommaAtNumberFormattedInput('#CouponForm');
				// disabled 해제
				$("#CouponForm * ").attr("readonly" , false);
				$("#CouponForm * ").prop("disabled" , false);
				// 필수값들 셋팅
				setReqValue();
				// 필수값 validation 체크
				if (!gagajf.validation('#CouponForm')) {
					return false;
				}
				if(!checkValidation()) {
					return false;
				}

				gagajf.ajaxFormSubmit($('#CouponForm').prop('action'), '#CouponForm', function() {
					uifnPopupClose('CouponRegForm');
					$('#btnSearch').trigger('click');
				});
			}
		});
	}
	// disabled 해제
	function setDisabledFalse(){ //debugger;


	}

	function checkValidation(){
		// 할인율 validation 체크 (100을 넘길수없음)
		if($('#dcWay').val() == 'G240_11') {
			if($('#dcPval').val() > 100) {
				mcxDialog.alert('PC할인율은 100을 초과할수없습니다.');
				$('#dcPval').focus();
				return false;
			} else if( $('#dcMval').val() > 100) {
				mcxDialog.alert('모바일(웹)할인율은 100을 초과할수없습니다.');
				$('#dcMval').focus();
				return false;
			}  else if( $('#dcAval').val() > 100) {
				mcxDialog.alert('모바일(앱)할인율은 100을 초과할수없습니다.');
				$('#dcAval').focus();
				return false;
			}
		}

		return true;
	}

	// 할인방식 변경
	$("#CouponForm input[name=rdoDcWay]").bind('click change', function () {
		var radioValue = $(this).val();
		//발급이력이있으면 수정안됨
		if(issueCnt > 0 ) {
			return false;
		}

		if(radioValue == 'G240_10') {		//할인금액
			$('#dcPvalSpan').text("원");
			$('#dcMvalSpan').text("원");
			$('#dcAvalSpan').text("원");
			$('#dcPval').val(0);
			$('#dcMval').val(0);
			$('#dcAval').val(0);
			$('#maxDcAmt').val(0);
			$("#CouponForm .maxDcAmtArea").hide();
		} else {		//할인율
			$('#dcPvalSpan').text("%");
			$('#dcMvalSpan').text("%");
			$('#dcAvalSpan').text("%");
			$('#dcPval').val(0);
			$('#dcMval').val(0);
			$('#dcAval').val(0);
			$('#maxDcAmt').val(0);

			if($("#CouponForm input[name=rdoCpnType]:checked").val() == 'G230_10'){
				$("#CouponForm .maxDcAmtArea").hide();
			}else{
				$("#CouponForm .maxDcAmtArea").show();
			}
		}
	});

	// 쿠폰 상태 변경
	$("#CouponForm input[name=rdoCpnType]").bind('click change', function () {
		var radioValue = $(this).val();

		if(mode == "U") {
			radioValue = cpnDetail.cpnType;
		}

		// 즉시할인아닌 쿠폰들 할인금액체크시 최대할인금액 숨김
		var rdoDcWayVal = $("#CouponForm input[name=rdoDcWay]:checked").val();

		// 즉시할인쿠폰일때 유효기간 노출, 그외 유효기간/일수 선택
		var pgGbVal = $('#CouponForm select[name="pdGb"] option:selected').val();
		if(pgGbVal == 'P') {	//기간
			$('#CouponForm .availDaysArea').hide();
			$('#CouponForm .availDateTr').show();
		}else{	//일수
			$('#CouponForm .availDateTr').hide();
			$('#CouponForm .availDaysArea').show();
		}

		// 즉시할인 쿠폰일때
		if(radioValue == 'G230_10'){
			$('#CouponForm .dcCdCheck1').hide();
			$('#CouponForm .availDaysArea').hide();
			// 다운로드 시작,종료 , 기간/일수 , 제휴채널, 고객 등급, 구매제한 , 할인율일때 구매제한한도, 1회발행수량, 다운로드 가능여부 숨기기
			$('#CouponForm .downStdtArea').hide();
			$('#CouponForm .downEddtArea').hide();
			$('#CouponForm .pdGbArea').hide();
			$('#CouponForm .buyLimitAmtArea').hide();
			$('#CouponForm .downAblArea').hide();
			$('#CouponForm .dcCdCheck2').hide();
			$('#CouponForm .maxDcAmtArea').hide();
			$('#CouponForm .availDateTr').show();
			$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=I]").prop('checked', true);
			$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('disabled', true);
			$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('readonly', true);
		}else{
			$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=A]").prop('checked', true);
			$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('disabled', false);
			$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('readonly', false);


			$("#CouponForm").find("input:radio[name='rdoDcWay']").attr('disabled', false);
			$("#CouponForm").find("input:radio[name='rdoDcWay']").attr('readonly', false);
			$('#CouponForm .maxDcAmtArea').show();
			// 적용대상 탭
			$("#CouponForm .supplyTrArea").show();
			$("#CouponForm .brandTrArea").show();
			$("#CouponForm .categoryTrArea").show();
			$("#CouponForm .goodsTrArea").show();
			$("#CouponForm .exceptArea").show();

			$('#CouponForm .dcCdCheck1').show();
			$('#CouponForm .pdGbArea').show();
			// 다운로드 시작,종료 , 기간/일수 , 제휴채널, 고객 등급, 구매제한 , 할인율일때 구매제한한도, 1회발행수량, 다운로드 가능여부 숨기기
			$('#CouponForm .downStdtArea').show();
			$('#CouponForm .downEddtArea').show();
			$('#CouponForm .buyLimitAmtArea').show();
			$('#CouponForm .downAblArea').show();
			$('#CouponForm .dcCdCheck2').show();

			// 즉시할인아닌 쿠폰들 할인금액체크시 최대할인금액 숨김
			if(rdoDcWayVal == 'G240_10'){
				$('#CouponForm .maxDcAmtArea').hide();
			}else{
				$('#CouponForm .maxDcAmtArea').show();
			}
		}

		// 즉시할인쿠폰만 개별, 나머진 전체/개별
		if(radioValue == 'G230_10') {
			$("input:radio[name='rdoApplyScope']:radio[value='I']").prop('checked', true);
		} else {
			$("input:radio[name='rdoApplyScope']:radio[value='A']").prop('checked', true);
		}

		$('#CouponForm #cpnType').val(radioValue);
	});

	// 적용대상 - 브랜드 추가 버튼시
	$('#btnBrandAdd').on('click' , function(){
		cfnOpenBrandListPopup("fnSetPopupBrandInfo", "M");
	});

	// 브랜드 설정 / 브랜드 추가 콜백함수 (단수로 가져오므로 복수일 경우에 수정 확인 필요)
	var fnSetPopupBrandInfo = function(result) {
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(brandGridOptions);		// 받아온 모든 데이터

			// 받아온 data for
			for(let j = 0 ; j < gridListValue.length ; j++) {
				if(gridListValue[j].brandCd == result[i].brandCd) {	addChk = false;	}					// 중복체크
			}

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(brandGridOptions, {"brandCd" : result[i].brandCd, "brandEnm" : result[i].brandEnm, "supplyCompNm" : result[i].supplyCompNm});
			}
		}
	};


	// 적용대상 - 공급처 추가 버튼시
	$('#btnSupplyAdd').on('click' , function (){
		cfnOpenCompanyListPopup("fnSetPopupComapnyInfo" , "M" ,"","","N");
	});

	// 공급업체 설정 / 업체 추가 콜백함수
	var fnSetPopupComapnyInfo = function(result) {
		// 기존 리스트 데이터 for
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(supplyGridOptions);		// 받아온 모든 데이터

			// 받아온 data for
			for(let j = 0 ; j < gridListValue.length ; j++) {
				// 동일한 data는 추가하지 않음
				if(gridListValue[j].supplyCompCd == result[i].supplyCompCd) {	addChk = false;	}		// 중복체크
			}

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(supplyGridOptions, {"supplyCompCd" : result[i].supplyCompCd, "supplyCompNm" : result[i].supplyCompNm});
			}
		}
	};

	// 적용대상 - 카테고리 추가시
	$('#btnCateAdd').on('click' , function () {
		cfnOpenCategoryPopup("fnSetPopupCategoryInfo");
	});

	// 카테고리 추가 콜백 함수
	var fnSetPopupCategoryInfo = function (result) {
		// 기존 리스트 데이터 for
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(cateGridOptions);		// 받아온 모든 데이터

			// 받아온 data for
			for(let j = 0 ; j < gridListValue.length ; j++) {
				// 동일한 data는 추가하지 않음
				if(gridListValue[j].cateNo == result[i].cateNo) {	addChk = false;	}		// 중복체크
			}

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(cateGridOptions, {"siteCd":result[i].siteCd , "cateGb":result[i].cateGb , "cateNo":result[i].cateNo, "cateNm":result[i].cateNm , "formalGb":result[i].formalGb , "brandEnm":null});
			}
		}
	}
	// 적용대상 - 상품 추가시
	$('#btnGoodsAdd').on('click' , function () {
		cfnOpenGoodsPopup("fnSetPopupApplyGoodsInfo");
	});

	// 적용 상품 리스트 콜백함수
	var fnSetPopupApplyGoodsInfo = function(result) {
		gridAddGoodsList(goodsGridOptions, result , "apply");
	};

	// 적용대상 - 제외상품 추가시
	$('#btnExcepGoodsAdd').on('click' , function(){
		cfnOpenGoodsPopup("fnSetPopupExceptGoodsInfo");
	});
	// 적용 상품 리스트 콜백함수
	var fnSetPopupExceptGoodsInfo = function(result) {
		gridAddGoodsList(excepGoodsGridOptions, result , "except");
	};

	// ag-grid 상품관련 list 콜백함수
	function gridAddGoodsList(OriginGridListOption, result, gubun) {
		var goodsGbVal = "G800_10";
		if(gubun == 'except'){
			goodsGbVal = "G800_30";
		}

		let addCnt = 0;
		let failCnt = 0;
		let dupliCnt = 0;

		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(OriginGridListOption);		// 받아온 모든 데이터

			// 받아온 data for
			for(let j = 0 ; j < gridListValue.length ; j++) {
				if(gridListValue[j].goodsCd == result[i].goodsCd) {	addChk = false;	dupliCnt++;}				// 중복체크
			}

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(OriginGridListOption, {"goodsGb": goodsGbVal, "goodsCd" : result[i].goodsCd, "goodsNm" : result[i].goodsNm});
				addCnt++;
			}
		}
		uifnPopupClose('popupGoods');
		failCnt = result.length - addCnt - dupliCnt;
		mcxDialog.alert("데이터가 적용되었습니다.<br/>" + addCnt + "건 성공, "+ dupliCnt + "건 중복, " + failCnt + "건 실패");
	}

	// 기간 일수 변경시
	function pdGbChange(pThis){
		var selectVal = $(pThis).val();

		if(typeof selectVal == "undefined") {
			if(mode == "U") {
				selectVal = cpnDetail.pdGb;
			} else {
				selectVal = "P";
			}
		}

		if(selectVal == "P") {
			$('.availDateTr').css('display' , '');
			$("#CouponForm .availDaysArea").hide();
			// $('.availDayTr').css('display' , 'none');
			$('#CouponForm #availDays').attr('required' , false);
			$('#CouponForm #availStDay').attr('required' , true);
			$('#CouponForm #availEdDay').attr('required' , true);
			$('#CouponForm #availStdt').attr('required' , true);
			$('#CouponForm #availEddt').attr('required' , true);
		} else {
			$('.availDateTr').css('display' , 'none');
			// $('.availDayTr').css('display' , '');
			$("#CouponForm .availDaysArea").show();
			$('#CouponForm #availDays').attr('required' , true);
			$('#CouponForm #availStDay').attr('required' , false);
			$('#CouponForm #availEdDay').attr('required' , false);
			$('#CouponForm #availStdt').attr('required' , false);
			$('#CouponForm #availEddt').attr('required' , false);
		}
	}

	// 발급받은회원 팝업
	var fnPubCustListPopUp = function (){
		let cpnId = $("#CouponForm #cpnId").val();
		var actionUrl = "/marketing/coupon/pubCust/popup/form?cpnId=" + cpnId;
		cfnOpenModalPopup(actionUrl, 'CpnPubCustListPopup');
	};

	// 전송시 값 세팅
	function setReqValue(){
		// 쿠폰유형값 세팅
		$('#CouponForm #cpnType').val($('#CouponForm input:radio[name="rdoCpnType"]:checked').val());
		// 할인방식값 세팅
		$('#CouponForm #dcWay').val($('#CouponForm input:radio[name="rdoDcWay"]:checked').val());
		// 적용범위값 세팅
		$('#CouponForm #applyScope').val($('#CouponForm input:radio[name="rdoApplyScope"]:checked').val());
		// 쿠폰상태
		$('#CouponForm input[name=cpnStat]').val($('input:radio[name="disCpnStat"]:checked').val());
		// 다운로드기간 세팅
		let downStdt = "";
		let downEddt = "";
		downStdt = $('#CouponForm input[name=downStDay]').val()+$('#CouponForm select[name=downStHH]').val()+$('#CouponForm select[name=downStMM]').val()+'00';
		if($('#CouponForm select[name=downEdHH]').val() == "24"){
			downEddt = $('#CouponForm input[name=downEdDay]').val()+'235959';
		}else{
			downEddt = $('#CouponForm input[name=downEdDay]').val()+$('#CouponForm select[name=downEdHH]').val()+$('#CouponForm select[name=downEdMM]').val()+'00';
		}
		downStdt = downStdt.replace(/[^0-9]/g, '');
		downEddt = downEddt.replace(/[^0-9]/g, '');
		$('#CouponForm #downStdt').val(downStdt);
		$('#CouponForm #downEddt').val(downEddt);

		// 유효기간 세팅
		let availStdt = "";
		let availEddt = "";
		if($("#CouponForm #pdGb").val() == 'P') {
			availStdt = $('#CouponForm input[name=availStDay]').val()+$('#CouponForm select[name=availStHH]').val()+$('#CouponForm select[name=availStMM]').val()+'00';
			if($('#CouponForm select[name=availEdHH]').val() == "24"){
				availEddt = $('#CouponForm input[name=availEdDay]').val()+'235959';
			}else{
				availEddt = $('#CouponForm input[name=availEdDay]').val()+$('#CouponForm select[name=availEdHH]').val()+$('#CouponForm select[name=availEdMM]').val()+'00';
			}
			availStdt = availStdt.replace(/[^0-9]/g, '');
			availEddt = availEddt.replace(/[^0-9]/g, '');
			$('#CouponForm #availStdt').val(availStdt);
			$('#CouponForm #availEddt').val(availEddt);
			$('#CouponForm #availDays').val('');
		} else {
			$('#CouponForm #availStdt').val('');
			$('#CouponForm #availEddt').val('');
		}
	}

	$(document).ready(function() {
		gagaAgGrid.createGrid('inComGridList', inComGridOptions);
		gagaAgGrid.createGrid('brandGridList', brandGridOptions);
		gagaAgGrid.createGrid('cateGridList', cateGridOptions);
		gagaAgGrid.createGrid('supplyGridList', supplyGridOptions);
		gagaAgGrid.createGrid('goodsGridList', goodsGridOptions);
		gagaAgGrid.createGrid('excepGoodsGridList', excepGoodsGridOptions);

		// 일단 버튼 숨김
		$(".couponButton").hide();

		// 초기화시 데이터 세팅
		if (mode == "N") {
			$('input[name=rdoCpnType]').eq(0).attr("checked", true);
			$('input[name=rdoDcWay]').eq(0).attr("checked", true);
			$('input[name=rdoApplyScope]').eq(0).attr("checked", true)
			$('#CouponForm #availEdHH option:last').attr("selected", "selected");
			$('#CouponForm #availEdMM option').hide();
			$('#CouponForm #availEdMM option:first').show().prop("selected", true);
			$('#downEdHH option:last').attr("selected", "selected");
			$('#downEdMM option').hide();
			$('#downEdMM option:first').show().prop("selected", true);
			$("#CouponForm .maxDcAmtArea").hide();
			$("input:radio[name='disCpnStat']:radio[value='G232_10']").prop('checked', true); // 선택하기
			if($('input:radio[name="rdoCpnType"]:checked').val() == 'G230_10'){
				$('#CouponForm .dcCdCheck1').hide();
				// 다운로드 시작,종료 , 기간/일수 , 제휴채널, 고객 등급, 구매제한 , 할인율일때 구매제한한도, 1회발행수량, 다운로드 가능여부 숨기기
				$('#CouponForm .downStdtArea').hide();
				$('#CouponForm .downEddtArea').hide();
				$('#CouponForm .pdGbArea').hide();
				$('#CouponForm .buyLimitAmtArea').hide();
				$('#CouponForm .downAblArea').hide();
				$('#CouponForm .dcCdCheck2').hide();
				$('#CouponForm .maxDcAmtArea').hide();
				$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=I]").prop('checked', true);
				$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('disabled', true);
				$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('readonly', true);
			}
			$("#btnCouponSave").show();	// 저장버튼
			$("#CouponForm .buttonSpan").show();

		} else {
			// 수정모드시 그리드 세팅
			inComGridOptions.api.setRowData(cpnDtlBurdenList);
			supplyGridOptions.api.setRowData(cpnDtlRefvalSupplyCompList);
			goodsGridOptions.api.setRowData(cpnDtlRefvalApplyGoodsList);
			excepGoodsGridOptions.api.setRowData(cpnDtlRefvalExceptGoodsList);
			brandGridOptions.api.setRowData(cpnDtlRefvalBrandList);
			cateGridOptions.api.setRowData(cpnDtlRefvalCateList);

			if(cpnDetail.cpnStat == "G232_10"){
				$("#btnCouponSave").show();		// 저장버튼
				$("#btnChangeStatIng").show();	// 진행버튼
				$("#btnCouponEnd").show();		// 종료버튼
				$("#CouponForm .buttonSpan").show();	//행추가,삭제버튼
			}else if(cpnDetail.cpnStat == "G232_11"){
				$("#btnCouponSave").hide();		// 저장버튼
				$("#btnCouponStop").show();		// 중지버튼
				$("#btnCouponEnd").show();		// 종료버튼
				$("#CouponForm .buttonSpan").hide();	//행추가,삭제버튼
			}else{
				$("#CouponForm .buttonSpan").hide();	//행추가,삭제버튼
			}

			// 수정모드시 그리드 세팅
			if(cpnDetail.cpnType == "G230_30"){
				$("#CouponForm .supplyTrArea").show();
				$("#CouponForm .brandTrArea").hide();
				$("#CouponForm .categoryTrArea").hide();
				$("#CouponForm .goodsTrArea").hide();
				$("#CouponForm .exceptArea").hide();
			}

			// 기본정보 세팅
			$("#CouponForm input:radio[name='rdoDcWay']:radio[value=" + cpnDetail.dcWay + "]").prop('checked', true);
			$("#CouponForm input:radio[name='rdoCpnType']:radio[value=" + cpnDetail.cpnType + "]").prop('checked', true);
			$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=" + cpnDetail.applyScope + "]").prop('checked', true);
			$("#CouponForm #dcPval").val(cpnDetail.dcPval);
			$("#CouponForm #dcMval").val(cpnDetail.dcMval);
			$("#CouponForm #dcAval").val(cpnDetail.dcAval);
			$("#CouponForm #maxDcAmt").val(cpnDetail.maxDcAmt);
			$("#CouponForm #totPubLimitQty").val(cpnDetail.totPubLimitQty);
			$("#CouponForm #custPubLimitQty").val(cpnDetail.custPubLimitQty);

			if(cpnDetail.cpnStat!='G232_10'){
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").attr('readonly', true);
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('disabled', true);
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent().prop('disabled', true);
				$("#CouponForm #totPubLimitQty").attr('readonly', true);
				$("#CouponForm #totPubLimitQty").attr('disabled', true);

				$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").attr('readonly', true);
				$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('disabled', true);
				$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").parent().prop('disabled', true);
				$("#CouponForm #custPubLimitQty").attr('readonly', true);
				$("#CouponForm #custPubLimitQty").attr('disabled', true);
				if(cpnDetail.totPubLimitQty<1){
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent("label").addClass("checked");
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', true);
				}else{
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', false);
				}

				if(cpnDetail.custPubLimitQty<1){
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").parent("label").addClass("checked");
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('checked', true);
				}else{
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('checked', false);
				}
			}else{
				if(cpnDetail.totPubLimitQty<1){
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent("label").addClass("checked");
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', true);
					$("#CouponForm #totPubLimitQty").attr('readonly', true);
					$("#CouponForm #totPubLimitQty").attr('disabled', true);
				}else{
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', false);
					$("#CouponForm #totPubLimitQty").attr('readonly', false);
					$("#CouponForm #totPubLimitQty").attr('disabled', false);
				}

				if(cpnDetail.custPubLimitQty<1){
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").parent("label").addClass("checked");
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('checked', true);
					$("#CouponForm #custPubLimitQty").attr('readonly', true);
					$("#CouponForm #custPubLimitQty").attr('disabled', true);
				}else{
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('checked', false);
					$("#CouponForm #custPubLimitQty").attr('readonly', false);
					$("#CouponForm #custPubLimitQty").attr('disabled', false);
				}
			}

			$("#CouponForm #onePubQty").val(cpnDetail.onePubQty);
			$("input:radio[name='disCpnStat']:radio[value="+cpnDetail.cpnStat+"]").prop('checked', true); // 선택하기
			$("#CouponForm #pdGb").val(cpnDetail.pdGb).prop("selected", true);
			$("#CouponForm #siteCd").val(cpnDetail.siteCd).prop("selected", true);
			$("#CouponForm #cpnNm").val(cpnDetail.cpnNm);
			$("#CouponForm #downAblYn").val(cpnDetail.downAblYn);
			$("#CouponForm #buyLimitAmt").val(cpnDetail.buyLimitAmt);
			$("#CouponForm #cpnId").val(cpnDetail.cpnId);
			$("#CouponForm #cpnDesc").val(cpnDetail.cpnDesc);

			if(cpnDetail.cpnType == "G230_10"){
				$('#CouponForm .dcCdCheck1').hide();
				$('#CouponForm .availDaysArea').hide();
				// 다운로드 시작,종료 , 기간/일수 , 제휴채널, 고객 등급, 구매제한 , 할인율일때 구매제한한도, 1회발행수량, 다운로드 가능여부 숨기기
				$('#CouponForm .downStdtArea').hide();
				$('#CouponForm .downEddtArea').hide();
				$('#CouponForm .pdGbArea').hide();
				$('#CouponForm .buyLimitAmtArea').hide();
				$('#CouponForm .downAblArea').hide();
				$('#CouponForm .dcCdCheck2').hide();
				$('#CouponForm .maxDcAmtArea').hide();
				$('#CouponForm .availDateTr').show();
			}else{
				$('#CouponForm .dcCdCheck1').show();
			}

			// 한번 저장되면 쿠폰유형, 할인쿠폰유형, 난수 생성수량, 시리얼명, 시리얼쿠폰발급수량 수정 불가 처리
			$("#CouponForm input:radio[name='rdoCpnType']").attr('readonly', true);
			$("#CouponForm input:radio[name='rdoCpnType']").prop('disabled', true);
			$("#CouponForm input:radio[name='rdoCpnType']").parent().prop('disabled', true);

			// 할인방식이 할인율이면 최대할인금액 노출
			if(cpnDetail.dcWay == "G240_11"){
				$("#CouponForm .maxDcAmtArea").show();
			}

			if($("#CouponForm input[name=rdoDcWay]:checked").val() == 'G240_10') {
				$("#CouponForm .maxDcAmtArea").hide();
			}else{
				$('#dcPvalSpan').text("%");
				$('#dcMvalSpan').text("%");
				$('#dcAvalSpan').text("%");
			}

			// 쿠폰다운 날짜
			let edDtArr;
			if(!gagajf.isNull(cpnDetail.downEddt)){
				edDtArr = cpnDetail.downEddt.split(" ");
				if(edDtArr[1] == "23:59:59") {
					edHour = "24";
					edMinute = "00";
					$("#CouponForm #downEdMM option").hide();
					$('#CouponForm #downEdMM option:first').show().prop("selected", true);
				}
			}

			// 유효 날짜
			let availEdDtArr;
			if(!gagajf.isNull(cpnDetail.availEddt)){
				availEdDtArr = cpnDetail.availEddt.split(" ");
				if(availEdDtArr[1] == "23:59:59") {
					edHour = "24";
					edMinute = "00";
					$("#CouponForm #availEdMM option").hide();
					$('#CouponForm #availEdMM option:first').show().prop("selected", true);
				}
			}

			// 만약 쿠폰 발급한 내역이 있으면 쿠폰수정못하게 readonly , disabled 속성 추가
			if (issueCnt > 0) {
				$("#CouponForm #pdGb").attr('readonly', true);
				$("#CouponForm #pdGb").attr('disabled', true);
				$("#CouponForm #downAblYn").attr('readonly', true);
				$("#CouponForm #downAblYn").attr('disabled', true);
				$("#CouponForm #siteCd").attr('readonly', true);
				$("#CouponForm #siteCd").attr('disabled', true);
				$("#CouponForm #cpnNm").attr('readonly', true);
				$("#CouponForm #cpnNm").attr('disabled', true);
				$("#CouponForm #dcPval").attr('readonly', true);
				$("#CouponForm #dcPval").attr('disabled', true);
				$("#CouponForm #dcMval").attr('readonly', true);
				$("#CouponForm #dcMval").attr('disabled', true);
				$("#CouponForm #dcAval").attr('readonly', true);
				$("#CouponForm #dcAval").attr('disabled', true);
				$("#CouponForm #maxDcAmt").attr('readonly', true);
				$("#CouponForm #maxDcAmt").attr('disabled', true);
				$("#CouponForm #totPubLimitQty").attr('readonly', true);
				$("#CouponForm #totPubLimitQty").attr('disabled', true);
				$("#CouponForm #custPubLimitQty").attr('readonly', true);
				$("#CouponForm #custPubLimitQty").attr('disabled', true);
				$("#CouponForm #onePubQty").attr('readonly', true);
				$("#CouponForm #onePubQty").attr('disabled', true);
				$("#CouponForm #downStDay").attr('readonly', true);
				$("#CouponForm #downStDay").attr('disabled', true);
				$("#CouponForm #downStHH").attr('readonly', true);
				$("#CouponForm #downStHH").attr('disabled', true);
				$("#CouponForm #downStMM").attr('readonly', true);
				$("#CouponForm #downStMM").attr('disabled', true);
				$("#CouponForm #buyLimitAmt").attr('readonly', true);
				$("#CouponForm input:radio[name='rdoDcWay']").attr('readonly', true);
				$("#CouponForm input:radio[name='rdoApplyScope']").attr('readonly', true);
				$("#CouponForm .rdoBtn").css('cursor', 'auto');
				$("#CouponForm #cpnId").attr('readonly', true);
				$("#CouponForm #cpnId").attr('disabled', true);
			}
			// 다운로드기간 세팅
			splitDate("start", cpnDetail.downStdt, "down");
			splitDate("end", cpnDetail.downEddt, "down");
			// 유효기간이 날짜인경우 날짜 세팅
			if (cpnDetail.pdGb == "P") {
				splitDate("start", cpnDetail.availStdt, "avail");
				splitDate("end", cpnDetail.availEddt, "avail");
				if(issueCnt > 0) {
					$("#CouponForm #availStDay").attr('readonly', true);
					$("#CouponForm #availStDay").attr('disabled', true);
					$("#CouponForm #availStHH").attr('readonly', true);
					$("#CouponForm #availStHH").attr('disabled', true);
					$("#CouponForm #availStMM").attr('readonly', true);
					$("#CouponForm #availStMM").attr('disabled', true);
				}
			} else {
				$("#CouponForm #availDays").val(cpnDetail.availDays);
				$('#CouponForm #availEdHH option:last').attr("selected", "selected");
				$('#CouponForm #availEdMM option:last').attr("selected", "selected");

			}

		}
		// 기본세팅
		pdGbChange();

	});

	// 날짜분리 ( 시작/종료날짜구분(start , end) , 날짜String , 적용타겟대상 )
	function splitDate(stedGb , date , targetGb ){
		var str = date;
		var dateStr = str.split(' ');
		var timeArr = dateStr[1].split(':');

		if(stedGb == "start") {
			$("#CouponForm #"+targetGb+"StDay").val(dateStr[0]);
			$("#CouponForm #"+targetGb+"StHH").val(timeArr[0]);
			$("#CouponForm #"+targetGb+"StMM").val(timeArr[1]);
		} else {
			$("#CouponForm #"+targetGb+"EdDay").val(dateStr[0]);
			$("#CouponForm #"+targetGb+"EdHH").val(timeArr[0]);
			$("#CouponForm #"+targetGb+"EdMM").val(timeArr[1]);
		}
	}
	// 제한없음 문구 변경
	$("input[name=totPubLimitQty],input[name=custPubLimitQty],input[name=buyLimitAmt],input[name=onePubQty]").change(function(){
		if($(this).val() == "0"){
			$("#"+$(this).attr("name")+"Span").html("*제한없음");
		}else{
			$("#"+$(this).attr("name")+"Span").html("");
		}
		$("#"+$(this).attr("name")+"Span").css("color", "red");
	});
	setTimeout(function(){
		$("input[name=totPubLimitQty],input[name=custPubLimitQty],input[name=buyLimitAmt],input[name=onePubQty]").change();
	}, 1);

	// 콤마 찍어주기
	$(function(){
		setComma("CouponForm" , true);
	});

	function setComma(formId, pBoolean){
		setTimeout(function(){
			//숫자타입 콤마 찍어주기
			$("#"+formId+" [data-valid-type=numeric]").each(function(){
				$(this).change(function(){
					if(pBoolean){
						$(this).val($(this).val().addComma());
					}else{
						$(this).val($(this).val().removeComma());
					}
				});
				if(pBoolean){
					$(this).val($(this).val().addComma());
				}else{
					$(this).val($(this).val().removeComma());
				}
			});
		}, 300);
	}

	// 진행 버튼 클릭
	$("#btnChangeStatIng").on("click", function() {
		mcxDialog.confirmC("쿠폰을 진행하시겠습니까?<br/>진행 후에는 수정이 제한될 수 있습니다.", {
			btn: ["아니오","예"],
			btnClick: function(index) {
				if(index == 2) {
					let data = { cpnStat : "G232_11"				// 진행
						, cpnId : $('#CouponForm input[name=cpnId]').val()
					}
					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/changeStat', jsonData, fnCouponSaveCollback);
				}
			}
		});
	});

	// 중지 버튼 클릭
	$("#btnCouponStop").on("click", function() {
		mcxDialog.confirmC("쿠폰 진행을 중지하시겠습니까?<br/>중지 후에는 진행으로 복원하실 수 없습니다.", {
			btn: ["아니오","예"],
			btnClick: function(index) {
				if(index == 2) {
					let data = { cpnStat : "G232_12"			// 중지
						, cpnId : $('#CouponForm input[name=cpnId]').val()
					}
					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/changeStat', jsonData, fnCouponSaveCollback);
				}
			}
		});
	});

	// 종료 버튼 클릭
	$("#btnCouponEnd").on("click", function() {
		mcxDialog.confirmC("쿠폰을 종료하시겠습니까?<br/>종료한 프로모션은 복원하실 수 없습니다.", {
			btn: ["아니오","예"],
			btnClick: function(index) {
				if(index == 2) {
					let data = { cpnStat: "G232_13"			// 종료
						, cpnId : $('#CouponForm input[name=cpnId]').val()
					}
					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/changeStat', jsonData, fnCouponSaveCollback);
				}
			}
		});
	});


	/*]]>*/
</script>
</html>