<!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/NoMemberLayoutWeb">
<!--
 *******************************************************************************
 * @source  : NoMemberExchangeFormWeb.html
 * @desc    : 비회원 > 교환신청 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.05.02   card007     최초 작성
 *******************************************************************************
 -->
<body>

<th:block layout:fragment="content">
	<div class="content myOrderView"> <!-- 페이지특정 클래스 = 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="exchangeForm">
					<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>주문일 <span th:text="${oneData.ordDt}"></span></p>
							</div>
							<div class="goods_cont">
								<th:block th:if="${exchangeList.returnList}" th:each="exchange, status : ${exchangeList.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=${exchange.goodsCd}, optCd1=${exchange.goodsType == 'G056_N' ? exchange.optCd1 : ''}, ithrCd='IN21_03'" onclick="fnGoToGoodsDetail(this)">
													<span class="thumb">
														<img th:src="${imageUrl + '/' + exchange.sysImgNm + '?RS=100'}" width="100%" alt="">
													</span>
													<p>
														<span class="brand" th:text="${exchange.brandNm}"></span>
														<span class="tag primary" th:if="${exchange.shotDelvYn == 'Y'}">총알배송</span>
														<span class="tag" th:if="${exchange.shotDelvYn == 'N' and exchange.selfGoodsYn == 'Y'}">STYLE24 일반배송</span>
														<span class="tag" th:if="${exchange.selfGoodsYn == 'N'}">업체직배송</span>
													</p>
													<p>
														<span class="name" th:text="${exchange.goodsNm}"></span>
													</p>
												</a>
											</div>
											<div class="gd_opt">
												<div class="option_wrap">
													<span class="title sr-only">주문 옵션</span>
													<span class="option" th:if="${exchange.goodsType == 'G056_S'}" th:each="option, status : ${exchange.colorNmArr}" th:text="|${exchange.itemNmArr[status.index]} / ${option} / ${exchange.optCd2Arr[status.index]}|"></span>
													<span class="option" th:unless="${exchange.goodsType == 'G056_S'}" th:text="|${exchange.colorNm} / ${exchange.optCd2}|"></span>
												</div>
											</div>
											<div class="gd_calc">
												<p>
													<span class="count"><em th:text="${exchange.ordQty - exchange.cnclRtnQty}"></em>개</span>
												</p>
												<p>
													<span class="price_org" th:if="${(exchange.ordAmt - exchange.cnclRtnAmt) > (exchange.realOrdAmt + exchange.pntDcAmt + exchange.gfcdUseAmt)}"><em th:text="${#numbers.formatInteger(exchange.ordAmt - exchange.cnclRtnAmt, 1, 'COMMA')}"></em>원</span>
													<span class="price_sale"><em th:text="${#numbers.formatInteger(exchange.realOrdAmt + exchange.pntDcAmt + exchange.gfcdUseAmt, 1, 'COMMA')}"></em>원</span>
												</p>
											</div>
											<div class="gd_opt exchangeOption" style="display:none" th:attr="ordDtlNo=${exchange.ordDtlNo}">
												<div class="option_wrap"></div>
											</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=${exchange.ordDtlNo}, ordCanChgQty=${exchange.ordCanChgQty}"/>
																<input type="hidden" name="chgOptionList" th:attr="ordDtlNo=${exchange.ordDtlNo}"/>
																<div class="select">선택</div>
																<ul class="list">
																	<!-- 선택처리 class="selected" / 선택불가 aria-disabled="true" 추가  -->
																	<li class="selected" qty="0" th:attr="ordDtlNo=${exchange.ordDtlNo}" onclick="fnChangeExchangeQty(this);">선택</li>
																	<li th:if="${exchange.ordCanChgQty > 0}" th:each="num : ${#numbers.sequence(1,exchange.ordCanChgQty)}" th:attr="qty=${num}, ordDtlNo=${exchange.ordDtlNo}" th:text="${num}" onclick="fnChangeExchangeQty(this);"></li>
																</ul>
															</div>
														</div>
													</div>
												</form>
												<button type="button" id="btn_exchange_pop" class="btn btn_dark btn_sm" th:attr="ordNo=${exchange.ordNo}, ordDtlNo=${exchange.ordDtlNo}" onclick="fnChangeOption(this)"><span>교환 옵션 변경</span></button>
											</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">
<!--															<li class="selected">교환 사유를 선택하세요.</li>-->
															<li th:if="${exchangeReason}" th:each="oneData, status : ${exchangeReason}" th:attr="chgReason=${oneData.cd}" th:text="${oneData.cdNm}" onclick="fnChangeExchangeReason(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" maxlength="200" placeholder="자세한 사유를 입력해주세요." onkeyup="fnGetTextLength(this, 200);" style="resize: none;"></textarea>
													<p class="txt_cnt"><span id="reason_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="fnChangeAddr('chger');"><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 type1">
							<input type="hidden" name="recipNm" th:value="${deliveryAddrInfo.recipNm}">
							<input type="hidden" name="recipPhnno" th:value="${deliveryAddrInfo.recipPhnno}">
							<input type="hidden" name="recipZipcode" th:value="${deliveryAddrInfo.recipZipcode}">
							<input type="hidden" name="recipBaseAddr" th:value="${deliveryAddrInfo.recipBaseAddr}">
							<input type="hidden" name="recipDtlAddr" th:value="${deliveryAddrInfo.recipDtlAddr}">
							<input type="hidden" name="delvMemo" th:value="${deliveryAddrInfo.delvMemo}">
							<table>
								<colgroup>
									<col width="210">
									<col width="*">
								</colgroup>
								<tbody>
									<tr>
										<th>
											배송지 정보
										</th>
										<td>
											<div class="block_line">
												<ul>
													<li>
														<span id="recipNm" th:text="${deliveryAddrInfo.recipNm}"></span>
													</li>
													<li>
														<span id="recipPhnno" th:text="${deliveryAddrInfo.recipPhnno}"></span>
													</li>
													<li>
														<span id="recipAddr" th:text="|${deliveryAddrInfo.recipBaseAddr} ${deliveryAddrInfo.recipDtlAddr}|"></span>
														<button type="button" class="btn btn_default btn_sm" onclick="fnChangeAddr('recip')"><span>배송지 변경</span></button>
													</li>
													<li>
														배송요청 사항&nbsp;:&nbsp;<span id="delvMemo" th:text="${deliveryAddrInfo.delvMemo}"></span>
														<button type="button" class="btn_underline" onclick="fnChangeDeliveryMemo(this)"><span>변경하기</span></button>
													</li>
												</ul>
											</div>
										</td>
									</tr>
								</tbody>
							</table>
						</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_NOMEMBER_ORDER_LIST);"><span>취소</span></button>
							<button type="button" id="btn_confirm_exchange" class="btn btn_dark btn_md" onclick="fnExchange()"><span>교환 신청</span></button>
						</div>
					</div>
				</form>
			</div>
			<!-- // CONT-BODY -->
		</div>
	</div>
<script src="/ux/plugins/gaga/gaga.paging.js"></script>
<script th:inline="javascript">
	var isLogin = [[${isLogin}]];
	let oneData = [[${oneData}]];
	let isCustomer = false;
	let addrGb = '';
	let jsonObj = {};

	$(document).ready(function() {
		// 비회원 LNB 설정
		fnSetNoMemberLnbList(2);
		
		// 비회원 location 설정
		fnSetNoMemberLocation('취소/반품/교환 내역', '교환 신청');
		
		// 셀렉트박스 활성화
		$('.select_custom').each(function() {
			new sCombo($(this));
		});

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

	// 교환 옵션 변경 팝업
	var fnChangeOption = function(param) {
		let ordNo = $(param).attr('ordNo');
		let ordDtlNo = $(param).attr('ordDtlNo');

		// 옵션변경 수량 체크
		let chgQtyArr = [];
		let chgOrdDtlNoArr = [];

		$.each($('#exchangeForm input[name=chgQty]'), function(idx, item) {
			chgQtyArr.push($(item).val());
			chgOrdDtlNoArr.push($(item).attr('ordDtlNo'));
		});

		let index = chgOrdDtlNoArr.indexOf(ordDtlNo);
		let chgQty = chgQtyArr[index];
		
		if (chgQty == null || chgQty <= 0) {
			mcxDialog.alert('교환 옵션 변경 수량을 선택해주세요.');
			return false;
		}

		var jsonObj = {};
		jsonObj.ordNo = ordNo;
		jsonObj.ordDtlNo = ordDtlNo;
		jsonObj.chgQty = chgQty;

		$.ajax({
			type		: "POST",
			url 		: "/noMember/change/option/popup/form",
			data		: jsonObj,
			dataType 	: "html",
			success 	: function(result) {
				if (result != null) {
					$("#exchangePop .modal-content").html(result);
					$("#exchangePop").modal("show");
				}
			}
		});
	}

	// 교환 옵션 변경 팝업 콜백 처리
	var fnChangeOptionCallback = function(param) {
		let ordDtlNo;

		// 교환옵션 HTML 처리
		let html = '												<span class="title">교환 옵션</span>\n';
		$.each(param, function(idx, item) {
			ordDtlNo = item.ordDtlNo;
			let colorNm = item.colorNm;
			let itemNm = item.itemNm;
			let goodsType = item.goodsType;
			let optCd2 = item.chgOptCd2;

			if (goodsType == 'G056_S') {
				html += '												<span class="option">' + itemNm + ' / ' + colorNm + ' / ' + optCd2 + '</span>\n';
			} else {
				html += '												<span class="option">' + colorNm + ' / ' + optCd2 + '</span>\n';
			}
		});

		$.each($('.exchangeOption'), function(idx, item) {
			if (ordDtlNo == $(item).attr('ordDtlNo')) {
				$(item).css('display', '');
				$(item).find('.option_wrap').html(html);
			}
		});

		// 교환옵션 값 JSON 형태로 설정
		$.each($('#exchangeForm input[name=chgOptionList]'), function(idx, item) {
			if (ordDtlNo == $(item).attr('ordDtlNo')) {
				$(item).val(JSON.stringify(param));
			}
		});
	}

	// 교환 처리
	var fnExchange = function() {
		let url = '/noMember/exchange';
		let delvFeeCd = oneData.delvFeeCd;
		let ordDtlNo = oneData.ordDtlNo;
		let supplyCompCd = oneData.supplyCompCd;
		let excDelvFee = oneData.excDelvFee;
		let rtnDelvFee = oneData.rtnDelvFee;
		let chgReason = $('#exchangeForm input[name=chgReason]').val();
		let addPayCost = $('#exchangeForm input[name=addPayCost]').val();
		
		// 교환 사유 체크
		if (gagajf.isNull(chgReason)) {
			mcxDialog.alert('교환 사유를 선택해주세요.');
			return false;
		}

		// 교환 상품 설정
		let chgOrdDtlNoArr = [];
		$.each($('#exchangeForm input[name=chgQty]'), function(idx, item) {
			if (Number($(item).val()) > 0) {
				chgOrdDtlNoArr.push($(item).attr('ordDtlNo'));
			}
		});

		// 교환옵션 설정
		let cancelReqList = [];
		let optionCnt = 0;
		$.each($('#exchangeForm input[name=chgOptionList]'), function(idx, item) {
			if (chgOrdDtlNoArr.includes($(item).attr('ordDtlNo')) && !gagajf.isNull($(item).val())) {
				let json = $(item).val();
				let jsonData = JSON.parse(json);
				$.each(jsonData, function (index, chgOpt) {
					let cancelReq = {};
					cancelReq.ordDtlNo = chgOpt.ordDtlNo;
					cancelReq.ordDtlItemSq = chgOpt.ordDtlItemSq;
					cancelReq.delvFeeCd = delvFeeCd;
					cancelReq.supplyCompCd = supplyCompCd;
					cancelReq.excDelvFee = excDelvFee;
					cancelReq.rtnDelvFee = rtnDelvFee;
					// 2021.07.26 교환옵션 optCd2 -> optCd로 변경 처리
					//cancelReq.ordChgOpt = chgOpt.chgOptCd2;
					cancelReq.ordChgOpt = chgOpt.chgOptCd;
					cancelReq.chgQty = chgOpt.chgQty;
					cancelReqList.push(cancelReq);
				});
				
				optionCnt++;
			}
		});

		// 교환 수량 및 변경 옵션 체크
		if (chgOrdDtlNoArr.length > optionCnt) {
			mcxDialog.alert('교환하실 상품의 변경 옵션을 선택해주세요.');
			return false;
		} else if (chgOrdDtlNoArr.length < optionCnt || chgOrdDtlNoArr.length == 0) {
			mcxDialog.alert('교환하실 상품의 수량을 선택해주세요.');
			return false;
		}

		// 교환 필요 데이터 설정
		let wdGb = $('#exchangeForm input[name=wdGb]:radio:checked').val();
		let data = {};
		data.ordNo = oneData.ordNo;
		data.ordNm = oneData.ordNm;
		data.ordPhnno = oneData.ordPhnno;
		data.isCustomer = isCustomer;
		data.wdGb = wdGb;
		data.wdInvoiceNo = $('#exchangeForm input[name=wdInvoiceNo]').val();
		data.recipNm = $('#exchangeForm input[name=recipNm]').val();
		data.recipPhnno = $('#exchangeForm input[name=recipPhnno]').val();
		data.recipTelno = $('#exchangeForm input[name=recipTelno]').val();
		data.recipZipcode = $('#exchangeForm input[name=recipZipcode]').val();
		data.recipBaseAddr = $('#exchangeForm input[name=recipBaseAddr]').val();
		data.recipDtlAddr = $('#exchangeForm input[name=recipDtlAddr]').val();
		data.delvMemo = $('#exchangeForm input[name=delvMemo]').val();
		data.chgReason = $('#exchangeForm input[name=chgReason]').val();
		data.chgMemo = $('#exchangeForm textarea[name=chgMemo]').val();
		data.chgerNm = wdGb == 'W' ? $('#exchangeForm input[name=chgerNm]').val() : '';
		data.chgerPhnno = wdGb == 'W' ? $('#exchangeForm input[name=chgerPhnno]').val() : '';
		data.chgerTelno = wdGb == 'W' ? $('#exchangeForm input[name=chgerTelno]').val() : '';
		data.chgerEmail = wdGb == 'W' ? $('#exchangeForm input[name=chgerEmail]').val() : '';
		data.chgerZipcode = wdGb == 'W' ? $('#exchangeForm input[name=chgerZipcode]').val() : '';
		data.chgerBaseAddr = wdGb == 'W' ? $('#exchangeForm input[name=chgerBaseAddr]').val() : '';
		data.chgerDtlAddr = wdGb == 'W' ? $('#exchangeForm input[name=chgerDtlAddr]').val() : '';
		data.chgerRtnMemo = wdGb == 'W' ? $('#exchangeForm input[name=chgerRtnMemo]').val() : '';
		data.addPayCost = addPayCost;
		data.addPayAmt = 0;
		data.cancelReqList = cancelReqList;
		data.shipCompCd = $('#exchangeForm input[name=shipCompCd]').val();

		let jsonData = JSON.stringify(data);

		// 교환 처리
		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_NOMEMBER_CRE_LIST);
			}
		}, true);
	}

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

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

		// 추가 배송비 계산
		fnAddCost();
	});

	// 교환 수량 변경 이벤트
	var fnChangeExchangeQty = function(param) {
		let ordDtlNo = $(param).attr('ordDtlNo');

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

		// 교환옵션 표기 초기화
		$.each($('.exchangeOption'), function(idx, item) {
			if (ordDtlNo == $(item).attr('ordDtlNo')) {
				$(item).css('display', 'none');
				$(item).find('.option_wrap').html('');
			}
		});

		// 교환옵션 값 초기화
		$.each($('#exchangeForm input[name=chgOptionList]'), function(idx, item) {
			if (ordDtlNo == $(item).attr('ordDtlNo')) {
				$(item).val('');
			}
		});
		
		// 추가 배송비 계산
		fnAddCost();
	}

	// 교환 사유 변경 이벤트
	var fnChangeExchangeReason = function(param) {
		var customerReasonArr = ['G689_10', 'G689_30'];
		let chgReason = $(param).attr('chgReason');

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

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

		// 추가 배송비 계산
		fnAddCost();
	}

	// 추가 배송비 계산
	var fnAddCost = function() {
		let addPayCost = 0;
		let delvFee = oneData.rtnDelvFee;
		let rtnDelvFee = oneData.rtnDelvFee;

		// 교환 수량 체크
		let qty = 0;
		$.each($('#exchangeForm input[name=chgQty]'), function (idx, item) {
			qty += Number($(item).val());
		});

		// 교환 수량이 있고 고객 귀책 사유 시 추가 배송비 계산
		if (isCustomer && qty > 0) {
			addPayCost = delvFee;

			// 회수 요청 시 반품배송비 추가
			if ($('#exchangeForm input[name=wdGb]:radio:checked').val() == 'W') {
				addPayCost += rtnDelvFee;
			}

			// 추가배송비 영역 설정
			$('#addDeliveryFee').css('display', '');
			$('#addPayCost').text(addPayCost.addComma() + '원');
			$('#exchangeForm input[name=addPayCost]').val(addPayCost);
		} else {
			$('#addDeliveryFee').css('display', 'none');
			$('#exchangeForm input[name=addPayCost]').val(0);
		}
	}

	// 배송지 정보 설정
	var delvAddrSet = function(delvObj) {
		let recipNm = delvObj.recipNm;
		let recipPhnno = delvObj.recipPhnno;
		let recipZipcode = delvObj.recipZipcode;
		let recipBaseAddr = delvObj.recipBaseAddr;
		let recipDtlAddr = delvObj.recipDtlAddr;
		let delvMemo = delvObj.delvMemo;

		if (addrGb == 'recip') {
			$('#recipNm').text(recipNm);
			$('#recipPhnno').text(recipPhnno);
			$('#recipAddr').text(recipBaseAddr + ' ' + recipDtlAddr);
			$('#delvMemo').text(delvMemo);

			$('#exchangeForm input[name=recipNm]').val(recipNm);
			$('#exchangeForm input[name=recipPhnno]').val(recipPhnno);
			$('#exchangeForm input[name=recipZipcode]').val(recipZipcode);
			$('#exchangeForm input[name=recipBaseAddr]').val(recipBaseAddr);
			$('#exchangeForm input[name=recipDtlAddr]').val(recipDtlAddr);
			$('#exchangeForm input[name=delvMemo]').val(delvMemo);
		} else if (addrGb == 'chger') {
			//let chgerAddr = recipBaseAddr + ' ' + recipDtlAddr + '\n';
			//chgerAddr += '<button type="button" class="btn btn_default btn_sm" onclick="fnChangeAddr(\'chger\');"><span>회수지 변경</span></button>';

			$('#exchangeForm input[name=chgerNm]').val(recipNm);
			$('#exchangeForm input[name=chgerPhnno]').val(recipPhnno);
			$('#exchangeForm input[name=chgerZipcode]').val(recipZipcode);
			$('#exchangeForm input[name=chgerBaseAddr]').val(recipBaseAddr);
			$('#exchangeForm input[name=chgerDtlAddr]').val(recipDtlAddr);
			$('#exchangeForm input[name=chgerRtnMemo]').val(delvMemo);

			$('#chgerNm').text(recipNm);
			$('#chgerPhnno').text(recipPhnno);
			$('#chgerAddr').text(recipBaseAddr + ' ' + recipDtlAddr);
			//$('#chgerAddr').html(chgerAddr);
		}
	}

	// 배송메모 설정
	var delvMemoSet = function(delvMemoObj) {
		let delvMemo = delvMemoObj.delvMemo;
		$('input[name=delvMemo]').val(delvMemo);
		$("#delvMemo").text(delvMemo);
	}

	// 배송지 및 교환지 변경 처리
	var fnChangeAddr = function(param) {
		addrGb = param;
		fnChangeDeliveryAddr();
	}

	// 택배사 변경 이벤트
	var fnSelectShipComp = function(param) {
		let shipCompCd = $(param).attr('shipCompCd');
		
		// 반품 사유 설정
		$(param).parent().parent().find('input[name=shipCompCd]').val(shipCompCd);
	}
</script>

</th:block>

</body>
</html>
