<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : AssignPopupForm.html
 * @desc    : 출고처 지정 팝업
 *============================================================================
 * ISTYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.04.19   moon       최초 작성
 *******************************************************************************
 -->
	<div class="modalPopup" data-width="700" data-height="800">
		<div class="panelStyle">
		<!-- TITLE -->
		<div class="panelTitle">
			<h2>출고처 지정</h2>
			<button type="button" class="close" onclick="uifnPopupClose('popupAssignForm')"><i class="fa fa-times"></i></button>
		</div>
		<!-- //TITLE -->

		<form id="assignPopupForm" name="assignPopupForm" th:action="@{'/delivery/assign/popup/list'}" >
		<input type="hidden" name="ordDtlNo" id="ordDtlNo" th:value="${orderDetail.ordDtlNo}">
		<input type="hidden" name="goodsCd" id="goodsCd" th:value="${orderDetail.goodsCd}">
		<input type="hidden" name="sizeCd" id="ordNo" th:value="${orderDetail.ordNo}"> 
			<table class="frmStyle">
				<colgroup>
					<col style="width:10%;"/>
					<col style="width:20%;"/>
					<col style="width:10%;"/>
					<col style="width:20%;"/>
					<col style="width:10%;"/>
					<col style="width:30%;"/>
				</colgroup>
				<tr>
					<th>주문상세번호</th>
					<td class="aC solidR" th:text="${orderDetail.ordDtlNo}"></td>
					<th>상품가격</th>
					<td class="aC solidR" th:text="${#numbers.formatDecimal(orderDetail.currPrice, 0,'COMMA', 0,'POINT')}">
					<th>상품코드</th>
					<td class="aC solidR" th:text="${orderDetail.goodsCd}"></td>
				</tr>
			</table>
		</form>

		<ul class="panelBar">
			<li class="center">
			<button type="button" class="btn btn-base btn-sm" id="btnPopupSearch">조회</button>
			<button type="button" class="btn btn-danger btn-sm" id="btnPopupAssign">출고처 지정</button>
			</li>
		</ul>
		<!-- 테이블 영역  영역 -->
		
		<div id="gridDelvLocList" style="width: 100%; height: 500px;" class="ag-theme-balham"></div>
		
		<!-- 테이블 영역 -->
		</div>
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	var assignPopupColumnDefs = [
		// group cell renderer needed for expand / collapse icons
		{headerName: "출고처", 		field: "delvLocNm", width: 350, cellClass: 'text-center'},
		{headerName: "출고처코드", 	field: "delvLocCd",	width: 100,	cellClass: 'text-center'},
		{headerName: "수량",      	field: "stockQty", 	width: 100,	cellClass: 'text-center'},
		{headerName: "출고거부여부",	field: "delvArGb",	width: 100, cellClass: 'text-center'}
	];

	//Get GridOptions
	var assignPopupGridOptions = gagaAgGrid.getGridOptions(assignPopupColumnDefs);

	assignPopupGridOptions.rowSelection = 'single';

	$(document).ready(function() {
	    gagaAgGrid.createGrid('gridDelvLocList', assignPopupGridOptions);
	});

	$('#btnPopupSearch').on('click', function() {
		fnPopupSearchList();
	});

	var fnPopupSearchList = function() {
		gagaAgGrid.fetch($('#assignPopupForm').prop('action'), assignPopupGridOptions, '#assignPopupForm', function(){
		});
	}

	// 출고처지정 버튼 클릭 시
	$('#btnPopupAssign').on('click', function() {
		var selectedRowData = gagaAgGrid.selectedRowData(assignPopupGridOptions);

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

		mcxDialog.confirm('출고처를 지정하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var updatedData = selectedRowData[0];
				updatedData.ordDtlNo = $('#ordDtlNo').val();
				updatedData.ordNo = $('#ordNo').val();
				var jsonData = JSON.stringify(updatedData);
				 gagajf.ajaxJsonSubmit('/delivery/assign/save'
						, jsonData
						, function() {
							$('#btnSearch').trigger('click');
							uifnPopupClose('popupAssignForm');
						});
			}
		});
	});

	$(document).ready(function() {
		fnPopupSearchList();
	});
/*]]>*/
</script>
</html>