<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : ExtmallForm.html
 * @desc    : 제휴몰관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.11.05   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="@{'/ocm/extmall/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>제휴몰벤더</th>
						<td>
							<select name="vendorId">
								<option value="">[전체]</option>
								<option th:if="${vendorList}" th:each="oneData, status : ${vendorList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></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 class="right">
					<button type="button" class="btn btn-default btn-lg" id="btnExcel">엑셀다운로드</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
			
			<div id="gridList" style="width: 100%; height: 470px" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->
		
		<!-- 등록/수정 -->
		<div class="panelStyle">
			<div class="panelTitle">
				<h3><i class="fa fa-info-circle"></i><font color="red">신규등록 시 WMS에도 꼭 등록요청해주세요.</font></h3>
			</div>
			<form id="detailForm" name="detailForm" action="#" th:action="@{'/ocm/extmall/save'}">
				<table class="frmStyle" aria-describedby="등록/수정 폼">
					<colgroup>
						<col style="width:8%;"/>
						<col style="width:17%;"/>
						<col style="width:8%;"/>
						<col style="width:17%;"/>
						<col style="width:8%;"/>
						<col style="width:17%;"/>
						<col style="width:8%;"/>
						<col style="width:17%;"/>
					</colgroup>
					<tr>
						<th>제휴몰벤더<i class="required" title="필수"></i></th>
						<td>
							<select name="vendorId" required="required" data-valid-name="제휴몰벤더">
								<option value="">[선택]</option>
								<option th:if="${vendorList}" th:each="oneData, status : ${vendorList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						
						<th>제휴몰ID<i class="required" title="필수"></i></th>
						<td>
							<input type="text" class="w150" name="extmallId" maxlength="20" required="required" data-valid-name="제휴몰ID"/>
						</td>
						<th>제휴몰사용자ID<i class="required" title="필수"></i></th>
						<td>
							<input type="text" class="w150" name="extmallUserId" maxlength="20" required="required" data-valid-name="제휴몰사용자ID"/>
						</td>
						<th>제휴몰명<i class="required" title="필수"></i></th>
						<td>
							<input type="text" name="extmallNm" maxlength="50" required="required" data-valid-name="제휴몰명"/>
						</td>
					</tr>
					<tr>
						<th>공급업체</th>
						<td>
							<select name="supplyCompCd">
								<option value="">[선택]</option>
								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>

						<th>고객센터연락처</th>
						<td>
							<input type="text" class="w150" name="extmallTel" maxlength="20"/>
						</td>
						<th>수수료율(관리용)</th>
						<td>
							<input type="text" class="w100 aR" name="sellFeeRate" maxlength="3" required="required" data-valid-type="real" data-valid-name="수수료율(관리용)"/>%
						</td>
						<td colspan="2"></td>
						<!-- 숨김처리 사용안하기로 함
						<th>판매매장코드</th>
						<td>
							<input type="text" class="w150" name="sellStoreCd" maxlength="20"/>
						</td>
						<th>재고판매비율<i class="required" title="필수"></i></th>
						<td>
							<input type="text" class="w100 aR" name="stockSellRate" maxlength="3" required="required" data-valid-type="real" data-valid-name="재고판매비율"/>%
						</td>
						<th>가격차이허용율<i class="required" title="필수"></i></th>
						<td>
							<input type="text" class="w100 aR" name="priceAcceptRate" maxlength="3" required="required" data-valid-type="real" data-valid-name="가격차이허용율"/>%
						</td>
						 -->
					</tr>
					<tr>
						<th>직접회수여부</th>
						<td>
							<label class="rdoBtn"><input type="radio" name="dwdpYn" value="Y" checked="checked">제휴몰에서 회수<span></span></label>
							<label class="rdoBtn"><input type="radio" name="dwdpYn" value="N">자사몰에서 회수<span></span></label>
						</td>
						<th>취소문자발송여부</th>
						<td colspan="3">
							<label class="rdoBtn"><input type="radio" name="cnclsmsSendYn" value="Y" checked="checked">제휴몰에서 발송<span></span></label>
							<label class="rdoBtn"><input type="radio" name="cnclsmsSendYn" value="N">자사몰에서 발송<span></span></label>
						</td>
						<th>사용여부<i class="required" title="필수"></i></th>
						<td>
							<label class="rdoBtn"><input type="radio" name="useYn" value="Y" checked="checked">Yes<span></span></label>
							<label class="rdoBtn"><input type="radio" name="useYn" value="N">No<span></span></label>
						</td>
					</tr>
				</table>
			</form>
			
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-info btn-lg" id="btnNew">신규</button>
					<button type="button" class="btn btn-success btn-lg" id="btnSave">저장</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
		</div>
		<!-- 등록/수정 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	let vendorList = gagajf.convertToArray([[${vendorList}]]);
	let supplyCompList = gagajf.convertToArray([[${supplyCompList}]]);

	let columnDefs = [
// 		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
// 		{headerName: "CRUD", field: "crud", width: 75, minWidth: 75, hide: true},
		{
			headerName: "제휴몰벤더", field: "vendorId", width: 150, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(vendorList, params.data.vendorId); }
		},
		{
			headerName: "제휴몰ID", field: "extmallId", width: 120, cellClass: 'text-center',
			cellRenderer: function(params) {
				return '<a href="javascript:void(0);">' + params.value + '</a>';
			}
		},
		{headerName: "제휴몰사용자ID", field: "extmallUserId", width: 150, cellClass: 'text-center'},
		{headerName: "제휴몰명", field: "extmallNm", width: 200},
		{
			headerName: "업체", field: "supplyCompCd", width: 150, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(supplyCompList, params.data.supplyCompCd); }
		},
		{headerName: "고객센터연락처", field: "extmallTel", width: 150, cellClass: 'text-center'},
		{headerName: "수수료율(관리용)", field: "sellFeeRate", width: 120, cellClass: 'text-center'},
		/* {headerName: "판매매장코드", field: "sellStoreCd", width: 120, cellClass: 'text-center'},
		{headerName: "재고판매비율(%)", field: "stockSellRate", width: 150, cellClass: 'text-center'},
		{headerName: "가격차이허용율(%)", field: "priceAcceptRate", width: 150, cellClass: 'text-center'}, */
		{
			headerName: "직접회수여부", field: "dwdpYn", width: 150, cellClass: 'text-center',
			cellRenderer: function (params) {
				return params.value == 'Y' ? '제휴몰에서회수' : '자사몰에서회수';
			}
		},
		{
			headerName: "취소문자발송여부", field: "cnclsmsSendYn", width: 150, cellClass: 'text-center',
			cellRenderer: function (params) {
				return params.value == 'Y' ? '제휴몰에서발송' : '자사몰에서발송';
			}
		},
		{
			headerName: "사용여부", field: "useYn", width: 100, cellClass: 'text-center',
			cellRenderer: function (params) {
				return params.value == 'Y' ? 'Yes' : 'No';
			}
		}
	];

	let gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// Cell click
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field != 'extmallId')
			return;
		
		$('#detailForm select[name=vendorId]').val(event.data.vendorId);
		$('#detailForm input[name=extmallId]').val(event.data.extmallId);
		$('#detailForm input[name=extmallUserId]').val(event.data.extmallUserId);
		$('#detailForm input[name=extmallNm]').val(event.data.extmallNm);
		$('#detailForm input[name=extmallTel]').val(event.data.extmallTel);
		$('#detailForm select[name=supplyCompCd]').val(event.data.supplyCompCd);
		$('#detailForm input[name=sellFeeRate]').val(event.data.sellFeeRate);
		//$('#detailForm input[name=sellStoreCd]').val(event.data.sellStoreCd);
		//$('#detailForm input[name=stockSellRate]').val(event.data.stockSellRate);
		//$('#detailForm input[name=priceAcceptRate]').val(event.data.priceAcceptRate);

		if (event.data.dwdpYn == 'Y') {
			$('#detailForm input:radio[name=dwdpYn]').eq(0).trigger('click');
		} else {
			$('#detailForm input:radio[name=dwdpYn]').eq(1).trigger('click');
		}
		
		if (event.data.cnclsmsSendYn == 'Y') {
			$('#detailForm input:radio[name=cnclsmsSendYn]').eq(0).trigger('click');
		} else {
			$('#detailForm input:radio[name=cnclsmsSendYn]').eq(1).trigger('click');
		}
		
		if (event.data.useYn == 'Y') {
			$('#detailForm input:radio[name=useYn]').eq(0).trigger('click');
		} else {
			$('#detailForm input:radio[name=useYn]').eq(1).trigger('click');
		}
	}

	// 검색
	$('#btnSearch').on('click', function() {
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
	});
	
	// 신규버튼
	$('#btnNew').on('click', function() {
		$("#detailForm")[0].reset();
	});

	// 저장
	$("#btnSave").on("click", function() {
		// 필수값 체크
		if (!gagajf.validation('#detailForm'))
			return false;

		mcxDialog.confirm("저장하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				gagajf.ajaxFormSubmit($('#detailForm').prop('action'), '#detailForm', function() {
					$('#btnNew').trigger('click');
					$('#btnSearch').trigger('click');
				});
			}
		});
	});
	
	// 엑셀다운로드
	$('#btnExcel').on('click', function() {
		gagaAgGrid.exportToExcel('제휴몰 목록', gridOptions);
	});

	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
	});
/*]]>*/
</script>

</html>
