<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
    String basePath = request.getContextPath();
%>
<div class="table-responsive">
    <table class="table table-striped table-bordered table-hover " >
        <thead>
        <tr>
            <th>申请人</th>
            <th>发票类型</th>
            <th>发票金额</th>
            <th>可开票金额</th>
            <th>发票抬头</th>
            <th>申请时间</th>
            <th>状态</th>
            <th>操 作</th>
        </tr>
        </thead>
        <tbody>
        <c:choose>
            <c:when test="${list!=null}">
                <c:forEach items="${list}" var="item" >
                    <tr>
                        <td><a onclick="aaa(${item.userId})" >${item.userName}</a></td>
                        <td>${item.invoiceType}</td>
                        <td>${item.invoiceAmount}</td>
                        <td>${item.invoicedAmount}</td>
                        <td>${item.orgName}</td>
                        <td><fmt:formatDate value="${item.invoicedAt}" pattern="yyyy-MM-dd"></fmt:formatDate> </td>
                        <td>
                            <c:if test="${item.invoiceState==null}">开票中</c:if>
                            <c:if test="${item.invoiceState!=null}">${item.invoiceState}</c:if>
                        </td>
                        <td class="btn-table hidden-print">
                            <input type="hidden" name="id" value="${item.id}" />
                            <input type="hidden" name="userId" value="${item.userId}" />
                            <input type="hidden" name="orderId" value="${item.orderId}" />
                            <c:if test="${item.id==null}">
                                <button name="btnEdit" class="btn btn-sm btn-primary m-r-sm"><i class="fa fa-edit"></i>开票登记</button>
                            </c:if>
                            <c:if test="${item.id!=null}">
                                <button name="btnDetail" class="btn btn-sm btn-primary m-r-sm"><i class="fa fa-check"></i>发票详情</button>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
            </c:when>
            <c:otherwise>
                <tr>
                    <td colspan="4">无数据</td>
                </tr>
            </c:otherwise>
        </c:choose>
        </tbody>
    </table>
</div>
<jsp:include page="../../../common/admin/pager.jsp">
    <jsp:param name="pageNo" value="${pager.pageNo}"/>
    <jsp:param name="pageSize" value="${pager.pageSize}"/>
    <jsp:param name="total" value="${pager.total}"/>
</jsp:include>
<script type="text/javascript">
    $("#divGrid table tbody tr td:last-child")
        .on("click", "button[name='btnEdit']", function () {

            var id = $(this).parent().children("input[type='hidden'][name='id']").val();
            var userId = $(this).parent().children("input[type='hidden'][name='userId']").val();
            var orderId = $(this).parent().children("input[type='hidden'][name='orderId']").val();
            if(id!="") {
                $.popBsPartial({ url: "<%=basePath%>/admin/Invoice/add.htm/"+id+"/"+userId+"/"+orderId});
            }else {
                $.popBsPartial({ url: "<%=basePath%>/admin/Invoice/add1.htm/"+userId+"/"+orderId});
            }
        })

        .on("click", "button[name='btnDetail']", function () {

            var id = $(this).parent().children("input[type='hidden'][name='id']").val();
            $.popBsPartial({ url: "<%=basePath%>/admin/Invoice/toDetail.htm/" + id });
        });
    function aaa(id) {
        debugger;
        $.popBsPartial({ url: "<%=basePath%>/admin/Invoice/userView.htm/"+id});
    }

</script>