<!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 allSet(){
		$('#subInsureCheck').prop("checked");
		$('.insureRateInput').val($('#subInsureRate').val());
		$('.insureYnCheck').prop("checked", $('#subInsureCheck').prop("checked"));
	}
	
	
	function saveInsure(){
		
		if($('#upperSiteId').val()==""){
			alert("보험적용컴파니를 선택하세요");return;			
		}

		var ret = []
		  $('#rateList tr').each(function(index,item){
			var checkYn = "N";
			if($(this).find(".insureYnCheck").prop("checked")){checkYn = "Y";}
			  
		   var row = {vendorIdx:$(this).find("td").data('vidx'),insureRate:$(this).find(".insureRateInput").val(), insureYn:checkYn };
		   ret.push(row);
		  });
		
		
		
		 $.ajax({
  			type : "post",
  			url : "/insurance/setSave",
  			data : {
  				param :{uppersiteIdx: $('#upperSiteId').val()}, 						
 				paramlist:ret
  			},
  			async : false,
  			dataType : "json",
  			success : function(data) {
  				if(data.RES=="SUCCESS"){
  					
  					alert("처리완료");
  				}else{
  					
  				}
  				
  			}
  		});
		
	}	
	
	</script>
</th:block>
		<th:block layout:fragment="content">

            <div class="container-fluid">
              <div class="page-name">
                  <h1>보험설정</h1>
              </div>

              <div class="table insur">
                <div class="head"><h6>상부 보험 설정</h6></div>
                <div class="body">
                  <div class="tableserachwrap">
                  	<div>
                      <ul class="tableserach">
                        <li>
                          <div class="input-group">
                            <div>
                              <label class="input-group-text" >보험 적용 에이전시</label>
                            </div>
                            <select id="upperSiteId">
                            	 <option value="">없음</option>
                           	 <th:block th:each="list,seq : ${flowList}"> 
                              <option th:if="${seq.index >0}" th:value="${list.siteIdx}" th:text="|${list.upperSiteId}(${seq.index+1})|"  th:selected="${uppersiteIdx eq list.siteIdx}"></option>
                              </th:block>
                              
                            </select>
                          </div>
                        </li>
                      </ul>
                    </div>
                    <div>
                      <ul class="tableserach">
                        <li>
                          <div class="input-group">
                            <div>
                              <label class="input-group-text">보험률(%)</label>
                            </div>
                            <input type="text" value="0" id="subInsureRate"/>
                          </div>
                        </li>
                        <li>
                          <div class="input-group">                            
                              <label class="input-group-text">보험사용여부</label>  
                              <input type="checkbox" class="set-switch" id="subInsureCheck"/>
                          </div>
                        </li>
                        <li class="ml05"><a class="btn" href="javascript:allSet();">전체적용</a></li>
                        <li class="ml05"><a class="btn" href="javascript:saveInsure();">저장</a></li>
                      </ul>
                    </div>                    
                  </div>

                  <div class="table-responsive">
                    <table>
                      <thead>
                        <tr>
                          <th>게임구분</th>
                          <th>회사별 보험률(%)</th>
                          <th>보험적용여부</th>
                        </tr>
                      </thead>
                      <tbody class="insurTable" id="rateList">                      
                         <th:block th:each="list,seq : ${vederRateList}">
                        <tr>
                          <td th:text="${list.vendorName}" class="vendor" th:data-vidx="${list.vendorIdx}">에볼루션</td>
                          <td><input type='number' class="insureRateInput"  th:value="|${list.get('insureRate')}|"></input>%</td>
                          <td><input type="checkbox" class="set-switch insureYnCheck" th:checked="${list.get('insureYn') =='Y'}"/></td>
                        </tr>
                        </th:block>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
              <div class="table insur">
                <div class="head"><h6>하부 보험 설정</h6></div>
                <div class="body">
                  <div class="tableserachwrap">
                  	<div>
                      <ul class="tableserach">
                        <li>
                          <div class="input-group">
                            <div>
                              <label class="input-group-text" >하부 보험 에이전시 목록</label>
                            </div>
                            <select id="upperSiteId">
                            	 <option value="">없음</option>
                           	 <th:block th:each="list,seq : ${flowList}"> 
                              <option th:if="${seq.index >0}" th:value="${list.siteIdx}" th:text="|${list.upperSiteId}(${seq.index+1})|"  th:selected="${uppersiteIdx eq list.siteIdx}"></option>
                              </th:block>
                              
                            </select>
                          </div>
                        </li>
                      </ul>
                    </div>
                    <div>
                      <ul class="tableserach">                        
                        <li>
                          <div class="input-group">                            
                              <label class="input-group-text">보험사용여부</label>  
                              <input type="checkbox" class="set-switch" id="subInsureCheck"/>
                          </div>
                        </li>
                        <li class="ml05"><a class="btn" href="javascript:allSet();">전체적용</a></li>
                        <li class="ml05"><a class="btn" href="javascript:saveInsure();">저장</a></li>
                      </ul>
                    </div>                    
                  </div>

                  <div class="table-responsive">
                    <table>
                      <thead>
                        <tr>
                          <th style="width:16%;">게임구분</th>
                          <th style="width:28%;">회사별 보험률(%)</th>
                          <th style="width:28%;">게임 롤링 요율</th>
                          <th style="width:28%;">보험적용여부</th>
                        </tr>
                      </thead>
                      <tbody class="insurTable" id="rateList">                      
                         <th:block th:each="list,seq : ${vederRateList}">
                        <tr>
                          <td th:text="${list.vendorName}" class="vendor" th:data-vidx="${list.vendorIdx}">에볼루션</td>
                          <td><input type='text' class="btinsureRate"  th:value="|${list.get('insureRate')}|" readonly></input>%</td>
                          <td><input type='text' value="1.5"></input>%</td>
                          <td><input type="checkbox" class="set-switch insureYnCheck" th:checked="${list.get('insureYn') =='Y'}"/></td>
                        </tr>
                        </th:block>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>

            </div><!-- container-fluid -->

</th:block>