<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorate="~{admin/layout/layout}" th:with="title='',active='home'">
<th:block layout:fragment="html_head">
	<script>
	function agentDetail(siteIdx){
		
		var popup = window.open('/agent/detail/'+siteIdx, 'detail', '');
	}
	

	function goPage(pageNo){
		var form = document.searchVO;
		form.page.value = pageNo;	
		form.action = "/agent";
		form.submit();
	}
	
	
	function goSearch(pageNo){
		var form = document.searchVO;
		form.page.value = 1;	
		form.action = "/agent";
		form.submit();
	}
	
	
	function siteUseUpdate(siteId, useYn){
		
		if(confirm("상태를 변경하시겠습니까?")){	
			 $.ajax({
		 			type : "post",
		 			url : "/agent/siteUpdate",
		 			data : {
		 				siteId:siteId,
		 				siteUseYn:useYn
		 				
		 			},
		 			async : true,
		 			dataType : "json",
		 			success : function(data) {
		 				if(data.RES=="SUCCESS"){
		 					alert("변경완료");		
		 				//	location.href = location.href; 
		 					//$('#ciCreditAmt').val();
		 					location.reload();
		 				}else{
		 					alert(data.MSG);
		 				
		 				}
		 			}
		 		});
		}
		
	}

	
		function siteAdd(){
			
			if(confirm("생성하시겠습니까?")){	 
	        	 $.ajax({
	     			type : "post",
	     			url : "/agent/addProc",
	     			data : {
	     				siteId:$('#siteId').val(),
	     				siteName:$('#siteName').val(),
	     				sitePass:$('#sitePass').val(),
	     				siteCreditRate:$('#siteCreditRate').val(),
	     				memo:$('#memo').val()
	     				
	     			},
	     			async : false,
	     			dataType : "json",
	     			success : function(data) {
	     				if(data.RES=="SUCCESS"){
	     					
	     			
	     				}else{
	     					
	     				}
	     				
	     			}
	     		});
			
			}
		}
	
	</script>

</th:block>

<th:block layout:fragment="content">

            <div class="container-fluid">
              <div class="page-name">
                  <h1>에이전시 목록</h1>
              </div>

			  <ul class="tabletab">
                <li><a class="active">전체(<em class="num" th:text="${searchVO.tatal_list_count}">0</em>)</a></li>
                <li><a>계정 숨겨짐</a></li>
              </ul>
              <div class="tableserachwrap">	                	
                 <div>
                   <form class="searchWrap-form" name="searchVO">
                     <input type="hidden" id="page" name="page" th:value="${searchVO.page}"/>
	                   <ul class="tableserach">
	                     <li>
	                       <div class="input-group">
	                         <select class="br0" name="searchType">
	                           <option value="siteId" th:selected="${searchVO.searchType eq 'siteId'}">에이전시 아이디</option>
	                           <option value="siteGubun" th:selected="${searchVO.searchType eq 'siteGubun'}">에이전시 분류</option>
	                           <option value="siteType" th:selected="${searchVO.searchType eq 'siteType'}">에이전시 타입</option>
	                         </select>
	                       </div>
	                     </li>
	                     <li>
	                       <div class="input-group">
	                         <input type="text" name="searchValue" class="br0 mr10" value="검색어" th:value="${searchVO.searchValue}"/>
	                       </div>
	                     </li>
	                     <li>
	                       <a class="btn" href="javascript:goSearch()">
	                         전체검색
	                       </a>
	                     </li>
	                   </ul>
					</form>
                 </div>
	          </div>
              <div class="table">
                <!--div class="head"><h6>에이전시 목록 (<em class="num" th:text="${searchVO.tatal_list_count}">0</em>)</h6></div-->
                <div class="body">                  
                  
                  <div class="table-responsive">
                    <table class="center">
                      <thead>
                        <tr>
                         <th>번호</th>
                          <th>단계</th>
                          <th>아이디</th>                                           
                          <th>에이전시 명</th>
                          <th>현재 보유 금액</th>
                          <th>요율</th>
                          <th>총 지급받은 금액</th>
                          <th>총 충전받은 금액</th>
                          <th>가입 시각</th>
                          <th>사용</th>
                          <th>옵션</th>
                        </tr>
                      </thead>
                      <tbody>
                      	
						<th:block th:each="site,siteSeq : ${siteList}">
                      	<tr>
                          <td th:text="${site.siteIdx}">-</td>
                          <td th:text="${site.siteLevel}">-</td>
                          <td><a th:text="${site.siteId}" th:href="|/agent/detail/${site.siteIdx}|">-</a></td>
                          <td  ><a th:text="${site.siteName}" th:href="|/agent/detail/${site.siteIdx}|" >에이전시</a></td>
                          <td th:text="${#numbers.formatInteger(site.get('credit'), 0, 'COMMA')}">현재 보유 금액</dt>
                          <td th:text="|${site.siteCreditRate}%|">요율</th>
                          <td th:text="${#numbers.formatInteger(site.get('aiCredit'), 0, 'COMMA')}">총 지급받은 금액</dt>
                          <td th:text="${#numbers.formatInteger(site.get('ciCredit'), 0, 'COMMA')}">총 충전받은 금액</dt>
                          <td th:text="${#temporals.format(site.regDate, 'yyyy-MM-dd HH:mm:ss')}">가입 시각</td>
                           <td th:text="${site.siteUseYn}">정지</td><!--td class="black">블랙</td-->
                          <td class="stop" >
                          	 <a th:if="${site.siteUseYn eq 'Y'}" th:href="|javascript:siteUseUpdate('${site.siteId}', 'N')|">정지</a>
                          	  <a th:if="${site.siteUseYn eq 'N'}" th:href="|javascript:siteUseUpdate('${site.siteId}', 'Y')|">복구</a>
                          </td><!--td class="black">블랙</td-->
                        </tr>
                      	</th:block>
                      </tbody>
                    </table>
                    <th:block th:utext="${pageInfo}"></th:block>
                  </div>
                </div>
              </div>
              <!--div class="btnwrap">
                <a class="btn modalBtn"><i class="fas fa-plus fa-sm"></i> 에이전시 생성</a>
              </div-->

              <!--div class="modal-content">
                <div class="modal-header"><h5>에이전시 생성</h5><a>×</a></div>
                <div class="modal-body">
                  <ul>
                    <li>소속 에이전시</li>
                    <li>
                      <select>
                        <option th:text="${loginSite.siteName}" th:value="${loginSite.siteId}">no.1 (@no.1)</option>
                      </select>
                    </li>
                  </ul>
                  <ul>
                    <li>아이디</li>
                    <li><input type="text" id="siteId" /></li>
                  </ul>
                  <ul>
                    <li>닉네임</li>
                    <li><input type="text" id="siteName" /></li>
                  </ul>
                  <ul>
                    <li>비밀번호</li>
                    <li><input type="text" id="sitePass"/><span>숫자+영문+특수문자로 입력해주시기 바랍니다. 아이디를 포함할 수 없으며, 최소 8글자 이상으로 입력해야 합니다.</span></li>
                  </ul>
                  <ul>
                    <li>타입</li>
                    <li>
                      <select>
                      	<option value="">단계</option>
                        <option value="0">0</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                        
                      </select>
                    </li>
                  </ul>
                  <ul>
                    <li>요율</li>
                    <li><input type="text" id="siteCreditRate" /></li>
                  </ul>
                  <ul>
                    <li>메모</li>
                    <li>
                      <textarea></textarea>
                    </li>
                  </ul>
                </div>
                <div class="modal-footer">
                  <a>취소</a>
                  <a href="javascript:siteAdd()">생성</a>
                </div>
              </div-->             

            </div><!-- container-fluid -->
            
            
            
            
            
            <!--div class="container-fluid">
              <div class="page-name">
                  <h1>에이전시 생성</h1>
              </div>

              <div class="table">
                <div class="body">                  
                  <div class="table-responsive">
                  	<h4 class="h4">에이전시 정보</h4>
                    <table>
                      <colgroup>
                        <col width="30%">
                        <col width="70%">
                      </colgroup>
                      <tbody>
                        <tr>
                          <th>에이전시명</th>
                          <td>
                            <div><input type="text" class="input" ></div>
                          </td>
                        </tr>
                        <tr>
                          <th>아이디</th>
                          <td>
                            <div><input type="text" class="input" ></div>
                          </td>
                        </tr>
                        <tr>
                          <th>비밀번호</th>
                          <td>
                            <div><input type="text" class="input" ></div>
                          </td>
                        </tr>
                        <tr>
                          <th>비밀번호 확인</th>
                          <td>
                            <div><input type="text" class="input" ></div>
                          </td>
                        </tr>
                        <tr>
                          <th>등급</th>
                          <td>
                            <div>
                            	<select class="select">
                            		<option>에이전시</option>
                            	</select>
							</div>
                          </td>                          
                        </tr>
                        <tr>
                          <th>연락처</th>
                          <td>
                            <div><input type="text" class="input" ></div>
                          </td>
                        </tr>
                      </tbody>
                    </table>  
                    <h4 class="h4">에이전시 잔고</h4>
                    <table>
                      <colgroup>
                        <col width="30%">
                        <col width="70%">
                      </colgroup>
                      <tbody>                        
                        <tr>
                          <th>에이전시 한도</th>
                          <td>
                            <div><input type="text" class="input" ></div>
                          </td>
                        </tr>
                        <tr>
                          <th>수수료율(%)</th>
                          <td>
                            <div>
                            	<select class="select">
                            		<option>에이전시</option>
                            	</select>
							</div>
                          </td>                          
                        </tr>                        
                      </tbody>
                    </table>                 
                  </div>
                </div>
              </div>
              <div class="btnwrap">
                <a class="btn"><i class="fas fa-plus fa-sm"></i> 등록하기</a>
              </div>                  
            </div><!- container-fluid -->
            
            
            
            
</th:block>