<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : OrderListForm.html
 * @desc    : 주문목록 Page
 *============================================================================
 * SISUN
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.11.16   jsh77b       최초 작성
 *******************************************************************************
 -->
 <style>
 .ag-neo .ag-cell.top-row-span {
     border-bottom: 0px;
}
.ag-neo .ag-cell.bottom-row-span {
     border-top: 0px;
     text-indent: -100em;
}
 </style>
 
<div id="main">
	<!-- 메인타이틀 영역 -->
	<div class="main-title">
	</div>
	<!-- //메인타이틀 영역 -->
	
	<!-- 메뉴 설명 -->
	<div class="infoBox menu-desc">
	</div>
	
	<form id="searchForm" name="searchForm" action="#" th:action="@{'/order/list'}">
		<input type="hidden" id="searchGb" name="searchGb" />
		
		<!-- 패널 영역1 -->
		<div class="panelStyle" >
			<!-- 검색조건 영역 -->
			<!-- TITLE -->
			<div class="panelTitle">
				<h3>
					<i class="fa fa-info-circle"></i>아래 검색조건 중 <font color="red">주문번호</font> 또는 <font color="red">검색조건</font> 하나를 꼭 입력해 주세요.
				</h3>
				<span class="panelControl">
					<i class="fa fa-chevron-up"></i>
				</span>
			</div>
			
			<div class="panelContent">
				<table class="frmStyle">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
					</colgroup>
					<tr>
						<th>사이트</th>
						<td>
							<select name="siteCd">
								<option value="">[전체]</option>
								<option th:if="${siteCdList}" th:each="oneData, status : ${siteCdList}" th:value="${oneData.cd}"
										th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>몰구분</th>
						<td>
							<select name="mallCd">
								<option value="">[전체]</option>
								<option th:if="${mallGbList}" th:each="oneData, status : ${mallGbList}" th:value="${oneData.cd}"
										th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>업체/브랜드<em class="required" title="필수"></em></th>
						<td colspan="3">
							<label class="rdoBtn"><input type="radio" name="selfYn" id="selfYnY" value="Y"  checked/>자사</label>
							<label class="rdoBtn"><input type="radio" name="selfYn" id="selfYnN" value="N"/>입점</label>
							<select name="supplyCompCd" id="supplyCompCd">
								<option value="" th:if="${sessionInfo.roleCd} != 'G001_B000'">[전체]</option>
								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
							<span id="multiBrand"></span>
						</td>
					</tr>
					<tr>
						<th>주문상태</th>
						<td>
							<div class="multiCheckBox" style="width:270px">
								<button type="button" class="sltBtn" style="overflow-x: hidden; padding-right:5px;">[전체]</button>
								<ul style="display: none; box-shadow: 3px 3px 3px; overflow-y: scroll; height: 112px;">
									<li th:if="${ordStatList}" th:each="oneData, status : ${ordStatList}">
										<label class="chkBox">
											<input type="checkbox" name="multiOrdStat" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|">
										</label>
									</li>
								</ul>
							</div>
						</td>
						<th>주문상세상태</th>
						<td colspan="3">
							<div class="multiCheckBox" style="width:270px">
								<button type="button" class="sltBtn" style="overflow-x: hidden; padding-right:5px;">[전체]</button>
								<ul style="display: none; box-shadow: 3px 3px 3px; overflow-y: scroll; height: 112px;">
									<li th:if="${ordDtlStatList}" th:each="oneData, status : ${ordDtlStatList}">
										<label class="chkBox">
											<input type="checkbox" name="multiOrdDtlStat" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|">
										</label>
									</li>
								</ul>
							</div>
						</td>
						<th rowspan="5">키워드<i class="star"></i></th>
						<td rowspan="5">
							<select name="search" id="search">
								<option value="searchOrdNo">주문번호</option>
								<option value="searchExtmallOrderId">외부몰주문번호</option>
								<option value="searchAgentOrderId">에이전트주문번호</option>
							</select>
							<textarea class="textareaR3 w70p" name="condition" id="condition"></textarea>
						</td>
					</tr>
					<tr>
						<th>변경구분</th>
						<td>
							<select name="chgGb">
								<option value="">[전체]</option>
								<option th:if="${chgGbList}" th:each="oneData, status : ${chgGbList}" th:value="${oneData.cd}"
										th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>변경요청처리상태</th>
						<td>
							<select name="chgStat">
								<option value="">[전체]</option>
								<option value="9999">[품절취소]</option>
								<option th:if="${chgStatList}" th:each="oneData, status : ${chgStatList}" th:value="${oneData.cd}"
										th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>결제수단</th>
						<td>
							<select name="payMeans">
								<option value="">[전체]</option>
								<option th:if="${payMeansList}" th:each="oneData, status : ${payMeansList}" th:value="${oneData.cd}"
										th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th>주문자명</th>
						<td>
							<input type="text" name="orderNm" placeholder="" maxlength="20"/>
						</td>
						<th>고객ID</th>
						<td>
							<input type="text" name="custId" placeholder="" maxlength="20"/>
						</td>
						<th>주문자휴대폰번호</th>
						<td>
							<input type="text" name="orderPhnno" placeholder="" maxlength="20"/>
						</td>
					</tr>
					<tr>
						<th>상품코드</th>
						<td>
							<input type="text" name="goodsCd" placeholder="" maxlength="20"/>
						</td>
						<th>사이즈</th>
						<td>
							<input type="text" name="sizeCd" placeholder="" maxlength="20"/>
						</td>
						<th>단품명</th>
						<td>
							<input type="text" name="goodsNm" placeholder="" maxlength="20"/>
						</td>
					</tr>
					<tr>
						<th>수취인명</th>
						<td>
							<input type="text" name="recipNm" placeholder="" maxlength="20"/>
						</td>
						<th>송장번호</th>
						<td>
							<input type="text" name="invoiceNo" placeholder="" maxlength="20"/>
						</td>
						<th>회수지시전송여부</th>
						<td>
							<select name="wdInvoiceSendYn" class="w150">
								<option value="">전체</option>
								<option value="Y">전송</option>
								<option value="N">미전송</option>
							</select>
						</td>
					</tr>
					<tr>
						<th>조회일자</th>
						<td colspan="7">
							<select name="searchDateGb">
								<option value="ordDt">주문일자</option>
								<option value="delvStdt">출고일자</option>
								<option value="cnclReqDt">@취소요청일자</option>
								<option value="changReqDt">@교환요청일자</option>
								<option value="rtnReqDt">@반품요청일자</option>
								<option value="soldoutDt">품절일자</option>
							</select>
							<span id="terms"></span>
						</td>
					</tr>
				</table>
				
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-info btn-lg" id="btnOrderSearch">조회</button>
						<button type="button" class="btn btn-gray btn-lg" id="btnInit">초기화</button>
					</li>
				</ul>
				
			</div>
		</div>

		<div class="panelStyle">
			<ul class="panelBar">
				<li>
					<button type="button" class="btn btn-info btn-lg" onclick="fnOrderExcelList();">엑셀다운로드</button>
				</li>
				<li class="aR">
					검색결과 : <strong><span id="rowCntOrderList">0</span> 건</strong>&nbsp;
					쪽번호 <span id="pgNo">0</span>/ <strong id="endPgNo">0</strong>&nbsp;&nbsp;
					<select id="pageSize" name="pageSize">
						<option value="100" selected="selected">100개씩 보기</option>
						<option value="500">500개씩 보기</option>
						<option value="1000">1000개씩 보기</option>
						<option value="5000">5000개씩 보기</option>
					</select>
					<input type="hidden" name="pageNo" id="pageNo" value ="1"/>
				</li>
			</ul>
			
			<div class="panelContent" style="overflow: hidden;">
				<div id="gridOrderList" style="width: 100%; height: 600px;" class="ag-theme-balham lh60"></div>
			</div>
			
			<ul class="panelBar">
				<li class="center">
					<div class="tablePaging" id="orderListPagination"></div>
				</li>
			</ul>
		</div>

	</form>
</div>

<label class="off">
	<a href="javascript:void(0);" id="hdOrderExcelList" style="display: none;">엑셀다운로드</a>
</label>

<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js?v=2019072202"></script>

<script th:inline="javascript">
/*<![CDATA[*/
var sessRoleCd 		= [[${sessionInfo.roleCd}]];
var siteCdList 		= gagajf.convertToArray([[${siteCdList}]]);
var mallGbList 		= gagajf.convertToArray([[${mallGbList}]]);
var ordDtlStatList 	= gagajf.convertToArray([[${ordDtlStatList}]]);
var payMeansList 	= gagajf.convertToArray([[${payMeansList}]]);
var chgStatList 	= gagajf.convertToArray([[${chgStatList}]]);
var chgGbList 		= gagajf.convertToArray([[${chgGbList}]]);
var formalGbList 	= gagajf.convertToArray([[${formalGbList}]]);
var frontGbList 	= {'P': 'PC', 'M': 'MO'};
var uploadGoodsUrl 	= [[${@environment.getProperty('upload.goods.view')}]];

// 1. 주문기본정보
var columnDefsOrderList = [
	{
		headerName	: "주문기본정보"
		, cellClass	: 'text-center'
		, children	: [
			{
				headerName		: "주문번호"
				, field			: 'ordNo'
				, width			: 70
				, cellClass		: 'text-center'
				, sortable		: true
				, cellRenderer	: function (params) {
					var roleCd = [[${sessionInfo.roleCd}]];
					if (!roleCd.startsWith("C")) {
						return "<a href=\"javascript:void(0);\" onclick=\"fnOpenOrderDetailPopup('" + params.value + "');\">" + params.value + "</a>";
					} else {
						return params.value;
					}
				}
			},
			{
				headerName		: "주문자"
				, field			: "ordNm"
				, width			: 120
				, cellClass		: 'text-left'
				, sortable		: true
				, cellRenderer	: function (params) {
					var custNo = '';
					if (!gagajf.isNull(params.data.custNo)) {
						custNo = params.data.custNo;
					}
					
					var roleCd = [[${sessionInfo.roleCd}]];
					if (!roleCd.startsWith("C") && !gagajf.isNull(params.data.custNo)  && params.data.mallGb === '10' ) {
						return '<a href="javascript:void(0);" onclick=\"cfnOpenCustDetailPopup(' + params.data.custNo + ');\">' + params.value + '(' + custNo + ')' + '</a>';
					} else {
						return params.value + '(' + custNo + ')';
					}
				}
			},
			{headerName: "고객고유번호"	, field: "custNo"		, width: 120, cellClass: 'text-center', hide: true},
			{headerName: "외부몰"		, field: "extmallNm"	, width: 100, cellClass: 'text-center', sortable: true},
			{headerName: "휴대폰번호"	, field: "orderPhnno"	, width: 120, cellClass: 'text-center', hide: true},
			{
				headerName		: "사이트"
				, field			: "siteCd"
				, width			: 80
				, cellClass		: 'text-center'
				, hide			: true
				, valueGetter	: function (params) { 
					return gagaAgGrid.lookupValue(siteCdList, params.data.siteCd); 
				}
			},
			{
				headerName		: "프론트"
				, field			: "frontGb"
				, width			: 80
				, cellClass		: 'text-center'
				, sortable		: true
				, valueGetter	: function (params) { 
					return gagaAgGrid.lookupValue(frontGbList, params.data.frontGb); 
				}
			},
			{
				headerName		: "몰구분"
				, field			: "mallGb"
				, width			: 60
				, cellClass		: 'text-center'
				, hide			: true
				, valueGetter	: function (params) { 
					return gagaAgGrid.lookupValue(mallGbList, params.data.mallGb); 
				}
			},
			{
				headerName		: "주문일시"
				, field			: "ordDt"
				, width			: 140
				, cellClass		: 'text-center'
				, sortable		: true
				, valueGetter	: function (params) { 
					return gagaAgGrid.toDateTimeFormat(params.data.ordDt); 
				}
			},
			{
				headerName		: "결제수단"
				, field			: "payMeans"
				, width			: 110
				, cellClass		: 'text-center'
				, hide			: true
				, valueGetter	: function (params) { 
					return gagaAgGrid.lookupValue(payMeansList, params.data.payMeans); 
				}
			},
			{
				headerName		: "신규/교환"
				, field			: "ordExchGb"
				, width			: 100
				, cellClass		: 'text-center',
				valueGetter 	: function (params) {
					return params.data.ordExchGb === 'O' ? '신규' : '교환';
				}
			},
			{
				headerName		: "주문상세상태"
				, field			: "ordDtlStat"
				, width			: 140
				, cellClass		: 'text-center'
				, sortable		: true
				, valueGetter	: function (params) {
					var ordDtlStat = gagaAgGrid.lookupValue(ordDtlStatList, params.data.ordDtlStat);
					var chgStat='';
					if (params.data.ordDtlStat === '99') {
						chgStat = gagaAgGrid.lookupValue(chgStatList, params.data.chgStat);
						if (!gagajf.isNull(chgStat)) {
							chgStat = chgStat.substr(0, 2);
							if (params.data.soldoutYn === 'Y') {
								chgStat = '품절';
							}
							ordDtlStat = ordDtlStat + '-' + chgStat;
						}

					}
					return ordDtlStat;
				}
			},
			{headerName: "출고처", field: "delvLocNm", width: 110, cellClass: 'text-center', sortable: true},
		]
	},
	{
		headerName	: "주문상품정보"
		, cellClass	: 'text-center'
		, children	: [
			{headerName: "상품코드"	, field: "goodsCd"		, width: 100	, cellClass: 'text-center'	, sortable: true},
			{
				headerName		: "상품명"
				, field			: 'goodsNm'
				, width			: 75
				, cellClass		: 'text-center'
				, sortable		: true
				, cellRenderer	: function (params) {
					var roleCd = [[${sessionInfo.roleCd}]];
					if (!roleCd.startsWith("C")) {
						return "<a href=\"javascript:void(0);\" onclick=\"fnOpenOrderDetailPopup('" + params.value + "');\">" + params.value + "</a>";
					} else {
						return params.value;
					}
				}
			}
		]
	},
	{
		headerName	: "주문상품단품정보"
		, cellClass	: 'text-center'
		, children	: [
			{
				headerName		: "이미지"
				, field			: "imgPath1"
				, width			: 70
				, height		: 60
				, cellClass		: 'text-center'
				, cellRenderer	: function(params) {
					if (params.data.imgType == "A") {
						if (!gagajf.isNull(params.data.imgPath6)) {
							return '<img width="60" src="' + uploadGoodsUrl + params.data.imgPath6.replace("/1000/","/100/") + '" alt=""  onerror="this.src=\'/image/no.gif\';"/>';
						} else {
							return '<img width="60" src="' + uploadGoodsUrl + params.value.replace("/1000/","/100/") + '" alt=""  onerror="this.src=\'/image/no.gif\';"/>';
						}
					} else {
						if (!gagajf.isNull(params.data.imgPath6)) {
							return '<img width="60" src="' + params.data.imgPath1 + '" alt="" onerror="this.src=\'/image/no.gif\';"/>';
						} else {
							return '<img width="60" src="' + params.value + '" alt="" onerror="this.src=\'/image/no.gif\';"/>';
						}
					}
				}
			},
			{headerName: "브랜드"		, field: "brandEnm"		, width: 130, cellClass: 'text-center', sortable: true},
			{
				headerName		: "단품코드"
				, field			: "itemCd"
				, width			: 130
				, cellClass		: 'text-center'
				, sortable		: true
				, cellRenderer: function (params) {
					var roleCd = [[${sessionInfo.roleCd}]];
					if (!roleCd.startsWith("C")) {
						return "<a href=\"javascript:void(0);\" onclick=\"cfnOpenGoodsDetailPopup('U','" + params.value + "');\">" + params.value + "</a>";
					} else {
						return params.value;
					}
				}
			},
			{headerName: "색상"		, field: "optCd1"		, width: 100	, cellClass: 'text-center'	, sortable: true},
			{headerName: "사이즈"		, field: "optCd2"		, width: 60		, cellClass: 'text-center'	, sortable: true},
			{headerName: "단품명"		, field: "itemNm"		, width: 200	, cellClass: 'text-left'	, sortable: true},
			{headerName: "구성유형"	, field: "goodsTypeNm"	, width: 200	, cellClass: 'text-left'	, sortable: true},
			{
				headerName		: "외부몰벤더"
				, field			: "vendorId"
				, width			: 110
				, cellClass		: 'text-center'
				, hide			: true
				, valueGetter	: function (params) { 
					return gagaAgGrid.lookupValue(vendorList, params.data.vendorId); 
				}
			},
			{headerName: "외부몰주문번호"	, field: "extmallOrderId"	, width: 150, cellClass: 'textFormat', sortable: true},
			{headerName: "외부몰부주문번호"	, field: "agentOrderId"		, width: 120, cellClass: 'textFormat', sortable: true},
			{
				headerName		: "주문수량"
				, field			: "ordQty"
				, width			: 80
				, cellClass		: 'text-center'
				, valueGetter: function (params) { 
					return params.data.ordQty.addComma(); 
				}
			},
			{
				headerName		: "취소수량"
				, field			: "cnclRtnQty"
				, width			: 80
				, cellClass		: 'text-center'
				, valueGetter	: function (params) { 
					return params.data.cnclRtnQty.addComma(); 
				}
			},
			{
				headerName		: "주문금액"
				, field			: "ordAmt"
				, width			: 80
				, cellClass		: 'text-right'
				, valueGetter	: function (params) { 
					return params.data.ordAmt.addComma(); 
				}
			},
			{
				headerName		: "취소반품금액"
				, field			: "cnclRtnAmt"
				, width			: 120
				, cellClass		: 'text-right'
				, valueGetter	: function (params) { 
					return params.data.cnclRtnAmt.addComma(); 
				}
			},
			{
				headerName		: "총할인금액"
				, field			: "totDcAmt"
				, width			: 120
				, cellClass		: 'text-right'
				, valueGetter: function (params) { 
					return params.data.totDcAmt.addComma(); 
				}
			},
			{
				headerName		: "실판매금액"
				, field			: "realOrdAmt"
				, width			: 100
				, cellClass		: 'text-right'
				, valueGetter	: function (params) { 
					return params.data.realOrdAmt.addComma(); 
				}
			},
			{headerName: "원코드"		, field: "supplyGoodsCd"	, width: 130, cellClass: 'text-center', sortable: true},
			{
				headerName		: "정상/이월"
				, field			: "formalGb"
				, width			: 100
				, cellClass		: 'text-center'
				, sortable		: true 
				, valueGetter	: function (params) { 
					return gagaAgGrid.lookupValue(formalGbList, params.data.formalGb); 
				}
			},
			{
				headerName		: "출고처지정일시"
				, field			: "delvAssignDt"
				, width			: 150
				, cellClass		: 'text-center'
				, valueGetter	: function (params) { 
					return gagaAgGrid.toDateTimeFormat(params.data.delvAssignDt); 
				}
			},
			{
				headerName		: "송장출력일시"
				, field			: "invoiceDt"
				, width			: 150
				, cellClass		: 'text-center'
				, valueGetter	: function (params) { 
					return gagaAgGrid.toDateTimeFormat(params.data.invoiceDt); 
				}
			},
			{headerName: "출고택배사"		, field: "shipCompNm"	, width: 150, cellClass: 'text-center'},
			{headerName: "출고송장"		, field: "invoiceNo"	, width: 150, cellClass: 'text-center'},
			{
				headerName		: "출고일시"
				, field			: "delvResDt"
				, width			: 150
				, cellClass		: 'text-center'
				, valueGetter: function (params) { 
					return gagaAgGrid.toDateTimeFormat(params.data.delvResDt); 
				}
			},
			{headerName: "품절여부"		, field: "soldoutYn"	, width: 90		, cellClass: 'text-center', sortable: true},
			{headerName: "품절메모"		, field: "soldoutMemo"	, width: 120	, cellClass: 'text-left'},
			{
				headerName		: "품절일시"
				, field			: "soldoutRegDt"
				, width			: 150
				, cellClass		: 'text-center'
				, valueGetter	: function (params) { 
					return gagaAgGrid.toDateTimeFormat(params.data.soldoutRegDt); 
				}
			},
			{headerName: "품절처리자", field: "soldoutRegId", width: 120, cellClass: 'text-center'},
			{
				headerName		: "변경요청번호"
				, field			: "ordChgSq"
				, width			: 120
				, cellClass		: 'text-center'
				, valueGetter	: function (params) {
					return params.data.ordChgSq === 0 ? '' : params.data.ordChgSq;
				}
			},
			{
				headerName		: "변경구분"
				, field			: "chgGb"
				, width			: 120
				, cellClass		: 'text-center'
				, valueGetter: function (params) { 
					return gagaAgGrid.lookupValue(chgGbList, params.data.chgGb); 
				}
			},
			{
				headerName		: "변경상태"
				, field			: "chgStat"
				, width			: 120
				, cellClass		: 'text-center'
				, valueGetter	: function (params) { 
					return gagaAgGrid.lookupValue(chgStatList, params.data.chgStat); 
				}
			},
			{headerName: "회수지시여부"		, field: "wdInvoiceSendYn"		, width: 100, cellClass: 'text-center'},
			{headerName: "회수택배사"		, field: "wdShipCompNm"			, width: 100, cellClass: 'text-center'},
			{headerName: "회수송장"		, field: "wdInvoiceNo"			, width: 120, cellClass: 'text-center'},
			{headerName: "수취인명"		, field: "recipNm"				, width: 100, cellClass: 'text-center'},
			{headerName: "수취인연락처"		, field: "recipPhnno"			, width: 120, cellClass: 'text-center'},
			{headerName: "수취인주소"		, field: "recipAddr"			, width: 500, cellClass: 'text-left'},
			{
				headerName		: "배송메모"
				, field			: "delvMemo"
				, width			: 500
				, cellClass		: 'left'
				, valueGetter: function (params) {
					var delvMemo = '';
					if (!gagajf.isNull(params.data.delvMemo)) {
						delvMemo = fnRemoveEmojis(params.data.delvMemo);
					}
					return delvMemo;
				}
			},
			{headerName: "출고메모", field: "dstrbtNote", width: 300, cellClass: 'left'}
		]
	}
];

var gridOptionsOrderList = {
	columnDefs					: columnDefsOrderList
	, 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
};

// 상품이미지 노출을 위해 높이 조정
gridOptionsOrderList.rowHeight 					= 60;
gridOptionsOrderList.rowSelection 				= 'multiple';
gridOptionsOrderList.suppressRowClickSelection 	= true;
gridOptionsOrderList.getRowStyle = function (params) {
	if (params.data.ordExchGb === 'E') {
		return {background: 'orange'}
	}
}

//Rowspan
gridOptionsOrderList.defaultColDef.resizable = true;
gridOptionsOrderList.suppressRowTransform = true;

function onFirstDataRendered(params) {
	
}

// 최근상세보기한 주문번호
var currOrdNo = '';

// 조회
$('#btnOrderSearch').on('click', function () {
	fnSearchList();
});

var fnSearchList = function () {
	var ordNo 	= $('#searchForm input[name=ordNo]').val();
	var stDate 	= $('#stDate').val();
	var edDate 	= $('#edDate').val();

	if (gagajf.isNull(ordNo)) {
		if (gagajf.isNull(stDate)) {
			mcxDialog.alert('시작 기간을 입력하세요.');
			return;
		}

		if (gagajf.isNull(edDate)) {
			mcxDialog.alert('종료 기간을 입력하세요.');
			return;
		}
	}
	
	gagaPaging.init('searchForm', fnSearchCallBack, 'orderListPagination', $('#searchForm').find('#pageSize').val());
	gagaPaging.load($("#searchForm input[name=pageNo]").val());
	
	// 2020.12.08 페이징 처리 때문에 주석 처리
	//gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptionsOrderList, '#searchForm', function (result) {
		//$("#rowCntOrderList").text(gridOptionsOrderList.api.getDisplayedRowCount());
		// 주문리스트 합계 정보
		//gagajf.ajaxFormSubmit('/order/list/sum/info', '#searchForm', fnOrderListSumInfoCallback);
	//});
};

var fnSearchCallBack = function(result){
	$('#searchForm').find('#gridRowTotalCount').html(result.pageing.pageable.totalCount.addComma());
	$('#searchForm').find('#pageNo').val(result.pageing.pageable.pageNo.addComma());
	$('#searchForm').find('#pgNo').html(result.pageing.pageable.pageNo.addComma());
	$('#searchForm').find('#endPgNo').html(result.pageing.pageable.totalPage.addComma());
	
	gridOptionsOrderList.api.setRowData(result.orderList);
	gagaPaging.createPagination(result.pageing.pageable);
}

// 주문리스트 합계 정보
var fnOrderListSumInfoCallback = function(result) {
	if (!gagajf.isNull(result)) {
		var sumOrdAmt 		= 0;
		var sumOrdCnclAmt 	= 0;
		var sumRealPayAmt 	= 0;
		var ordNoCnt 		= 0;
		var sumOrdQty 		= 0;
		var sumOrdCnclQty 	= 0;

		if (!gagajf.isNull(result.sumOrdAmt)) {
			sumOrdAmt = result.sumOrdAmt.addComma();
		}
		if (!gagajf.isNull(result.sumOrdCnclAmt)) {
			sumOrdCnclAmt = result.sumOrdCnclAmt.addComma();
		}
		if (!gagajf.isNull(result.sumRealPayAmt)) {
			sumRealPayAmt = result.sumRealPayAmt.addComma();
		}
		if (!gagajf.isNull(result.ordNoCnt)) {
			ordNoCnt = result.ordNoCnt.addComma();
		}
		if (!gagajf.isNull(result.sumOrdQty)) {
			sumOrdQty = result.sumOrdQty.addComma();
		}
		if (!gagajf.isNull(result.sumOrdCnclQty)) {
			sumOrdCnclQty = result.sumOrdCnclQty.addComma();
		}

		$('#sumOrdAmt').text(sumOrdAmt);
		$('#sumOrdCnclAmt').text(sumOrdCnclAmt);
		$('#sumRealPayAmt').text(sumRealPayAmt);
		$('#ordNoCnt').text(ordNoCnt);
		$('#sumOrdQty').text(sumOrdQty);
		$('#sumOrdCnclQty').text(sumOrdCnclQty);
	}
};

// 엑셀조회
$("#btnSearchExcel").on('click', function () {
	cfnExcelUploadPopup('', 'fnExcelUpoadCallback');
});

var fnExcelUpoadCallback = function (data) {
	$("#excelFileNm").val(data.excelFileNm);
	gagaAgGrid.fetch('/order/excel/search', gridOptionsOrderList, '#searchForm', function () {
		$("#rowCntOrderList").text(gridOptionsOrderList.api.getDisplayedRowCount());
	});
};

// 초기화 클릭시
$('#btnInit').on('click', function() {
	$('#searchForm')[0].reset();
	$("#multiBrand").empty();
});

// 엑셀 다운로드
// 2020.12.11 현재는 그리드의 조회 목록을 엑셀 다운로드 하고 있지만 추후 에는 조건의 엑셀 조회 후 다운로드 기능으로 변경 해야 할듯함
// 기존의 주문목록은 페이징 기능이 없었지만 페이징 기능을 추가 하면서 엑셀다운로드시 조회 후 파일다운 기능 필요  
var fnOrderExcelList = function () {
	gagaAgGrid.showOrHideColumn(gridOptionsOrderList	, "custNo", true);
	gagaAgGrid.exportToExcel('주문목록'					, gridOptionsOrderList);
	gagaAgGrid.showOrHideColumn(gridOptionsOrderList	, "custNo", false);
};

var fnOpenOrderDetailPopup = function (ordNo) {
	currOrdNo = ordNo;
	cfnOpenOrderDetailPopup(ordNo);
};

var fnReOpenOrderDetailPopup = function () {
	cfnOpenOrderDetailPopup(currOrdNo);
};
	
//자사/입점 변경여부
$("#searchForm input[name=selfYn]").bind('click change', function () {
	var radioValue = $(this).val();
	var selfGb = "S";	// 자사 공급 업체
	
	if (radioValue == "N"){
		selfGb = "E";	//입점 공급업체
	}
	
	var actionUrl = '/renderer/supply/company/list/'+ selfGb;	

	$('#searchForm').find('#multiBrand').empty();

	cfnCreateCombo(actionUrl, $('#searchForm select[name=supplyCompCd]'), "[전체]", "");
});
	
// 업체변경시
$('#searchForm select[name=supplyCompCd]').on('change', function() {
	var actionUrl = '/renderer/supplyCompany/brand/list/' + $(this).val();

	if(sessRoleCd == "G001_B000"){
		actionUrl = '/renderer/brand/AuthBrandlist';
	}

	cfnCreateMultiCombo(actionUrl,"multiBrand",  "[전체]",null, 'Y');
});

//페이징
$('#searchForm select[name=pageSize]').on('change', function() {
	$("#searchForm input[name=pageNo]").val('1');
	fnGoodsListSearch($("#searchForm input[name=searchGb]").val());
});

// 초기설정
$(document).ready(function() {
	// 달력기능 활성화
	cfnCreateCalendar('#terms', 'stDate', 'edDate', true, '주문');
	gagaAgGrid.createGrid('gridOrderList', gridOptionsOrderList);
	gridOptionsOrderList.api.hideOverlay();
});
</script>

</html>





