<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : OrderSellerDelvListForm.html
 * @desc    : 입점발주최종확인 Page
 *============================================================================
 * SISUN
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.04.20   xodud1202   최초 작성
 *******************************************************************************
 -->
 
<div id="main">
	<!-- 메인타이틀 영역 -->
	<div class="main-title">
	</div>
	<!-- //메인타이틀 영역 -->
	
	<!-- 메뉴 설명 -->
	<div class="infoBox menu-desc">
	</div>
	
	<form id="searchForm" name="searchForm" action="#" th:action="@{'/order/seller/unorder/list'}">
		<input type="hidden" name="ordDtlStat" 						value="G013_40" />
		<input type="hidden" name="pageNo" 			id="pageNo" 	value ="1"/>
		<input type="hidden" name="supplyCompCd" 					th:value="${supplyCompCd}" />
		<div class="panelStyle">
			<ul class="panelBar">
				<li class="aR">
					<button type="button" id="btnSave" class="btn btn-success btn-lg">저장</button>
				</li>
			</ul>
			
			<div class="panelContent" style="overflow: hidden;">
				<div id="gridList" style="width: 100%; height: 700px;" class="ag-theme-balham lh30"></div>
			</div>
		</div>
	</form>
</div>

<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js?v=20210114"></script>

<script th:inline="javascript">
var shipCompanyList = gagajf.convertToArray([[${shipCompanyList}]]);
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:"supplyCompNm",		width:70, cellClass: 'text-center'},
	{headerName: "입점업체코드",		field:"supplyCompCd",		width:80, cellClass: 'text-center', hide: true},
	{headerName: "브랜드",			field:"brandKnm",			width:80, cellClass: 'text-center'},
	{headerName: "주문번호",			field:"ordNo",				width:70, cellClass: 'text-center'},
	{headerName: "주문상세번호",		field:"ordDtlNo",			width:100, cellClass: 'text-center'},
	{headerName: "업체상품코드",		field:"supplyGoodsCd",		width:100, cellClass: 'text-center'},
	{headerName: "상품코드",			field:"goodsCd",			width:100, cellClass: 'text-center'},
	{headerName: "상품명",			field:"goodsNm",			width:100, cellClass: 'text-center'},
	{headerName: "옵션1",			field:"optCd1",				width:100, cellClass: 'text-center'},
	{headerName: "옵션2",			field:"optCd2",				width:100, cellClass: 'text-center'},
	{headerName: "배송업체",			field:"shipCompCd",			width:120, cellClass: 'text-center'
		, valueFormatter: function (params) {
			return gagaAgGrid.lookupValue(shipCompanyList, params.value);
		}
		, valueParser: function (params) {
			return gagaAgGrid.lookupKey(shipCompanyList, params.newValue);
		}
	},
	{headerName: "송장",				field:"invoiceNo",			width:120, cellClass: 'text-center'},
	{headerName: "주문수량",			field:"ordQty",				width:100, cellClass: 'text-center'},
	{headerName: "취소수량",			field:"cnclRtnQty",			width:100, cellClass: 'text-center'},
	{headerName: "출고수량",			field:"delvQty",			width:100, cellClass: 'text-center'},
	{headerName: "미출고수량",			field:"cancelQty",			width:100, cellClass: 'text-center'
		, editable 			: true
		, cellEditor		: 'agRichSelectCellEditor'
		, cellStyle			: {color: '#fffff', 'background-color': '#aaaaff'}
		, cellEditorParams	: function(params){
			if(params.data.ordExchGb == "E") {
				return {values : [0]};
			} else {
				var qtyList = new Array();
				var qty = params.data.ordQty - params.data.cnclRtnQty

				if(params.data.pgGb == "NAVER_ORDER") {
					qtyList.push(0);
					qtyList.push(qty);
				} else {
					for(var i = 0 ; i <= qty ; i++) qtyList.push(i);
				}
				return {values: qtyList};
			}
		},
		onCellValueChanged : function(params) {
			if(params.data.cancelQty > -1) {
				// params.data.cnclRtnQty = params.data.cancelQty;
				params.data.delvQty = params.data.ordQty - params.data.cnclRtnQty - params.data.cancelQty;
				gridOptions.api.refreshCells();
			}
		}
	},
	{headerName: "결제PG",			field: "pgGb",				width: 100, cellClass: 'text-center', hide: true},
	{headerName: "결제수단",			field: "payMeans",			width: 100, cellClass: 'text-center', hide: true},
	{headerName: "고객번호",			field: "custNo",			width: 100, cellClass: 'text-center', hide: true},
	{headerName: "주문고객명",			field: "ordNm",				width: 100, cellClass: 'text-center', hide: true},
	{headerName: "환불계좌은행코드",	field: "bankCd",			width: 100, cellClass: 'text-center', hide: true},
	{headerName: "환불계좌예금주명",	field: "accountNm",			width: 100, cellClass: 'text-center', hide: true},
	{headerName: "주문고객휴대폰번호",	field: "ordPhnno",			width: 100, cellClass: 'text-center', hide: true},
	{headerName: "환불계좌번호",		field: "accountNo",			width: 100, cellClass: 'text-center', hide: true},
	{headerName: "배송정책",			field: "delvFeeCd",			width: 100, cellClass: 'text-center', hide: true},
	{headerName: "변경요청번호",		field: "ordChgSq",			width: 100, cellClass: 'text-center', hide: true}
];

var gridOptions = gagaAgGrid.getGridOptions(columnDefs);
gridOptions.suppressRowClickSelection = true;
gridOptions.rowSelection = 'multiple';
gridOptions.stopEditingWhenGridLosesFocus = true;

// 검색
var fnSearch = function() {
	//var formId 		= '#searchForm';
	//gagaAgGrid.fetch($(formId).prop('action'), gridOptions, formId);

	gagaPaging.init('searchForm', fnSearchCallBack, 'orderListPagination', 100);
	gagaPaging.load($("#searchForm input[name=pageNo]").val());
}

var fnSearchCallBack = function(result){
	$('#searchForm').find('#gridRowTotalCount').html(result.pageing.pageable.totalCount.addComma());
	$('#searchForm').find('#pageNo').val(result.pageing.pageable.pageNo.addComma());
	$('#searchForm').find('#pgNo').html(result.pageing.pageable.pageNo.addComma());
	$('#searchForm').find('#endPgNo').html(result.pageing.pageable.totalPage.addComma());

	gridOptions.api.setRowData(result.orderList);
	gagaPaging.createPagination(result.pageing.pageable);
}

//초기설정
$(document).ready(function() {
	// 달력기능 활성화
	gagaAgGrid.createGrid('gridList', gridOptions);
	gridOptions.api.hideOverlay();

	fnSearch();
});

$("#btnSave").on("click", function(e) {
	var selectedData = gridOptions.api.getSelectedRows();

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

	for(let i = 0 ; i < selectedData.length ; i++) {
		let rowData = selectedData[i];
		if(typeof rowData.cancelQty == "undefined") {
			mcxDialog.alert('선택된 행의 미출고수량을 입력해주세요.');
			return;
		}
	}

	mcxDialog.confirm('선택된 주문을 배송중으로 변경하시겠습니까?', {
		cancelBtnText	: "취소",
		sureBtnText		: "확인",
		sureBtnClick	: function(){
			var jsonData = JSON.stringify(selectedData);
			gagajf.ajaxJsonSubmit('/order/seller/delv/started', jsonData, fnEndFunction);
		}
	});

	// 엑셀다운로드
	var fnEndFunction = function(result){
		mcxDialog.alert("성공적으로 저장되었습니다.");
		fnSearch();
	}
});
</script>

</html>





