<!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 goPage(pageNo){
		var form = document.searchVO;
		form.page.value = pageNo;	
		form.action = "/insurance/apply";
		form.submit();
	}
	
	function goSearch(){
		
		var form = document.searchVO;
		form.page.value = 1;	
		form.action = "/insurance/apply";
		form.submit();
	}



		function statusUpdate(idx, status){
			
			
	        	 $.ajax({
	     			type : "post",
	     			url : "/insurance/updateStatus",
	     			data : {
	     				idx:idx,
	     				status:status	     				
	     				
	     			},
	     			async : false,
	     			dataType : "json",
	     			success : function(data) {
	     				if(data.RES=="SUCCESS"){
	     					$('#tr'+idx).remove();
	     					alert("처리완료");
	     				}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 th:class="${searchVO.status == '0' } ? active : ''" href="/insurance/apply?status=0">지급신청</a></li>
                <li><a th:class="${searchVO.status == '2' } ? active : ''" href="/insurance/apply?status=2">지급대기</a></li>
                <li><a th:class="${searchVO.status == '1' } ? active : ''" href="/insurance/apply?status=1">지급완료</a></li>
                <li><a th:class="${searchVO.status == '-1' } ? active : ''" href="/insurance/apply?status=-1">지급취소</a></li>
              </ul>
              <form class="searchWrap-form" name="searchVO">
                  <input type="hidden" id="page" name="page" th:value="${searchVO.page}"/>
                  <input type="hidden" id="status" name="status" th:value="${searchVO.status}"/>
                  <div class="tableserachwrap">
                    <div>
                      <ul class="tableserach">
                        <li>
                          <div class="input-group">
                            <div>
                              <label class="input-group-text">유형</label>
                            </div>
                              <select name="count_per_list">
                              <option value="10"  th:selected="${searchVO.count_per_list == 10}">10</option>
                              <option value="20"  th:selected="${searchVO.count_per_list == 20}">20</option>
                              <option value="50"  th:selected="${searchVO.count_per_list == 50}">50</option>
                              <option value="100"  th:selected="${searchVO.count_per_list == 100}">100</option>
                            </select>
                          </div>
                        </li>
                        <li>
                          <div class="input-group">
                            <div>
                              <label class="input-group-text">기간</label>
                            </div>
                            <input class="br0" type="date" name="startDate" th:value="${searchVO.startDate}"/>
                            <input type="date" name="endDate" th:value="${searchVO.endDate}"/>
                          </div>
                        </li>
                        <li>
                            <a class="btn" href ="javascript:goSearch()">
	                            전체검색
	                        </a>                         
                        </li>
                      </ul>

                    </div>
                  </div>
			  </form>
              <div class="table">
                <div class="head" th:test="${searchVO.status}"><h6>하부보험금신청내역</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>
                        </tr>
                      </thead>
                      <tbody>
                      <th:block th:each="list,seq : ${list}">
							<tr  th:id="|tr${list.idx}|">
								 <td th:text="${list.siteId}">컴퍼니아이디</td>
		                          <td th:text="${list.siteId}">회사명</td>
		                          <td th:text="|${#numbers.formatInteger(list.preInsureAmt, 0, 'COMMA')}|"> 전 보험금</td>
		                          <td th:text="|${#numbers.formatInteger(list.insureAmt, 0, 'COMMA')}|">신청 보험금</td>
		                          <td th:text="|-|">지급보험금</td>
		                          <td th:text="${#numbers.formatInteger(      (T(Long).parseLong(list.preInsureAmt)) + (T(Long).parseLong(list.insureAmt)), 0, 'COMMA') }">처리 후 보험금</td>
		                          <td th:text="${list.regDate}">신청일</td>
		                          <td th:text="${list.updDate}">완료일</td>
		                          <td>
		                          	<span th:if="${list.status eq '0' }" th:text="신청"></span>
	                        		<span th:if="${list.status eq '1' }" th:text="완료"></span>
	                        		<span th:if="${list.status eq '2' }" th:text="대기"></span>
	                        		<span th:if="${list.status eq '-1' }" th:text="취소"></span>
		                          </td>
		                          <td >
		                         	 <a th:if="${list.status eq '0' }" th:text="대기" th:href="|javascript:statusUpdate(${list.idx},2)|"></a>
	                        		<a th:if="${list.status eq '2' }" th:text="승인" th:href="|javascript:statusUpdate(${list.idx},1)|"> |</a>  
	                        		<a th:if="${list.status eq '2' }" th:text="취소" th:href="|javascript:statusUpdate(${list.idx},-1)|"></a>
	                        		<span th:if="${list.status eq '1' }" th:text="완료"></span>
		                          </td>
							</tr>
					</th:block>

                      </tbody>
                    </table>
                         <th:block th:utext="${pageInfo}"></th:block>
                  </div>
                </div>
              </div>

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

 </th:block>