<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : WithdrawExceptionListForm.html
 * @desc    : 회수예외관리 Page
 *=============================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *=============================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  ==================================
 * 1.0  2021.02.22   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/exception/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="recallStat" id="recallStat">
									<option value="">전체</option>
									<option value="P" selected>대기</option>
									<option value="S">처리완료</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 uploadGoodsUrl = [[${@environment.getProperty('upload.goods.view')}]]; 
	var roleCd = [[${sessionInfo.roleCd}]]; 

	var columnDefs = [
		{headerName: "반품예외처리번호",		field: "recallExceptionNo", width: 50,	cellClass: 'text-center', hide: true},
		{headerName: "No.",				field: "rnum",				width: 50,	cellClass: 'text-center'},
		{headerName: "처리상태",			field: "recallStat",		width: 100,	cellClass: 'text-center',rowSpan: params => params.data.rowspanRank === 1 ? params.data.rowspanCnt : 1,
		    cellClassRules: {
		        'cell-span': "data.rowspanRank == 1"
		      },
			cellRenderer: function(params) {
				var btnText = '';
				if(params.data.recallStat === 'P') {
					btnText= '<a href="javascript:void(0);"  onclick="fnComplete(\''+params.data.recallExceptionNo+'\')" class="btn btn-success btn-ssm">대기</a>';
				} else { btnText = '완료' }
				return btnText;
			}			
		},
		
		{headerName: "주문번호",			field: "orderNo",			width: 200,	cellClass: 'text-center', rowSpan: params => params.data.rowspanRank === 1 ? params.data.rowspanCnt : 1,  
		    cellClassRules: {
		        'cell-span': "data.rowspanRank == 1"
		      },
			
			cellRenderer: function (params) {
			if (roleCd.indexOf("C") < 0) {
				return "<a href=\"javascript:void(0);\" onclick=\"cfnOpenOrderDetailPopup('" + params.data.orderNo + "');\">" + params.data.orderNo + "</a>";
			} else {
				return params.value;
			}
			}
	
		},
		{headerName: "주문자명",			field: "customerName",		width: 100,	cellClass: 'text-center'},
		{headerName: "택배사명",			field: "logisticsName",		width: 100,	cellClass: 'text-center'},
		{headerName: "반송장번호",			field: "invoiceNo",			width: 120,	cellClass: 'text-center'},
		{headerName: "요금구분",			field: "chargeType",		width: 80,	cellClass: 'text-center'},
		{headerName: "배송비",			field: "chargeAmount",		width: 100,	cellClass: 'text-right'
			,valueFormatter: function(params) {
				if (params.value > 0) {
					return params.value.addComma();
				}else{
					return '0';
				}
			}
		},
		{headerName: "작업자",			field: "userNameCreated",	width: 100,	cellClass: 'text-center'},
		{headerName: "예외사유",			field: "reasonCd",			width: 150,	cellClass: 'text-center'},
		{headerName: "WMS메시지",			field: "adminMemo",			width: 300,	cellClass: 'text-left'},
		{headerName: "브랜드명",			field: "brandNm",			width: 150,	cellClass: 'text-center'},
		{headerName: "상품코드",			field: "productCode",		width: 100,	cellClass: 'text-center',
			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: "SKU코드",			field: "skuCode",			width: 100,	cellClass: 'text-center'},
		{headerName: "상품명",			field: "productName",		width: 200,	cellClass: 'text-left'},
		{headerName: "속성",		    	field: "skuValue",			width: 80,	cellClass: 'text-center'},
		{headerName: "원코드",			field: "skuModelNo",		width: 150,	cellClass: 'text-left'},
		{headerName: "수량",				field: "exceptionQty",		width: 80,	cellClass: 'text-right'},
		{headerName: "주문경로",			field: "siteCd",			width: 100,	cellClass: 'text-left'},
		{headerName: "등록일시",			field: "dateCreated",		width: 150,	cellClass: 'text-center'}
		
	];

	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);
	gridOptions.suppressRowTransform =true;
	//gridOptions.rowSelection = 'multiple';
	
	gridOptions.rowHeight = 35;
	/*************************************************************************
	*  조회 버튼 클릭 시
	**************************************************************************/
	$('#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.withdrawExceptionList);
		gagaPaging.createPagination(result.pageing.pageable);
		
	}
	
	/*************************************************************************
	*  달력 초기화 
	**************************************************************************/		
	var fnInitCalendar = function() {
		cfnChangeCalendar('7d', $('#stDate'), $('#edDate')); //달력 초기화
	}
	
	/*************************************************************************
	*  회수예외 처리완료 버튼 - 대기->완료  업데이트
	**************************************************************************/	
	var fnComplete = function(recallExceptionNo) {
		var params = {};
		params.recallExceptionNo = recallExceptionNo;
		mcxDialog.confirm('처리완료 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				var jsonData = JSON.stringify(params);
				gagajf.ajaxJsonSubmit('/withdraw/exception/complete', jsonData, fnCompleteCallback);
			}
		});
	};
	
	/*************************************************************************
	*  회수예외 처리완료 콜백
	**************************************************************************/		
	var fnCompleteCallback = function() {
		fnSearchList();
	};
	

	/*************************************************************************
	*  엑셀다운로드
	**************************************************************************/		
	$('#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);
		cfnCreateCalendar('#terms', 'stDate', 'edDate', true, '');
		fnInitCalendar();
	});

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