<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : WmsWithdrawListForm.html
 * @desc    : WMS회수목록 Page
 *=============================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *=============================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  ==================================
 * 1.0  2021.03.10   moon        최초 작성
 * 1.1  
 ********************************************************************************
 -->
 
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<!-- 검색조건 영역 -->
		<form id="searchForm" name="searchForm" action="#" th:action="@{'/withdraw/wms/list'}" onsubmit="fnSearchList(); 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 class="dashR">주문자명</th>
							<td class="dashR">
								<input type="text" class="w40p" name="customername" placeholder="" maxlength="20" />
							</td>
							<th class="dashR">주문번호</th>
							<td class="dashR">
								<input type="text" class="w40p" name="orderno" placeholder="" maxlength="20" data-valid-type="numeric"/>
							</td>
							<th class="dashR">입고상태</th>
							<td class="dashR">
								<select name="statuscd" id="statuscd" class="w100">
									<option value="" selected>전체</option>
									<option value="입고대기">입고대기</option>
									<option value="입고완료">입고완료</option>
								</select>
							</td>
						</tr>
						<tr>
							<th class="dashR">반품구분</th>
							<td class="dashR">
								<select name="recalltypecd" id="recalltypecd" class="w100">
									<option value="" selected>전체</option>
									<option value="10">일반</option>
									<option value="20">교환</option>
								</select>
							</td>
							<th class="dashR">삭제여부</th>
							<td colspan="4" class="dashR">
								<select name="isdeleted" id="isdeleted" class="w100">
									<option value="">전체</option>
									<option value="1">Y</option>
									<option value="0" selected>N</option>
								</select>
							</td>
						</tr>						
						<tr>
							<th class="dashR">회수요청일</th>
							<td colspan="6" class="dashR">
								<span id="terms"></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>

				</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="withdrawExceptionListPagination"></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[*/
	
	/*************************************************************************
	* AG-GRID 영역 
	**************************************************************************/
	var currOrdNo =0;
	var uploadGoodsUrl = [[${@environment.getProperty('upload.goods.view')}]]; 
	var roleCd = [[${sessionInfo.roleCd}]]; 

	var columnDefs = [
		//{headerName: "No.",				field: "rnum",				width: 50,	cellClass: 'text-center'},
		{headerName: "반품번호",			field: "recallno", 			width: 50,	cellClass: 'text-center', hide: true},
		{headerName: "주문변경번호",		field: "orderexceptionno",	width: 100,	cellClass: 'text-center'},
		{headerName: "주문번호",			field: "orderno",			width: 100,	cellClass: 'text-center',
			cellRenderer: function (params) {
				if (roleCd.indexOf("C") < 0) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderDetailPopup('" + params.data.orderno + "');\">" + params.data.orderno + "</a>";
				} else {
					return params.value;
				}
			}		
		},
		{headerName: "주문상세번호",		field: "orderdtlno",		width: 100,	cellClass: 'text-center'},
		{headerName: "상태",				field: "statuscd",			width: 100,	cellClass: 'text-center'},
		{headerName: "반품구분",			field: "recalltypecd",		width: 80,	cellClass: 'text-center',
			cellRenderer: function (params) { return params.value == '10' ? '일반' : '교환'; }	
		},
		{headerName: "수취인",			field: "receiver",			width: 100,	cellClass: 'text-center'},
		{headerName: "수취인전화번호",	field: "receivertelnum",	width: 120,	cellClass: 'text-center'},
		{headerName: "수취인휴대폰번호",	field: "receivercellnum",	width: 120,	cellClass: 'text-center'},
		{headerName: "우편번호",			field: "deliverypostalcode",width: 80,	cellClass: 'text-center'},
		{headerName: "기본주소",			field: "deliveryaddr1",		width: 300,	cellClass: 'text-left'},
		{headerName: "상세주소",			field: "deliveryaddr2",		width: 200,	cellClass: 'text-left'},
		{headerName: "주문자",			field: "customername",		width: 100,	cellClass: 'text-center'},
		{headerName: "ID",				field: "loginid",			width: 100,	cellClass: 'text-center'},
		{headerName: "CS메모",			field: "csmemo",			width: 250,	cellClass: 'text-left'},	
		{headerName: "CS메모 변경일",		field: "datecsmemoupdated",	width: 120,	cellClass: 'text-center'},
		{headerName: "WMS메모",			field: "wmsmemo",			width: 250,	cellClass: 'text-left'},
		{headerName: "WMS메모변경일",	field: "datewmsmemoupdated",width: 120,	cellClass: 'text-center'},
		{headerName: "회수요청일",		field: "datecreated",		width: 100,	cellClass: 'text-center'},
		{headerName: "삭제여부",			field: "isdeleted",			width: 80,	cellClass: 'text-center',
			cellRenderer: function (params) { return params.value == '0' ? 'N' : 'Y'; }		
		},
		{headerName: "상품코드",			field: "goodsCd",			width: 100,	cellClass: 'text-center'},
		{headerName: "상품명",			field: "productname",		width: 250,	cellClass: 'text-left',
			cellRenderer: function (params) {
				if (roleCd.indexOf("C") < 0) {
					return "<a href=\"javascript:void(0);\" onclick=\"cfnOpenGoodsDetailPopup('U','" + params.data.goodsCd + "');\">" + params.value + "</a>";
				} else {
					return params.value;
				}
			}					
		},
		{headerName: "productno",			field: "productno",			width: 100,	cellClass: 'text-center'},
		{headerName: "productcode",			field: "productcode",		width: 100,	cellClass: 'text-center'},		
		{headerName: "옵션코드",			field: "skucode",			width: 100,	cellClass: 'text-center'},
		{headerName: "옵션 내용",		field: "skuvalue",			width: 100,	cellClass: 'text-center'},
		{headerName: "수량",				field: "recallqty",			width: 100,	cellClass: 'text-center'},	
		{headerName: "완료일",			field: "datecompleted",		width: 100,	cellClass: 'text-center'},
		{headerName: "택배사 명",		field: "logisticsname",		width: 100,	cellClass: 'text-left'},
		{headerName: "회수운송장번호",	field: "recallinvoiceno",	width: 120,	cellClass: 'text-center'},
		{headerName: "원운송장번호",		field: "invoiceno",			width: 120,	cellClass: 'text-center'}

	];

	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);
	//gridOptions.suppressRowTransform =true;
	gridOptions.suppressRowClickSelection = true;
	//gridOptions.rowSelection = 'multiple';
	
	//gridOptions.rowHeight = 35;
	
	/*************************************************************************
	*  주문상세 팝업  
	**************************************************************************/		
	var fnOrderDetailPopup = function(ordNo){
		currOrdNo = ordNo;
		cfnOpenOrderDetailPopup(currOrdNo);
	}
	
	/*************************************************************************
	*  팝업 콜백 
	**************************************************************************/		
	var fnReOpenOrderDetailPopup = function () {
		cfnOpenOrderDetailPopup(currOrdNo);
		fnSearchList();
	};
	
	
	
	/*************************************************************************
	*  조회 버튼 클릭 시
	**************************************************************************/
	$('#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;
		}

		gagaPaging.init('searchForm', fnSearchCallBack, 'withdrawExceptionListPagination', $('#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.wmsWithdrawList);
		gagaPaging.createPagination(result.pageing.pageable);
		
	}
	
	/*************************************************************************
	*  달력 초기화 
	**************************************************************************/		
	var fnInitCalendar = function() {
		gagajf.setDate('#terms', 'stDate', 'edDate', '7d');
		
	}


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

		var date = new Date().format("YYYYMMDDHHmmss");
		var params = {
			fileName : "WMS회수목록_"+ date,
			sheetName: "DATA"
		}
		gridOptions.excelStyles = [
			{
				id: 'dateFormat',
				dataType: 'dateTime',
				numberFormat: {
					format: 'YYYY-MM-DD;@'
				}
			},
			{
				id: 'textFormat',
				dataType: 'string'
			}
		]
		gridOptions.api.exportDataAsExcel(params);
	});

	/*************************************************************************
	*  init
	**************************************************************************/		
	$(document).ready(function() {
		gagaAgGrid.createGrid('gridList', gridOptions);
		var hideList = ["btnThisWeek", "btnYesterWeek", "btnThisMonth", "btnYesterMonth", "btnRecent3Month"];
		cfnCreateCalendar('#terms', 'stDate', 'edDate', true, '','',  hideList);
		fnInitCalendar();
	});

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