<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : GoodsCategoryForm.html
 * @desc    : 상품별카테고리전시관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.13   bin2107     최초 작성
 *******************************************************************************
 -->
<div id="main">
	<!-- 메인타이틀 영역 -->
	<div class="main-title">
	</div>
	<!-- //메인타이틀 영역 -->

	<!-- 메뉴 설명 -->
	<div class="infoBox menu-desc">
	</div>
	<form id="goodsSearchForm" name="goodsSearchForm" action="#" th:action="@{'/display/goods/category/list'}">
		<input type="hidden" id="searchGb" name="searchGb" />
		<!-- 패널 영역1 -->
		<div class="panelStyle" >
			<!-- TITLE -->
			<div class="panelTitle">
				<h3><i class="fa fa-info-circle"></i>아래 검색조건 중 <font color="red">상품코드, 업체, 기간</font>중 하나를 꼭 입력해 주세요.</h3>
			</div>
			<!-- //TITLE -->
			<div class="panelContent">
				<table class="frmStyle">
					<colgroup>
						<col width="7%"/>
						<col width="18%"/>
						<col width="7%"/>
						<col width="18%"/>
						<col width="7%"/>
						<col width="18%"/>
						<col width="7%"/>
						<col/>
					</colgroup>
					<tr>
						<th>상품코드</th>
						<td>
							<input type="text" class="w100" name="goodsCd" id="goodsCd"/>
						</td>
						<th>원코드</th>
						<td>
							<input type="text" class="w100" name="supplyGoodsCd" maxlength="20" required="required" data-valid-name="원코드"/>
						</td>
						<th>상품명</th>
						<td>
							<input type="text" class="w100" name="goodsNm" maxlength="200" required="required" data-valid-name="상품명"/>
						</td>
						<th>상품상태</th>
						<td>
							<select name="goodsStat">
								<option value=''>[전체]</option>
								<option th:if="${goodsStatList}" th:each="oneData, status : ${goodsStatList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th>업체코드</th>
						<td>
							<select name="supplyCompCd">
								<option value=''>[전체]</option>
								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>담당MD</th>
						<td>
							<select name="mdId">
								<option value=''>[전체]</option>
								<option th:if="${mdIdList}" th:each="oneData, status : ${mdIdList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>브랜드/품목</th>
						<td colspan="3">
							<select name="brandCd">
								<option value=''>[전체]</option>
								<!--<option th:if="${brandCdList}" th:each="oneData, status : ${brandCdList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>-->
							</select>
							<select name="itemkindCd">
								<option value=''>[전체]</option>
								<option th:if="${itemkindList}" th:each="oneData, status : ${itemkindList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th>이월구분</th>
						<td>
							<select name="formalGb">
								<option value=''>[전체]</option>
								<option th:if="${formalGbList}" th:each="oneData, status : ${formalGbList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>재고수량</th>
						<td>
							<input type="text" class="w100" name="currStockQty" maxlength="11" required="required" data-valid-name="재고수량" data-valid-type="numeric"/>개 이상
						</td>
						<th>년도/시즌</th>
						<td>
							<select name="styleYear">
								<option value=''>[전체]</option>
								<option th:if="${styleYearList}" th:each="oneData, status : ${styleYearList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
							<select name="seasonCd">
								<option value=''>[전체]</option>
								<option th:if="${seasonList}" th:each="oneData, status : ${seasonList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>판매가</th>
						<td>
							<input type="text" class="w60" name="currPriceSt" required="required" data-valid-name="판매가" data-valid-type="integer"/>원 ~
							<input type="text" class="w60" name="currPriceEd" required="required" data-valid-name="판매가" data-valid-type="integer"/>원
						</td>
					</tr>
					<tr>
						<th>품절여부</th>
						<td>
							<select name="soldoutYn">
								<option value=''>[전체]</option>
								<option value='Y'>[Y] Yes</option>
								<option value='N'>[N] No</option>
							</select>
						</td>
						<th>반품/교환</th>
						<td colspan='3'>
							<label class="chkBox"><input type="checkbox" name="changeableYn"/>반품불가</label>
							<label class="chkBox"><input type="checkbox" name="returnableYn"/>교환불가</label>
							<label class="chkBox"><input type="checkbox" name="returnFeeFreeYn"/>무료반품</label>
							<label class="chkBox"><input type="checkbox" name="changeFeeFreeYn"/>무료교환</label>
						</td>
						<th>할인율(%)</th>
						<td>
							<input type="text" class="w50" name="dcRateSt" maxlength="3" required="required" data-valid-name="할인율" data-valid-type="numeric"/> ~
							<input type="text" class="w50" name="dcRateEd" maxlength="3" required="required" data-valid-name="할인율" data-valid-type="numeric"/>
						</td>
					</tr>
					<tr>
						<th>기간</th>
						<td id="sellTerms" colspan='5'></td>
						<th>전시여부</th>
						<td>
							<select name="useYn">
								<option value=''>[전체]</option>
								<option value='Y'>[Y] Yes</option>
								<option value='N'>[N] No</option>
							</select>
						</td>
					</tr>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-gray btn-lg" onclick="$('#goodsSearchForm')[0].reset();" >초기화</button>
						<button type="button" class="btn btn-info btn-lg" id="btnSearch" >조회</button>
					</li>
				</ul>
			</div>
			<!-- //검색조건 영역 -->
		</div>
		<!-- 패널 영역1 -->
		<div class="panelStyle">
			<!-- 검색결과 영역 -->
			<!-- 상단버튼 영역  -->
			<ul class="panelBar">
				<li>
					<button type="button" class="btn btn-default btn-lg" onclick="cfnDownloadSampleFile('SF003');">상품엑셀조회 양식 다운로드</button>
					<button type="button" class="btn btn-base btn-lg" id="btnGoodsExcelSearch">엑셀조회</button>
				</li>
				<li class="aR">
					검색결과 : <strong><span id="gridRowTotalCount">0</span> 건</strong>&nbsp;
					쪽번호 <span id="pgNo">0</span>/ <strong id="endPgNo">0</strong>&nbsp;&nbsp;
					<select id="pageSize" name="pageSize">
						<option value="50" selected="selected">50개씩 보기</option>
						<option value="100">100개씩 보기</option>
						<option value="500">500개씩 보기</option>
						<option value="1000">1000개씩 보기</option>
					</select>
					<input type="hidden" name="pageNo" id="pageNo" value ="1"/>
				</li>
			</ul>
			<!-- //상단버튼 영역  -->
			<div id="gridList" style="width: 100%; height: 500px;" class="ag-theme-balham lh60"></div>
			<ul class="panelBar">
				<li class="center">
					<div class="tablePaging" id="goodsCategoryListPagination"></div>
				</li>
			</ul>
		</div>
	</form>
	<!-- //패널 영역2 등록/수정 -->
	<div class="panelStyle">
		<form id="goodsCateForm" name="goodsCateForm" action="#" th:action="@{'/display/goods/category/save'}">
			<table class="frmStyle">
				<colgroup>
					<col style="width:20%;"/>
					<col style="width:20%;"/>
					<col style="width:20%;"/>
					<col style="width:20%;"/>
					<col style="width:20%;"/>
				</colgroup>
				<tr>
					<th>카테고리구분</th>
					<th>카테고리1</th>
					<th>카테고리2</th>
					<th>카테고리3</th>
					<th>카테고리4</th>
				</tr>
				<th:block th:each="num, index  : ${#numbers.sequence(1,4)}">
					<tr>
						<td>
							<select th:id="selCate+${num}+1" th:onchange="|fnChangeSelect($(this).val(), ${num}, 1);|">
								<option value="">[선택]</option>
								<option th:if="${cateGbList}" th:each="oneData, status : ${cateGbList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<td>
							<select name="cateCd1Arr" th:id="selCate+${num}+2" th:onchange="|fnChangeSelect($(this).val(), ${num}, 2);|">
								<option value="">[선택]</option>
							</select>
						</td>
						<td>
							<select name="cateCd2Arr" th:id="selCate+${num}+3" th:onchange="|fnChangeSelect($(this).val(), ${num}, 3);|">
								<option value="">[선택]</option>
							</select>
						</td>
						<td>
							<select name="cateCd3Arr" th:id="selCate+${num}+4" th:onchange="|fnChangeSelect($(this).val(), ${num}, 4);|">
								<option value="">[선택]</option>
							</select>
						</td>
						<td>
							<select name="cateCd4Arr" th:id="selCate+${num}+5" th:onchange="|fnChangeSelect($(this).val(), ${num}, 5);|">
								<option value="">[선택]</option>
							</select>
							<input type="hidden" th:id='cateCd+${num}' name='cateCdArr' value='' />
							<input type="hidden" th:id='cateGb+${num}' name='cateGbArr' value='' />
							<input type="hidden" th:id='leafYn+${num}' value='' />
							<input type="hidden" th:id='cateType+${num}' name='cateTypeArr' value='' />
						</td>
					</tr>
				</th:block>
			</table>
			<ul class="panelBar">
				<li class="center">
					<button type="button" class="btn btn-default btn-lg" id="btnCateInit">초기화</button>
					<button type="button" class="btn btn-success btn-lg" id="btnCateSave">전시저장</button>
					<input type="hidden" id='goodsCds' name='goodsCds' value='' />
					<input type="hidden" name='selLvl' value='' />
					<input type="hidden" name='cateIndex' value='' />
				</li>
			</ul>
		</form>
	</div>

	<!-- 카테고리 리스트 영역 -->
	<div class="panelStyle">
		<form id="deleteForm" name="deleteForm" action="#" th:action="@{'/display/goods/category/delete'}">
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-danger btn-lg" id="btnCateDelete">전시삭제</button>
					<input type="hidden" name='goodsCd' value='' />
				</li>
			</ul>
			<div id="gridCategoryList" style="width: 100%; height: 500px;" class="ag-theme-balham"></div>
		</form>
	</div>
	<!-- //카테고리 리스트 영역 -->


	<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js?v=2019072202"></script>
	<script th:inline="javascript">
		/*<![CDATA[*/
		var goodsStatList = gagajf.convertToArray([[${goodsStatList}]]);
		var cateGbList = gagajf.convertToArray([[${cateGbList}]]);
		var columnDefs = [];
		columnDefs = [
			{width: 40, minWidth: 40, cellClass: 'text-right', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
			{headerName: 'No', width: 60, cellClass: 'text-center',
				valueGetter: function(params) { return cfnGridNumner('goodsSearchForm',params.node.rowIndex, 'A');}
			},
			{headerName: "카테고리", field: "fullCateNm", width: 140, cellClass: 'text-center'
				,cellRenderer: function(params) {
					return '<a href="javascript:void(0);">'+params.value+'</a>';
				}
			},
			{headerName: "이미지", field: "sysImgNm", width: 100, height: 60, cellClass: 'text-center'
				,cellRenderer: function(params) {
					return '<img width="60" src="'+ _goodsUrl+ "/" + params.value + '" alt=""  onerror="this.src=\'/image/no.gif\';"/>';
				}
			},
			{headerName: "상품코드", field: "goodsCd", width: 140, cellClass: 'text-center'},
			{headerName: "상품명", field: "goodsNm", width: 350, cellClass: 'text-left'
				,cellRenderer: function(params) {
					return '<a href="javascript:void(0);">' + params.value + '</a>';
				}
			},
			{headerName: "재고", field: "currStockQty", width: 80, cellClass: 'text-right',
				valueFormatter: function(params) {return Number(params.value).addComma()}
			},
			{headerName: "할인율", field: "dcRate", width: 80, cellClass: 'text-right'},
			{headerName: "TAG가", field: "tagPrice", width: 80, cellClass: 'text-right',
				valueFormatter: function(params) {return Number(params.value).addComma()}
			},
			{headerName: "정상가", field: "listPrice", width: 80, cellClass: 'text-right',
				valueFormatter: function(params) {return Number(params.value).addComma()}
			},
			{headerName: "판매가", field: "currPrice", width: 80, cellClass: 'text-right',
				valueFormatter: function(params) {return Number(params.value).addComma()}
			},
			{headerName: "상품타입", field: "goodsType", width: 80, cellClass: 'text-center'},
			{headerName: "포인트적립율(PC)", field: "pntPrate", width: 80, cellClass: 'text-right'},
			{headerName: "선포인트사용가능여부(PC)", field: "prePpntUsableYn", width: 80, cellClass: 'text-right'},
			{headerName: "포인트적립율(모바일)", field: "pntMrate", width: 80, cellClass: 'text-right'},
			{headerName: "선포인트사용가능여부(모바일)", field: "preMpntUsableYn", width: 80, cellClass: 'text-right'},
			{headerName: "정상/이월", field: "formalGb", width: 80, cellClass: 'text-right'},
			{headerName: "상품상태", field: "goodsStat" , width: 100, cellClass: 'text-center',
				cellEditorParams: { values: gagaAgGrid.extractValues(goodsStatList) },
				valueFormatter: function (params) { return gagaAgGrid.lookupValue(goodsStatList, params.value); },
				valueParser: function (params) { return gagaAgGrid.lookupKey(goodsStatList, params.newValue); }
			},
			//{headerName: "판매가능재고", field: "currStockQty", width: 100, cellClass: 'text-right'}, // 추후 추가해야함 ㅠㅠ
			//{headerName: "품절여부", field: "soldoutYn", width: 80, cellClass: 'text-center'}, // 추후 추가해야함 ㅠㅠ
			{headerName: "기존품목코드", field: "itemkindCd", width: 150, cellClass: 'text-center' }
			/*{headerName: "품목명", field: "itemkindNm", width: 250, cellClass: 'text-left'},
            {headerName: "기존품목코드", field: "itemkindCd", width: 150, cellClass: 'text-center' },
            {headerName: "변경품목코드", field: "itemkindCdNew", width: 150, cellClass: 'text-center', editable : true,
                cellEditor: 'textCellEditor',
                cellEditorParams: { maxlength: 5, required: true, onblur: '$(this).val($(this).val().toUpperCase())' }
            }*/
		];

		var columCategoryDefs = [
			{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
			{headerName: "자동전시카테고리코드", field: "cateCd", width: 150, cellClass: 'text-center'},
			{headerName: "자동전시카테고리", field: "fullCateNm", width: 400, cellClass: 'text-left'},
			{headerName: "카테고리1", field: "cateCd1", width: 150, cellClass: 'text-left', hide: true},
			{headerName: "카테고리2", field: "cateCd2", width: 150, cellClass: 'text-left', hide: true},
			{headerName: "카테고리3", field: "cateCd3", width: 150, cellClass: 'text-left', hide: true},
			{headerName: "카테고리4", field: "cateCd4", width: 150, cellClass: 'text-left', hide: true},
			{headerName: "상품코드", field: "goodsCd", width: 150, cellClass: 'text-left', hide: true}
		];

		// Get GridOptions
		var gridOptions = gagaAgGrid.getGridOptions(columnDefs);
		var gridCategoryOptions = gagaAgGrid.getGridOptions(columCategoryDefs);

		// 중복 선택 가능
		gridOptions.rowSelection = 'multiple';
		gridOptions.suppressRowClickSelection = true;
		gridOptions.rowHeight = 60; //이미지가 있을경우 높이 지정해야함.
		gridOptions.stopEditingWhenGridLosesFocus = true;

		gridCategoryOptions.rowSelection = 'multiple';
		gridCategoryOptions.suppressRowClickSelection = true;

		gridOptions.onCellClicked = function(event) {
			if(event.colDef.field == "fullCateNm"){
				$('#deleteForm input[name=goodsCd]').val(event.data.goodsCd);
				fnDisplayCategorySearch();
				$(window).scrollTop($(window).height());
			}
		}

		// 상품별 전시카테고리 조회
		var fnDisplayCategorySearch = function(){
			var goodsCd = $('#deleteForm input[name=goodsCd]').val();
			var actionUrl = "/display/goods/category/view/list?goodsCd=" + goodsCd;
			gagaAgGrid.fetch(actionUrl, gridCategoryOptions);
		}

		// 조회
		$('#btnSearch').on('click', function() {
			if(gagajf.isNull($("#goodsSearchForm select[name=supplyCompCd]").val())
					&& gagajf.isNull($("#goodsSearchForm input[name=goodsCd]").val())
					&& (gagajf.isNull($("#goodsSearchForm input[name=stDate]").val()) && gagajf.isNull($("#goodsSearchForm input[name=edDate]").val()))){
				mcxDialog.alert('검색조건을 입력해 주세요.');
				return;
			}

			$('#goodsSearchForm input[name=changeableYn]').val($("#changeableYn").prop('checked')? 'N':'');
			$('#goodsSearchForm input[name=returnableYn]').val($("#returnableYn").prop('checked')? 'N':'');
			$('#goodsSearchForm input[name=returnFeeFreeYn]').val($("#returnFeeFreeYn").prop('checked')? 'Y':'');
			$('#goodsSearchForm input[name=changeFeeFreeYn]').val($("#changeFeeFreeYn").prop('checked')? 'Y':'');
			$("#goodsSearchForm input[name=searchGb]").val("BASIC");
			fnSearch();
		});

		$("#pageSize").on("change", function(){
			var rowCnt = gridOptions.api.getDisplayedRowCount();
			if(rowCnt > 0){
				fnSearch();
			}
		});

		var fnSearch = function(){
			gagaPaging.init('goodsSearchForm', fnSearchCallBack, 'goodsCategoryListPagination', $('#goodsSearchForm').find('#pageSize').val());
			gagaPaging.load(1);
		};

		var fnSearchCallBack = function(result){

			$('#goodsSearchForm').find('#gridRowTotalCount').html(result.pageing.pageable.totalCount.addComma());
			$('#goodsSearchForm').find('#pageNo').val(result.pageing.pageable.pageNo.addComma());
			$('#goodsSearchForm').find('#pgNo').html(result.pageing.pageable.pageNo.addComma());
			$('#goodsSearchForm').find('#endPgNo').html(result.pageing.pageable.totalPage.addComma());
			gridOptions.api.setRowData(result.goodsCategoryList);
			gagaPaging.createPagination(result.pageing.pageable);
		}

		// 카테고리 selectBox 변경
		var fnChangeSelect = function(val, cateIndex, selLvl){
			$("#cateCd"+cateIndex).val('');
			$("#cateGb"+cateIndex).val('');
			$("#leafYn"+cateIndex).val('');

			if (gagajf.isNull(val)) {
				if (selLvl > 1) {
					selLvl = selLvl - 1;
					if(selLvl>1){
						$("#cateCd"+cateIndex).val($("#selCate"+cateIndex+''+(selLvl-1)).val().split(',')[0]);
						$("#leafYn"+cateIndex).val($("#selCate"+cateIndex+''+(selLvl-1)).val().split(',')[1]);
					}
				} else {
					//selLvl = 1;
					var html = '<option value="">[선택]</option>';
					for(var i=2; i<6; i++){
						$("#selCate"+cateIndex+''+i).html(html);
					}
					return;
				}
			}else if(selLvl>1){
				$("#cateCd"+cateIndex).val(val.split(',')[0]);
				$("#leafYn"+cateIndex).val(val.split(',')[1]);
			}
			$("#goodsCateForm input[name=selLvl]").val(selLvl+1);
			$("#goodsCateForm input[name=cateIndex]").val(cateIndex);

			var cateGb = $('#selCate'+cateIndex+'1').val();
			var cate1No = $('#selCate'+cateIndex+'2').val().split(',')[0];
			var cate2No = $('#selCate'+cateIndex+'3').val().split(',')[0];
			var cate3No = $('#selCate'+cateIndex+'4').val().split(',')[0];
			var cate4No = $('#selCate'+cateIndex+'5').val().split(',')[0];

			$("#cateGb"+cateIndex).val(cateGb);
			if(selLvl==5 || (val=='' && selLvl==4)){
				return;
			}

			var data = { siteCd : 'G000_10'
				, selLvl : selLvl
				,cateGb : cateGb
				,cate1No : cate1No
				,cate2No : cate2No
				,cate3No : cate3No
				,cate4No : cate4No
			};

			var jsonData = JSON.stringify(data);
			gagajf.ajaxJsonSubmit('/display/category/list', jsonData, fnChangeCate);
		}

		var fnChangeCate = function(data){
			var selLvl = $("#goodsCateForm input[name=selLvl]").val();
			var cateIndex = $("#goodsCateForm input[name=cateIndex]").val();
			var html = '<option value="">[선택]</option>';

			for(var i=0; i<6; i++){
				i = i+1;
				if(i>selLvl){
					$("#selCate"+cateIndex+''+i).html(html);
				}
			}

			for(var i=0; i<data.length; i++){
				var cd = '';
				var nm = '';
				var leafYn = '';

				if(data[i].useYn=='Y'){
					if(selLvl=='1'){
						cd = data[i].cateGb;
						nm = gagaAgGrid.lookupValue(cateGbList, cd);
					}else{
						cd = data[i].cateNo;
						nm = data[i].cateNm;
						leafYn = ','+data[i].leafYn;
						$("#cateType"+cateIndex).val(data[i].cateType);
					}
					html += '<option value="'+cd+leafYn+'">['+cd+'] '+nm+'</option>';
				}
			}
			$("#selCate"+cateIndex+''+selLvl).html(html);
		}

		// 카테고리 저장
		$("#btnCateSave").on('click', function() {
			var data = gridOptions.api.getSelectedRows();
			if(data.length == 0){
				mcxDialog.alert('상품을 선택하세요.');
				return false;
			}

			var msgArr = ['', '첫 번째', '두 번째', '세 번째', '네 번째'];
			var cateCdBool = false;

			for(var i=1; i<5; i++){
				if($("#cateCd"+i).val()!=''){
					cateCdBool = true;
					if($("#leafYn"+i).val()!='Y'){
						mcxDialog.alert(msgArr[i]+' 행의 leaf카테고리를 선택하세요.');
						return;
					}
				}else if($("#cateGb"+i).val()!=''){
					mcxDialog.alert(msgArr[i]+' 행의 leaf카테고리를 선택하세요.');
					return;
				}
			}
			if(!cateCdBool){
				mcxDialog.alert('전시할 카테고리를 선택하세요.');
				return;
			}
			var goodsCdS = '';
			data.forEach(function(row){
				if (goodsCdS!=''){
					goodsCdS += ','
				}
				goodsCdS += row.goodsCd;
			});
			$("#goodsCds").val(goodsCdS);

			mcxDialog.confirm('저장하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){ //debugger;
					gagajf.ajaxFormSubmit($('#goodsCateForm').prop('action'), "#goodsCateForm", fnGoodsCateCallBack);
				}
			});
		});

		// 검색조건 초기화
		$('#btnCateInit').on('click', function() {
			$("#goodsCateForm")[0].reset();
			var html = '<option value="">[선택]</option>';
			for(var i=2; i<6; i++){
				for(var j=1; j<5; j++){
					$("#selCate"+j+''+i).html(html);
				}
			}
			for(var i=1; i<5; i++){
				$("#cateCd"+i).val('');
				$("#cateGb"+i).val('');
				$("#leafYn"+i).val('');
			}
		});

		// 전시카테고리 삭제
		$("#btnCateDelete").on("click", function(){
			var selectData = gridCategoryOptions.api.getSelectedRows();
			if(selectData.length == 0){
				mcxDialog.alert('삭제할 카테고리를 선택하세요.');
				return false;
			}

			var data = {
				goodsList : selectData
			};

			var jsonData = JSON.stringify(data);
			mcxDialog.confirm('삭제하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					gagajf.ajaxJsonSubmit($('#deleteForm').prop('action'), jsonData, fnGoodsCateCallBack);
				}
			});
		});

		// 저장,삭제 콜백
		var fnGoodsCateCallBack = function(){
			$('#btnCateInit').click();
			fnDisplayCategorySearch();
		};

		// 엑셀 상품 조회
		$("#btnGoodsExcelSearch").on('click', function(){
			cfnExcelUploadPopup('goodsExcelUpload', 'goodsExcelUpload');
		});

		var goodsExcelUpload = function(result){
			var data = {procJob : result.procJob
				,excelFileNm : result.excelFileNm
			};
			var jsonData = JSON.stringify(data);
			gagajf.ajaxJsonSubmit('/goods/search/excelupload/save', jsonData, fnGoodsExcelUploadCallBack);
		}

		var fnGoodsExcelUploadCallBack = function(result){
			$("#goodsSearchForm input[name=searchGb]").val("EXCEL");
			fnSearch();
		}

		$(document).ready(function() {
			cfnCreateCalendar('#sellTerms', 'stDate', 'edDate', true, '기간', 'X');
			// Create a agGrid
			gagaAgGrid.createGrid('gridList', gridOptions);
			gagaAgGrid.createGrid('gridCategoryList', gridCategoryOptions);
		});

		/*]]>*/
	</script>
</div>

</html>