<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	layout:decorator="web/common/layout/MypageLayoutWeb">
<!--
 *******************************************************************************
 * @source  : MypageReturnFormWeb.html
 * @desc    : 마이페이지 > 반품신청 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.02.25   card007     최초 작성
 * 1.1  2021.03.29   card007     퍼블 수정
 *******************************************************************************
 -->
<body>

<th:block layout:fragment="content">
	<div class="content myOrderView">
		<div class="cont_body">
			<!-- CONT-BODY -->
			<div class="lnb">
				<div class="lnb_tit">
					<h2>마이페이지</h2>
				</div>
				<div class="lnb_list">
					<ul id="mypageLnbList"></ul>
				</div>
			</div>
			<div class="cont">
				<form id="returnForm">
					<input type="hidden" name="accountNo" th:value="${oneData.accountNo}"/>
					<input type="hidden" name="accountNm" th:value="${oneData.accountNm}"/>
					<input type="hidden" name="bankCd" th:value="${oneData.bankCd}"/>
					<div class="sec_head">
						<h3 class="subH1">반품 신청</h3>
						<span class="order_number">주문번호&nbsp;:&nbsp;<em th:text="${oneData.ordNo}"></em></span>
					</div>
					<div class="sec_body">
						<div class="part_goods">
							<div class="goods_head">
								<p th:unless="${oneData.giftPackYn == 'Y'}">주문일 <span th:text="${oneData.ordDt}"></span></p>
								<p th:if="${oneData.giftPackYn == 'Y'}">선물일 <span th:text="${oneData.ordDt}"></span></p>
							</div>
							<div class="goods_cont">
								<th:block th:if="${returnList.returnList}" th:each="return, status : ${returnList.returnList}" th:with="imageUrl=${@environment.getProperty('upload.goods.view')}">
								<!-- 주문상품 -->
								<div class="goods_info">
									<div class="order_desc">
										<div class="goods_box">
											<div class="gd_item">
												<a href="javascript:void(0)" th:attr="goodsCd=${return.goodsCd}, optCd1=${return.goodsType == 'G056_N' ? return.optCd1 : ''}, ithrCd='IN21_03'" onclick="fnGoToGoodsDetail(this)">
													<span class="thumb">
														<img th:src="${imageUrl + '/' + return.sysImgNm + '?RS=100'}" width="100%" alt="">
													</span>
													<p>
														<span class="brand" th:text="${return.brandNm}"></span>
														<span class="tag primary" th:if="${return.shotDelvYn == 'Y'}">총알배송</span>
														<span class="tag" th:if="${return.shotDelvYn == 'N' and return.selfGoodsYn == 'Y'}">STYLE24 일반배송</span>
														<span class="tag" th:if="${return.selfGoodsYn == 'N'}">업체직배송</span>
													</p>
													<p>
														<span class="name" th:text="${return.goodsNm}"></span>
													</p>
												</a>
											</div>
											<div class="gd_opt">
												<div class="option_wrap">
													<span class="title sr-only">주문 옵션</span>
													<span class="option" th:if="${return.goodsType == 'G056_S'}" th:each="option, status : ${return.colorNmArr}" th:text="|${return.itemNmArr[status.index]} / ${option} / ${return.optCd2Arr[status.index]}|"></span>
													<span class="option" th:unless="${return.goodsType == 'G056_S'}" th:text="|${return.colorNm} / ${return.optCd2}|"></span>
												</div>
											</div>
											<div class="gd_calc">
												<p>
													<span class="count"><em th:text="${return.ordQty - return.cnclRtnQty}"></em>개</span>
												</p>
												<p>
													<span class="price_org" th:if="${(return.ordAmt - return.cnclRtnAmt) > (return.realOrdAmt + return.pntDcAmt + return.gfcdUseAmt)}"><em th:text="${#numbers.formatInteger(return.ordAmt - return.cnclRtnAmt, 1, 'COMMA')}"></em>원</span>
													<span class="price_sale"><em th:text="${#numbers.formatInteger(return.realOrdAmt + return.pntDcAmt + return.gfcdUseAmt, 1, 'COMMA')}"></em>원</span>
												</p>
											</div>
										</div>
										<div class="button_box">
											<div class="count_modify">
												<span class="txt">수량</span>
												<form class="form_wrap">
													<div class="form_field">
														<div class="select_custom select_count">
															<div class="combo">
																<input type="hidden" name="chgQty" value="0" th:attr="ordDtlNo=${return.ordDtlNo}, ordCanChgQty=${return.ordCanChgQty}"/>
																<div class="select">선택</div>
																<ul class="list">
																	<!-- 선택처리 class="selected" / 선택불가 aria-disabled="true" 추가  -->
																	<li class="selected" qty="0" onclick="fnChangeReturnQty(this);">선택</li>
																	<li th:if="${return.ordCanChgQty > 0}" th:each="num : ${#numbers.sequence(1,return.ordCanChgQty)}" th:attr="qty=${num}" th:text="${num}" onclick="fnChangeReturnQty(this);"></li>
																</ul>
															</div>
														</div>
													</div>
												</form>
											</div>
										</div>
									</div>
									<div class="order_text">
										<p>반품하실 상품의 수량을 선택하신 후 반품 신청을 하실 수 있습니다.</p>
									</div>
								</div>
								<!-- //주문상품 -->
								</th:block>
							</div>
						</div>
						<h4 class="subH3">반품 사유</h4>
						<div class="tbl type1">
							<table>
								<tbody>
									<tr>
										<td>
											<div class="form_field">
												<div class="select_custom select_reason">
													<div class="combo">
														<input type="hidden" name="chgReason"/>
														<div class="select">반품 사유를 선택하세요.</div>
														<ul class="list">
															<!-- 선택처리 class="selected" / 선택불가 aria-disabled="true" 추가  -->
<!--															<li class="selected">반품 사유를 선택하세요.</li>-->
															<li th:if="${returnReason}" th:each="oneData, status : ${returnReason}" th:attr="chgReason=${oneData.cd}" th:text="${oneData.cdNm}" onclick="fnChangeReturnReason(this);"></li>
														</ul>
													</div>
												</div>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="form_field">
												<div class="input_wrap">
													<textarea class="doc_reason" name="chgMemo" id="chgMemo" cols="30" rows="10" placeholder="자세한 사유를 입력해주세요." maxlength="200" onkeyup="fnGetTextLength(this, 200);" style="resize: none;"></textarea>
													<p class="txt_cnt"><span id="return_cnt" class="c_primary">0</span>/200</p>
												</div>
											</div>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
						<h4 class="subH3 wdGb">반품 방식 선택</h4>
						<div class="tbl type1 wdGb">
							<table>
								<tbody>
									<tr>
										<td>
											<div class="retrieve_method">
												<div class="form_field">
													<div>
														<input type="radio" name="wdGb" id="withdraw" value="W" checked>
														<label for="withdraw"><span>방문회수<em>택배사에서 고객에게 방문하여 회수</em></span></label>
													</div>
													<div>
														<input type="radio" name="wdGb" id="direct" value="D">
														<label for="direct"><span>직접배송<em>고객이 반품지로 직접 반송</em></span></label>
													</div>
												</div>
											</div>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
						<div class="retrieve_box visit" style="display:block;" id="chgerLocation">
							<h4 class="subH3">반품 회수지 주소 <span class="tit_info">택배사에서 반품 상품을 직접 회수할 장소 선택</span></h4>
							<div class="tbl type1">
								<input type="hidden" name="chgerZipcode" th:value="${deliveryAddrInfo.recipZipcode}">
								<input type="hidden" name="chgerBaseAddr" th:value="${deliveryAddrInfo.recipBaseAddr}">
								<input type="hidden" name="chgerDtlAddr" th:value="${deliveryAddrInfo.recipDtlAddr}">
								<input type="hidden" name="chgerRtnMemo" th:value="${deliveryAddrInfo.delvMemo}">
								<table>
									<colgroup>
										<col width="210">
										<col width="*">
									</colgroup>
									<tbody>
										<tr>
											<th>성명</th>
											<td id="chgerNm" th:text="${deliveryAddrInfo.recipNm}"></td>
											<input type="hidden" name="chgerNm" th:value="${deliveryAddrInfo.recipNm}">
										</tr>
										<tr>
											<th>연락처</th>
											<td id="chgerPhnno" th:text="${deliveryAddrInfo.recipPhnno}"></td>
											<input type="hidden" name="chgerPhnno" th:value="${deliveryAddrInfo.recipPhnno}">
										</tr>
										<tr>
											<th>주소</th>
											<td>
												<span id="chgerAddr" th:text="|${deliveryAddrInfo.recipBaseAddr} ${deliveryAddrInfo.recipDtlAddr}|"></span>
												<button type="button" class="btn btn_default btn_sm" onclick="fnChangeDeliveryAddr();"><span>회수지 변경</span></button>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
						<div class="retrieve_box direct" style="display:none;" id="returnLocation">
							<h4 class="subH3">반송 정보</h4>
							<div class="tbl type1">
								<table>
									<colgroup>
										<col width="210">
										<col width="*">
									</colgroup>
									<tbody>
										<tr>
											<th>
												반송주소
											</th>
											<td th:text="|${deliveryAddrInfo.rtnLocBaseAddr} ${deliveryAddrInfo.rtnLocDtlAddr}|"></td>
										</tr>
										<tr>
											<th>
												택배사 선택
											</th>
											<td>
												<div class="form_field">
													<div class="select_custom select_courier">
														<div class="combo">
															<input type="hidden" name="shipCompCd"/>
															<div class="select">택배사를 선택하세요.</div>
															<ul class="list">
																<!-- 선택처리 class="selected" / 선택불가 aria-disabled="true" 추가  -->
																<!-- <li class="selected">택배사를 선택하세요.</li> -->
																<li th:if="${shipCompanyList}" th:each="oneData, status : ${shipCompanyList}" th:attr="shipCompCd=${oneData.cd}" th:text="${oneData.cdNm}" onclick="fnSelectShipComp(this);"></li>
															</ul>
														</div>
													</div>
												</div>
											</td>
										</tr>
										<tr>
											<th>
												반송 송장번호
											</th>
											<td>
												<form class="form_wrap">
													<div class="form_field">
														<div class="input_wrap">
															<input type="text" class="form_control" name="wdInvoiceNo" data-valid-type="numeric" placeholder="송장번호를 입력해주세요.">
														</div>
													</div>
												</form>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
						<h4 class="subH3">환불정보</h4>
						<div class="tbl type6">
							<table>
								<colgroup>
									<col width="50%">
									<col width="50%">
								</colgroup>
								<tbody>
									<tr>
										<td>
											<dl>
												<div>
													<dt>환불 예정 금액</dt>
													<dd>
														<div class="price">
															<span class="return_total_price"><em id="returnAmt">0</em>원</span>
														</div>
													</dd>
												</div>
												<div class="include_item"> <!-- 할인항목 표기 class명 include_item -->
													<dt>상품 취소 금액</dt>
													<dd><em id="goodsCancelAmt">0</em>원</dd>
												</div>
												<div class="include_item">
													<dt>배송비</dt>
													<dd><em id="deliveryFee">0</em>원</dd>
												</div>
												<div class="include_item">
													<dt>할인 금액 차감</dt>
													<dd><em id="deductDcAmt">0</em>원</dd>
												</div>
											</dl>
										</td>
										<td>
											<dl>
												<div>
													<dt>환불 수단</dt>
													<dd th:if="${paymentInfo.pgGb == 'KCP'}" th:text="${paymentInfo.payMeansNm}"></dd>
													<dd th:if="${paymentInfo.pgGb == 'NAVER'}">네이버페이</dd>
													<dd th:if="${paymentInfo.pgGb == 'KAKAO'}">카카오페이</dd>
													<dd th:if="${paymentInfo.pgGb == 'PAYCO'}">PAYCO</dd>
													<dd th:if="${paymentInfo.pgGb == 'ISTYLE'}">상품권</dd>
												</div>
												<div>
													<dt>결제 금액 환불</dt>
													<dd>
														<em id="refundPayAmt">0</em>원
													</dd>
												</div>
												<div>
													<dt>포인트 환불</dt>
													<dd>
														<em id="refundPoint">0</em>P
													</dd>
												</div>
												<div>
													<dt>상품권 환불</dt>
													<dd>
														<em id="refundGiftCard">0</em>원
													</dd>
												</div>
											</dl>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
						<div class="txt_info">
							<ul>
								<li>
									카드사로 결제 취소 요청이 전달된 후 환불까지는 평일 기준 3 ~7일이 소요될 수 있습니다.
								</li>
							</ul>
						</div>
	
						<div class="info_footer_area" id="addDeliveryFee" style="display:none">
							<p>
								<span id="addPayCost">2,500원</span> 배송비 추가 결제가 필요합니다.
								<input type="hidden" name="addPayCost"/>
							</p>
						</div>
						<div class="btn_footer_area">
							<button type="button" class="btn btn_default btn_md" onclick="cfnGoToPage(_PAGE_MYPAGE_ORDER_LIST)"><span>취소</span></button>
							<button type="button" id="btn_refund_pop" class="btn btn_dark btn_md" onclick="fnReturn()"><span>반품 신청</span></button>
						</div>
					</div>
				</form>
			</div>
			<!-- // CONT-BODY -->
		</div>

		<!-- 환불계좌 등록 팝업 -->
		<div class="modal fade refund_pop" id="refundPop" tabindex="-1" role="dialog" aria-labelledby="refundLabel" aria-hidden="true">
			<div class="modal-dialog" role="document">
				<div class="modal-content"></div>
			</div>
			<a href="#close-modal" rel="modal:close" id="refundPop_close" class="close-modal">Close</a>
			<a href="#close-modal" rel="modal:close" class="close-modal ">Close</a>
		</div>
		<!-- //환불계좌 등록 팝업 -->
	</div>
<script src="/ux/plugins/gaga/gaga.paging.js"></script>
<script th:inline="javascript">
	var isLogin = [[${isLogin}]];
	let returnList = [[${returnList.returnList}]];
	let returnOrderInfo = [[${returnList.returnOrderInfo}]];
	let oneData = [[${oneData}]];
	let paymentInfo = [[${paymentInfo}]];
	let isCustomer = true;
	let jsonObj = {};

	$(document).ready(function() {
		// 마이페이지 LNB 설정
		fnSetMypageLnbList(2);

		// 마이페이지 location 설정
		fnSetMypageLocation('취소/반품/교환 내역', '_PAGE_MYPAGE_CRE_LIST', '반품 신청');

		// 셀렉트박스 활성화
		$('.select_custom').each(function() {
			new sCombo($(this));
		});

		// 입점업체의 경우 회수방식 직접배송 처리
		if (oneData.selfGoodsYn != 'Y') {
			$('#withdraw').click();
			$('.wdGb').css('display','none');
		}
	});

	// 반품 처리
	var fnReturn = function() {
		let url = '/mypage/return';

		// 반품 사유 체크
		let chgReason = $('#returnForm input[name=chgReason]').val();
		if (gagajf.isNull(chgReason)) {
			mcxDialog.alert('반품사유를 선택해주세요.');
			return false;
		}

		// 주문상세번호 및 반품 수량 설정
		let ordDtlNoArr = [];
		let cnclRtnReqQtyArr = [];
		let chkQty = 0;
		$.each($('#returnForm input[name=chgQty]'), function(idx, item) {
			let chgQty = $(item).val();
			let ordDtlNo = $(item).attr('ordDtlNo');

			if (chgQty > 0) {
				ordDtlNoArr.push(Number(ordDtlNo));
				cnclRtnReqQtyArr.push(Number(chgQty));
				chkQty += chgQty;
			}
		});

		// 반품 수량 체크
		if (chkQty == 0) {
			mcxDialog.alert('반품하실 상품의 수량을 선택해주세요.');
			return false;
		}

		// 환불계좌 체크
		let accountNo = $('#returnForm input[name=accountNo]').val();
		let accountNm = $('#returnForm input[name=accountNm]').val();
		let bankCd = $('#returnForm input[name=bankCd]').val();

		let chk = false;
		if (paymentInfo.payMeans == 'G014_20' && paymentInfo.payStat == 'G016_30') {
			if (gagajf.isNull(accountNo) || gagajf.isNull(accountNm) || gagajf.isNull(bankCd)) {
				let data = {};
				data.ordNo = oneData.ordNo;
				data.accountNm = oneData.accountNm;
				
				let jsonData = JSON.stringify(data);
				
				$.ajax({
					type: "POST",
					url: '/mypage/refund/account/register/popup/form',
					data: jsonData,
					dataType: 'html',
					beforeSend: function (xhr, settings) {
						xhr.setRequestHeader("AJAX", "true");
						xhr.setRequestHeader('Accept', 'application/json');
						xhr.setRequestHeader('Content-Type', 'application/json');
					},
					success: function (result) {
						$("#refundPop .modal-dialog .modal-content").html(result);
						$("#refundPop").modal("show");
					}
				});

				return false;
			} else {
				chk = true;
			}
		} else {
			accountNo = null;
			accountNm = null;
			bankCd = null;
		}

		// 추가배송비 PG 처리
		let addPayCost 			= $('#returnForm input[name=addPayCost]').val();
		let wdGb 				= $('#returnForm input[name=wdGb]:radio:checked').val();

		let data 				= {};
		data.ordNo 				= oneData.ordNo;
		data.ordChgSq 			= 0;
		data.chgReason 			= chgReason;
		data.chgMemo 			= $('#returnForm textarea[name=chgMemo]').val();
		data.accountNo 			= accountNo;
		data.accountNm 			= accountNm;
		data.bankCd 			= bankCd;
		data.isCustomer 		= isCustomer;
		data.wdGb 				= wdGb;
		data.chgerNm 			= wdGb == 'W' ? $('#chgerNm').text() : '';
		data.chgerZipcode 		= wdGb == 'W' ? $('#returnForm input[name=chgerZipcode]').val() : '';
		data.chgerBaseAddr		= wdGb == 'W' ? $('#returnForm input[name=chgerBaseAddr]').val() : '';
		data.chgerDtlAddr 		= wdGb == 'W' ? $('#returnForm input[name=chgerDtlAddr]').val() : '';
		data.chgerPhnno 		= wdGb == 'W' ? $('#returnForm input[name=chgerPhnno]').val() : '';
		data.chgerRtnMemo 		= wdGb == 'W' ? $('#returnForm input[name=chgerRtnMemo]').val() : '';
		data.ordDtlNoArr 		= ordDtlNoArr;
		data.wdInvoiceNo 		= $('#returnForm input[name=wdInvoiceNo]').val();
		data.addPayCost 		= addPayCost;
		data.cnclRtnReqQtyArr 	= cnclRtnReqQtyArr;
		data.delvFeeCdGrp 		= oneData.delvFeeCdGrp;
		data.shipCompCd 		= $('#returnForm input[name=shipCompCd]').val();

		// 2021.11.09 card007 휴대폰번호 유효성검증 추가
		if (wdGb == 'W' && !gagajf.checkPhnno(data.chgerPhnno)) {
			mcxDialog.alert("회수지 휴대폰 번호가 유효하지 않습니다.");

			let offset = $('#chgerLocation').offset();
			$('html, body').animate({scrollTop : offset.top - 100}, 0);

			return false;
		}

		let jsonData = JSON.stringify(data);
		
		// 무통장입금 취소의 경우 계좌인증처리 후 반품 진행
		if (chk) {
			// 무통장입금 계좌인증
			gagajf.ajaxJsonSubmit('/order/account/check', jsonData, function (result) {
				if (result.isValid) { // 유효하면 true
					gagajf.ajaxJsonSubmit(url, jsonData, function (result) {
						if (addPayCost > 0) {
							let ordChgSq = result.ordChgSq;
							let ordNo = result.ordNo;
							
							$('#addPaymentForm input[name=ordChgSq]').val(ordChgSq);
							$('#addPaymentForm input[name=ordNo]').val(ordNo);
							
							document.addPaymentForm.submit();
						} else {
							cfnGoToPage(_PAGE_MYPAGE_CRE_LIST);
						}
					}, true);
				} else {
					mcxDialog.alert('환불계좌가 유효하지 않습니다.');
					return false;
				}
			});
		} else {
			gagajf.ajaxJsonSubmit(url, jsonData, function (result) {
				if (addPayCost > 0) {
					let ordChgSq = result.ordChgSq;
					let ordNo = result.ordNo;
					
					$('#addPaymentForm input[name=ordChgSq]').val(ordChgSq);
					$('#addPaymentForm input[name=ordNo]').val(ordNo);
					
					document.addPaymentForm.submit();
				} else {
					cfnGoToPage(_PAGE_MYPAGE_CRE_LIST);
				}
			}, true);
		}
	}

	// 반품 수량 변경 이벤트 처리
	var fnChangeReturnQty = function(param) {
		let url = '/mypage/cancel/refund/amt/calculate';

		if (param != null) {
			$(param).parent().parent().find('input[name=chgQty]').val($(param).attr('qty'));
		}

		let chgReason = $('#returnForm input[name=chgReason]').val();

		if (!gagajf.isNull(chgReason)) {
			// 반품 수량 설정
			let cnclRtnReqQtyArr = [];
			let ordDtlNoArr = [];
			let ordCanChgQtyArr = [];
			let allDelvCanYn = '';
			$.each($('#returnForm input[name=chgQty]'), function(idx, item) {
				let chgQty = $(item).val();
				let ordDtlNo = $(item).attr('ordDtlNo');
				let ordCanChgQty = $(item).attr('ordCanChgQty');

				cnclRtnReqQtyArr.push(Number(chgQty));
				ordDtlNoArr.push(Number(ordDtlNo));
				ordCanChgQtyArr.push(Number(ordCanChgQty));
			});

			// 2021.09.07 card007 전체반품 원배송비 무료 해택 차감 처리
			let delvGfcdUseAmt;
			let realDelvAmt;
			let orgDelvFee;
			
			if (returnOrderInfo != null && returnOrderInfo.length > 0) {
				allDelvCanYn 	= 'Y';
				delvGfcdUseAmt 	= returnOrderInfo[0].delvGfcdUseAmt;
				realDelvAmt 	= returnOrderInfo[0].realDelvAmt;
				orgDelvFee 		= returnOrderInfo[0].orgDelvFee;

				$.each(returnOrderInfo, function (index, orderInfo) {
					let cnt = -1;
					$.each(ordDtlNoArr, function (idx, ordDtlNo) {
						if (orderInfo.ordDtlNo == ordDtlNo) {
							cnt = idx;
						}
					});

					if (cnt == -1) {
						allDelvCanYn = 'N';
					} else {
						if (orderInfo.ordQty != cnclRtnReqQtyArr[cnt]) {
							allDelvCanYn = 'N';
						}
					}
				});
			}

			let data = {};
			data.ordNo = oneData.ordNo;
			data.chgGb = 'G680_30';
			data.ordDtlNoArr = ordDtlNoArr;
			data.cnclRtnReqQtyArr = cnclRtnReqQtyArr;
			data.delvFeeCdGrp = oneData.delvFeeCdGrp;
			
			let jsonData = JSON.stringify(data);
			
			gagajf.ajaxJsonSubmit(url, jsonData, function (result) {
				let refundPoint 		= Number(result.spanPntDcAmt);							// 환불 포인트 금액
				let spanGfcdUseAmt 		= Number(result.spanGfcdUseAmt);						// 환불 상품권 금액
				let spanDelvGfcdUseAmt 	= Number(result.spanDelvGfcdUseAmt);					// 환불 배송비 상품권 금액 (반품에서는 안돌려줘서 항상 0일듯)
				let spanCnclRtnAmt 		= Number(result.spanCnclRtnAmt);						// 환불 상품 금액
				let spanCpnDcAmt 		= Number(result.spanCpnDcAmt);							// 쿠폰 할인 차감 금액
				let spanCpn1DcAmt 		= Number(result.spanCpn1DcAmt);							// 즉시할인 쿠폰 차감 금액
				let spanTmtbDcAmt 		= Number(result.spanTmtbDcAmt);							// 다다익선 할인 차감 금액
				let spanPrePntDcAmt 	= Number(result.spanPrePntDcAmt);						// 선포인트 할인 차감 금액
				let spanTotRtnDelvFee 	= Number(result.spanTotRtnDelvFee);						// 반품배송비 (회수요청으로 인한 반품 배송비)
				let spanRealCnclRtnAmt 	= Number(result.spanRealCnclRtnAmt);					// 환불 상품 실결제 금액 (환불상품금액 - 할인차감금액)
				let goodsCancelAmt 		= spanCnclRtnAmt + spanCpn1DcAmt;						// 상품취소금액
				let deductDcAmt 		= 0 - spanCpnDcAmt - spanTmtbDcAmt - spanPrePntDcAmt;	// 할인금액 차감 (쿠폰+다다익선+선포인트)
				let refundGiftCard 		= spanGfcdUseAmt + spanDelvGfcdUseAmt;					// 환불 상품권 금액 합계
				let spanRefundAmt 		= spanRealCnclRtnAmt;									// 환불예정금액 (환불상품실결제금액)

				// 반품 사유 및 반품 방식 배송비 계산
				let wdGb = $('#returnForm input[name=wdGb]:radio:checked').val();

				// 2021.08.10 card007 상품권 100% 결제 관련 로직 변경
				// 회사귀책이거나 직접배송일때 반품배송비 0
				if (!isCustomer || wdGb == 'D') {
					spanTotRtnDelvFee = 0;
				}

				// 2021.09.07 card007 전체반품 원배송비 무료 해택 차감 처리
				// 배송비정책 기준 전체 반품이고 귀책사유일때
				if (allDelvCanYn == 'Y' && isCustomer) {
					
					// 기 결제한 배송비 금액이 없을때
					if (delvGfcdUseAmt + realDelvAmt == 0) {
						// 원주문배송비 추가
						spanTotRtnDelvFee += orgDelvFee;
					}
				}

				// 추가배송비 영역 설정
				// 2021.08.10 card007 상품권100% 결제 로직 수정
				let refundAmt 			= spanRefundAmt + spanGfcdUseAmt;
				let leftAddDelvFee 		= spanTotRtnDelvFee;

				if (refundAmt < spanTotRtnDelvFee) {
					$('#addDeliveryFee').css('display', '');
					$('#addPayCost').text(spanTotRtnDelvFee.addComma() + '원');
					$('#returnForm input[name=addPayCost]').val(spanTotRtnDelvFee);
				} else {
					if (leftAddDelvFee > spanRefundAmt) {
						leftAddDelvFee -= spanRefundAmt;
						spanRefundAmt = 0;
					} else {
						spanRefundAmt -= leftAddDelvFee;
						leftAddDelvFee = 0;
					}

					if (leftAddDelvFee > 0) {
						refundGiftCard -= leftAddDelvFee;
						leftAddDelvFee = 0;
					}

					$('#addDeliveryFee').css('display', 'none');
					$('#returnForm input[name=addPayCost]').val(0);
				}
				
				let refundPayAmt 		= spanRefundAmt - leftAddDelvFee;					// 결제금액 환불
				let returnAmt 			= refundPayAmt + refundPoint + refundGiftCard;		// 환불예정금액

				// 금액 설정
				$('#returnAmt').text(returnAmt.addComma());
				$('#goodsCancelAmt').text(goodsCancelAmt.addComma());
				$('#deliveryFee').text((0 - spanTotRtnDelvFee).addComma());
				$('#deductDcAmt').text(deductDcAmt.addComma());
				$('#refundPayAmt').text(refundPayAmt.addComma());
				$('#refundPoint').text(refundPoint.addComma());
				$('#refundGiftCard').text(refundGiftCard.addComma());
			});
		}
	}

	// 반품 방식 변경 이벤트
	$('#returnForm input[name=wdGb]').on('change', function() {
		let wdGb = $('#returnForm input[name=wdGb]:radio:checked').val();

		if (wdGb == 'W') {
			$('#chgerLocation').css('display', '');
			$('#returnLocation').css('display', 'none');
		} else {
			$('#chgerLocation').css('display', 'none');
			$('#returnLocation').css('display', '');
		}

		// 환불금액 계산
		fnChangeReturnQty();
	});
	
	// 반품 사유 변경 이벤트
	var fnChangeReturnReason = function(param) {
		var customerReasonArr = ['G688_10'];
		let chgReason = $(param).attr('chgReason');

		// 귀책사유체크(취소,반품,교환)
		isCustomer = customerReasonArr.includes(chgReason);

		// 반품 사유 설정
		$(param).parent().parent().find('input[name=chgReason]').val(chgReason);

		// 환불금액 계산
		fnChangeReturnQty();
	}

	// 회수지 정보 설정
	var delvAddrSet = function(delvObj) {
		let chgerNm = delvObj.recipNm;
		let chgerPhnno = delvObj.recipPhnno;
		let chgerZipcode = delvObj.recipZipcode;
		let chgerBaseAddr = delvObj.recipBaseAddr;
		let chgerDtlAddr = delvObj.recipDtlAddr;
		let delvMemo = delvObj.delvMemo;
		let chgerAddr = chgerBaseAddr + ' ' + chgerDtlAddr;
		//let chgerAddr = chgerBaseAddr + ' ' + chgerDtlAddr + '\n';
		//chgerAddr += '<button type="button" class="btn btn_default btn_sm" onclick="fnChangeDeliveryAddr();"><span>회수지 변경</span></button>';

		$('#returnForm input[name=chgerNm]').val(chgerNm);
		$('#returnForm input[name=chgerPhnno]').val(chgerPhnno);
		$('#returnForm input[name=chgerZipcode]').val(chgerZipcode);
		$('#returnForm input[name=chgerBaseAddr]').val(chgerBaseAddr);
		$('#returnForm input[name=chgerDtlAddr]').val(chgerDtlAddr);
		$('#returnForm input[name=chgerRtnMemo]').val(delvMemo);
		
		$('#chgerNm').text(chgerNm);
		$('#chgerPhnno').text(chgerPhnno);
		$('#chgerAddr').text(chgerAddr);
		//$('#chgerAddr').html(chgerAddr);
	}

	// 환불계좌 등록 콜백 처리
	var fnRegisterAccountCallback = function(result) {
		// 환불계좌 정보 설정
		$('#returnForm input[name=accountNo]').val(result.accountNo);
		$('#returnForm input[name=accountNm]').val(result.accountNm);
		$('#returnForm input[name=bankCd]').val(result.bankCd);

		// 반품처리
		fnReturn();
	}
	
	// 택배사 변경 이벤트
	var fnSelectShipComp = function(param) {
		let shipCompCd = $(param).attr('shipCompCd');

		// 반품 사유 설정
		$(param).parent().parent().find('input[name=shipCompCd]').val(shipCompCd);
	}
</script>

</th:block>

</body>
</html>
