<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : CancelRequestForm.html
 * @desc    : 입점업체 회수컨펌 화면
 *============================================================================
 * STYLE24
 * Copyright(C) 2019 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.05.18   jsh77b       최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1400" data-height="520">
	<div class="panelStyle">
		<div class="panelTitle">
			<h2>회수컨펌</h2>
			<button type="button" class="close" onclick="uifnPopupClose('popupReturnRequestForm');"><i class="fa fa-times"></i></button>
		</div>
			
		<div class="panelContent" style="height:90%; overflow-y:auto; padding:0px 20px !important; ">
			<form id="cancelRequestFrm" name="cancelRequestFrm" action="/orderChange/return" method="post" target="hdFrameForOrderCancel">
				<input type="hidden" name="ordNo" 			th:value="${ordNo}"/>
				<input type="hidden" name="ordChgSq" 		th:value="${ordChgSq}"/>
				<input type="hidden" name="chgReason" 		th:value="${chgReason}"/>
				
				<th:block th:if="${chgGb} == 'G680_30'">
					<h4>반품정보</h4>
				</th:block>
				<th:block th:if="${chgGb} == 'G680_40'">
					<h4>교환정보</h4>
				</th:block>
				<div id="gridOrderWithdrawList" style="width:100%; height: 200px;" class="ag-theme-balham"></div>
				
				<div style="text-align:right; padding-bottom:5px; padding-top:5px;">
					<button type="button" class="btn btn-success" id="widthdrawConfirmBtn">회수컨펌</button>
				</div>
				
				<table class="frmStyle">
					<colgroup>
						<col style="width:160px;" />
						<col style="width:320px;" />
						<col style="width:160px;" />
						<col style="width:320px;" />
						<col style="width:160px;" />
						<col />
					</colgroup>
					<tbody>
						<tr>
							<!-- 반품회수 -->
							<th:block th:if="${chgGb} == 'G680_30'">
								<th>반품사유 <i class="star"></i></th>
								<td>
									<select name="selectChgReason" onchange="fnChangeChgReason($(this).val());">
										<option value="">[선택하세요]</option>
										<th:block th:if="${chgReasonList1}" th:each="oneData, status : ${chgReasonList1}">
											<th:block th:if="${oneData.cd} == ${chgReason}">
												<option th:value="|${oneData.cd}|" th:text="|${oneData.cdNm}|" selected></option>
											</th:block>
											<th:block th:unless="${oneData.cd} == ${chgReason}">
												<option th:value="|${oneData.cd}|" th:text="|${oneData.cdNm}|"></option>
											</th:block>
										</th:block>
									</select>
								</td>
							</th:block>
							<!-- //반품회수 -->
							<!-- 교환회수 -->
							<th:block th:if="${chgGb} == 'G680_40'">
								<th>교환사유 <i class="star"></i></th>
								<td>
									<select name="selectChgReason" onchange="fnChangeChgReason($(this).val());">
										<option value="">[선택하세요]</option>
										<th:block th:if="${chgReasonList2}" th:each="oneData, status : ${chgReasonList2}">
											<th:block th:if="${oneData.cd} == ${chgReason}">
												<option th:value="|${oneData.cd}|" th:text="|${oneData.cdNm}|" selected></option>
											</th:block>
											<th:block th:unless="${oneData.cd} == ${chgReason}">
												<option th:value="|${oneData.cd}|" th:text="|${oneData.cdNm}|"></option>
											</th:block>
										</th:block>
									</select>
								</td>
							</th:block>
							<!-- //교환회수 -->
							<th>회수방법</th>
							<td>
								<th:blcok th:if="${wdGb} == 'W'">회수요청</th:blcok>
								<th:blcok th:if="${wdGb} == 'D'">직접발송</th:blcok>
							</td>
							<th>귀책사유</th>
							<td><span id="imputeReason"></span></td>
						</tr>
						<tr>
							<th>요청메모</th>
							<td colspan="5">
								<textarea id="chgMemo" name="chgMemo" style="height:80px;" placeholder="취소사유를 300자내외로 작성해 주세요" th:text="${chgMemo}"></textarea>
							</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</div>

<!-- data -->
<script th:inline="javascript">
/*<![CDATA[*/
var orderWithdrawList 	= [[${orderWithdrawList}]];		// 회수대상목록
var sessRoleCd 			= [[${sessionInfo.roleCd}]];	// 권한코드
var chgReason			= [[${chgReason}]];				// 사유코드
var chgGb				= [[${chgGb}]];					// 요천구분

var columnWidthdrawList = [
	{headerName: "입점업체",			field:"supplyCompNm",		width:120, cellClass: 'text-center'	, hide: true},
	{headerName: "입점업체코드",		field:"supplyCompCd",		width:120, cellClass: 'text-center'	, hide: true},
	{headerName: "브랜드",			field:"brandKnm",			width:100, cellClass: 'text-center'	, hide: true},
	{headerName: "변경번호",			field:"ordChgSq",			width:80, cellClass: 'text-center'},
	{headerName: "주문번호",			field:"ordNo",				width:80, cellClass: 'text-center'},
	{headerName: "상세번호",			field:"ordDtlNo",			width:80, cellClass: 'text-center'},
	{headerName: "클레임상태",			field:"chgStatNm", 			width:100, cellClass: 'text-center'},
	{headerName: "요청일시",			field:"regDt", 				width:150, cellClass: 'text-center'},
	{headerName: "요청자명",			field:"chgerNm",			width:100, cellClass: 'text-center'},
	{headerName: "휴대전화",			field:"chgerPhnno",			width:120, cellClass: 'text-center'},
	{headerName: "회수지우편번호",		field:"chgerZipcode",		width:120, cellClass: 'text-center'	, hide: true},
	{headerName: "회수지기본주소",		field:"chgerBaseAddr",		width:150, cellClass: 'text-left'	, hide: true},
	{headerName: "회수지상세주소",		field:"chgerDtlAddr",		width:120, cellClass: 'text-left'	, hide: true},
	{headerName: "업체상품코드",		field:"supplyGoodsCd",		width:100, cellClass: 'text-center'},
	{headerName: "상품코드",			field:"goodsCd",			width:100, cellClass: 'text-center'},
	{headerName: "상품명",			field:"goodsNm",			width:100, cellClass: 'text-center'},
	{headerName: "옵션1",				field:"optCd1",				width:100, cellClass: 'text-center'},
	{headerName: "옵션2",				field:"optCd2",				width:100, cellClass: 'text-center'},
	{headerName: "요청수량",			field:"chgQty",				width:100, cellClass: 'text-center'},
	{headerName: "교환상세번호",		field:"exchangeOrdDtlNo",	width:100, cellClass: 'text-center'},
	{headerName: "교환옵션1",			field:"optCd11",			width:100, cellClass: 'text-center'},
	{headerName: "교환옵션2",			field:"optCd12",			width:100, cellClass: 'text-center'},
	{headerName: "물류메모",			field:"whMemo",				width:200, cellClass: 'text-left'	, editable:true}
];

var gridOptionsWidthdrawList = gagaAgGrid.getGridOptions(columnWidthdrawList);
</script>

<script th:inline="javascript">

// 사유코드체크
var fnChangeChgReason = function(reasonCd) {
	var customerReasonArr = ['G688_10', 'G689_10'];	
	isCustomer = false;
	
	// 귀책사유체크(취소,반품,교환)
	for (i=0 ; i<customerReasonArr.length ; i++) {
		if (customerReasonArr[i] == reasonCd) {
			isCustomer = true;
		}
	}
	
	// 귀책사유체크(회사,고객)
	if (isCustomer) {
		$("#imputeReason").text("고객");
	} else {
		$("#imputeReason").text("회사");
	}
	
	$('#cancelRequestFrm input[name=chgReason]').val(reasonCd);
}

$(document).ready(function() {
	// 1. 그리드생성
	gagaAgGrid.createGrid('gridOrderWithdrawList', gridOptionsWidthdrawList);
	gridOptionsWidthdrawList.api.setRowData(orderWithdrawList);
	
	// 2. TOTAL ROWS 없애기
	gagaAgGrid.hideStatusBar('gridOrderWithdrawList');
	
	// 사유체크실행
	fnChangeChgReason(chgReason);
});


// 회수컨펌버튼
$("#widthdrawConfirmBtn").on("click", function(){
	
	// 1. 취소사유 체크
	var chgReason = $("#cancelRequestFrm select[name=selectChgReason]").val();
	if (gagajf.isNull(chgReason)) {
		mcxDialog.alert("취소사유를 입력하세요."); 
		return ;
	}
	
	// 변경신청목록
	var withdrawConfirmList = [];
	
	for (i=0 ; i<orderWithdrawList.length ; i++) {
		var obj = new Object();
		obj.ordChgSq 		= orderWithdrawList[i].ordChgSq;
		obj.ordNo 			= orderWithdrawList[i].ordNo;
		obj.ordDtlNo		= orderWithdrawList[i].ordDtlNo;
		obj.whMemo 			= orderWithdrawList[i].whMemo;
		obj.supplyCompCd	= orderWithdrawList[i].supplyCompCd;
		
		withdrawConfirmList.push(obj);
	}
	
	// 2. 데이타적재
	var jsonObj = {
		"ordNo"					: $('#cancelRequestFrm input[name=ordNo]').val()
		,"ordChgSq"				: $('#cancelRequestFrm input[name=ordChgSq]').val()
		,"chgReason" 			: $('#cancelRequestFrm input[name=chgReason]').val()
		,"chgGb" 				: chgGb
		,"chgMemo"				: $('#chgMemo').val()
		,"isCustomer"			: isCustomer
		,"withdrawConfirmList"	: withdrawConfirmList
	}
	
	// 주문번호, 취소사유, 취소메모, (취소, 반품, 교환 신청 정보 목록), 환불계좌
	var jsonData = JSON.stringify(jsonObj);
	
	mcxDialog.confirm('회수컨펌을 진행 하시겠습니까?', {
		cancelBtnText		: "취소",
		sureBtnClick		: function(){
			gagajf.ajaxJsonSubmit(
				"/orderChange/seller/widthdraw/confirm/update"
				, jsonData
				, function() {
					uifnPopupClose('popupReturnRequestForm');
					fnSearch();
				}
			);
		}
	});
});
</script>
</html>





