<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : RefundRegisterListForm.html
 * @desc    : 환불관리 화면 Page
 *=============================================================
 * ISTYLE24
 * 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>
		<!-- //메뉴 설명 -->
		<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">

				<form id="searchForm" name="searchForm" action="#">
					<table class="frmStyle">
						<colgroup>
							<col style="width:10%" />
							<col style="width:40%" />
							<col style="width:10%" />
							<col style="width:40%" />
						</colgroup>
						<tbody>
							<tr>
								<th>구분</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="B">교환/반품접수완료(실물입고)</option>
										<option value="A">교환/반품접수대기(실물입고)</option>
										<option value="D">회수컨펌완료</option>
									</select>
								</td>
								<th>상품코드</th>
								<td>
									<input type="text" class="w200" name="goodsCd"/>
								</td>
							</tr>
							<tr>
								<th>회수컨펌지연일</th>
								<td>
									<input type="text" class="w50" id="delayDt" name="delayDt" value="" data-valid-type="numeric"/>일
									<select id="delayDtType" name="delayDtType">
										<option value="U">이상</option>
										<option value="D">미만</option>
									</select>
								</td>
								<th>등록ID</th>
								<td>
									<select id="regId" name="regId">
										<option value="">[전체]</option>
									</select>
								</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>
	
				</form>
			</div>
		</div>
		<div class="panelStyle">
			<div class="panelContent" style="overflow: hidden;">
				<div id="gridList" style="width:100%; height: 570px;" class="ag-theme-balham"></div>
			</div>
		</div>
		
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	// specify the columns
	var columnDefs = [
// 		주문자 미상 사용 할 경우 주석 풀 것.
		{headerName: "", field: "delete", width: 70, minWidth: 60, cellClass: 'text-center',
			cellRenderer: function(params) {
				if (params.data.chgGb == "미상") {
					return '<button type="button" class="btn btn-danger btn-sm" onclick="fnWithdrawDelete(\'' + params.data.wdInvoiceNo + '\' , \'' + params.data.goodsCd + '\' , \'' + params.data.sizeCd +'\');">삭제</button>';
				} else {
					return params.value;
				}
			}
		},
		{headerName: "회수지연일", 	field: "delayDt", 	width: 120, minWidth: 100, cellClass: 'text-center'},
		{headerName: "회수구분", 		field: "chgGb", 	width: 120, minWidth: 100, cellClass: 'text-center'},
		{headerName: "주문변경일련번호", field: "ordChgSq", 	width: 130, minWidth: 100, cellClass: 'text-center'},
		{headerName: "주문번호", 		field: "ordNo", 	width: 130, minWidth: 190, cellClass: 'text-center'},
		{headerName: "변경요청주문번호", field: "ordChgSq", 	width: 100, minWidth: 100, cellClass: 'text-center',
			cellRenderer: function(params) {
				if (gagajf.isNull(params.value)) { // 주문자 미상일 경우
					if (gagajf.isNull(params.data.orgGoodsCd)) {
						return "오반품";
					} else {
						return "<a href=\"javascript:void(0);\" class=\"btn btn-danger btn-sm\">회수등록</a>";
					}
				} else {
					if (params.data.delayDt == '컨펌완료') {
						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: 150, minWidth: 100, cellClass: 'text-center'},
		{headerName: "접수송장번호", 	field: "invoiceNo", 	width: 150, minWidth: 100, cellClass: 'text-center'},
		{headerName: "보내는사람", 	field: "senderNm", 		width: 100, minWidth: 100, cellClass: 'text-center'},
		{headerName: "요청성명", 		field: "chgerNm",		width: 100, minWidth: 100, cellClass: 'text-center'},
		{headerName: "보낸연락처", 	field: "senderPhnno", 	width: 150, minWidth: 100, cellClass: 'text-center'},
		{headerName: "도착일시", 		field: "arrivalDt", 	width: 190, minWidth: 120, cellClass: 'text-center'},
		{headerName: "회수확정일자", 	field: "wdEddt",	 	width: 190, minWidth: 120, cellClass: 'text-center'},
		{headerName: "회수메모", 		field: "wdMemo", 		width: 150, minWidth: 100, cellClass: 'text-lecenterft'},
		{headerName: "상품코드", 		field: "goodsCd", 		width: 150, minWidth: 100, cellClass: 'text-center'},
		{headerName: "사이즈", 		field: "sizeCd", 		width: 80, minWidth: 100, cellClass: 'text-center'},
		{headerName: "반품수량", 		field: "chgQty", 		width: 80, minWidth: 100, cellClass: 'text-center'},
		{headerName: "회수수량", 		field: "wdQty", 		width: 80, minWidth: 100, cellClass: 'text-center'},
		{headerName: "클레임메모", 	field: "chgMemo", 		width: 200, minWidth: 100, cellClass: 'text-lecenterft'},
		{headerName: "접수변경요청사유", field: "wdReqReason", 	width: 150, minWidth: 100, cellClass: 'text-center'},
	];

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

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

	//일자조회구분 변경시 처리
	$('#searchType').on('change', function() {
		$('#delayDt').val('');
	});

	$(document).ready(function() {
		cfnCreateCalendar('#terms', 'stDate', 'edDate', true, '조회');

		// Create a agGrid
		gagaAgGrid.createGrid('gridList', withDrawGridOptions);

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

		//uifnFitGrid('auto');
	});

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

	var fnSearch = function() {
		var formId = '#searchForm';
		gagaAgGrid.fetch("/withdraw/refund/list", withDrawGridOptions, formId);
	};

	// cell Click
	withDrawGridOptions.onCellClicked = function(event) {
		if (event.colDef.field != 'ordChgSq') return;

		// 회수등록 팝업
		if (event.data.ordChgSq > 0 && !gagajf.isNull(event.data.ordChgSq) && event.data.wdQty > 0) {
			// 회수 상세 화면
			detailPopup(event.data.ordChgSq, event.data.ordNo);
		} 
	}

	// 회수 상세 화면
	var detailPopup = function(ordChgSq, ordNo) {
		if (ordChgSq == 0) return;

		var actionUrl = "/withdraw/refund/detail/form?ordChgSq=" + ordChgSq + '&ordNo=' + ordNo;
		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>
