<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : WithdrawDirectiveListForm.html
 * @desc    : 회수지시 목록 Page
 *=============================================================
 * ISTYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *=============================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  ==================================
 * 1.0  2021.05.10   moon        최초 작성
 *******************************************************************************
 -->
 	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<!-- 검색조건 영역 -->
		<form id="searchForm" name="searchForm" action="#" th:action="@{'/withdraw/direct/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>
								<input type="text" class="w40p" name="ordNm" placeholder="" maxlength="20"/>
							</td>
							<th>주문번호</th>
							<td>
								<input type="text" class="w40p" name="ordNo" data-valid-type="integer" placeholder="" maxlength="20"/>
							</td>
							<th>주문변경번호</th>
							<td>
								<input type="text" class="w40p" name="ordChgSq" data-valid-type="integer" placeholder="" maxlength="20"/>
							</td>
						</tr>
						<tr>	
							<th>회수구분</th>
							<td>
								<select name="chgGb"class="w100">
									<option value="">&nbsp;전체&nbsp;</option>
									<option value="G680_30"> 반품 </option>
									<option value="G680_40"> 교환 </option>
								</select>
							</td>
							<th>진행상태</th>
							<td>
								<select name="chgStat" class="w100">
									<option value="">전체</option>
									<option th:if="${chgStatList}" th:each="oneData, status : ${chgStatList}" th:value="${oneData.cd}" th:text="${oneData.cdNm}"></option>	
								</select>
							</td>
							<th>반품방식</th>
							<td>
								<select name="wdGb" class="w100">
									<option value="">&nbsp;전체&nbsp;</option>
									<option value="W">방문회수</option>
									<option value="D">직접배송</option>
									
								</select>
							</td>
						</tr>
						<tr>
							<th>택배사전송여부</th>
							<td>
								<select name="sendYn" class="w100">
									<option value="">전체</option>
									<option value="Y">전송</option>
									<option value="N">미전송</option>
									
								</select>
							</td>
							<th>회수상태</th>
							<td colspan="3">
								<select name="wdShipState" class="w100">
									<option value="">전체</option>
									<option th:if="${wdShipStateList}" th:each="oneData, status : ${wdShipStateList}" th:value="${oneData.cd}" th:text="${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="10" >10개씩 보기</option>
						<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: 500px;" 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 columnDefs = [
		{headerName: "주문변경번호", 	field: "ordChgSq", 		width: 100, cellClass: "text-center",
			cellRenderer	: function(params) {
				var rtnStr = "";
				
				var paramData 	= params.data.ordNo;
				paramData 		+= '@' + params.data.ordDtlNo;
				paramData 		+= '@' + params.data.delvFeeCd;
				paramData 		+= '@' + params.data.delvFeeCdGrp;
				 
				// 반품접수, 반품대기, 회수요청, 상품검수중, 결제대기, 반품진행중
				if (params.data.chgStat == 'G685_50' || params.data.chgStat == 'G685_51' 
						|| params.data.chgStat == 'G685_30' || params.data.chgStat == 'G685_31' || params.data.chgStat == 'G685_32' || params.data.chgStat == 'G685_33') {
					rtnStr = '<a href="javascript:void(0);" onclick="fnReturnRequest(\'' + paramData + '\',\'' + params.value + '\');">' + params.value + '</a>';
				}
				// 교환접수, 교환대기, 회수요청, 상품검수중, 결제대기, 교환진행중
				else if (params.data.chgStat == 'G685_20' || params.data.chgStat == 'G685_21' 
						|| params.data.chgStat == 'G685_30' || params.data.chgStat == 'G685_31' || params.data.chgStat == 'G685_32' || params.data.chgStat == 'G685_34') {
					rtnStr = '<a href="javascript:void(0);" onclick="fnExchangeRequest(\'' + paramData + '\',\'' + params.value + '\');">' + params.value + '</a>';
				} 
				else {
					rtnStr = params.value;
				}
				return  rtnStr;
			}			
		
		},
		{headerName: "주문번호", 		field: "ordNo", 		width: 100, cellClass: "text-center",
			cellRenderer: function(params) { 
				return gagajf.isNull(params.value) ? '' : "<a href=\"javascript:void(0);\" onclick=\"fnOrderDetailPopup('" + params.data.ordNo + "');\">" + params.data.ordNo + "</a>";
			}
		},
		{headerName: "주문상세번호", 	field: "ordDtlNo", 		width: 100, cellClass: "text-center"},		
		{headerName: "회수구분", 		field: "chgGb", 		width: 80, cellClass: "text-center",
			cellRenderer: function (params) { return params.value == 'G680_30' ? '반품' : '교환'; }
		},
		
		{headerName: "사유", 			field: "chgReasonNm", 	width: 150, cellClass: "text-left"},
		{headerName: "회수요청일", 		field: "regDt", 	width: 100, cellClass: "text-center"},
		{headerName: "진행상태", 		field: "chgStatNm", 	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: "chgQty", 		width: 80, cellClass: "text-center"},
		{headerName: "반품방식", 		field: "wdGb", 			width: 80, cellClass: "text-center",
			cellRenderer: function (params) { return params.value == 'W' ? '방문회수' : '직접배송'; }
		},
		{headerName: "택배사전송", 	field: "sendYn", 		width: 80, cellClass: "text-center"},
		{headerName: "회수송장번호", 	field: "wdInvoiceNo", 	width: 100, cellClass: "text-center"},
		{headerName: "회수상태", 		field: "wdShipStateNm", width: 120, cellClass: "text-center"},
		{headerName: "회수상태수신일시", field: "wdStateDt", 	width: 120, cellClass: "text-center"},
		{headerName: "미회수사유", 	field: "wdReasonCdNm", 	width: 100, cellClass: "text-center"},
		{headerName: "재회수지시", 	field: "wdShipState", 		width: 100,	cellClass: 'text-center',
			cellRenderer: function(params) {
				return params.value == '12' && params.data.chgStat == 'G685_30' ? '<button type="button" class="btn btn-base btn-sm" onclick="fnReRecallOrder(\'' + params.data.chgGb + '\',\'' + params.data.ordDtlNo + '\',\''+params.data.ordChgSq+'\',\''+params.data.ordNo+'\');">&nbsp;재회수지시&nbsp;</button>' : "";
			}
		},	
		{headerName: "교환선발송여부 ", 	field: "wdBfSendYn", 	width: 110, cellClass: "text-center"},
		{headerName: "배송시작일시", 	field: "wdStdt", 		width: 120, cellClass: "text-center"},
		{headerName: "배송종료일시", 	field: "wdEddt", 		width: 120, cellClass: "text-center"},
		{headerName: "수취인명", 		field: "recipNm", 		width: 120, cellClass: "text-center"},
		
		{headerName: "LMS", 			field: "chgerPhnno", 	width: 80, cellClass: "text-center",
			cellRenderer: function(params) {
				return '<button type="button" class="btn btn-base btn-sm" onclick="fnLms(\'' + params.data.chgerPhnno + '\',\'' + params.data.custNo + '\');">&nbsp;LMS&nbsp;</button>';
			}			
		},
		
		
		{headerName: "변경자명", 		field: "chgerNm", 		width: 100, cellClass: "text-center"},
		{headerName: "변경자휴대전화", 	field: "chgerPhnno", 	width: 120, cellClass: "text-center"},
		{headerName: "변경자우편번호", 	field: "chgerZipcode", 	width: 120, cellClass: "text-center"},
		{headerName: "변경자기본주소", 	field: "chgerBaseAddr", width: 300, cellClass: "text-left"},
		{headerName: "변경자상세주소", 	field: "chgerDtlAddr", 	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') {
			// 주문 상세
			cfnOpenOrderDetailPopup(event.data.ordNo);
		} else if (event.colDef.field == 'goodsCd') {
			// 상품 상세
			cfnOpenGoodsDetailPopup('U', event.data.goodsCd);
		}
	};

	/*************************************************************************
	*  주문상세 팝업  
	**************************************************************************/		
	var fnOrderDetailPopup = function(ordNo){
		currOrdNo = ordNo;
		cfnOpenOrderDetailPopup(currOrdNo);
	}
	
	/*************************************************************************
	*  팝업 콜백 
	**************************************************************************/		
	var fnReOpenOrderDetailPopup = function () {
		cfnOpenOrderDetailPopup(currOrdNo);
		fnSearchList();
	};
	
	// 조회
	$('#btnSearch').on('click', function() {
		// Fetch data
		//gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
		fnSearchList();
	});

	/*************************************************************************
	*  조회 
	**************************************************************************/
	var fnSearchList = function() {
		
		var searchChk = "N";
		

		if ($('#searchForm input[name=ordNo]').val() != '') {
			searchChk = "Y";
		}		
		
		if ($('#searchForm input[name=ordChgSq]').val() != '') {
			searchChk = "Y";
		}
		
		
		if(searchChk == "N"){
			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.directList);
		gagaPaging.createPagination(result.pageing.pageable);
		
	}
	
	/*************************************************************************
	*  재회수지시
	**************************************************************************/	
	var fnReRecallOrder = function(chgGb, ordDtlNo, ordChgSq, ordNo ){
		mcxDialog.confirm("재회수지시 하시겠습니까?", {
		    cancelBtnText: "취소",
		    sureBtnText: "확인",
		    sureBtnClick: function() {
	            var param = new Object;
	            param.chgGb    = chgGb;
	            param.ordDtlNo = ordDtlNo;
	            param.ordNo    = ordNo;
	            param.ordChgSq = ordChgSq;
	            var jsonData = JSON.stringify(param);
	            gagajf.ajaxJsonSubmit('/withdraw/direct/recallorder', jsonData, fnSearchList);
	        }
		});
	}

	/*************************************************************************
	*  LMS
	**************************************************************************/	
	var fnLms = function(chgerPhnno, custNo){
		let param = {};
		param.elementCellPhnno = chgerPhnno; //'010-4016-1558'; //'#custInfoForm input[name=cellPhnno]';
		param.elementCustNo =    custNo; //'100025';// '#custInfoForm input[name=custNo]';
		param.pageGb = 'delv';
		cfnOpenLmsPopup(param);
	}

	/*************************************************************************
	*  반품요청
	**************************************************************************/		
	var fnReturnRequest = function (paramData, ordChgSq) {
		
		// 취소요청 구분 (orChgSq null 이면 취소요청화면 있으면 취소요청정보화면)
		if (ordChgSq == null) {
			ordChgSq = 0;
		}
		
		var param 		= "";
		var paramArr 	= paramData.split("@");
		param += "&ordNo=" 			+ paramArr[0];
		param += "&ordDtlNo=" 		+ paramArr[1];
		param += "&delvFeeCd="		+ paramArr[2];
		param += "&delvFeeCdGrp="	+ paramArr[3];
		
		param += "&ordChgSq=" 		+ ordChgSq;
		var actionUrl = "/orderChange/rtn/req/form?" + param;
		cfnOpenModalPopup(actionUrl, 'popupReturnRequestForm');
	};

	/*************************************************************************
	*  교환요청
	**************************************************************************/			
	var fnExchangeRequest = function (paramData, ordChgSq) {
		console.log(paramData);
		// 취소요청 구분 (orChgSq null 이면 취소요청화면 있으면 취소요청정보화면)
		if (ordChgSq == null) {
			ordChgSq = 0;
		}
		
		var paramArr 	= paramData.split("@");
		var param 		= "";
		param += "&ordNo=" 			+ paramArr[0];
		param += "&ordDtlNo=" 		+ paramArr[1];
		param += "&delvFeeCd="		+ paramArr[2];
		param += "&delvFeeCdGrp="	+ paramArr[3];
		param += "&ordChgSq=" 		+ ordChgSq;
		
		var actionUrl = "/orderChange/exchange/request/form?" + param;
		cfnOpenModalPopup(actionUrl, 'popupExchangeRequestForm');
	};
	
	//엑셀다운로드
	$('#btnExcel').on('click', function() {

		
		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);
		var hideList = ["btnThisWeek", "btnYesterWeek", "btnThisMonth", "btnYesterMonth", "btnRecent3Month"];
		cfnCreateCalendar('#terms', 'stDate', 'edDate', true, '','',  hideList);
		// grid 높이 조절
		//uifnFitGrid('auto');
		gagajf.setDate('#terms', 'stDate', 'edDate', '7d');

		//fnDatepickerDisabled();
	});

/*]]>*/
</script>

</html>