<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : MorebetterListForm.html
 * @desc    : 다다익선 관리 페이지
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.12.28   bin2107   최초 작성
 *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->

		<form id="searchForm" name="searchForm" action="#" th:action="@{'/marketing/morebetter/list'}">
			<input type="hidden" id="searchGb" name="searchGb" />
			<input type="hidden" id="imageViewYn" name="imageViewYn" />
			<input type="hidden" id="goodsPriceYn" name="goodsPriceYn" value="Y"/> <!-- 즉시할인판매가 조회 -->

				<!-- 패널 영역1 -->
			<div class="panelStyle" >
				<!-- 검색조건 영역 -->
				<!-- TITLE -->
				<div class="panelTitle">
					<!--<h3><i class="fa fa-info-circle"></i>아래 검색조건 중 <font color="red">업체, 키워드, 발생일</font>중 하나를 꼭 입력해 주세요.</h3>-->
					<h3><i class="fa fa-info-circle"></i>검색조건</h3>
					<span class="panelControl">
						<i class="fa fa-chevron-up"></i>
					</span>
				</div>
				<!-- //TITLE -->
				<div class="panelContent">
					<table class="frmStyle">
						<colgroup>
							<col style="width: 7%;"/>
							<col/>
						</colgroup>

						<tr>
							<th>기간</th>
							<td id="sellTerms"></td>
						</tr>

						<tr>
							<th>프로모션 조회</th>
							<td>
								<label class="rdoBtn"><input type="radio" name="searchGubun" id="promotionId" value="tmtbSq"  checked/>프로모션ID</label>
								<label class="rdoBtn"><input type="radio" name="searchGubun" id="promotionName" value="tmtbNm"/>프로모션명</label>
								<input type="text" class="w900" name="searchTxt" id="searchTxt" />
							</td>
						</tr>
					</table>
					<ul class="panelBar">
						<li class="center">
							<button type="button" class="btn btn-gray btn-lg" id="btnInit" >초기화</button>
							<button type="button" class="btn btn-info btn-lg" id="btnSearch" >조회</button>
						</li>
					</ul>
				</div>
				<!-- //검색조건 영역 -->
			</div>

			<!-- 패널 영역1 -->
			<div class="panelStyle">
				<!-- 상단버튼 영역  -->
				<ul class="panelBar">
					<li class="right">
						검색결과 : <strong><span id="gridRowTotalCount">0</span> 건</strong>&nbsp;
						쪽번호 <span id="pgNo">0</span>/ <strong id="endPgNo">0</strong>&nbsp;&nbsp;
						<select id="pageSize" name="pageSize">
							<option value="50" selected="selected">50개씩 보기</option>
							<option value="100">100개씩 보기</option>
							<option value="500">500개씩 보기</option>
							<option value="1000">1000개씩 보기</option>
						</select>
						<input type="hidden" name="pageNo" id="pageNo" value ="1"/>
					</li>
				</ul>
				<div class="panelBar">
					<div class="right">
						<button type="button" class="btn btn-info btn-lg" id="btnMorebetterReg" >다다익선 등록</button>
					</div>
				</div>
				<!-- 검색결과 영역 -->
				<!--<div id="gridList" style="width: 100%; height: 700px;" class="ag-theme-balham lh60"></div>-->
				<div id="gridList" style="width: 100%; height: 570px" class="ag-theme-balham"></div>
				<ul class="panelBar">
					<li class="center">
						<div class="tablePaging" id="morebetterListPagination"></div>
					</li>
				</ul>
			</div>
		</form>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js?v=2019072202"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	var columnDefs = [];
	columnDefs = [
		{headerName: 'No', width: 60, cellClass: 'text-center',
			valueGetter: function(params) { return cfnGridNumner('searchForm',params.node.rowIndex, 'A');}
		},
		{headerName: "프로모션ID", field: "tmtbSq", width: 80, cellClass: 'text-center'
			// cellRenderer: function(params) {
			// 	return "<a href=\"javascript:void(0);\" onclick=\"cfnOpenMorebetterSetPopup('U','" + params.value + "');\">" + params.value + "</a>";
			// }
		},
		{headerName: "프로모션명", field: "tmtbNm", width: 200, cellClass: 'text-center'
			,cellRenderer: function(params) {
				return '<a href="javascript:void(0);">' + params.value + '</a>';
			}
		},
		{headerName: "상태", field: "tmtbStat", width: 140, cellClass: 'text-center'},
		{headerName: "시작일", field: "tmtbStdt", width: 140, cellClass: 'text-center'},
		{headerName: "종료일", field: "tmtbEddt", width: 140, cellClass: 'text-center'},
		{headerName: "등록자", field: "regNm", width: 200, cellClass: 'text-left'
			,cellRenderer: function(params) {
				return params.value + "(" + params.data.regDt + ")";
			}
		},
		{headerName: "최종수정자", field: "updNm", width: 200, cellClass: 'text-left'
			,cellRenderer: function(params) {
				return params.value + "(" + params.data.updDt + ")";
			}
		}
	];

	// Get GridOptions
	var gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// Row Click
	gridOptions.onCellClicked = function(event) {
		var tmtbSq = event.data.tmtbSq;
		if (event.colDef.field == "tmtbNm"){
			// 수정 필요
			cfnOpenMorebetterSetPopup('U',tmtbSq);
		}
	}

	// 어떤건지 확인 필요
	/* gridOptions.getRowStyle = function(params) {
		if ("G008_00" == params.data.goodsStat  || "G008_10" == params.data.goodsStat || "G008_20" == params.data.goodsStat || "G008_30" == params.data.goodsStat) {
			return { background: '#23c6c8' };
		}
	} */

	// 초기화 클릭시
	$('#btnInit').on('click', function() {

		$('#searchForm')[0].reset();
		//$("#searchForm input[type=radio]").removeClass("checked");
		$("#searchForm input[type=checkbox]").removeClass("checked");
		//$("#searchForm input[type=radio]").parent("label").removeClass("checked");
		$("#searchForm input[type=checkbox]").parent("label").removeClass("checked");
		$("#searchForm input[type=radio][checked]").parent("label").addClass("checked");
	});

	// 조회클릭시
	$('#btnSearch').on('click', function() {
		if(!fnConditionCheck()) return;
		fnMorebetterListSearch();
	});

	// 조회
	var fnMorebetterListSearch = function() {
		gagaPaging.init('searchForm', fnSearchCallBack, 'morebetterListPagination', $('#searchForm').find('#pageSize').val());
		gagaPaging.load(1);
	}

	//검색 조건 확인
	var fnConditionCheck = function(){
		var fromDate = $('#searchForm input[name=tmtbStdt]').val();
		var toDate = $('#searchForm input[name=tmtbEddt]').val();

		if (!gagajf.isNull(fromDate) || !gagajf.isNull(toDate)) {

			if (gagajf.isNull(fromDate) || gagajf.isNull(toDate)) {
				mcxDialog.alertC("기간 조회시 시작일자와 종료일자를 입력하세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#searchForm input[name=tmtbStdt]').focus();
					}
				});
				return false;
			}

			if (fromDate > toDate) {
				mcxDialog.alertC("등록 시작일자는 종료일자 보다 클 수 없습니다.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#searchForm input[name=tmtbEddt]').focus();
					}
				});
				return false;
			}
		}

		return true;
	}

	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());
		gridOptions.api.setRowData(result.morebetterList);
		gagaPaging.createPagination(result.pageing.pageable);
		
	}

	// 등록클릭시
	$('#btnMorebetterReg').on('click', function() {
		cfnOpenMorebetterSetPopup('N');
	});


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

	$(document).ready(function() {

		cfnCreateCalendar('#sellTerms', 'tmtbStdt', 'tmtbEddt', true, '기간', 'X');

		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);

	});

/*]]>*/
</script>
	</div>

</html>