<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : BangoodsListForm.html
 * @desc    : 출고금지상품관리 Page
 *=============================================================
 * ISTYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *=============================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  ==================================
 * 1.0  2020.11.10   moon        최초 작성
 * 1.1  
 ********************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		<!-- 검색조건 영역 -->
		<div class="panelStyle">
			<!-- TITLE -->
			<div class="panelTitle">
				<h3><i class="fa fa-info-circle"></i>아래 검색조건 중 <font color="red">기간, 키워드</font>중 하나를 꼭 입력해 주세요.</h3>
				<span class="panelControl">
					<i class="fa fa-chevron-up"></i>
				</span>
			</div>
			<!-- //TITLE -->
			<div class="panelContent">	
				<form id="searchForm" name="searchForm" action="#" th:action="@{'/delivery/bangoods/list'}" onsubmit="fnSearchList(); return false;">
					<table class="frmStyle">
						<colgroup>
							<col style="width:8%;"/>
							<col style="width:30%;"/>
							<col style="width:8%;"/>
							<col style="width:30%;"/>
						</colgroup>
						<tr>
							<th class="dashR">업체/브랜드</th>
							<td class="dashR">
								<select name="supplyCompCd" id="supplyCompCd">
									<option value="">[전체]</option>
									<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${oneData.cdNm}"></option>
								</select>
								/
								<select name="brandCd" id="brandCd">
									<option value="">[전체]</option>
								</select>
							</td>
							<th class="dashR">구분</th>
							<td class="dashR">
								<select name="goodsGb" id="">
									<option value="goodsCd">상품코드</option>
									<option value="goodsNm">상품명</option>
								</select>
								<input type="text" class="w40p" name="searchTxt" placeholder="" maxlength="20" />
							</td>
						</tr>
	
						<tr>
							<th class="dashR">출고처</th>
							<td class="dashR">
								<select name="delvLocCd" id="delvLocCd">
									<option value="">[전체]</option>
									<option th:if="${getDeliveryLocList}" th:each="oneData, status : ${getDeliveryLocList}" th:value="${oneData.cd}" th:text="${oneData.cdNm}"></option>
								</select>
							</td>
							<th class="dashR">삭제여부</th>
							<td class="dashR">
								<select name="delYn" id="delYn" class="w80">
									<option value="">전체</option>
									<option value="N" selected>N</option>
									<option value="Y">Y</option>
								</select>
							</td>
						</tr>
						<tr>
							<th class="dashR">등록일</th>
							<td colspan="4" class="dashR">
								<span id="terms"></span>
							</td>
						</tr>
						<tr>
							<th class="dashR">출고금지시작일자</th>
							<td colspan="" class="dashR">
								<span id="terms2"></span>
							</td>
							<th class="dashR">출고금지종료일자</th>
							<td colspan="" class="dashR">
								<span id="terms3"></span>
							</td>
						</tr>			
					</table>
	
					<ul class="panelBar">
						<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearch">조회</button>
						<button type="button" class="btn btn-gray btn-lg" onclick="$('#searchForm')[0].reset(); fnInitCalendar();">초기화</button>
						<button type="button" id="btnExcel" class="btn btn-info btn-lg" >엑셀다운로드</button>
						</li>
					</ul>
				</form>
				</div>
		</div>
		<!-- //검색조건 영역 -->

		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<ul class=panelBar>
				<li class="left">
					<button type="button" id="btnSoldout" class="btn btn-danger btn-lg" onclick="deleteBangoods();" >삭제</button>
				</li>
				<li class="right">
					<button type="button" id="btnSave" class="btn btn-success btn-lg btnRight" onclick="registerBangoods();">등록</button>
				</li>
			</ul>
			<div class="panelContent" style="overflow: hidden;">
				<div id="gridList" style="width:100%; height: 500px;" class="ag-theme-balham lh60"></div>
			</div>
		</div>
		<!-- //리스트 영역 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	
	/*************************************************************************
	* AG-GRID 영역 
	**************************************************************************/
	
	var uploadGoodsUrl = [[${@environment.getProperty('upload.goods.view')}]]; 
	var roleCd = [[${sessionInfo.roleCd}]]; 

	var columnDefs = [
		{ width: 42, minWidth: 42, cellClass: 'text-center', headerCheckboxSelection: true, headerCheckboxSelectionFilteredOnly: true
			, checkboxSelection: function (params) {
				return  (params.data.delYn == 'N' ) ? true : false;
			},
			
		},
		{headerName: "출고금지상품번호",			field: "delvBanGoodsSq",width: 50,	cellClass: 'text-center', hide: true},
		{headerName: "삭제",					field: "delYn",			width: 50,	cellClass: 'text-center'},
		{headerName: "브랜드",				field: "brandKnm",		width: 150,	cellClass: 'text-center'},
		{headerName: "출고처명",				field: "delvLocNm",		width: 150,	cellClass: 'text-center'},
		{headerName: "이미지",				field: "sysImgNm",		width: 100,	height: 60, cellClass: 'text-center', 
			cellRenderer: function(params) {

				return '<img width="60" src="'+ _goodsUrl+ "/" +params.value + '" alt=""/>';

			}
		},
		{headerName: "상품명",				field: "goodsNm",		width: 150,	cellClass: 'text-center'},
		{
			headerName: "상품코드", field: "goodsCd", width: 130, cellClass: 'text-center', sortable: true,
			cellRenderer: function (params) {
				
				if (roleCd.indexOf("C") < 0) {
					return "<a href=\"javascript:void(0);\" onclick=\"cfnOpenGoodsDetailPopup('U','" + params.value + "');\">" + params.value + "</a>";
				} else {
					return params.value;
				}
			}
		},
		{headerName: "옵션1",		    field: "optCd1",		width: 80,	cellClass: 'text-center'},
		{headerName: "옵션2",			field: "optCd2",		width: 80,	cellClass: 'text-center'},
		{headerName: "상품상태",		field: "goodsStat",		width: 80,	cellClass: 'text-center'},
		{headerName: "출고금지시작일자",	field: "delvBanStdt",	width: 150,	cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.toDateFormat(params.value); }},
		{headerName: "출고금지종료일자",	field: "delvBanEddt",	width: 150,	cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.toDateFormat(params.value); }},
		{headerName: "등록일자",		field: "regDt",			width: 100,	cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.toDateFormat(params.value); }}
		
	];

	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);
	//gridOptions.rowSelection = 'multiple';
	//gridOptions.suppressRowClickSelection = true;
	gridOptions.isRowSelectable = function(rowNode) {
		return rowNode.data.delYn == 'N';
	}
	gridOptions.rowHeight = 60; //이미지가 있을경우 높이 지정해야함.
	
	//gridOptions.rowHeight = 60;
	/*************************************************************************
	*  조회 버튼 클릭 시
	**************************************************************************/
	$('#btnSearch').on('click', function() {
		fnSearchList();
	});

	/*************************************************************************
	*  조회 
	**************************************************************************/
	var fnSearchList = function() {
		if($('#stDate').val() == ''){
			mcxDialog.alert('시작 기간을 입력하세요.');
			return;
		}

		if($('#edDate').val() == ''){
			mcxDialog.alert('종료 기간을 입력하세요.');
			return;
		}

		// 날짜 유효성 체크
		if (Number($('#stDate').val().replaceAll("-", "")) > Number($('#edDate').val().replaceAll("-", ""))) {
			mcxDialog.alert("시작일은 종료일보다 클 수 없습니다.");
			return;
		}

		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm', function() {
		});
	}

	/*************************************************************************
	*  달력 초기화 
	**************************************************************************/		
	var fnInitCalendar = function() {
		cfnChangeCalendar('7d', $('#stDate'), $('#edDate')); //달력 초기화
	}

	/*************************************************************************
	*  업체 콤보박스 변경 시
	**************************************************************************/	
	$('#searchForm select[name=supplyCompCd]').on('change', function() {
		var actionUrl = '/renderer/supplyCompany/brand/list/'+ $(this).val();
		cfnCreateCombo(actionUrl, $('#searchForm select[name=brandCd]'), "[전체]");
		
		var actionUrl2 = '/renderer/delvloc/list/'+ $(this).val();	

		cfnCreateCombo(actionUrl2, $('#searchForm select[name=delvLocCd]'), "[전체]");
		
	});

	/*************************************************************************
	*  엑셀다운로드
	**************************************************************************/		
	$('#btnExcel').on('click', function() {
		var totalRows = gridOptions.api.getDisplayedRowCount();
		if(totalRows==0){
			mcxDialog.alert('조회된 내역이 없습니다.');
			return;
		}

		var date = new Date().format("YYYYMMDDHHmmss");
		var params = {

			fileName : "출고금지상품목록_"+ date,
			sheetName: "DATA"
		}
		gridOptions.excelStyles = [
			{
				id: 'dateFormat',

				dataType: 'dateTime',
				numberFormat: {
					format: 'YYYY-MM-DD;@'
				}
			},
			{
				id: 'textFormat',
				dataType: 'string'
			}
		]

		gridOptions.api.exportDataAsExcel(params);
	});

	/*************************************************************************
	*  삭제
	**************************************************************************/	
	var deleteBangoods = function(){
		
		var selectedData = gridOptions.api.getSelectedNodes();
		
		$.each(selectedData, function(idx, row) {
	
	 		if(row.data.delYn == "Y") {
	 			gridOptions.api.deselectIndex(row.rowIndex);
	 		}
	 	});
		
		
		mcxDialog.confirm("삭제하시겠습니까?", {
		    cancelBtnText: "취소",
		    sureBtnText: "확인",
		    sureBtnClick: function() {

	            var gridData = gagaAgGrid.removeRowData(gridOptions,false);

	            if (gridData.length == 0) {
	            	mcxDialog.alert('선택된 행이 없습니다.');
	                return;
	            }

	            var createData = [];
	            $.each(gridData, function(idx, item) {
	                var param = new Object;

	                param.delvBanGoodsSq = item.delvBanGoodsSq;
	                param.goodsCd = item.goodsCd;
	                param.optCd1  = item.optCd1;
	                param.optCd2  = item.optCd2;

	                createData.push(param);
	            });

	            var jsonData = JSON.stringify(createData);
	            gagajf.ajaxJsonSubmit('/delivery/bangoods/delete', jsonData, fnSearchList);
	        }
		});
	}

	/*************************************************************************
	*  등록 팝업 호출 
	**************************************************************************/	
	var registerBangoods = function(){
		var actionUrl = "/delivery/bangoods/regist/form";
		cfnOpenModalPopup(actionUrl,'popupRegistBangoods');
	}

	$(document).ready(function() {
		gagaAgGrid.createGrid('gridList', gridOptions);
		gridOptions.api.hideOverlay();
		
		var hideList = ["btnThisWeek", "btnYesterWeek", "btnRecentMonth", "btnThisMonth", "btnYesterMonth", "btnRecent3Month"];
		
		cfnCreateCalendar('#terms', 'stDate', 'edDate', true, '출고금지상품관리');
		cfnCreateCalendar('#terms2', 'stDate2', 'edDate2', true, '출고금지상품관리','',hideList);
		cfnCreateCalendar('#terms3', 'stDate3', 'edDate3', true, '출고금지상품관리','',hideList);
		
		
		//var hideList = ["btnThisWeek", "btnYesterWeek", "btnRecentMonth", "btnThisMonth", "btnYesterMonth", "btnRecent3Month"];
		//cfnCreateCalendar('#terms', 'stDate', 'edDate', true, '출고금지상품관리', '', hideList);
		fnInitCalendar();
	});

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