<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : DeliveryWithdrawDirectiveListForm.html
 * @desc    : 배송/회수지시 목록 Page
 *=============================================================
 * ISTYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *=============================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  ==================================
 * 1.0  2021.03.11   moon        최초 작성
 *******************************************************************************
 -->
 	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<!-- 검색조건 영역 -->
		<form id="searchForm" name="searchForm" action="#" th:action="@{'/delivery/dwdirect/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
		<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">	
				
					<table class="frmStyle">
						<colgroup>
							<col style="width:8%;"/>
							<col style="width:12%;"/>
							<col style="width:8%;"/>
							<col style="width:12%;"/>
							<col style="width:8%;"/>
							<col style="width:12%;"/>
						</colgroup>
												<tr>
							<th>지시구분</th>
							<td>
								<select name="delvGb">
									<option value="">전체</option>
									<option value="D">배송지시</option>
									<option value="W">회수지시</option>
								</select>
							</td>
							<th>택배사 전송여부</th>
							<td>
								<select name="sendYn">
									<option value="">전체</option>
									<option value="N">미전송</option>
									<option value="Y">전송</option>
								</select>
							</td>
							<th>사이트</th>
							<td>
								<select name="siteCd">
									<option value="">전체</option>
									<option th:if="${siteCdList}" th:each="oneData, status : ${siteCdList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
								</select>
							</td>
						</tr>
						<tr>
							<th>주문일/회수요청일</th>
							<td colspan="5" id="terms">
							</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>

				</div>
		</div>
		<!-- //검색조건 영역 -->

		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<ul class="panelBar">
				<li class="right">
					검색결과 : <strong><span id="gridRowTotalCount">0</span> 건</strong>&nbsp;
					쪽번호 <span id="pgNo">0</span>/ <strong id="endPgNo">0</strong>&nbsp;&nbsp;
					<select id="pageSize" name="pageSize">
						<option value="20" selected="selected">20개씩 보기</option>
						<option value="50">50개씩 보기</option>
						<option value="100">100개씩 보기</option>
						<option value="500">500개씩 보기</option>
						<option value="1000">1000개씩 보기</option>
					</select>
					<input type="hidden" name="pageNo" id="pageNo" value ="1"/>
				</li>
			</ul>
			<div id="gridList" style="width:100%; height: 700px;" class="ag-theme-balham"></div>
			<ul class="panelBar">
				<li class="center">
					<div class="tablePaging" id="delvWithdrawListPagination"></div>
				</li>
			</ul>
					 
		</div>
		</form>
		<!-- //리스트 영역 -->
	</div>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js?v=20210114"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	// 사이트목록
	var currOrdNo = 0;
	var siteList = gagajf.convertToArray([[${siteCdList}]]);

	var columnDefs = [
		{headerName: "지시구분", 		field: "delvGbNm", 		width: 80, cellClass: "text-center"},
		{headerName: "택배사전송", 	field: "sendYn", 		width: 80, cellClass: "text-center",
			cellRenderer: function (params) { return params.value == 'Y' ? '전송' : '미전송'; }
		},
		{headerName: "사이트", 		field: "siteCd", 		width: 80, cellClass: "text-center",
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(siteList, params.value); }
		},
		{headerName: "주문번호", 		field: "ordNo", 		width: 100, cellClass: "text-center",
			cellRenderer: function(params) { return gagajf.isNull(params.value) ? '' : '<a href="javascript:void(0);">' + params.value + '</a>'; }
		},
		{headerName: "주문상세번호", 	field: "ordDtlNo", 		width: 100, cellClass: "text-center"},
		{headerName: "상품코드", 		field: "goodsCd", 		width: 120, cellClass: "text-center",
			cellRenderer: function(params) { return gagajf.isNull(params.value) ? '' : '<a href="javascript:void(0);">' + params.value + '</a>'; }
		},
		{headerName: "상품명", 		field: "goodsNm", 		width: 200, cellClass: "text-left"},
		{headerName: "수취인명", 		field: "recipNm", 		width: 120, cellClass: "text-center"},
		{headerName: "수취인휴대전화", 	field: "recipPhnno", 	width: 120, cellClass: "text-center"},
		{headerName: "수취인전화번호", 	field: "recipTelno", 	width: 120, cellClass: "text-center"},
		{headerName: "수취인우편번호", 	field: "recipZipcode", 	width: 120, cellClass: "text-center"},
		{headerName: "수취인기본주소", 	field: "recipBaseAddr", width: 300, cellClass: "text-left"},
		{headerName: "수취인상세주소", 	field: "recipDtlAddr", 	width: 200, cellClass: "text-left"},
		{headerName: "주문자명", 		field: "ordNm", 		width: 100, cellClass: "text-center"},
		{headerName: "주문자휴대전화", 	field: "ordPhnno", 		width: 120, cellClass: "text-center"},
		{headerName: "주문자전화번호", 	field: "ordTelno", 		width: 120, cellClass: "text-center"},
		{headerName: "주문자이메일", 	field: "ordEmail", 		width: 120, cellClass: "text-left"}
	];

	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// 셀 클릭 이벤트
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field == 'ordNo') {
			currOrdNo = event.data.ordNo;
			// 주문 상세
			cfnOpenOrderDetailPopup(event.data.ordNo);
		} else if (event.colDef.field == 'goodsCd') {
			// 상품 상세
			cfnOpenGoodsDetailPopup('U', event.data.goodsCd);
		}
	};

	/*************************************************************************
	*  팝업 콜백 
	**************************************************************************/		
	var fnReOpenOrderDetailPopup = function () {
		cfnOpenOrderDetailPopup(currOrdNo);
		fnSearchList();
	};
	
	// 조회
	$('#btnSearch').on('click', function() {
		// Fetch data
		//gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
		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;
		}

		gagaPaging.init('searchForm', fnSearchCallBack, 'delvWithdrawListPagination', $('#searchForm').find('#pageSize').val());
	    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.dwdirectList);
		gagaPaging.createPagination(result.pageing.pageable);
		
	}
	


	//엑셀다운로드
	$('#btnExcel').on('click', function() {
		gagaAgGrid.exportToExcel('배송/회수지시 목록', gridOptions);
		
		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);
		
	});

	$(document).ready(function() {
		

		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
		cfnCreateCalendar('#terms', 'stDate', 'edDate', false);
		// grid 높이 조절
		//uifnFitGrid('auto');

		gagajf.setDate('#terms', 'stDate', 'edDate', 't');

		//fnDatepickerDisabled();
	});

/*]]>*/
</script>

</html>