<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : OrderListForm.html
 * @desc    : 주문상세화면
 *============================================================================
 * SISUN
 * 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>
				<div id="gridOrderInfo" style="width:100%; height:100px;" class="ag-theme-balham"></div>
									
				<h4>주문상품정보</h4>
				<button type="button" class="btn btnRight btn-base btn-sm" id="btnExchange" style="margin-left:10px;" >교환요청</button>
				<button type="button" class="btn btnRight btn-base btn-sm" id="btnReturn">반품요청</button>
				<button type="button" class="btn btnRight btn-base btn-sm" id="btnCancel">취소요청</button>
				<div id="gridOrderGoodsInfo" style="width:100%; height:200px;" class="ag-theme-balham"></div>
				
				<h4>주문사은품정보</h4>
				<button type="button" class="btn btnRight btn-base btn-sm" id="btnFreeGiftCancel" style="margin-left:10px;" >사은품취소</button>
				<div id="gridOrderFreeGiftInfo" style="width:100%; height:120px;" class="ag-theme-balham"></div>
				
				<h4>배송정보</h4>
				<button type="button" style="margin-left:10px;" class="btn btnRight btn-base btn-sm" id="btnUpdateOrderAddr">수정</button>
				<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="">
								<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: 100px; 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>

				<table style="width:100%;">
					<colgroup>
						<col style="width:65%;"/>
						<col/>
					</colgroup>
					<tbody>
						<tr>
							<td style="">
								<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 goodsCpnDcAmtClass 		= (orderGoodsInfo[0].goodsCpnDcAmt > 0) 	? 'bgPink' : 'text-right';
var cartCpnDcAmtClass 		= (orderGoodsInfo[0].cartCpnDcAmt > 0) 		? 'bgPink' : 'text-right';
var plusCpnDcAmtClass 		= (orderGoodsInfo[0].plusCpnDcAmt > 0) 		? 'bgPink' : 'text-right';
var pntDcAmtClass 			= (orderGoodsInfo[0].pntDcAmt > 0) 			? 'bgPink' : 'text-right';
var prePntDcAmtClass 		= (orderGoodsInfo[0].prePntDcAmt > 0) 		? 'bgPink' : 'text-right';
var savePntAmtClass 		= (orderGoodsInfo[0].savePntAmt > 0) 		? 'bgSky' : 'text-right';

var custNo 					= orderInfo[0].custNo;
var payMeans 				= orderInfo[0].payMeans;
var mallGb 					= orderInfo[0].mallGb;
</script>

<!-- AgGrid 컬럼 세팅 -->
<script>
// 공통1. 주문상세 그리드 옵션 정보 적용
var orderAgGrid = {
	getGridOptions : function(colDefs) {
		return {
			columnDefs					: colDefs
			, detailCellRendererParams	: {
				detailGridOptions	: {
					columnDefs				: []
					, defaultColDef			: {
						resizable: true
					}
					, suppressLoadingOverlay: false
					, onGridReady			: function (params) {
						params.api.setDomLayout('autoHeight');
					}
					, onFirstDataRendered	: function (params) {
						params.api.sizeColumnsToFit();
					}
				}
				, getDetailRowData: function (params) {
					params.successCallback(params.data.orderDetailList);
				}
			}
			, defaultColDef: {
				resizable: true
			}
			, isRowMaster: function (dataItem) {
				return dataItem ? dataItem.orderDetailList.length > 1 : false;
			}
			, suppressRowTransform: true
			, enableRangeSelection: true
		};
	}
}

// 1.주문기본정보 그리드 바인딩
var columnDefsOrderInfo = [
	{
		headerName			: "사이트"
		, field				: "siteCd"
		, width				: 100
		, cellClass			: 'text-center'
		, valueFormatter	: function (params) {
			return gagaAgGrid.lookupValue(siteCdList, params.value);
		}
	},
	{headerName: "몰구분"		, field: "mallGbNm"		, width: 80		, cellClass: 'text-center'},
	{headerName: "웹구분"		, field: "frontGbNm"	, width: 80		, cellClass: 'text-center'},
	{headerName: "외부몰"		, field: "extmallNm"	, width: 80		, cellClass: 'text-center'},
	{
		headerName			: "주문일시"	
		, field				: "ordDt"
		, 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: "ordNm"		, width: 80		, cellClass: 'text-center'},
	{
		headerName			: "고객번호"
		, field				: "custNo"
		, width				: 100
		, cellClass			: 'text-center'
		, valueFormatter	: function (params) {
			return (params.data.mallGb == '20') ? '' : params.value;
		}
	},
	{headerName: "주문번호", field: "ordNo", width: 100, cellClass: 'text-center'},
	{
		headerName			: "이메일"
		, field				: "ordEmail"
		, width				: 240
		, cellClass			: 'text-center'
		, cellRenderer		: function (params) {
			return params.value ? params.value + '&nbsp&nbsp<button type="button" class="btn btn-base btn-sm" onclick="fnOpenEmailForm(\'' + params.data.orderEmail + '\',\'' + params.data.orderNm + '\',\'' + params.data.custNo + '\');"> 메일발송 </button>' : '';
		}
	},
	{
		headerName			: "핸드폰번호"
		, field				: "ordPhnno"
		, width				: 220
		, cellClass			: 'text-center'
		, cellRenderer		: function (params) {
			return params.value + '&nbsp&nbsp<button type="button" class="btn btn-base btn-sm" onclick="fnOpenLmsForm(\'' + params.data.orderPhnno + '\',\'' + params.data.custNo + '\');"> LMS발송 </button>';
		}
	},
	{headerName: "회원구분"	, field: "custGbNm"		, width: 80		, cellClass: 'text-center'},
	{headerName: "관리대상"	, field: "managedRsnNm"	, width: 80		, cellClass: 'text-center'},
	{headerName: "등급"		, field: "custGradeNm"	, width: 80		, cellClass: 'text-center'}
];
var gridOptionsOrderInfo = orderAgGrid.getGridOptions(columnDefsOrderInfo);

// 2.상품별 상세정보
var columnDefsGoodsInfo = [
	{
		headerName	: "상품정보",
		children	: [
			{headerName: "상품코드"	, field: "goodsCd"		, width: 110, cellClass: 'text-center'},
			{
				headerName		: "상품명"
				, field			: "goodsNm"
				, width			: 180
				, 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: 100, cellClass: 'text-center'},
			{headerName: "브랜드"		, field: "brandEnm"		, width: 100, cellClass: 'text-center'},
			{headerName: "단품코드"	, field: "itemCd"		, width: 100, cellClass: 'text-center'},
			{
				headerName		: "단품명"
				, field			: "itemNm"
				, width			: 180
				, cellClass		: 'text-left'
				, cellRenderer: function (params) {
					return '<a href="javascript:void(0);" onclick="cfnOpenFrontGoodsPopup(\'' + params.data.itemCd + '\',\'' + params.data.siteCd + '\');">' + params.value + '</a>';
				}
			},
			{headerName: "칼라"		, field: "optCd1"		, width: 80, cellClass: 'text-center'},
			{headerName: "사이즈"		, field: "optCd2"		, width: 80, cellClass: 'text-center'},
			{headerName: "단품수량"	, field: "itemQty"		, width: 80, cellClass: 'text-center'},
			{
				headerName		: "단품금액"
				, field			: "itemPrice"
				, width			: 100
				, cellClass		: 'text-right' //cartCpnDcAmtClass
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "옵션추가금액"
				, field			: "optAddPrice"
				, width			: 100
				, cellClass		: 'text-right' //cartCpnDcAmtClass
				, cellRenderer	: function (params) {
					return params.value.addComma();
				}
			}
		]
	},
	{
		headerName	: "주문상세",
		children	: [
			{headerName: "주문상세번호"	, field: "ordDtlNo"		, width: 120, cellClass: 'text-center'},
			{
				headerName		: "주문상세상태"
				, field			: "ordDtlStatNm"
				, width			: 120
				, cellClass		: 'text-left'
				, 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	: "수량",
		children	: [
			{headerName: "주문"		, field: "itemOrdQty"		, width: 60, cellClass: 'text-center'},
			{headerName: "취소"		, field: "itemCnclRtnQty"	, width: 60, cellClass: 'text-center'}
		]
	},
	{
		headerName	: "쿠폰",
		children	: [
			{
				headerName		: "즉시할인"
				, field			: "cpn1DcAmt"
				, width			: 70
				, cellClass		: 'text-right' //goodsCpnDcAmtClass
				, cellRenderer: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderCouponHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			},
			{
				headerName		: "상품"
				, field			: "goodsCpnDcAmt"
				, width			: 70
				, cellClass		: 'text-right' //goodsCpnDcAmtClass
				, cellRenderer: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderCouponHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			},
			{
				headerName		: "장바구니"
				, field			: "cartCpnDcAmt"
				, width			: 70
				, cellClass		: 'text-right' //cartCpnDcAmtClass
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderCouponHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			}
		]
	},
	{
		headerName	: "다다익선",
		children	: [
			{
				headerName		: "수량"
				, field			: "tmtb1DcAmt"
				, width			: 70
				, 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			: 70
				, 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			: 60
				, cellClass		: 'text-right' //pntDcAmtClass
				, 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' //prePntDcAmtClass
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderPointHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			},
			{
				headerName		: "적립"
				, field			: "savePntAmt"
				, width			: 60
				, cellClass		: 'text-right' //savePntAmtClass
				, 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' //pntDcAmtClass
				, cellRenderer	: function (params) {
					return "<a href=\"javascript:void(0);\" onclick=\"fnOrderGiftcardHst('" + params.data.ordNo + "');\">" + params.value.addComma() + "</a>";
				}
			}
		]
	},
	{
		headerName	: "금액(원/단위)",
		children	: [
			{
				headerName		: "판매"
				, field			: "ordAmt"
				, width			: 70
				, cellClass		: 'text-right'
				, valueFormatter: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "실결제"
				, field			: "realOrdAmt"
				, width			: 70
				, cellClass		: 'text-right'
				, valueFormatter: function (params) {
					return params.value.addComma();
				}
			},
			{
				headerName		: "취소"
				, field			: "cnclRtnAmt"
				, width			: 70
				, cellClass		: 'text-right'
				, valueFormatter: function (params) {
					return params.value.addComma();
				}
			},
		]
	},
	{headerName: "결품", field: "soldoutYn", width: 60, cellClass: 'text-center'},
	{
		headerName	: "배송",
		children	: [
			{
				headerName		: "송장번호"
				, field			: "invoiceNo"
				, width			: 100
				, 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>';
					return retStr;
				}
			},
			{headerName: "출고처", field: "delvLocNm", width: 120, cellClass: 'text-center'}
		]
	}
];
var gridOptionsGoodsInfo = orderAgGrid.getGridOptions(columnDefsGoodsInfo);

// 2.5 주문사은품정보
var columnDefsOrderFreeGiftInfo = [
	{headerName: "주문사은품번호"	, field: "ordFreegiftSq"	, width: 100, cellClass: 'text-center', hide: true},
	{headerName: "주문번호"		, field: "ordNo"			, width: 100, cellClass: 'text-center'},
	{headerName: "사은품프로모션"	, field: "freegiftSq"		, width: 100, cellClass: 'text-center', hide: true},
	{headerName: "사은품프로모션명"	, field: "freegiftNm"		, width: 200, cellClass: 'text-center'},
	{headerName: "사은품혜택번호"	, field: "freegiftValSq"	, width: 100, cellClass: 'text-center', hide: true},
	{
		headerName			: "사용포인트"		
		, field				: "usePoint"			
		, width				: 100
		, cellClass			: 'text-right'
		, valueFormatter	: function (params) {
			return params.value.addComma();
		}
	},
	{headerName: "사은품코드"		, field: "itemCd"			, width: 100, cellClass: 'text-center'},
	{headerName: "사은품명"		, field: "itemNm"			, width: 100, cellClass: 'text-center'},
	{headerName: "사은품수량"		, field: "itemQty"			, width: 100, cellClass: 'text-center'},
	{headerName: "옵션명"			, field: "optCd"			, width: 100, cellClass: 'text-center'},
	{headerName: "옵션코드1"		, field: "optCd1"			, width: 100, cellClass: 'text-center'},
	{headerName: "옵션코드2"		, field: "optCd2"			, width: 100, cellClass: 'text-center'},
	{headerName: "삭제여부"		, field: "delYn"			, width: 100, cellClass: 'text-center'}
];
var gridOptionsOrderFreeGiftInfo = orderAgGrid.getGridOptions(columnDefsOrderFreeGiftInfo);

// 3.배송정보
var columnDefsDeliveryInfo = [
	{headerName: "배송지번호"		, field: "delvAddrSq"	, width: 100, 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: "recipTelno"	, width: 120, cellClass: 'text-left', editable: true},
	{
		headerName		: "우편번호"		
		, field			: "recipZipNo"
		, width			: 200
		, cellClass		: 'text-left'
		, cellRenderer	: function (params) {
			return params.value + "<button type=\"button\" style=\"margin-left:10px\" class=\"btn btn-info\" onclick=\"cfnOpenPostFindPopup('grid');\">우편번호찾기</button>";
		}
	},
	{headerName: "주소(기본)"		, field: "recipBaseAddr"	, width: 350, cellClass: 'text-left'},
	{headerName: "주소(상세)"		, field: "recipDtlAddr"		, width: 200, cellClass: 'text-left', editable: true},
	{headerName: "배송메모"		, field: "delvMemo"			, width: 280, cellClass: 'text-left', editable: true}
];
var gridOptionsDeliveryInfo = orderAgGrid.getGridOptions(columnDefsDeliveryInfo);

// 4.결제정보
var columnDefsPaymentInfo = [
	{headerName: "에스크로여부"		, field: "escrowYn"		, width: 100	, cellClass: 'text-center'},
	{headerName: "결제수단"		, field: "payMeansNm"	, width: 100	, cellClass: 'text-center'},
	{
		headerName		: "카드(은행)"
		, field			: "cardNm"
		, width			: 100
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			if (params.data.payMeans == '20') {
				return params.data.vaNm;
			} else if (params.data.payMeans == '10' || params.data.payMeans == '30') {
				return params.data.cardNm;
			}
		}
	},
	{
		headerName		: "할부(입금계좌)"
		, field			: "cardMips"
		, width			: 120
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			if (params.data.payMeans == '20') {
				return params.data.vaNo;
			} else if (params.data.payMeans == '10') {
				return params.value;
			}
		}
	},
	{
		headerName		: "승인번호"
		, field			: "pgTradeNo"
		, width			: 80
		, 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>';
			}

			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: "vaDeadline"	, width: 150	, cellClass: 'text-center'}
];
var gridOptionsPaymentInfo = orderAgGrid.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: "delvUsacYn", width: 120, cellClass: 'text-center'},
	{
		headerName			: "배송비정산일시"	
		, field				: "delvUsacDt"
		, width				: 180
		, cellClass			: 'text-center' 
		, cellRenderer: function(params) {
			return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmm").format("YYYY-MM-DD HH:mm") : '';
		}
	}
];
var gridOptionsDeliveryFeeInfo = orderAgGrid.getGridOptions(columnDefsDeliveryFeeInfo);

// 6. 반품/교환 정보
var columnDefsOrderChangeInfo = [
	{headerName: "요청번호"		, field: "ordChgSq"		, width: 60		, cellClass: 'text-center'},
	{headerName: "요청구분"		, field: "chgGbNm"		, width: 75		, cellClass: 'text-center'},
	{headerName: "상품코드"		, field: "goodsCd"		, width: 100	, cellClass: 'text-center'},
	{headerName: "사이즈"			, field: "sizeCd"		, width: 50		, cellClass: 'text-center'},
	{headerName: "수량"			, field: "chgQty"		, width: 40		, cellClass: 'text-center'},
	{headerName: "요청상태"		, field: "chgStatNm"	, width: 80		, cellClass: 'text-center'},
	{
		headerName		: "요청일자"		
		, field			: "chgRegDt"		
		, width			: 90		
		, 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: "chgMemo"		, width: 120	, cellClass: 'text-center'},
	{headerName: "변경자명"		, field: "chgerNm"		, width: 70		, cellClass: 'text-center'},
	{headerName: "변경자핸드폰"		, field: "chgerPhnno"	, width: 105	, cellClass: 'text-center', editable: true},
	{headerName: "우편번호"		, field: "chgerPostNo"	, width: 60		, cellClass: 'text-center'},
	{
		headerName		: "주소(기본)"
		, field			: "chgerBaseAddr"
		, width			: 250
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var retStr = "";

			if (params.data.wdInvoiceSendYn == 'N') {
				retStr += "<button type=\"button\" class=\"btn btn-info\" onclick=\"fnOpenPostFindPopup('" + params.node.rowIndex + "');\">POST</button>";
				retStr += "<button type=\"button\" class=\"btn btn-info\" onclick=\"fnSaveChgerAddr('" + params.node.rowIndex + "');\">저장</button>";
			}

			retStr += (gagajf.isNull(params.value)) ? '' : (gagajf.isNull(params.data.chgerDtlAddr)) ? params.value : params.value + params.data.chgerDtlAddr;
			return retStr;
		}
	},
	{headerName: "주소(상세)"		, field: "chgerDtlAddr"	, width: 105	, cellClass: 'text-center'	, editable: true},
	{
		headerName		: "택배사전송"
		, field			: "wdInvoiceSendYn"
		, width			: 70
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			return (params.value == 'N') ? '미전송' : '전송';
		}
	},
	{
		headerName		: "요청취소"
		, field			: "ordDtlNo"
		, width			: 100
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			var retStr = "";

			if (params.data.chgGb == "30" && params.data.chgStat == "40") {
				retStr = ' <button type="button" class="btn btn-success" onclick="fnReturnReqeustCancel(\'' + params.data.ordChgSq + '\',\'' + params.value + '\',\'' + params.node.rowIndex + '\');"> 반품취소 </button>';
			} else if (params.data.chgGb == "40" && params.data.chgStat == "30") {
				retStr = ' <button type="button" class="btn btn-success" onclick="fnExchangeReqeustCancel(\'' + params.data.ordChgSq + '\',\'' + ordNo + '\',\'' + params.value + '\',\'' + params.node.rowIndex + '\');"> 교환취소 </button>';
			} else if (params.data.chgGb == "20" && params.data.chgStat == "20") {
				//retStr = '<button type="button" class="btn btn-success" onclick="fnCancelConfirmRequestCancel(\'' + params.data.ordChgSq + '\')">요청철회 </button>';
			}

			return retStr;
		}
	},
	{
		headerName		: "회수지시전송"
		, field			: "wdInvoiceSendYn"
		, width			: 90
		, cellClass		: 'text-center'
	},
	{headerName: "회수송장번호", field: "wdInvoiceNo", width: 90, cellClass: 'text-center'}
];
var gridOptionsOrderChangeInfo = orderAgGrid.getGridOptions(columnDefsOrderChangeInfo);

// 7.환불정보
var columnDefsRefundInfo = [
	{headerName: "환불수단"		, field: "payMeansNm"	, width: 80		, cellClass: 'text-center'},
	{headerName: "환불은행(카드)"	, field: "raBank"		, width: 100	, cellClass: 'text-center'},
	{headerName: "환불은행계좌번호"	, field: "raNo"			, width: 100	, 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			: "regDt"		
		, 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: "regNo"		, width: 80		, cellClass: 'text-center'}
];
var gridOptionsRefundInfo = orderAgGrid.getGridOptions(columnDefsRefundInfo);

// 8.상담내역
var columnDefsOrderCounselInfo = [
	{headerName: "상담구분"		, field: "counselClsfNm"	, width: 120	, cellClass: 'text-center'},
	{headerName: "상품코드"		, field: "goodsCd"			, width: 120	, cellClass: 'text-center'},
	{
		headerName		: "질문제목"
		, field			: "questTitle"
		, width			: 400
		, cellClass		: 'text-center'
		, cellRenderer	: function (params) {
			return '<a href="javascript:void(0);" onclick="cfnOpenOneToOneAskDetailPopup(\'' + params.data.counselSq + '\')">' + params.value + '</a>';
		}
	},
	{
		headerName		: "등록일"			
		, field			: "questDt"	
		, width			: 120	
		, cellClass		: 'text-center'
		, cellRenderer	: function(params) {
			return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmm").format("YYYY-MM-DD HH:mm") : '';
		}
	},
	{
		headerName		: "답변일"			
		, field			: "ansDt"	
		, width			: 120	
		, cellClass		: 'text-center'
		, cellRenderer	: function(params) {
			return !gagajf.isNull(params.value) ? params.value.toDate("YYYYMMDDHHmm").format("YYYY-MM-DD HH:mm") : '';
		}
	},
	{headerName: "답변자"			, field: "ansNm"	, width: 80		, cellClass: 'text-center'},
	{headerName: "삭제여부"		, field: "delYn"	, width: 80		, cellClass: 'text-center'}
];
var gridOptionsOrderCounselInfo = orderAgGrid.getGridOptions(columnDefsOrderCounselInfo);

// 9.주문메모
var columnDefsOrderMemoInfo = [
	{headerName: "등록일시"		, field: "regDt"	, width: 135	, cellClass: 'text-center'},
	{
		headerName		: "등록자"
		, field			: "regNm"
		, width			: 130
		, cellClass		: 'text-center'
	},
	{
		headerName		: "관리메모"
		, field			: "memo"
		, width			: 250
		, 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.orderMemoSq + '\',\'U' + '\');">' + params.value + '</a>';
			}
			return retStr;
		}
	},
	{
		headerName		: "삭제"
		, field			: "orderMemoSq"
		, 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 = orderAgGrid.getGridOptions(columnDefsOrderMemoInfo);
</script>

<script>
var fnSetGridHeightInit = function () {
	if (_windowWidth < 1780) {
		_girdRowH1 = 33 + _scrollH;
		_girdRowH2 = 80 + _scrollH;
	} else {
		_girdRowH1 = 33
		_girdRowH2 = 80;
	}
	
	//$('#gridOrderInfo').css('height', _girdRowH1 + _girdRowH);					//기본정보
	//$('#gridDeliveryInfo').css('height', _girdRowH1 + _girdRowH);					//배송정보
	//if (orderGoodsInfo != null && orderGoodsInfo.length > 0) $('#gridOrderGoodsInfo').css('height', _girdRowH2 + _girdRowH * orderGoodsInfo.length);
	//if (orderPaymentInfo != null && orderPaymentInfo.length > 0) $('#gridPaymentInfo').css('height', _girdRowH1 + _girdRowH * orderPaymentInfo.length);
	//if (orderDeliveryFeeInfo != null && orderDeliveryFeeInfo.length > 0) $('#gridDeliveryFeeInfo').css('height', _girdRowH1 + _girdRowH * orderDeliveryFeeInfo.length);
	//if (orderChangeInfo != null && orderChangeInfo.length > 0) $('#gridOrderChangeInfo').css('height', _girdRowH1 + _girdRowH * orderChangeInfo.length);
	//if (orderRefundInfo != null && orderRefundInfo.length > 0) $('#gridOrderRefundInfo').css('height', _girdRowH1 + _girdRowH * orderRefundInfo.length);
	//if (orderCounselInfo != null && orderCounselInfo.length > 0) $('#gridOrderCounselInfo').css('height', _girdRowH1 + _girdRowH * orderCounselInfo.length);
	//if (orderAdminMemoInfo != null && orderAdminMemoInfo.length > 0) $('#gridOrderMemoInfo').css('height', _girdRowH1 + _girdRowH * orderAdminMemoInfo.length);
	//if (orderRfAccountInfo != null && orderRfAccountInfo.length > 0) $('#gridOptionsRefundAccountInfo').css('height', _girdRowH1 + _girdRowH * orderRfAccountInfo.length);
}
</script>

<!-- 버튼 이벤트 바인딩 -->
<script>
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();
});

</script>
<!-- AgGrid 생성 -->
<script>
// 팝업닫기
var fnOrderDetailClose = function(){
	uifnPopupClose('popupOrderDetail');
}

$(document).ready(function () {
	
	// 1. 그리드 그리기
	gagaAgGrid.createGrid('gridOrderInfo'					, gridOptionsOrderInfo);			// 기본정보
	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('gridOrderCounselInfo'			, gridOptionsOrderCounselInfo);		// 상담내역
	gagaAgGrid.createGrid('gridOrderMemoInfo'				, gridOptionsOrderMemoInfo);		// 관리자메모
	
	// 2. 그리드 데이터 바인딩
	gridOptionsOrderInfo.api.setRowData(orderInfo);									// 기본정보
	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);							// 환불정보
	gridOptionsOrderCounselInfo.api.setRowData(orderCounselInfo);					// 상담내역
	gridOptionsOrderMemoInfo.api.setRowData(orderAdminMemoInfo);					// 관리자메모
	
	// 3. 그리드 높이 설정
	fnSetGridHeightInit();
});

$(document).ready(function () {
	$('#orderDetailContents').css("width", "97%").css("height", "96%");
	
	// 취소요청
	$('#btnCancel').on('click', function () {
		fnCancelRequest(ordNo, 'N');
	});
	// 반품요청
	$('#btnReturn').on('click', function () {
		fnReturnRequest(ordNo, 'N');
	});
	// 교환요청
	$('#btnExchange').on('click', function () {
		fnExchangeRequest(ordNo, 'N');
	});
	// 메모등록
	$('#btnCreateOrderMemo').on('click', function () {
		fnCreateOrderMemo(ordNo, 0, 'N');
	});
	// 배송 정보 수정
	$('#btnUpdateOrderAddr').on('click', function () {
		fnUpdateOrderAddr();
	});
	// 환불계좌 등록
	$('#btnSaveAccount').on('click', function () {
		fnCreateOrderRfAccount(ordNo, custNo);
	});
});
</script>

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

	// 반품요청
	var fnReturnRequest = function () {
		var actionUrl = "/order/return/request/form?ordNo=" + ordNo;
		cfnOpenModalPopup(actionUrl, 'popupReturnRequestForm');
	};

	// 교환요청
	var fnExchangeRequest = function () {
		var actionUrl = "/order/exchange/request/form?ordNo=" + ordNo;
		cfnOpenModalPopup(actionUrl, 'popupExchangeRequestForm');
	};

	// 취소요청
	var fnCancelRequest = function () {
		var actionUrl = "/order/cancel/request/form?ordNo=" + ordNo + "&cncWait=N";
		cfnOpenModalPopup(actionUrl, 'popupCancelRequestForm');
	};

	// 취소승인
	var fnCancelConfirmRequest = function (ordChgSq) {
		mcxDialog.confirm("요청번호 [" + ordChgSq + "] 에 대한 취소승인 처리를 하시겠습니까?", {
			cancelBtnText	: "취소",
			sureBtnText		: "확인",
			sureBtnClick	: function () {
				var data = new Object();
				data.ordNo 		= ordNo;	//전역변수
				data.ordChgSq 	= ordChgSq;

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

	// 취소요청철회
	var fnCancelConfirmRequestCancel = function (ordChgSq) {
		mcxDialog.confirm("요청번호 [" + ordChgSq + "] 에 대한 요청철회 처리를 하시겠습니까?", {
			cancelBtnText	: "취소",
			sureBtnText		: "확인",
			sureBtnClick	: function () {
				var data = new Object();
				data.ordChgSq = ordChgSq;
				
				var jsonData = JSON.stringify(data);
				gagajf.ajaxJsonSubmit(
					'/order/cancel/wait/cancel'
					, jsonData
					, function (result) {
						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));
			}
		);
	};

	// 환불계좌 정보
	var fnBindOrderRfAccountInfo = function () {
		gagaAgGrid.fetch(
			"/order/refund/account/info/list?ordNo=" + ordNo+"&custNo="+custNo
			, gridOptionsRefundAccountInfo
			, null
			, function (result) {
				$('#gridOptionsRefundAccountInfo').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 fnSetPostValue = function(zipNo, baseRoadAddr1, baseRoadAddr2, etcAddr, postPosition) {
		if (postPosition == 'grid') {
			gridOptionsDeliveryInfo.api.getRowNode(0).data.recipPostNo = zipNo;
			gridOptionsDeliveryInfo.api.getRowNode(0).data.recipBaseAddr = baseRoadAddr1;
			gridOptionsDeliveryInfo.api.getRowNode(0).data.recipDtlAddr = baseRoadAddr2;
			gridOptionsDeliveryInfo.api.refreshCells();
		} 
		else if (postPosition == 'returnRequest') {
			$("#returnRequestFrm input[name=chgerPostNo]").val(zipNo);
			$("#returnRequestFrm input[name=chgerBaseAddr]").val(baseRoadAddr1);
			$("#returnRequestFrm input[name=chgerDtlAddr]").val(baseRoadAddr2);
		} 
		else if (postPosition == 'updateOrderChangeAddr') {
			gridOptionsOrderChangeInfo.api.getRowNode(gridOrderChangeInfoSelectedIdx).data.chgerPostNo = zipNo;
			gridOptionsOrderChangeInfo.api.getRowNode(gridOrderChangeInfoSelectedIdx).data.chgerBaseAddr = baseRoadAddr1;
			gridOptionsOrderChangeInfo.api.getRowNode(gridOrderChangeInfoSelectedIdx).data.chgerDtlAddr = baseRoadAddr2;
			gridOptionsOrderChangeInfo.api.refreshCells();

		}
	}

	// 변경요청 > 우편번호찾기
	var fnOpenPostFindPopup = function (idx) {
		gridOrderChangeInfoSelectedIdx = idx;
		cfnOpenPostFindPopup('updateOrderChangeAddr');
	}

	// 변경요청 > 회수지정보 저장
	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 () {
						
					}
				);
			}
		});
	}

	// 반품요청 철회
	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();
					}
				);
			}
		});
	};
	
	// 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');
	};

	// 카드전표 영수증 조회
	var fnReceiptPage = function (tid) {
		var fullUrl = "https://npg.nicepay.co.kr/issue/IssueLoader.do?TID=" + tid + "&type=0";
		window.open(fullUrl, '_blank');
	};
	
	// 수동 회수 지시 
	var fnWdinvocieSend = function (ordChgSq) {
		mcxDialog.confirm("요청번호 [" + ordChgSq + "] 회수지시 처리 하시겠습니까? <br> 시스템에서 회수지시를 보내지는않습니다.", {
			cancelBtnText	: "취소",
			sureBtnText		: "확인",
			sureBtnClick	: function () {
				var data = new Object();
				data.ordChgSq = ordChgSq;
				
				var jsonData = JSON.stringify(data);
				gagajf.ajaxJsonSubmit(
					'/order/wdinvoice/send/save'
					, jsonData
					, function (result) {
						uifnPopupClose('popupOrderDetail');
						fnReOpenOrderDetailPopup();
					}
				);
			}
		});
	};
	
	// 구매확정철회
	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();
						}
					);
				}
			});
		}
	};
</script>

</html>





