<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : GoodsWmsInstockForm.html
 * @desc    : WMS입고상품관리 화면
 *============================================================================
 * SISUN
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.11.18   eskim       최초 작성
 *******************************************************************************
 -->	
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<form id="goodsUnregisterListForm" name="goodsUnregisterListForm" action="#" th:action="@{'/goods/unregister/list'}">
		<input type="hidden" id="searchGb" name="searchGb" />
		<input type="hidden" id="dateGbn" name="dateGbn" value="R" />
 		<!-- 패널 영역1 -->
		<div class="panelStyle" >
			<div class="panelTitle">
				<h3><i class="fa fa-info-circle"></i>아래 검색조건 중 하나를 꼭 입력해 주세요.</h3>
			</div>
			<div class="panelContent">
				<table class="frmStyle">
					<colgroup>
						<col width="10%"/>
						<col width="40%"/>
						<col width="10%"/>
						<col/>
					</colgroup>
					<tr>
						<th>업체/브랜드<i class="star"></i></th>
						<td>
							<select name="supplyCompCd" id="supplyCompCd">
								<option value="" th:if="${sessionInfo.roleCd} != 'B000'">[전체]</option>
								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
							<select name="brandCd" id="brandCd">
								<option value="">[전체]</option>
							</select>
						</td>
						<th>상품코드<i class="star"></i></th>
						<td>
							<input id="goodsCd" name=goodsCd type="text" class="w150"  maxlength="20"/>
						</td>
					</tr>
					<tr>
						<th>등록일<i class="star"></i></th>
						<td colspan="3" id="sellTerms"></td>
					</tr>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-gray btn-lg" id="btnInit" >초기화</button>
						<button type="button" class="btn btn-info btn-lg" id="btnSearch" >조회</button>
					</li>
				</ul>
			</div>
			<!-- //검색조건 영역 -->
		</div>
		<!-- 패널 영역1 -->
		<div class="panelStyle">
			<!-- 검색결과 영역 -->
			<div id="gridList" style="width: 100%; height: 500px;" class="ag-theme-balham"></div>
			<ul class="panelBar">
				<li class="center">
					<div class="tablePaging" id="goodsListPagination"></div>
				</li>
			</ul>
			<!-- 검색결과 영역 -->
		</div>
		</form>
		<!-- //패널 영역2 -->
	</div>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js?v=2019072202"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	var sessRoleCd = [[${sessionInfo.roleCd}]];
	var goodsStatList = gagajf.convertToArray([[${goodsStatList}]]);
	var itemkindList = gagajf.convertToArray([[${itemkindList}]]);
	var 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 params.node.rowIndex + 1 }},
		{headerName: "브랜드", field: "brandCd", width: 100, cellClass: 'text-center'},
		{headerName: "브랜드명", field: "brandEnm", width: 130, cellClass: 'text-center'},
		{headerName: "상품코드", field: "goodsCd", width: 120, cellClass: 'text-center'},
		{headerName: "ERP상품명", field: "erpGoodsNm", width: 200, cellClass: 'text-left'},
		{headerName: "상품명", field: "goodsNm", width: 200, cellClass: 'text-left'},
		//{headerName: "품목코드", field: "itemkindCd", width: 100, cellClass: 'text-center'},
		{headerName: "품목명", field: "itemkindCd" , width: 200, cellClass: 'text-left',
			cellEditorParams: { values: gagaAgGrid.extractValues(itemkindList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(itemkindList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(itemkindList, params.newValue); }
		},
		{headerName: "등록일시", field: "regDt", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) {
				return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm:ss") : '';
			}
		},
		{headerName: "등록자", field: "regId", width: 100, cellClass: 'text-center'},
		{headerName: "수정일시", field: "updDt", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) {
				return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm:ss") : '';
			}
		},
		{headerName: "수정자", field: "updId", width: 100, cellClass: 'text-center'}
	];
	
	// Get GridOptions
	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);

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

	// 초기화 클릭시
	$('#btnInit').on('click', function() {
		fnInit();
	});
	
	var fnInit = function(){
		$('#goodsUnregisterListForm')[0].reset();
		//$("#goodsUnregisterListForm input[type=radio]").removeClass("checked");
		$("#goodsUnregisterListForm input[type=checkbox]").removeClass("checked");
		//$("#goodsUnregisterListForm input[type=radio]").parent("label").removeClass("checked");
		$("#goodsUnregisterListForm input[type=checkbox]").parent("label").removeClass("checked");
		$("#goodsUnregisterListForm input[type=radio][checked]").parent("label").addClass("checked");
	}
	
	// 조회클릭시
	$('#btnSearch').on('click', function() {
		fnGoodsUnregisterListSearch('BASIC');
	});

	// 조회
	var fnGoodsUnregisterListSearch = function(gbn) {

		if (typeof(gbn) != 'undefined' &&  gbn == 'EXCEL'){
			$("#goodsUnregisterListForm input[name=searchGb]").val("EXCEL");
		}else if (typeof(gbn) != 'undefined' &&  gbn == 'EXCELRESULT'){
			$("#goodsUnregisterListForm input[name=searchGb]").val("EXCELRESULT");
		}else{
			$("#goodsUnregisterListForm input[name=searchGb]").val("BASIC");
		}
		
		if(!fnConditionCheck()) return;
		
		gagaAgGrid.fetch($('#goodsUnregisterListForm').prop('action'), gridOptions, '#goodsUnregisterListForm');
	}

	//검색 조건 확인
	var fnConditionCheck = function(){
		var formId = '#goodsUnregisterListForm';
		var form = document.goodsUnregisterListForm;

		if($("#goodsUnregisterListForm input[name=searchGb]").val() == "EXCEL" || $("#goodsUnregisterListForm input[name=searchGb]").val() == "EXCELRESULT") {
			return true;
		}
		
		var searchFlag = false;
		var cnt = 0;

		/* if( !gagajf.isNull($("#goodsUnregisterListForm select[name=supplyCompCd]").val())
				|| !gagajf.isNull($("#goodsUnregisterListForm input[name=condition]").val())
				|| (!gagajf.isNull($("#goodsUnregisterListForm input[name=stDate]").val()) && !gagajf.isNull($("#goodsUnregisterListForm input[name=edDate]").val()))
			){
			searchFlag = true;
		}else{ */
			for (i = 0; i < form.elements.length; i++ ) {
				var el = form.elements[i];
				
				if ($(el).prop("type") == "text" || ($(el).prop("type") == "select-one" && el.name != "search" && el.name != "pageSize")) {
					if (!(el.value == null || el.value == "")) {
						cnt++;
					}
				}
			}
			
			if(cnt > 0) searchFlag = true;
			
		/* } */
		
		if(searchFlag == false){
			mcxDialog.alert("검색조건을 입력하세요.");
			return false;
		}
		
		var fromDate = $('#goodsUnregisterListForm input[name=stDate]').val();
		var toDate = $('#goodsUnregisterListForm input[name=edDate]').val();
		
		if (!gagajf.isNull(fromDate) || !gagajf.isNull(toDate)) {
			
			if (gagajf.isNull(fromDate) || gagajf.isNull(toDate)) {
				mcxDialog.alertC("등록일 조회시 시작일자와 종료일자를 입력하세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#goodsUnregisterListForm input[name=stDate]').focus();
					}
				});
				return false;
			}

			if (fromDate > toDate) {
				mcxDialog.alert("노출기간 시작일자는 종료일자 보다 클 수 없습니다.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#goodsUnregisterListForm input[name=stDate]').focus();
					}
				});
				return false;
			} 
		}

		return true;
	}
	
	//업체변경시
	$('#goodsUnregisterListForm select[name=supplyCompCd]').on('change', function() {
		var actionUrl = '/renderer/supplyCompany/brand/list/' + $(this).val();

		if(sessRoleCd == "B000"){
			actionUrl = '/renderer/brand/AuthBrandlist';
		}
		$("#goodsUnregisterListForm select[name=brandCd] option:gt(0)").remove();

		cfnCreateCombo(actionUrl, $('#goodsUnregisterListForm select[name=brandCd]'), "[전체]", "");
	});
	
	//엑셀 다운로드 클릭시
	$('#btnGoodsUnregisterExcelDownLoad').on('click', function() {
		//gagaAgGrid.exportToExcel('온라인미등록상품', gridOptions);
		var date = new Date().format("YYYYMMDDHHmmss");
		var params = {
			
			fileName : "온라인미등록상품_"+ date,
			sheetName: "DATA"
		}
		gridOptions.excelStyles = [
			{
				id: 'text-center',
				dataType: 'string',
				font: {size : 10, bold: false}
			},
			{
				id: 'text-left',
				dataType: 'string',
				font: {size : 10, bold: false}
			}
		]
		
		gridOptions.api.exportDataAsExcel(params);
	});
	
	//엑셀 상품명/품목코드 저장
	$('#btnGoodsExcelSave').on('click', function() {
		cfnExcelUploadPopup('goodsInfoExcelUpload', 'goodsInfoExcelSave');
	});
	
	var goodsInfoExcelSave = function(result){
		mcxDialog.confirm('상품명/품목코드 저장을 진행하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				var data = {procJob : result.procJob
						,excelFileNm : result.excelFileNm
						};
			var jsonData = JSON.stringify(data);
			gagajf.ajaxJsonSubmit('/goods/unregister/excelupload/save', jsonData, fnGoodsInfoExcelSaveCallBack);
			}
		});	
	}
	
	var fnGoodsInfoExcelSaveCallBack = function(result){
		fnGoodsUnregisterListSearch("EXCELRESULT");
	}
	
	$(document).ready(function() {

		cfnCreateCalendar('#sellTerms', 'stDate', 'edDate', true, '등록일');
		
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);

	});

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