<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : RefundRegisterListForm.html
 * @desc    : 환불관리 화면 Page
 *=============================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *=============================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  ==================================
 * 1.0  2020.11.16   moon        최초 작성
 *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<form id="searchForm" name="searchForm" action="#" th:action="@{'/withdraw/refund/list'}" onsubmit="fnSearch(); 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:10%" />
							<col style="width:40%" />
							<col style="width:10%" />
							<col style="width:40%" />
						</colgroup>
						<tbody>
							<tr>
								<th>구분<em class="required" title="필수"></em></th>
								<td colspan="3">
									<select id="searchType" name="searchType">
										<option value="withdrawDt">회수등록일자</option>
										<option value="returnDt">반품신청일자</option>
										<option value="confirmDt">반품완료일자</option>
									</select>
									<span id="terms">
										<input type="text" class="schDate w100" id="stDate" name="stDate" maxlength="10"/>
										~
										<input type="text" class="schDate w100" id="edDate" name="edDate" maxlength="10"/>
									</span>
								</td>
							</tr>
							<tr>
								<th>주문번호</th>
								<td >
									<input type="text" id="ordNo" name="ordNo" class="w200" />
								</td>
								<th>회수송장번호</th>
								<td>
									<input type="text" name="wdInvoiceNo" class="w200" />
								</td>
							</tr>
							<tr>
								<th>환불상태</th>
								<td >
									<select id="withdrawType" name="withdrawType">
										<option value="">전체</option>
										<option value="N" selected>환불대기</option>
										<option value="Y">환불완료</option>
									</select>
								</td>
								<th>상품코드</th>
								<td>
									<input type="text" class="w200" name="goodsCd"/>
								</td>
							</tr>
							<tr>
								<th>주문자명</th>
								<td>
									<input type="text" id="ordNm" name="ordNm" class="w200" />
								</td>
								<th>보내는사람</th>
								<td>
									<input type="text" id="senderNm" name="senderNm" class="w200" />
								</td>
							</tr>
						</tbody>
					</table>
	
					<ul class="panelBar">
						<li class="center">
						<button type="button" class="btn btn-base btn-lg btn-lg" id="btnSearch">조회</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: 570px;" 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[*/
	// specify the columns
	var columnDefs = [
		{headerName: "환불상태 ",		field: "rfndStat",	width: 80,  cellClass: 'text-center'},
		{headerName: "회수구분", 		field: "wdGb",		width: 80,  cellClass: 'text-center'},
		{headerName: "주문번호", 		field: "ordNo",		width: 100,  cellClass: 'text-center'},
		{headerName: "주문상세번호", 	field: "ordDtlNo",	width: 100,  cellClass: 'text-center'},
		{headerName: "주문변경번호", 	field: "ordChgSq",	width: 100,  cellClass: 'text-center'},
		{headerName: "환불컨펌", field: "refundConfirm",	width: 120,  cellClass: 'text-center',
			cellRenderer: function(params) {
				if (params.data.rfndStat == '환불완료') {
					return "<a href=\"javascript:void(0);\" class=\"btn btn-dark btn-sm\">환불완료</a>";
				}else{
					return "<a href=\"javascript:void(0);\" class=\"btn btn-base btn-sm\">환불컨펌</a>";
				}
			}
		},
		{headerName: "회수송장번호", field: "wdInvoiceNo", 	width: 100, cellClass: 'text-center'},
		{headerName: "보내는사람", 	field: "senderNm", 		width: 100, cellClass: 'text-center'},
		{headerName: "보낸연락처", 	field: "senderPhnno", 	width: 120, cellClass: 'text-center'},
		{headerName: "주문자명", 	field: "ordNm",			width: 100, cellClass: 'text-center'},
		{headerName: "주문자연락처", field: "ordPhnno",		width: 120, cellClass: 'text-center'},
		{headerName: "도착일", 		field: "arrivalDt", 	width: 100,  cellClass: 'text-center'},
		{headerName: "환불확정일", 	field: "completeDt",	width: 100,  cellClass: 'text-center'},
		{headerName: "WMS회수메모", 	field: "wdMemo", 		width: 200,  cellClass: 'text-left'},
		{headerName: "요청사유",		field: "chgReasonNm", 	width: 150,  cellClass: 'text-center'},
		{headerName: "클레임메모", 	field: "chgMemo", 		width: 200,  cellClass: 'text-left'},
		{headerName: "상품코드", 	field: "goodsCd", 		width: 150,  cellClass: 'text-center'},
		{headerName: "옵션1", 		field: "optCd1", 		width: 80,  cellClass: 'text-center'},
		{headerName: "옵션2", 		field: "optCd2", 		width: 80,  cellClass: 'text-center'},
		{headerName: "반품수량", 	field: "chgQty", 		width: 80,  cellClass: 'text-center'},
		{headerName: "회수수량", 	field: "wdQty", 		width: 80,  cellClass: 'text-center'},
		{headerName: "회수등록일", 	field: "wdRegDt", 		width: 80,  cellClass: 'text-center'},
		{headerName: "반품신청일", 	field: "rcRegDt", 		width: 80,  cellClass: 'text-center'},
		{headerName: "반품완료일", 	field: "wdEddt", 		width: 80,  cellClass: 'text-center'}

	];

	// Get GridOptions
	var withDrawGridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// Grid editable
	//withDrawGridOptions.defaultColDef.editable = false;


	/*************************************************************************
	*  init
	**************************************************************************/	
	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', withDrawGridOptions);
		cfnCreateCalendar('#terms', 'stDate', 'edDate', true, '조회');

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

	});

	/*************************************************************************
	*  조회 버튼 클릭 시
	**************************************************************************/
	$('#btnSearch').on('click', function() {
		fnSearch();
	});

	/*************************************************************************
	*  조회 
	**************************************************************************/	
	var fnSearch = function() {
		var searchNm = $('#searchType option:selected').text();
		
		if($('#stDate').val() == ''){
			mcxDialog.alert(searchNm+' 시작 기간을 입력하세요.');
			return;
		}

		if($('#edDate').val() == ''){
			mcxDialog.alert(searchNm+' 종료 기간을 입력하세요.');
			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());
		withDrawGridOptions.api.setRowData(result.refundList);
		gagaPaging.createPagination(result.pageing.pageable);
		
	}
	
	/*************************************************************************
	*  cell Click
	**************************************************************************/	
	withDrawGridOptions.onCellClicked = function(event) {
		if (event.colDef.field != 'refundConfirm') return;
		// 회수등록 팝업
		if (event.data.ordChgSq > 0 && !gagajf.isNull(event.data.ordChgSq) && event.data.wdQty > 0) {
			// 회수 상세 화면
			detailPopup(event.data.ordChgSq, event.data.ordNo, event.data.userNo);
		} 
	}


	/*************************************************************************
	*  회수 상세 화면
	**************************************************************************/		
	var detailPopup = function(ordChgSq, ordNo, userNo) {
		if (ordChgSq == 0) return;
		var actionUrl = "/withdraw/refund/detail/form?ordChgSq=" + ordChgSq + '&ordNo=' + ordNo + '&userNo=' + userNo;
		cfnOpenModalPopup(actionUrl, "popupWithdrawDetail");
	}

	
	/*   회수 삭제 필요성이 현재 없어보임!!!
	// 회수 삭제
	var fnWithdrawDelete = function(wdInvoiceNo, goodsCd, sizeCd) {
		var params = new Object();
		params.wdInvoiceNo = wdInvoiceNo;
		params.goodsCd = goodsCd;
		params.sizeCd = sizeCd;

		var jsonData = JSON.stringify(params);
		mcxDialog.confirm('회수 데이터를 삭제 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				gagajf.ajaxJsonSubmit('/withdraw/refund/Withdraw/delete', jsonData, fnSearch);
			}
		});
	}
	*/

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