<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : BanGoodsRegistForm.html
 * @desc    : 출고금지상품 등록 팝업
 *=============================================================
 * ISTYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *=============================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  ==================================
 * 1.0  2020.11.11   moon        최초 작성
 * 1.1  2020.11.23   moon        이미지관련 수정 
 *******************************************************************************
 -->
	<div class="modalPopup" data-width="1200">
		<div class="panelStyle">
		<!-- TITLE -->
		<div class="panelTitle">
			<h2>출고금지 상품 등록</h2>
			<button type="button" class="close" onclick="uifnPopupClose('popupRegistBangoods')"><i class="fa fa-times"></i></button>
		</div>
		<!-- //TITLE -->

		<form id="bangoodsRegistForm" name="BangoodsRegistForm" action="#" th:action="@{'/delivery/bangoods/regist/list'}" th:method="post">
			<table class="frmStyle">
				<colgroup>
					<col style="width:8%" />
					<col style="width:20%;" />
					<col style="width:8%" />
					<col style="width:20%;" />
				</colgroup>
				<tbody>
					<tr>
						<th>업체/브랜드</th>
						<td>
							<select name="supplyCompCd" id="supplyCompCd" class="w120">
								<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" class="w120">
								<option value="">[전체]</option>
							</select>
						</td>
						<th>구분</th>
						<td>
								<select name="goodsGb" id="">
									<option value="goodsCd">상품코드</option>
									<option value="goodsNm">상품명</option>
								</select>
								<input type="text" class="w60p" name="searchTxt" placeholder="" maxlength="20" />
						</td>
					</tr>
					<tr>
						<th>상품상태</th>
						<td colspan="3">
							<select  name="goodsStat" id="goodsStat">
								<option value="">[전체]</option>
								<option th:if="${goodsStatList}" th:each="oneData, status : ${goodsStatList}" th:value="${oneData.cd}" th:text="${oneData.cdNm}"></option>
							</select>
						</td>
					</tr>
				</tbody>
			</table>
			<ul class="panelBar">
				<li class="center">
				<button type="button" class="btn btn-info btn-sm" onclick="fnPopSearch();">상품조회</button>
				</li>
			</ul>
			
			
			<div class="frmBtnB">
			<table class="frmStyle">
				<colgroup>
					<col style="width:20%" />
					<col />
				</colgroup>
				<tr>
					<th>출고금지기간</th>
					<td>
						<span>
							<input type="text" class="schDate w100" id="delvBanStdt" name="delvBanStdt" maxlength="10"/>~
							<input type="text" class="schDate w100" id="delvBanEddt" name=delvBanEddt maxlength="10"/>
						</span>
					</td>
					<th>출고금지출고처</th>
					<td>
						<select  name="popDelvLocCd" id="popDelvLocCd">
							<option value="">[전체]</option>
							<option th:if="${getDeliveryLocList}" th:each="oneData, status : ${getDeliveryLocList}" th:value="${oneData.Cd}" th:text="${oneData.cdNm}"></option>
						</select>
					</td>
				</tr>
			</table>
			</div>

			<div id="gridBanGoodsList" style="width: 100%; height: 260px; padding-top:10PX;" class="ag-theme-balham"></div>
		
		</form>
		<!-- 버튼 배치 영역 -->
		<ul class="panelBar">
			<li class="right">
			<button type="button" class="btn btn-success btn-lg" id="btnBangoodsSave">저장</button>
			</li>
		</ul>
		<!-- //버튼 -->

		</div>
	</div>
<script th:inline="javascript">
/*<![CDATA[*/
	var doubleSubmitFlag = false;

	// specify the columns
	var columnBanDefs = [
		{width: 42, minWidth: 42, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: "브랜드",	field: "brandKnm", width: 150, minWidth: 80, cellClass: 'text-center'},
		{headerName: "이미지",	field: "sysImgNm", width: 130, height: 80, cellClass: 'text-center'
			,cellRenderer: function(params) {
				return '<img width="60" src="'+ _goodsUrl+ "/" +params.value + '" alt=""/>';
			}
		},
		{headerName: "상품명",	field: "goodsNm",     width: 330, minWidth: 100},
		{headerName: "상품코드",	field: "goodsCd",     width: 150, minWidth: 100, cellClass: 'text-center'},
		{headerName: "컬러",	    field: "colorCd",     width: 100, minWidth: 100, cellClass: 'text-center'},
		{headerName: "사이즈",	field: "sizeCd",      width: 100, minWidth: 100, cellClass: 'text-center'},
		{headerName: "상품상태",	field: "goodsStatNm", width: 150, minWidth: 100, cellClass: 'text-center'},
	];

	// Get popGridOptions
	var popGridOptions = gagaAgGrid.getGridOptions(columnBanDefs);

	// Add on options
	popGridOptions.rowSelection = 'multiple';
	popGridOptions.rowHeight = 80; //이미지가 있을경우 높이 지정해야함.

	$(document).ready(function() {
		gagaAgGrid.createGrid('gridBanGoodsList', popGridOptions);
	});

	// 조회
	var fnPopSearch = function() {
		var formId = '#bangoodsRegistForm';
		gagaAgGrid.fetch($(formId).prop('action'), popGridOptions, formId);
	}

	// 저장
 	$('#btnBangoodsSave').on('click', function() {

		var delvLocCd = $("#popDelvLocCd option:selected").val();

		if (gagajf.isNull(delvLocCd)) {
			mcxDialog.alert("출고처를 선택해주세요!");
 			 $("#popDelvLocCd").focus();
			return;
 		}

		var delvBanStdt = $('#delvBanStdt').val();
		var delvBanEddt = $('#delvBanEddt').val();

		if (gagajf.isNull(delvBanStdt) || gagajf.isNull(delvBanEddt)) {
			mcxDialog.alert("출고금지 기간을 입력 해주세요!");
			return false;
 		}

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

		mcxDialog.confirm("등록 하시겠습니까?", {
		    cancelBtnText: "취소",
		    sureBtnText: "확인",
		    sureBtnClick: function() {

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

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

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

	                param.goodsCd     = item.goodsCd;
	                param.colorCd     = item.colorCd;
	                param.sizeCd      = item.sizeCd;
	                param.delvBanStdt = delvBanStdt;
	                param.delvBanEddt = delvBanEddt;
	                param.delvLocCd   = delvLocCd;

	                createData.push(param);
	            });

	            var jsonData = JSON.stringify(createData);
	            gagajf.ajaxJsonSubmit('/delivery/bangoods/regist/save', jsonData, fnPopSearch);
	        }
		});

 	});

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

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