<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : ReviewForm.html
 * @desc    : 상품평관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.25   gagamel     최초 작성
 *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<!-- 검색조건 영역 -->
		<div class="panelStyle">
			<form id="searchForm" name="searchForm" action="#" th:action="@{'/marketing/review/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
				<input type="hidden" name="pageNo" value ="1"/>
				<input type="hidden" name="pageSize" value="50"/>
				
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:8%;"/>
						<col style="width:10%;"/>
						<col style="width:13%;"/>
						<col style="width:10%;"/>
						<col style="width:10%;"/>
						<col style="width:10%;"/>
						<col style="width:8%;"/>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>등록일자</th>
						<td colspan="7" id="terms">
						</td>
						<th rowspan="2">상품코드</th>
						<td rowspan="2">
							<textarea class="textareaR2 w150" name="goodsCd" id="goodsCd"></textarea>
						</td>
					</tr>
					<tr>
						<th>상품평유형</th>
						<td>
							<select name="reviewGb">
								<option value="">[전체]</option>
								<option value="R">일반</option>
								<option value="P">포토/영상</option>
							</select>
						</td>
						<th>회원검색</th>
						<td>
							<select name="searchGb">
								<option value="memNm">회원명</option>
								<option value="email">이메일</option>
							</select>
							<input type="text" name="seachTxt" class="w100" maxlength="50"/>
						</td>
						<th>포인트지급상태</th>
						<td>
							<select name="pntGiveStat">
								<option value="">[전체]</option>
								<option th:if="${pntGiveStatList}" th:each="oneData, status : ${pntGiveStatList}" th:value="${oneData.cd}" th:text="${oneData.cdNm}"></option>
							</select>
						</td>
						<th>노출여부</th>
						<td>
							<select name="dispYn">
								<option value="">[전체]</option>
								<option value="Y" selected="selected">[Y] Yes</option>
								<option value="N">[N] No</option>
							</select>
						</td>
					</tr>
				</table>
				
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearch">조회</button>
						<button type="button" class="btn btn-gray btn-lg" onclick="$('#searchForm')[0].reset();">초기화</button>
					</li>
				</ul>
			</form>
		</div>
		<!-- //검색조건 영역 -->
		
		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li>
					<button type="button" class="btn btn-info btn-lg" id="btnSaveBestReview">베스트상품평 선정</button>
				</li>
				<li class="right">
					검색결과 : <strong><span id="totCnt">0</span> 건</strong>&nbsp;
					쪽번호 <span id="pageNo">0</span>/ <strong id="totPage" class="marR10">0</strong>
					<select 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>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
			
			<div id="gridList" style="width: 100%; height: 670px" class="ag-theme-balham lh60"></div>
			
			<ul class="panelBar">
				<li class="center">
					<div class="tablePaging" id="pagination"></div>
				</li>
			</ul>
		</div>
		<!-- //리스트 영역 -->
	</div>

<script type="text/javascript" src="/ux/plugins/gaga/gaga.paging.js"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	let scoreSizeList = gagajf.convertToArray([[${scoreSizeList}]]);
	let scoreColorList = gagajf.convertToArray([[${scoreColorList}]]);
	let scoreFitList = gagajf.convertToArray([[${scoreFitList}]]);
	let scoreThickList = gagajf.convertToArray([[${scoreThickList}]]);
	let scoreWeightList = gagajf.convertToArray([[${scoreWeightList}]]);
	let scoreBallList = gagajf.convertToArray([[${scoreBallList}]]);
	let pntGiveStatList = gagajf.convertToArray([[${pntGiveStatList}]]);
	
	// specify the columns
	let columnDefs = [
		{
			width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false,
			checkboxSelection: function (params) { return params.data.bestYn == 'N' ? true : false; }
		},
		{
			headerName: "상품평번호", field: "reviewSq", width: 90, cellClass: 'text-center',
			cellRenderer: function(params) { return '<a href="javascript:void(0);">' + params.value + '</a>'; }
		},
		{
			headerName: "상품평유형", field: "reviewGb", width: 90, cellClass: 'text-center',
			cellRenderer: function(params) {
				return params.value == 'R' ? '일반' : '포토/영상';
			}
		},
		{
			headerName: "주문상품", cellClass: 'text-center',
			children: [
				{
					headerName: "이미지", field: "goodsImg", width: 100, height: 60, cellClass: 'text-center',
					cellRenderer: function(params) {
						return '<img width="60" src="' + _goodsUrl + '/' + params.value + '" alt="" onclick="cfnOpenImagePreViewPopup(\'goodsImgView\', \'' + _goodsUrl + '/' + params.value + '\')" onerror="this.src=\'/image/no.png\';"/>';
					}
				},
				{headerName: "상품코드", field: "goodsCd", width: 120, cellClass: 'text-center', cellRenderer: function(params) { return '<a href="javascript:void(0);">' + params.value + '</a>'; }},
				{headerName: "상품명", field: "goodsNm", width: 240, cellClass: 'text-center'},
				{headerName: '회원번호', field: 'custNo', width: 100, cellClass: 'text-center', hide: true},
				{
					headerName: '주문자명', field: 'maskingCustNm', width: 100, cellClass: 'text-center',
					cellRenderer: function(params) {
						if (gagajf.isNull(params.value)) return '';
						return '<a href="javascript:void(0);">' + params.value + '</a>';
					}
				},
				{headerName: '주문번호', field: 'ordNo', width: 90, cellClass: 'text-center', cellRenderer: function(params) { return '<a href="javascript:void(0);">' + params.value + '</a>'; }},
				{headerName: '주문상세번호', field: 'ordDtlNo', width: 120, cellClass: 'text-center', hide: true}
			]
		},
		{headerName: "상품평 제목", field: "reviewTitle", width: 200, cellClass: 'text-center', hide: true},
		{headerName: "상품평 내용", field: "reviewContent", width: 500, cellClass: 'text-center', hide: true},
		{
			headerName: "포인트지급", cellClass: 'text-center',
			children: [
				{headerName: "지급예정포인트", field: "giveDuePnt", width: 120, cellClass: 'text-center'},
				{
					headerName: "포인트지급상태", field: "pntGiveStat", width: 120, cellClass: 'text-center',
					cellEditorParams: { values: gagaAgGrid.extractValues(pntGiveStatList) },
					valueFormatter: function (params) { return gagaAgGrid.lookupValue(pntGiveStatList, params.value); }
				}
			]
		},
		{
			headerName: "베스트", cellClass: 'text-center',
			children: [
				{headerName: '베스트여부', field: 'bestYn', width: 90, cellClass: 'text-center'},
				{headerName: '포인트지급여부', field: 'bpntGiveYn', width: 120, cellClass: 'text-center', cellRenderer: function(params) { return params.value == 'N' ? '미지급' : '지급'; }},
				{headerName: '지급포인트', field: 'giveDueBpnt', width: 100, cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); }}
			]
		},
		{
			headerName: "만족도 점수", cellClass: 'text-center',
			children: [
				{headerName: '총점', field: 'score', width: 100, cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.toAddComma(params.value); }},
				{headerName: '사이즈점수', field: 'scoreSize', width: 100, cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.lookupValue(scoreSizeList, params.value); }},
				{headerName: '컬러점수', field: 'scoreColor', width: 100, cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.lookupValue(scoreColorList, params.value); }},
				{headerName: '핏점수', field: 'scoreFit', width: 100, cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.lookupValue(scoreFitList, params.value); }},
				{headerName: '두께감점수', field: 'scoreThick', width: 100, cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.lookupValue(scoreThickList, params.value); }},
				{headerName: '무게감점수', field: 'scoreWeight', width: 100, cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.lookupValue(scoreWeightList, params.value); }},
				{headerName: '볼넓이점수', field: 'scoreBall', width: 100, cellClass: 'text-center', cellRenderer: function (params) { return gagaAgGrid.lookupValue(scoreBallList, params.value); }}
			]
		},
		{
			headerName: "노출여부", field: "dispYn", width: 90, cellClass: 'text-center',
			cellRenderer: function(params) { return params.value == 'N' ? '미노출' : '노출'; }
		},
		{headerName: "삭제여부", field: "delYn", width: 90, cellClass: 'text-center', hide: true},
		{
			headerName: "확인", cellClass: 'text-center',
			children: [
				{headerName: '확인여부', field: 'confirmYn', width: 90, cellClass: 'text-center', cellRenderer: function(params) { return params.value == 'N' ? '미확인' : '확인'; }},
				{headerName: '확인자', field: 'confirmUnm', width: 90, cellClass: 'text-center'},
				{headerName: '확인일시', field: 'confirmDt', width: 150, cellClass: 'text-center', cellRenderer: function(params) { gagaAgGrid.toDateTimeFormat(params.value); }}
			]
		},
		{
			headerName: "등록일시", field: "regDt", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) { gagaAgGrid.toDateTimeFormat(params.value); }
		}
	];
	
	// Get GridOptions
	let gridOptions = gagaAgGrid.getGridOptions(columnDefs);
	
	gridOptions.rowSelection = 'multiple';
	gridOptions.rowHeight = 60; // 이미지가 있을경우 높이 지정해야함.
	
	// 셀 클릭 이벤트
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field == 'reviewSq') {
			// 상품평 상세
			cfnOpenReviewDetailPopup(event.data.reviewSq);
		} else if (event.colDef.field == 'ordNo') {
			// 주문 상세
			cfnOpenOrderDetailPopup(event.data.ordNo);
		} else if (event.colDef.field == 'goodsCd') {
			// 상품 상세
			cfnOpenGoodsDetailPopup('U', event.data.goodsCd);
		} else if (event.colDef.field == 'maskingCustNm') {
			// 고객 상세
			cfnOpenCustDetailPopup(event.data.custNo);
		}
	}
	
	// 조회
	$('#btnSearch').on('click', function() {
		gagaPaging.init('searchForm', fnSearchCallBack, 'pagination', $('#searchForm input[name=pageSize]').val());
		gagaPaging.load($("#searchForm input[name=pageNo]").val());
	});
	
	// 조회 콜백함수
	var fnSearchCallBack = function(result) {
		gridOptions.api.setRowData(result.dataList);
		gagaPaging.createPagination(result.paging.pageable);
		$('#totCnt').html(result.paging.pageable.totalCount.addComma());
		$('#pageNo').val(result.paging.pageable.pageNo.addComma());
		$('#totPage').val(result.paging.pageable.totalPage.addComma());
	}

	// 페이징크기 변경 시
	$('select[name=pageSize]').on('change', function() {
		$('#searchForm input[name=pageSize]').val($(this).val());
		$('#searchForm input[name=pageNo]').val(1);
		$('#btnSearch').trigger('click');
	});
	
	// 베스트상품평 선정
	$('#btnSaveBestReview').on('click', function() {
		let chooseData = gagaAgGrid.selectedRowData(gridOptions);
		
		if (chooseData.length == 0) {
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}
		
		mcxDialog.confirm("베스트 상품평으로 선정하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var updatedData = [];
				
				$.each(chooseData, function(idx, item) {
					if (item.bestYn == 'N') {
						item.bestYn = 'Y';
						updatedData.push(item);
					}
				});
				
				var jsonData = JSON.stringify(updatedData);
				gagajf.ajaxJsonSubmit('/marketing/review/best/list/save'
						, jsonData
						, function() {
							$('#btnSearch').trigger('click');
						});
			}
		});
	});
	
	$(document).ready(function() {
		cfnCreateCalendar('#terms', 'startDt', 'endDt', true, '등록');
		$('.btnToday').trigger('click');
		
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
	});
/*]]>*/
</script>

</html>
