<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : OrderDetailForm.html
 * @desc    : 주문상세화면
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.11.16   jsh77b       최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1500" data-height="700"> <!-- data-width="1500" data-height="870" -->
	<div class="panelStyle">
		<div class="panelTitle">
			<h2>주문상세내역</h2>
			<button type="button" class="close" onclick="fnOrderDetailClose()"><i class="fa fa-times"></i></button>
		</div>
			
		<div class="panelContent" style="height:90%; overflow-y:auto; padding:0px 20px !important; ">
			<form id="orderDetailInfo" name="orderDetailInfo" action="#" th:method="post">
				<input type="hidden" name="custNo"/>
				<input type="hidden" name="orderNm"/>
				<input type="hidden" name="orderPhnno"/>
				<input type="hidden" name="orderEmail"/>
				
				<h4>기본정보</h4>
				<!-- TABLE -->
				<table class="tableStyle">
					<colgroup>
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
						<col width="">
					</colgroup>
					<thead>
						<tr>
							<th>사이트</th>
							<th>몰구분</th>
							<th>웹구분</th>
							<th>외부몰</th>
							<th>주문일시</th>
							<th>주문자</th>
							<th>고객번호</th>
							<th>주문번호</th>
							<th>이메일</th>
							<th>핸드폰번호</th>
							<th>회원구분</th>
							<th>관리대상</th>
							<th>등급</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td th:text="${orderInfo[0].siteCdNm}"></td>
							<td th:text="${orderInfo[0].mallGbNm}"></td>
							<td th:text="${orderInfo[0].frontGbNm}"></td>
							<td th:text="${orderInfo[0].extmallNm}"></td>
							<td th:text="${orderInfo[0].ordDt}"></td>
							<td th:text="${orderInfo[0].ordNm}"></td>
							<td>
								<th:block th:if="${orderInfo[0].custNo} > 0">
									<a href="script:void(0)" class="custDetailPop" th:attr="custNo=${orderInfo[0].custNo}"><th:block th:text="${orderInfo[0].custNo}"></a>
								</th:block>
								<th:block th:unless="${orderInfo[0].custNo} > 0">
									<th:block th:text="${orderInfo[0].custNo}">
								</th:block>
							</td>
							<td th:text="${orderInfo[0].ordNo}"></td>
							<td th:text="${orderInfo[0].ordEmail}"></td>
							<td th:text="${orderInfo[0].ordPhnno}"></td>
							<td th:text="${orderInfo[0].custGbNm}"></td>
							<td th:text="${orderInfo[0].managedRsnNm}"></td>
							<td th:text="${orderInfo[0].custGradeNm}"></td>
						</tr>
					</tbody>
				</table>
				<!-- //TABLE -->
									
				<h4>주문상품정보</h4>
				<div id="gridOrderGoodsInfo" style="width:100%; height:200px;" class="ag-theme-balham"></div>
				
				<div id="wrapOrderFregift">
					<h4>주문사은품정보</h4>
					<!-- <button type="button" class="btn btnRight btn-base btn-sm off" id="btnFreeGiftCancel" style="margin-left:10px;" >사은품취소</button> -->
					<div id="gridOrderFreeGiftInfo" style="width:100%; height:120px;" class="ag-theme-balham"></div>
				</div>
				
				<h4>배송정보</h4>
				<div id="gridDeliveryAddrInfo" style="width:100%; height:100px;" class="ag-theme-balham"></div>
				
				<table style="width:100%;">
					<colgroup>
						<col style="width:65%;"/>
						<col/>
					</colgroup>
					<tbody>
						<tr>
							<td style="width:916px;display:inline-block">
								<h4>결제정보</h4>
								<div id="gridPaymentInfo" style="width:100%; height: 100px;" class="ag-theme-balham"></div>
							</td>
							<td style="">
								<h4>배송비정보</h4>
								<div id="gridDeliveryFeeInfo" style="width:100%; height: 100px;" class="ag-theme-balham"></div>
							</td>
						<tr>
					</tbody>
				</table>

				<div id="wrapOrderChange">
					<h4>(취소/반품/교환) 요청 정보</h4>
					<div id="gridOrderChangeInfo" style="width:100%; height: 180px; min-height:99px;" class="ag-theme-balham"></div>
				</div>

				<div id="wrapRefund">
					<h4>환불정보</h4>
					<div id="gridOrderRefundInfo" style="width:100%; height: 100px;" class="ag-theme-balham"></div>
				</div>
				
				<div>
					<h4>관리자메모</h4>
					<button type="button" id="btnCreateOrderMemo" class="btn btnRight btn-base btn-sm" style="margin-left:10px;"> +</button>
					<div id="gridOrderMemoInfo" style="width:100%; height: 100px;" class="ag-theme-balham"></div>
				</div>
				
				<!-- 
				<table style="width:100%;">
					<colgroup>
						<col style="width:65%;"/>
						<col/>
					</colgroup>
					<tbody>
						<tr>
							<td style="width:916px;display:inline-block">
								<h4>상담내역</h4>
								<div id="gridOrderCounselInfo" style="width:100%; height: 100px;" class="ag-theme-balham"></div>
							</td>
							<td style="">
								<h4>관리자메모</h4>
								<button type="button" id="btnCreateOrderMemo" class="btn btnRight btn-base btn-sm" style="margin-left:10px;"> +</button>
								<div id="gridOrderMemoInfo" style="width:100%; height: 100px;" class="ag-theme-balham"></div>
							</td>
						</tr>
					</tbody>
				</table>
				 -->
				
			</form>
		</div>
	</div>
</div>

<!-- data -->
<script th:inline="javascript">
var ordNo 					= [[${ordNo}]];							// 주문번호
var userNo 					= [[${userNo}]];						// 관리자번호

var orderInfo 				= [[${orderInfo}]];						// 기본정보
var orderGoodsInfo 			= [[${orderGoodsInfo}]];				// 주문상세정보
var orderFreeGiftInfo 		= [[${orderFreeGiftInfo}]];				// 주문사은품정보
var orderDeliveryAddrInfo	= [[${orderDeliveryAddrInfo}]];			// 배송정보
var orderPaymentInfo 		= [[${orderPaymentInfo}]];				// 결제정보
var orderDeliveryFeeInfo 	= [[${orderDeliveryFeeInfo}]];			// 배송비정보
var orderChangeInfo 		= [[${orderChangeInfo}]];				// 취소/반품/교환요청 정보
var orderRefundInfo 		= [[${orderRefundInfo}]];				// 환불정보
var orderCounselInfo 		= [[${orderCounselInfo}]];				// 상담내역
var orderAdminMemoInfo 		= [[${orderAdminMemoInfo}]];			// 관리자메모
var allCanYn				= [[${allCanYn}]];						// 배송지수정가능여부
var orderGoodsCnt 			= [[${orderGoodsInfo.size()}]];			// 주문상세정보
var orderFreeGiftCnt		= [[${orderFreeGiftInfo.size()}]];		// 주문사은품정보
var orderDeliveryAddrCnt	= [[${orderDeliveryAddrInfo.size()}]];	// 배송정보
var orderChangeCnt 			= [[${orderChangeInfo.size()}]];		// 취소/반품/교환요청 정보
var orderRefundCnt 			= [[${orderRefundInfo.size()}]];		// 환불정보
var roleCd 					= [[${sessionInfo.roleCd}]];			// 권한코드 

// 2021.05.12 
var hiddenTemp				= true;
if (userNo == "24" || userNo == "33" || userNo == "8") {
	hiddenTemp				= false;
}

</script>

<!-- AgGrid 컬럼 세팅 -->
<script th:inline="javascript">

// 1.주문기본정보 그리드 바인딩
// 2.상품별 상세정보
var columnDefsGoodsInfo = [
	{
		headerName	: "주문상세정보",
		children	: [
			{headerName: "상세번호"	, field: "ordDtlNo"		, width: 80, cellClass: 'text-center'},
			{headerName: "주문구분"	, field: "exchGbNm"		, width: 80, cellClass: 'text-center'},
			{
				headerName: "상품코드", field: "goodsCd", width: 120, cellClass: 'text-center', sortable: true,
				cellRenderer: function (params) {
					if (roleCd.indexOf("C") < 0) {
						return "<a href=\"javascript:void(0);\" onclick=\"cfnOpenGoodsDetailPopup('U','" + params.value + "');\">" + params.value + "</a>";
					} else {
						return params.value;
					}
				}
			},
			{
				headerName		: "상품명"
				, field			: "goodsNm"
				, width			: 200
				, cellClass		: 'text-left'
				, cellRenderer: function (params) {
					return '<a href="javascript:void(0);" onclick="cfnOpenFrontGoodsPopup(\'' + params.data.goodsCd + '\',\'' + params.data.siteCd + '\');">' + params.value + '</a>';
				}
			},
			{headerName: "상품타입"	, field: "goodsTypeNm"	, width: 130, cellClass: 'text-center',
				cellRenderer: function (params) {
					var option;
					if (params.data.goodsType == 'G056_S') {
						option = "<a href=\"javascript:void(0);\" onclick=\"fnOrderDetailItemForm('" + params.data.ordDtlNo + "');\">" + params.value + "</a>";
					} else {
						option = params.value
					}
					return option;
				}
			},
			{headerName: "브랜드"		, field: "brandGroupNm"	, width: 100, cellClass: 'text-center'},
			{headerName: "옵션1"		, field: "colorNm"		, width: 80, cellClass: 'text-center'},
			{headerName: "옵션2"		, field: "optCd2"		, width: 80, cellClass: 'text-center'},
			{
				headerName		: "정상가"
				, field			: "listPrice"
				, width			: 100
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "판매가"
				, field			: "currPrice"
				, width			: 100
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "옵션추가금액"
				, field			: "optAddPrice"
				, width			: 100
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{headerName: "주문수량"	, field: "ordQty"		, width: 80, cellClass: 'text-center'},
			{headerName: "취소수량"	, field: "cnclRtnQty"	, width: 80, cellClass: 'text-center'},
			{headerName: "변경요청수량"	, field: "ordReqChgQty"	, width: 100, cellClass: 'text-center'},
			{headerName: "주문상태"	, field: "ordDtlStat"	, width: 120, cellClass: 'text-center', hide: true},
			{
				headerName		: "주문상태"
				, field			: "ordDtlStatNm"
				, width			: 120
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					var retVal = "";
					retVal += (params.data.cancelRequestQty > 0) ? " 취" + params.data.cancelRequestQty : "";
					retVal += (params.data.returnRequestQty > 0) ? " 반" + params.data.returnRequestQty : "";
					retVal += (params.data.exchangeRequestQty > 0) ? " 교" + params.data.exchangeRequestQty : "";
					
					if (!gagajf.isNull(retVal)) {
						retVal = "-" + retVal;
					}
					
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderDetailChangeHst('" + params.data.ordDtlNo + "');\">" + params.value + retVal + "</a>";
				}
			},
			{
				headerName		: "상태변경"
				, field			: "ordDtlStatChg"
				, width			: 140
				, hide			: hiddenTemp
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					var strVal 		= "";
					var strCheck	= "";
					
					// 2021.04.30 상태값 임시 기능
					strVal += "<select class='ordDtlStatChg' name='ordDtlStatChg' ordDtlNo='"+params.data.ordDtlNo+"' ordNo='"+params.data.ordNo+"' onChange='fnChangOrdDtlStat(this);'>";
					strVal += "	<option value=''>선택</option>";
					strVal += "	<option value='G013_20'>결제완료</option>";
					strVal += "	<option value='G013_30'>상품준비중</option>";
					strVal += "	<option value='G013_40'>배송준비중</option>";
					strVal += "	<option value='G013_50'>배송중</option>";
					strVal += "	<option value='G013_60'>배송완료</option>";
					strVal += "</select>";
					
					return strVal;
				}
			},
			{
				headerName		: "변경요청"
				, field			: "ordDtlStat"
				, width			: 200
				, cellClass		: 'text-center'
				, cellRenderer: function (params) {
					var retStr = "";
					// 네이버페이 주문형은 버튼 생성X
					if(params.data.pgGb == "NAVER_ORDER") return retStr;

					// 결제완료, 상품준비중, 출고처지정, 배송준비중 (주문취소)
					// 2021.07.08 card007 교환상품은 취소 안되게 수정
					if (params.data.ordExchGb == 'O') {
						if (params.value == 'G013_20' || params.value == 'G013_30' || params.value == 'G013_35' || params.value == 'G013_40') {
							if (params.data.ordQty > (params.data.cnclRtnQty + params.data.ordReqChgQty)) {
								var paramData = params.data.ordNo;
								paramData += '@' + params.data.ordDtlNo;
								paramData += '@' + params.data.delvFeeCd;
								paramData += '@' + params.data.delvFeeCdGrp;
								paramData += '@' + params.data.ordDtlStat;
								retStr += '<button type="button" class="btn btn-base btn-sm" onclick="fnCancelRequest(\'' + paramData + '\', null);">취소요청</button>';
							}
						}
					}
					
					// 배송중, 배송완료 (교환신청, 반품신청) 
					if (params.value == 'G013_50' || params.value == 'G013_60') {
						if (params.data.ordQty > (params.data.cnclRtnQty + params.data.ordReqChgQty)) {
							var paramData 	= params.data.ordNo;
							paramData 		+= '@' + params.data.ordDtlNo;
							paramData 		+= '@' + params.data.delvFeeCd;
							paramData 		+= '@' + params.data.delvFeeCdGrp;
							paramData 		+= '@' + params.data.ordDtlStat;
														
							if (params.data.changeableYn == 'Y') {
								retStr 			+= '<button type="button" class="btn btn-base btn-sm" onclick="fnReturnRequest(\'' + paramData + '\', null);">반품요청</button>';
							}
							if (params.data.returnableYn == 'Y') {
								retStr 			+= '<button type="button" class="btn btn-base btn-sm" onclick="fnExchangeRequest(\'' + paramData + '\', null);">교환요청</button>';
							}
						}
					}
					return retStr;
				}
			},
		],
	},
	{
		headerName	: "금액",
		children	: [
			{
				headerName		: "주문"
				, field			: "ordAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, valueFormatter: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "취소"
				, field			: "cnclRtnAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, valueFormatter: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "실결제"
				, field			: "realOrdAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, valueFormatter: function (params) {
					return params.value.addComma();
				}
			}
		]
	},
	{
		headerName	: "쿠폰",
		children	: [
			{
				headerName		: "즉시할인"
				, field			: "cpn1DcAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "상품"
				, field			: "goodsCpnDcAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderCouponHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			},
			{
				headerName		: "장바구니"
				, field			: "cartCpnDcAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderCouponHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			}
		]
	},
	{
		headerName	: "다다익선",
		children	: [
			{
				headerName		: "수량"
				, field			: "tmtb1DcAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderTmtbHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			},
			{
				headerName		: "금액"
				, field			: "tmtb2DcAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderTmtbHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			}
		]
	},
	{
		headerName	: "포인트",
		children	: [
			{
				headerName		: "사용"
				, field			: "pntDcAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderPointHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			},
			{
				headerName		: "즉시사용"
				, field			: "prePntDcAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "적립"
				, field			: "savePntAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderPointHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			}
		]
	},
	{
		headerName	: "상품권",
		children	: [
			{
				headerName		: "사용"
				, field			: "gfcdUseAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderGiftcardHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			}
		]
	},
	{
		headerName	: "배송",
		children	: [
			{headerName: "품절여부"	, field: "soldoutYn"	, width: 90, cellClass: 'text-center'},
			{headerName: "택배사코드"	, field: "shipCompCd"	, width: 150, cellClass: 'text-center',  hide: true},
			{headerName: "출고택배사"	, field: "shipCompNm"	, width: 150, cellClass: 'text-center'},
			{
				headerName		: "송장번호"
				, field			: "invoiceNo"
				, width			: 150
				, cellClass		: 'text-center'
				, cellRenderer	: function (params) {
					var retStr = '';
					if (!gagajf.isNull(params.value)) {
						//retStr = '<a href="javascript:void(0);" onclick="fnSearchDelivery(\'' + params.data.trackingUrl + '\',\'' + params.data.invoiceNo + '\');">' + params.value + '</a>';
						retStr = '<a href="javascript:void(0);" onclick="fnSweetTracker(\'' + params.data.shipCompCd + '\',\'' + params.data.invoiceNo + '\');">' + params.value + '</a>';
					}
					return retStr;
				}
			},
			{headerName: "출고처"		, field: "delvLocNm"	, width: 120, cellClass: 'text-center'},
			{headerName: "배송지번호"	, field: "delvAddrSq"	, width: 120, cellClass: 'text-center'}
		]
	}
];
var gridOptionsGoodsInfo = gagaAgGrid.getGridOptions(columnDefsGoodsInfo);

// 2.5 주문사은품정보
var columnDefsOrderFreeGiftInfo = [
	{headerName: "주문사은품번호"	, field: "ordFreegiftSq"	, width: 120, cellClass: 'text-center', hide: true},
	{headerName: "사은품프로모션"	, field: "freegiftSq"		, width: 100, cellClass: 'text-center', hide: true},
	{headerName: "사은품프로모션명"	, field: "freegiftNm"		, width: 250, cellClass: 'text-left'},
	{
		headerName			: "구분"
		, field				: "allYn"
		, width				: 100
		, cellClass			: 'text-center'
		, cellRenderer	: function (params) {
			var rtnStr = ""
			
			if (params.value == 'Y') {
				rtnStr = "필수";
			} else {
				rtnStr = "선택";
			}
			return rtnStr;
		}
	},
	{headerName: "사은품혜택번호"	, field: "freegiftValSq"	, width: 100, cellClass: 'text-center', hide: true},
	{
		headerName			: "사용포인트"		
		, field				: "usePoint"			
		, width				: 100
		, cellClass			: 'text-center'
		, cellRenderer	: function (params) {
			var rtnStr = ""
			
			if (params.value == '0') {
				rtnStr = "무료";
			} else {
				rtnStr = params.value.addComma();
			}
			return rtnStr;
		}
	},
	{headerName: "사은품코드"		, field: "productNo"		, width: 150, cellClass: 'text-center'},
	{headerName: "사은품명"		, field: "itemNm"			, width: 250, cellClass: 'text-center'},
	{headerName: "사은품수량"		, field: "itemQty"			, width: 100, cellClass: 'text-center'},
	{headerName: "삭제여부"		, field: "delYn"			, width: 100, cellClass: 'text-center'}
];
var gridOptionsOrderFreeGiftInfo = gagaAgGrid.getGridOptions(columnDefsOrderFreeGiftInfo);

// 3.배송정보
var columnDefsDeliveryInfo = [
	{headerName: "배송지번호"		, field: "delvAddrSq"		, width: 80, cellClass: 'text-center'},
	{headerName: "주문구분"		, field: "exchGbNm"			, width: 80, cellClass: 'text-center'},
	{headerName: "받는분"			, field: "recipNm"			, width: 80, cellClass: 'text-left', editable: true},
	{headerName: "핸드폰번호"		, field: "recipPhnno"		, width: 120, cellClass: 'text-left', editable: true},
	{
		headerName		: "우편번호"		
		, field			: "recipZipcode"
		, width			: 220
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var rtnStr = "";
			
			if (allCanYn == 'Y') {
				rtnStr += params.value;
				rtnStr += "<button type=\"button\" style=\"margin-left:10px\" class=\"btn btn-info\" onclick=\"fnOpenDaumAddr('" + params.node.rowIndex + "', 'ADDR');\">POST</button>";
				rtnStr += "<button type=\"button\" class=\"btn btn-info\" onclick=\"fnUpdateOrderAddr('" + params.node.rowIndex + "');\">저장</button>";
			} else {
				rtnStr += params.value;
			}
			
			return rtnStr;
		}
	},
	{headerName: "주소(기본)"		, field: "recipBaseAddr"	, width: 220, cellClass: 'text-left'},
	{headerName: "주소(상세)"		, field: "recipDtlAddr"		, width: 220, cellClass: 'text-left', editable: true},
	{headerName: "배송메모"		, field: "delvMemo"			, width: 250, cellClass: 'text-left', editable: true}
];
var gridOptionsDeliveryInfo = gagaAgGrid.getGridOptions(columnDefsDeliveryInfo);

// 4.결제정보
var columnDefsPaymentInfo = [
	{headerName: "결제방법"		, field: "pgGb"			, width: 100	, cellClass: 'text-center'},
	{headerName: "결제수단"		, field: "payMeansNm"	, width: 120	, cellClass: 'text-center'},
	{headerName: "카드(은행)"		, field: "cardNm"		, width: 100	, cellClass: 'text-center'},
	{
		headerName		: "할부(입금계좌)"
		, field			: "cardMips"
		, width			: 150
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var retStr = '';
			// 무통장입금
			if (params.data.payMeans == 'G014_20') {
				retStr = params.data.vaNo;
			} else {
				if (params.value == '00' || params.value == '0') {
					retStr = "일시불";
				} else {
					if (parseInt(params.value) > 0) {
						retStr = parseInt(params.value) + "개월할부";
					} else {
						retStr = params.value;
					}
				}
			}
			return retStr;
		}
	},
	{
		headerName		: "승인번호"
		, field			: "pgTradeNo"
		, width			: 100
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var retStr = '';
			
			/*
			if (!gagajf.isNull(params.value)) {
				retStr = '<a href="javascript:void(0);" onclick="fnReceiptPage(\'' + params.data.pgTid + '\');">' + params.value + '</a>';
			}

			if (gagajf.isNull(params.value) && !gagajf.isNull(params.data.pgTid)) {
				retStr = '<a href="javascript:void(0);" onclick="fnReceiptPage(\'' + params.data.pgTid + '\');">' + '거래내역' + '</a>';
			}
			*/
			
			retStr = params.value;

			return retStr;
		}
	},
	{
		headerName			: "결제일시"	
		, field				: "payDt"
		, width				: 130
		, cellClass			: 'text-center' 
		, cellRenderer: function(params) {
			return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmm").format("YYYY-MM-DD HH:mm") : '';
		}
	},
	{headerName: "결제상태"	, field: "payStatNm"	, width: 80		, cellClass: 'text-center'},
	{
		headerName			: "결제금액"
		, field				: "payAmt"
		, width				: 80
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			return params.value.addComma();
		}
	},
	{
		headerName			: "주결제금액"
		, field				: "mainPayAmt"
		, width				: 80
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			let mainPayAmt = params.data.payAmt - params.data.pgCpnAmt - params.data.npayPntAmt;
			return mainPayAmt.addComma();
		}
	},
	{
		headerName			: "제휴할인"
		, field				: "pgCpnAmt"
		, width				: 80
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			return params.value.addComma();
		}
	},
	{
		headerName			: "마일리지"
		, field				: "npayPntAmt"
		, width				: 80
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			return params.value.addComma();
		}
	},
	{headerName: "계좌만료일"	, field: "vaDeadline"	, width: 150	, cellClass: 'text-center'}
];
var gridOptionsPaymentInfo = gagaAgGrid.getGridOptions(columnDefsPaymentInfo);

// 5.배송비
var columnDefsDeliveryFeeInfo = [
	{headerName: "배송비종류"		, field: "delvFeeGbNm", width: 120, cellClass: 'text-center'},
	{
		headerName			: "배송비"
		, field				: "delvFee"
		, width				: 100
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			return params.value.addComma();
		}
	},
	{
		headerName			: "쿠폰할인배송비"
		, field				: "delvCpnDcAmt"
		, width				: 120
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			return params.value.addComma();
		}
	},
	{
		headerName			: "실제배송비"
		, field				: "realDelvAmt"
		, width				: 100
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			return params.value.addComma();
		}
	},
	{headerName: "배송비정산여부"	, field: "delvUsacYn", width: 120, cellClass: 'text-center'},
	{
		headerName			: "배송비정산일시"	
		, field				: "delvUsacDt"
		, width				: 140
		, cellClass			: 'text-center' 
		, cellRenderer: function(params) {
			return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmm").format("YYYY-MM-DD HH:mm") : '';
		}
	}
];
var gridOptionsDeliveryFeeInfo = gagaAgGrid.getGridOptions(columnDefsDeliveryFeeInfo);

// 6. 반품/교환 정보
var columnDefsOrderChangeInfo = [
	{
		headerName		: "요청번호"		
		, field			: "ordChgSq"		
		, width			: 100	
		, cellClass		: 'text-center'
		, cellRenderer	: function(params) {
			var rtnStr = "";
			
			var paramData 	= params.data.ordNo;
			paramData 		+= '@' + params.data.ordDtlNo;
			paramData 		+= '@' + params.data.delvFeeCd;
			paramData 		+= '@' + params.data.delvFeeCdGrp;
			paramData 		+= '@' + params.data.chgStat;
			
			/*
			// 취소접수, 취소대기
			if (params.data.chgStat == 'G685_10' || params.data.chgStat == 'G685_11') {
				rtnStr = '<a href="javascript:void(0);" onclick="fnCancelRequest(\'' + paramData + '\',\'' + params.value + '\');">' + params.value + '</a>';
			} 
			// 반품접수, 반품대기, 회수요청, 상품검수중, 결제대기, 반품진행중
			else if (params.data.chgGb == 'G680_30' && (params.data.chgStat == 'G685_50' || params.data.chgStat == 'G685_51' 
					|| params.data.chgStat == 'G685_30' || params.data.chgStat == 'G685_31' || params.data.chgStat == 'G685_32' || params.data.chgStat == 'G685_33')) {
				rtnStr = '<a href="javascript:void(0);" onclick="fnReturnRequest(\'' + paramData + '\',\'' + params.value + '\');">' + params.value + '</a>';
			}
			// 교환접수, 교환대기, 회수요청, 상품검수중, 결제대기, 교환진행중
			else if (params.data.chgGb == 'G680_40' && (params.data.chgStat == 'G685_20' || params.data.chgStat == 'G685_21' 
					|| params.data.chgStat == 'G685_30' || params.data.chgStat == 'G685_31' || params.data.chgStat == 'G685_32' || params.data.chgStat == 'G685_34')) {
				rtnStr = '<a href="javascript:void(0);" onclick="fnExchangeRequest(\'' + paramData + '\',\'' + params.value + '\');">' + params.value + '</a>';
			} 
			else {
				rtnStr = params.value;
			}
			*/
			
			// 2021.06.29 변경구분값으로 변경
			// 취소요청
			if (params.data.chgGb == "G680_20") {
				rtnStr = '<a href="javascript:void(0);" onclick="fnCancelRequest(\'' + paramData + '\',\'' + params.value + '\');">' + params.value + '</a>';
			}
			// 반품요청
			else if (params.data.chgGb == "G680_30") {
				rtnStr = '<a href="javascript:void(0);" onclick="fnReturnRequest(\'' + paramData + '\',\'' + params.value + '\');">' + params.value + '</a>';
			}
			// 교환요청
			else if (params.data.chgGb == "G680_40") {
				rtnStr = '<a href="javascript:void(0);" onclick="fnExchangeRequest(\'' + paramData + '\',\'' + params.value + '\');">' + params.value + '</a>';
			}
			else {
				rtnStr = params.value;
			}
			
			return  rtnStr;
		}
	},
	{headerName: "요청상태"		, field: "chgStatNm"	, width: 100	, cellClass: 'text-center'},
	{headerName: "상품코드"		, field: "goodsCd"		, width: 100	, cellClass: 'text-center'},
	{headerName: "옵션1"			, field: "colorNm"		, width: 100	, cellClass: 'text-center'},
	{headerName: "옵션2"			, field: "optCd2"		, width: 100	, cellClass: 'text-center'},
	{headerName: "수량"			, field: "chgQty"		, width: 100	, cellClass: 'text-center'},
	{
		headerName		: "요청일자"		
		, field			: "regDt"		
		, width			: 150		
		, cellClass		: 'text-center'
		, cellRenderer	: function(params) {
			return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmm").format("YYYY-MM-DD HH:mm") : '';
		}
	},
	{headerName: "변경사유"		, field: "chgReasonNm"	, width: 100	, cellClass: 'text-center'},
	{
		headerName: "회수구분", field: "wdGb", width: 100, cellClass: 'text-center',
		cellRenderer: function (params) {
			return params.value == 'W' ? '회수요청' : '직접배송'; 
		}
	},
	{headerName: "요청메모"		, field: "chgMemo"		, width: 150	, cellClass: 'text-left'},
	{headerName: "변경자명"		, field: "chgerNm"		, width: 100	, cellClass: 'text-center'},
	{headerName: "변경자핸드폰"	, field: "chgerPhnno"	, width: 120	, cellClass: 'text-center', editable: true},
	{
		headerName		: "우편번호"		
		, field			: "chgerZipcode"
		, width			: 220
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var rtnStr = ""
			
			// 2021.06.29 회수지, 배송지 정보 수정 교환, 반품 상세화면 수정 변경
			if (params.data.wdGb == 'W' && (params.data.chgGb == 'G680_30' || params.data.chgGb == 'G680_40')) {
				rtnStr += params.value;
			} else {
				rtnStr += "";
			}

			return rtnStr;
		}
	},
	{headerName: "주소(기본)"		, field: "chgerBaseAddr", width: 220	, cellClass: 'text-left'},
	{headerName: "주소(상세)"		, field: "chgerDtlAddr"	, width: 150	, cellClass: 'text-center'	, editable: true},
	{
		headerName		: "택배사전송"
		, field			: "wdInvoiceSendYn"
		, width			: 120
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			return (params.value == 'N') ? '미전송' : '전송';
		}
	},
	{
		headerName		: "회수지시전송"
		, field			: "wdInvoiceSendYn"
		, width			: 120
		, cellClass		: 'text-center'
	},
	{
		headerName		: "회수송장번호"
		, field			: "wdInvoiceNo"
		, width			: 150
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var retStr = '';
			if (!gagajf.isNull(params.value)) {
				retStr = '<a href="javascript:void(0);" onclick="fnSweetTracker(\'' + params.data.shipCompCd + '\',\'' + params.data.wdInvoiceNo + '\');">' + params.value + '</a>';
			}
			return retStr;
		}
	}
];
var gridOptionsOrderChangeInfo = gagaAgGrid.getGridOptions(columnDefsOrderChangeInfo);

// 7.환불정보
var columnDefsRefundInfo = [
	{headerName: "요청번호"		, field: "ordChgSq"		, width: 80		, cellClass: 'text-center'},
	{headerName: "환불수단"		, field: "payMeansNm"	, width: 80		, cellClass: 'text-center'},
	{headerName: "환불은행(카드)"	, field: "cardNm"		, width: 120	, cellClass: 'text-center'},
	{headerName: "환불은행계좌번호"	, field: "raNo"			, width: 150	, cellClass: 'text-center'},
	{headerName: "예금주"			, field: "raNm"			, width: 80		, cellClass: 'text-center'},
	{
		headerName			: "환불금액"
		, field				: "refundAmt"
		, width				: 100
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			return params.value.addComma();
		}
	},
	{
		headerName		: "환불완료일자"		
		, field			: "updDt"		
		, width			: 140	
		, cellClass		: 'text-center'
		, cellRenderer	: function(params) {
			return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmm").format("YYYY-MM-DD HH:mm") : '';
		}
	},
	{
		headerName		: "변경아이디"		
		, field			: "userId"
		, width			: 120
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var rtnStr = "";
			
			if (params.value != null && params.value != '') {
				rtnStr += params.value;
			} else {
				rtnStr += params.data.custId;
			}
			
			return rtnStr;
		}
	}
];
var gridOptionsRefundInfo = gagaAgGrid.getGridOptions(columnDefsRefundInfo);

// 9.주문메모
var columnDefsOrderMemoInfo = [
	{headerName: "등록일시"		, field: "regDt"	, width: 135	, cellClass: 'text-center'},
	{
		headerName		: "등록자"
		, field			: "regNm"
		, width			: 100
		, cellClass		: 'text-center'
	},
	{
		headerName		: "관리메모"
		, field			: "memo"
		, width			: 150
		, cellClass		: 'text-left'
		, cellRenderer	: function (params) {
			var retStr = '';
			
			if (!gagajf.isNull(params.value)) {
				retStr = '<a href="javascript:void(0);" onclick="fnCreateOrderMemo(\'' + params.data.ordNo + '\',\'' + params.data.ordMemoSq + '\',\'U' + '\');">' + params.value + '</a>';
			}
			return retStr;
		}
	},
	{
		headerName		: "삭제"
		, field			: "ordMemoSq"
		, width			: 80
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var retStr = '';
			
			if (params.data.updNo == userNo) {
				retStr = '<button type="button" class="btn btn-danger" onclick="fnDeleteOrderMemo(\'' + params.data.ordNo + '\',\'' + params.value + '\');"> - </button>';
			}
			return retStr;
		}
	}
];
var gridOptionsOrderMemoInfo = gagaAgGrid.getGridOptions(columnDefsOrderMemoInfo);
</script>

<!-- 버튼 이벤트 바인딩 -->
<script th:inline="javascript">
var _windowWidth 	= $(window).width();		/* 위도우창 넓이 */
var _girdRowH 		= 33;						/* 그리드 Row 줄 높이 */
var _girdRowH1 		= 33;						/* 그리드 타이틀 1줄 짜리 높이*/
var _girdRowH2 		= 62;						/* 그리드 타이틀 2줄 짜리 높이*/
var _scrollH 		= 27;						/* 가로스크롤bar 높이 */

$(window).resize(function () {
	_windowWidth = $(window).width();
	fnSetGridHeightInit();
});

var fnSetGridHeightInit = function () {
	if (_windowWidth < 1780) {
		_girdRowH1 = 33 + _scrollH;
		_girdRowH2 = 80 + _scrollH;
	} else {
		_girdRowH1 = 33
		_girdRowH2 = 80;
	}
}
</script>
<!-- AgGrid 생성 -->
<script th:inline="javascript">
// 팝업닫기
var fnOrderDetailClose = function(){
	uifnPopupClose('popupOrderDetail');
}

$(document).ready(function () {
	
	// 1. 그리드 그리기
	gagaAgGrid.createGrid('gridOrderGoodsInfo'				, gridOptionsGoodsInfo);			// 상품정보
	gagaAgGrid.createGrid('gridOrderFreeGiftInfo'			, gridOptionsOrderFreeGiftInfo);	// 사은품정보
	gagaAgGrid.createGrid('gridDeliveryAddrInfo'			, gridOptionsDeliveryInfo);			// 배송정보
	gagaAgGrid.createGrid('gridPaymentInfo'					, gridOptionsPaymentInfo);			// 결제정보
	gagaAgGrid.createGrid('gridDeliveryFeeInfo'				, gridOptionsDeliveryFeeInfo);		// 배송비정보
	gagaAgGrid.createGrid('gridOrderChangeInfo'				, gridOptionsOrderChangeInfo);		// 취소/반품/교환 요청 정보
	gagaAgGrid.createGrid('gridOrderRefundInfo'				, gridOptionsRefundInfo);			// 환불정보
	gagaAgGrid.createGrid('gridOrderMemoInfo'				, gridOptionsOrderMemoInfo);		// 관리자메모
	
	// 2. 그리드 데이터 바인딩
	gridOptionsGoodsInfo.api.setRowData(orderGoodsInfo);							// 상품정보
	gridOptionsOrderFreeGiftInfo.api.setRowData(orderFreeGiftInfo);					// 사은품품정보
	gridOptionsDeliveryInfo.api.setRowData(orderDeliveryAddrInfo);					// 배송정보
	gridOptionsPaymentInfo.api.setRowData(orderPaymentInfo);						// 결제정보
	gridOptionsDeliveryFeeInfo.api.setRowData(orderDeliveryFeeInfo);				// 배송비정보
	gridOptionsOrderChangeInfo.api.setRowData(orderChangeInfo);						// 취소/반품/교환요청 정보
	gridOptionsRefundInfo.api.setRowData(orderRefundInfo);							// 환불정보
	gridOptionsOrderMemoInfo.api.setRowData(orderAdminMemoInfo);					// 관리자메모
	
	// 2.1 TOTAL ROWS 없애기
	gagaAgGrid.hideStatusBar('gridOrderGoodsInfo');
	gagaAgGrid.hideStatusBar('gridOrderFreeGiftInfo');
	gagaAgGrid.hideStatusBar('gridDeliveryAddrInfo');
	gagaAgGrid.hideStatusBar('gridPaymentInfo');
	gagaAgGrid.hideStatusBar('gridDeliveryFeeInfo');
	gagaAgGrid.hideStatusBar('gridOrderChangeInfo');
	gagaAgGrid.hideStatusBar('gridOrderRefundInfo');
	gagaAgGrid.hideStatusBar('gridOrderMemoInfo');
	
	// 3. 그리드 높이 설정
	fnSetGridHeightInit();
	
	// 4. 그리드 숨김 처리
	if (orderFreeGiftInfo == null || orderFreeGiftInfo.length === 0) {
		$("#wrapOrderFregift").addClass("off");
	}
	
	if (orderChangeInfo == null || orderChangeInfo.length === 0) {
		$("#wrapOrderChange").addClass("off");
	}
	
	if (orderRefundInfo == null || orderRefundInfo.length === 0) {
		$("#wrapRefund").addClass("off");
	}
	
	// 고객정보팝업
	$(".custDetailPop").on("click", function(){
		var custNo = $(this).attr("custNo");
		if (roleCd.indexOf("C") < 0 && parseInt(custNo) > 0) {
			cfnOpenCustDetailPopup(custNo);
		}
	});
});

$(document).ready(function () {
	// 2021.05.11 그리드 높이정보 수정
	var orderGoodsHeight 			= 90 + (33 * orderGoodsCnt);
	var orderFreeGiftHeight 		= 40 + (38 * orderFreeGiftCnt);
	var orderDeliveryAddrHeight 	= 40 + (38 * orderDeliveryAddrCnt);
	var orderChangeHeight 			= 40 + (38 * orderChangeCnt);
	var orderRefundHeight 			= 40 + (38 * orderRefundCnt);
	
	$("#gridOrderGoodsInfo").css("height"		, orderGoodsHeight+"px");
	$("#gridOrderFreeGiftInfo").css("height"	, orderFreeGiftHeight+"px");
	$("#gridDeliveryAddrInfo").css("height"		, orderDeliveryAddrHeight+"px");
	$("#gridOrderChangeInfo").css("height"		, orderChangeHeight+"px");
	$("#gridOrderRefundInfo").css("height"		, orderRefundHeight+"px");

	$('#orderDetailContents').css("width", "97%").css("height", "96%");
	
	// 메모등록
	$('#btnCreateOrderMemo').on('click', function () {
		fnCreateOrderMemo(ordNo, 0, 'N');
	});
	// 배송 정보 수정
	$('#btnUpdateOrderAddr').on('click', function () {
		fnUpdateOrderAddr();
	});
});
</script>

<!-- function -->
<script th:inline="javascript">
var gridOrderChangeInfoSelectedIdx = '';

// 배송지변경
var fnUpdateOrderAddr = function (rowIdx) {	
	gridOptionsDeliveryInfo.api.stopEditing();
	var jsonData = JSON.stringify(gridOptionsDeliveryInfo.api.getRowNode(rowIdx).data);
	
	mcxDialog.confirm("주소를 변경하시겠습니까?", {
		cancelBtnText	: "취소",
		sureBtnText		: "확인",
		sureBtnClick	: function () {
			gagajf.ajaxJsonSubmit(
				"/order/deliver/addr/update"
				, jsonData
				, function () {
					
				}
			);
		}
	});
}

// 2021.01.25 추가
// 취소요청, 교환요청, 반품요청 일때는 요청 정보 확인 팝업 정보
var fnCancelRequest = function (paramData, ordChgSq) {
	// 취소요청 구분 (orChgSq null 이면 취소요청화면 있으면 취소요청정보화면)
	if (ordChgSq == null) {
		ordChgSq = 0;
	}
	
	var paramArr 	= paramData.split("@");
	var param 		= "";
	param += "&ordNo=" 			+ paramArr[0];
	param += "&ordDtlNo=" 		+ paramArr[1];
	param += "&delvFeeCd="		+ paramArr[2];
	param += "&delvFeeCdGrp="	+ paramArr[3];
	param += "&chgStat="		+ paramArr[4];
	param += "&ordChgSq=" 		+ ordChgSq;
	
	var actionUrl = "/orderChange/cncl/req/form?" + param;
	
	// 2021.06.30 취소완료일때 취소완료정보 조회
	if (paramArr[4] == "G685_17" || paramArr[4] == "G685_18") {
		actionUrl = "/orderChange/cnclRtn/complete/view?" + param;	
	}

	cfnOpenModalPopup(actionUrl, 'popupCancelRequestForm');
	
	return false;
};

//2021.01.25 추가
// 반품요청
var fnReturnRequest = function (paramData, ordChgSq) {
	
	// 취소요청 구분 (orChgSq null 이면 취소요청화면 있으면 취소요청정보화면)
	if (ordChgSq == null) {
		ordChgSq = 0;
	}
	
	var param 		= "";
	var paramArr 	= paramData.split("@");
	param += "&ordNo=" 			+ paramArr[0];
	param += "&ordDtlNo=" 		+ paramArr[1];
	param += "&delvFeeCd="		+ paramArr[2];
	param += "&delvFeeCdGrp="	+ paramArr[3];
	param += "&chgStat="		+ paramArr[4];
	param += "&ordChgSq=" 		+ ordChgSq;

	var actionUrl = "/orderChange/rtn/req/form?" + param;
	
	// 2021.06.30 취소완료일때 취소완료정보 조회
	if (paramArr[4] == "G685_60") {
		actionUrl = "/orderChange/cnclRtn/complete/view?" + param;
	}
	
	cfnOpenModalPopup(actionUrl, 'popupReturnRequestForm');
};

// 교환요청
var fnExchangeRequest = function (paramData, ordChgSq) {
	// 취소요청 구분 (orChgSq null 이면 취소요청화면 있으면 취소요청정보화면)
	if (ordChgSq == null) {
		ordChgSq = 0;
	}
	
	var paramArr 	= paramData.split("@");
	var param 		= "";
	param += "&ordNo=" 			+ paramArr[0];
	param += "&ordDtlNo=" 		+ paramArr[1];
	param += "&delvFeeCd="		+ paramArr[2];
	param += "&delvFeeCdGrp="	+ paramArr[3];
	param += "&chgStat="		+ paramArr[4];
	param += "&ordChgSq=" 		+ ordChgSq;
	//param += "&ordChgGb=G681_20";
	var actionUrl = "/orderChange/exchange/request/form?" + param;
	cfnOpenModalPopup(actionUrl, 'popupExchangeRequestForm');
};

// 반품요청 철회
var fnReturnReqeustCancel = function (ordChgSq, ordDtlNo, rowIdx) {
	mcxDialog.confirm('반품요청을 철회하시겠습니까?', {
		cancelBtnText	: "취소",
		sureBtnText		: "확인",
		sureBtnClick	: function () {
			var data = new Object();
			data.ordChgSq = ordChgSq;
			data.ordDtlNo = ordDtlNo;
			
			var jsonData = JSON.stringify(data);
			gagajf.ajaxJsonSubmit(
				'/order/return/request/cancel'
				, jsonData
				, function (result) {
					if (result.message != '회수컨펌 된 내역이 있습니다.') {
						var selectedRow = gridOptionsOrderChangeInfo.api.getRowNode(rowIdx).data;
						gridOptionsOrderChangeInfo.api.updateRowData({remove: [selectedRow]});
					}
				}
			);
		}
	});
};

// 교환요청 철회
var fnExchangeReqeustCancel = function (ordChgSq, ordNo, ordDtlNo, rowIdx) {
	mcxDialog.confirm('교환요청을 취소하시겠습니까?', {
		cancelBtnText	: "취소",
		sureBtnText		: "확인",
		sureBtnClick	: function () {
			var data = new Object();
			data.ordNo 		= ordNo;
			data.ordDtlNo 	= ordDtlNo;
			data.ordChgSq 	= ordChgSq;
			
			var jsonData = JSON.stringify(data);
			gagajf.ajaxJsonSubmit(
				'/order/exchange/request/cancel'
				, jsonData, function () {
					uifnPopupClose('popupOrderDetail');
					fnReOpenOrderDetailPopup();
				}
			);
		}
	});
};

// 주문상품 상세 변경 이력 팝업
var fnOrderDetailChangeHst = function (ordDtlNo) {
	var actionUrl = "/order/detail/change/hst/form/" + ordDtlNo;
	cfnOpenModalPopup(actionUrl, 'popupOrderDetailChangeHstForm');
};

// 쿠폰내역 팝업
var fnOrderCouponHst = function (ordNo) {
	var actionUrl = "/order/detail/coupon/hst/form/" + ordNo;
	cfnOpenModalPopup(actionUrl, 'popupOrderDetailCouponHstForm');
};

// 다다익선내역 팝업
var fnOrderTmtbHst = function (ordNo) {
	var actionUrl = "/order/detail/tmtb/hst/form/" + ordNo;
	cfnOpenModalPopup(actionUrl, 'popupOrderDetailTmtbHstForm');
};

// 포인트내역 팝업
var fnOrderPointHst = function (ordNo) {
	var actionUrl = "/order/detail/point/hst/form/" + ordNo;
	cfnOpenModalPopup(actionUrl, 'popupOrderDetailPointHstForm');
};

// 상품권내역 팝업
var fnOrderGiftcardHst = function (ordNo) {
	var actionUrl = "/order/detail/giftcard/hst/form/" + ordNo;
	cfnOpenModalPopup(actionUrl, 'popupOrderDetailGiftcardHstForm');
};

// 관리자메모 등록
var fnCreateOrderMemo = function (ordNo, seq, mode) {
	var actionUrl = "/order/memo/create/form?ordNo=" + ordNo + "&seq=" + seq + "&mode=" + mode;
	cfnOpenModalPopup(actionUrl, 'popupCreateOrderMemo');
};

// 환불계좌 등록
var fnCreateOrderRfAccount = function (ordNo, custNo) {
	var actionUrl = "/order/refund/account/create/form?ordNo=" + ordNo + "&custNo="+custNo;
	cfnOpenModalPopup(actionUrl, 'popupCreateRefundAccount');
};

// 주문메모 삭제
var fnDeleteOrderMemo = function (ordNo, orderMemoSq) {
	mcxDialog.confirm('삭제하시겠습니까?', {
		cancelBtnText	: "취소",
		sureBtnText		: "확인",
		sureBtnClick	: function () {
			var data = new Object();
			data.ordNo 	= ordNo;
			data.seq 	= orderMemoSq;
			
			var jsonData = JSON.stringify(data);
			gagajf.ajaxJsonSubmit(
				'/order/memo/delete'
				, jsonData
				, function () {
					fnBindOrderMemo();
				}
			);
		}
	});
}

// 주문메모 바인딩
var fnBindOrderMemo = function() {
	gagaAgGrid.fetch(
		"/order/admin/memo/list/" + ordNo
		, gridOptionsOrderMemoInfo
		, null
		, function (result) {
		}
	);
};

// 주문 변경요청정보 바인딩
var fnBindOrderChangeInfo = function() {
	gagaAgGrid.fetch(
		"/order/return/info/list/" + ordNo
		, gridOptionsOrderChangeInfo
		, null
		, function (result) {
			$('#gridOrderChangeInfo').css('height', 31 + 33 * ((result.length == 0 || result == null) ? 1 : result.length));
		}
	);
};

// 배송비 DATA 바인딩
var fnBindDeliveryAddr = function(delvAddrSq) {
	if (typeof (delvAddrSq) != 'undefined') {
		var strLink = '/order/deliver/addr/info/' + delvAddrSq;
		var jsonData = JSON.stringify([]);
		gagajf.ajaxJsonSubmit(strLink, jsonData, fnBindDeliveryAddrCallBack);
	}
};

// 배송정보
var fnBindDeliveryAddrCallBack = function(result) {
	gridOptionsDeliveryInfo.api.setRowData(result);
};

// 변경요청 > 회수지정보 저장
var fnSaveChgerAddr = function (rowIdx) {
	gridOptionsOrderChangeInfo.api.stopEditing();
	
	var jsonData = JSON.stringify(gridOptionsOrderChangeInfo.api.getRowNode(rowIdx).data);
	
	mcxDialog.confirm("주소를 변경하시겠습니까?", {
		cancelBtnText	: "취소",
		sureBtnText		: "확인",
		sureBtnClick	: function () {
			gagajf.ajaxJsonSubmit(
				"/order/change/info/addr/update"
				, jsonData
				, function () {
					
				}
			);
		}
	});
}

// LMS 전송
var fnOpenLmsForm = function (orderPhnno, custNo) {
	if (gagajf.isNull(custNo) && gagajf.isNull(orderPhnno)) {
		mcxDialog.alert("정보가 올바르지 않습니다.");
		return false;
	}

	$('#orderDetailInfo input[name=orderPhnno]').val(orderPhnno);
	$('#orderDetailInfo input[name=custNo]').val(custNo);

	var param = {};
	param.elementCellPhnno = '#orderDetailInfo input[name=orderPhnno]';
	param.elementCustNo = '#orderDetailInfo input[name=custNo]';
	cfnOpenLmsPopup(param);
};

// EMAIL 전송
var fnOpenEmailForm = function (orderEmail, orderNm, custNo) {
	if (gagajf.isNull(orderEmail) && gagajf.isNull(orderNm) && gagajf.isNull(custNo)) {
		mcxDialog.alert("정보가 올바르지 않습니다.");
		return false;
	}
	$('#orderDetailInfo input[name=orderEmail]').val(orderEmail);
	$('#orderDetailInfo input[name=orderNm]').val(orderNm);
	$('#orderDetailInfo input[name=custNo]').val(custNo);

	var param = {};
	param.elementRecipEmail = '#orderDetailInfo input[name=orderEmail]';
	param.elementCustNm = '#orderDetailInfo input[name=orderNm]';
	param.elementCustNo = '#orderDetailInfo input[name=custNo]';

	cfnOpenEmailPopup(param);
};

// 송장조회
var fnSearchDelivery = function (url, invoiceNo) {
	var fullUrl = url + invoiceNo;
	window.open(fullUrl, '_blank');
};

// 2021.06.17스윗트래커 송장조회
var fnSweetTracker = function (shipCompCd, invoiceNo) {
	var actionUrl = "/order/delivery/sweetTrackerDeliveryInfo?shipCompCd=" + shipCompCd + "&invoiceNo=" + invoiceNo;
	cfnOpenModalPopup(actionUrl, 'popupSweetTrackerDeliveryInfo');
	
};


// 카드전표 영수증 조회
var fnReceiptPage = function (tid) {
	var fullUrl = "https://npg.nicepay.co.kr/issue/IssueLoader.do?TID=" + tid + "&type=0";
	window.open(fullUrl, '_blank');
};

// 구매확정철회
var fnChangedCompleteDelivery = function (ordNo, ordDtlNo, ordDtlStat) {
	if ('70' !== ordDtlStat) {
		mcxDialog.alert("구매확정철회는 구매확정인 상태여만 가능합니다.");
		return false;
	}
	
	var data = {};
	data.ordDtlNo = ordDtlNo;
	data.ordNo = ordNo;
	var jsonData = JSON.stringify(data);
	
	gagajf.ajaxJsonSubmit('/order/check/status', jsonData, fnChangedCompleteDeliveryCallback);
};

var fnChangedCompleteDeliveryCallback = function (result) {
	// 구매확정 처리 가능 하지 않으면 얼럿 노출 끝
	if (!result.isPossible) {
		mcxDialog.alert("구매확정철회는 구매확정인 상태여만 가능합니다.");
		return false;
	} else {
		mcxDialog.confirm("구매확정 철회 하시겠습니까? <br> 지급된 포인트에 대한 처리는 별도로 하셔야 합니다. ", {
			cancelBtnText	: "취소",
			sureBtnText		: "확인",
			sureBtnClick	: function () {
				var data = {};
				data.ordDtlNo = result.ordDtlNo;
				data.ordNo = result.ordNo;
				
				var jsonData = JSON.stringify(data);
				gagajf.ajaxJsonSubmit(
					'/order/complete/delivery/changed'
					, jsonData
					, function (result) {
						uifnPopupClose('popupOrderDetail');
						fnReOpenOrderDetailPopup();
					}
				);
			}
		});
	}
};

// 주문상세 상태값 변경
var fnChangOrdDtlStat = function (obj) {
	var ordNo 			= $(obj).attr("ordNo");
	var ordDtlNo 		= $(obj).attr("ordDtlNo");
	var ordDtlStat 		= $(obj).val();
	var ordDtlStatNm 	= $(obj).children("option:selected").text();
	var strConfirm		= "주문상태를 " + ordDtlStatNm + "(으)로 변경 하시겠습니까?"
	
	mcxDialog.confirm(strConfirm, {
		cancelBtnText	: "취소",
		sureBtnText		: "확인",
		sureBtnClick	: function () {
			var data = new Object();
			data.ordNo			= ordNo;
			data.ordDtlNo 		= ordDtlNo;
			data.ordDtlStat 	= ordDtlStat;

			var jsonData = JSON.stringify(data);
			gagajf.ajaxJsonSubmit(
				'/order/detail/ordDtlStat/changed'
				, jsonData
				, function (result) {
					uifnPopupClose('popupOrderDetail');
					fnReOpenOrderDetailPopup();
				}
			);
		}
	});
};

// DAUM을 이용한 우편번호 팝업 레이어
var fnOpenDaumAddr = function(idx, addrGb) {
		
	let daumZip = new daum.Postcode({
		oncomplete: function(data) {
			// 배송지주소 수정
			if ("ADDR" == addrGb) {
				gridOptionsDeliveryInfo.api.gre
				gridOptionsDeliveryInfo.api.getRowNode(idx).data.recipZipcode 		= data.zonecode;
				gridOptionsDeliveryInfo.api.getRowNode(idx).data.recipBaseAddr 		= cfnGetDaumRoadAddr(data);
				gridOptionsDeliveryInfo.api.getRowNode(idx).data.recipDtlAddr 		= "";
				gridOptionsDeliveryInfo.api.refreshCells();
			}
			// 회수지주소 수정
			else {
				gridOptionsOrderChangeInfo.api.getRowNode(idx).data.chgerZipcode	= data.zonecode;
				gridOptionsOrderChangeInfo.api.getRowNode(idx).data.chgerBaseAddr 	= cfnGetDaumRoadAddr(data);
				gridOptionsOrderChangeInfo.api.getRowNode(idx).data.chgerDtlAddr 	= "";
				gridOptionsOrderChangeInfo.api.refreshCells();
			}
			
			cfnCloseDaumAddr();
		},
		width: '100%'
	});
	
	cfnOpenDaumAddr(daumZip);
}


// 2021.06.17 구성상품 내역 팝업 호출 
var fnOrderDetailItemForm = function (ordDtlNo) {
	var actionUrl = "/delivery/detail/item/form/" + ordDtlNo;
	cfnOpenModalPopup(actionUrl, 'popupDeliveryDetailItemForm');
}
</script>

</html>





