<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="<%=basePath %>resource/css/base.css" rel="stylesheet">
    <link rel="stylesheet" href="<%=basePath %>resource/easyui/uimaker/easyui.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath %>resource/easyui/uimaker/icon.css">
    <link rel="stylesheet" href="<%=basePath %>resource/css/providers.css">
    <!-- validate 验证中英文 -->
    <script type="text/javascript" src="<%=basePath %>resource/validate/jquery.validate-${pageContext.response.locale}.js"></script>
</head>
<body>
<div class="container">
    <div data-options="closable:true">
        <table id="dg" style="width:100%;" title="<spring:message code="handlebill.record" />" data-options="
                rownumbers:true,
                singleSelect:false,
                autoRowHeight:false,
                pagination:true,
                fitColumns:true,
                striped:true,
                collapsible:true,
                toolbar:'#tb',
                pageSize:10">
            <thead>
            <tr>
                <th field="id" checkbox="true"></th>
                <th field="."  formatter="editFormat" width="25"><spring:message code="opt.edit" /></th>
                <th field="deliveryStation" width="226"><spring:message code="handlebill.station" /></th>
                <th field="agent" width="110"><spring:message code="handlebill.agent" /></th>
                <th field="flightNo" width="112"><spring:message code="handlebill.flight" /></th>
                <th field="status" width="170" formatter="statusFormatter"><spring:message code="handlebill.ishandle" /></th>
                <th field="createDate" width="130" sortable="true" ><spring:message code="handlebill.handledate" /></th>
            </tr>
            </thead>
        </table>
        <div id="tb" style="padding:0 30px;">
            <form id="searchForm">
               	<spring:message code="handlebill.agent" />:<input class="easyui-textbox" type="text" name="search_LIKE_agent" style="width:166px;height:35px;line-height:35px;">
                <spring:message code="handlebill.flight" />:<input class="easyui-textbox" type="text" name="search_LIKE_flightNo" style="width:166px;height:35px;line-height:35px;">
                <a href="javascript:doSearch()" class="easyui-linkbutton" iconCls="icon-search" data-options="selected:true"><spring:message code="opt.search" /></a>
                <a href="javascript:editRow()" class="easyui-linkbutton" style="background:#18A197;color:#FFF;border: 1px solid #18A197;" iconCls="icon-add"><spring:message code="handlebill.handlebill" /></a>
                <a href="javascript:doDelete()" class="easyui-linkbutton" style="background:red;color:#FFF;border: 1px solid red" iconCls="icon-no"><spring:message code="opt.delete" /></a>
            </form>
        </div>

</div>

<script type="text/javascript" src="<%=basePath %>resource/easyui/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath %>resource/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=basePath %>resource/easyui/easyui-lang-${pageContext.response.locale}.js"></script>
<script type="text/javascript" src="<%=basePath %>resource/js/tools.js"></script>
<!--弹出层引入的JS-->
<script type="text/javascript" src="<%=basePath %>resource/layer-v3.0.3/layer/layer.js"></script>

<script type="text/javascript">
    $('#dg').datagrid({
        url:'<%=basePath %>handlebill/grid.json',
        queryParams:$("#searchForm").serializeJson()
    });
    
    function statusFormatter(val,row,index){ 
    	if(val ==0) {
    		return "<font style='color:red;'><spring:message code="handlebill.yes" /></font>";
    	} else {
    		return "<font style='color:green;'><spring:message code="handlebill.no" /></font>";
    	}
    }

    function editFormat(val,row,index){
        var html='<a href="javascript:void(0)" style="text-decoration:none;" onclick="editRow('+row.id+')"><i class="iconfont">&#xe65a;</i></a>'
        return html;
    }

    function editRow(id){
        if(id==undefined){
            window.location.href='<%=basePath %>handlebill/edit?id=';
        }else{
            window.location.href='<%=basePath %>handlebill/edit?id='+id;
        }
    }

    function doSearch(){
        $('#dg').datagrid("options").queryParams=$("#searchForm").serializeJson();
        $('#dg').datagrid("reload");
    }
    function getIds() {
        var ids = [];
        var rows = $("#dg").datagrid('getChecked');
        $.each(rows,function(key,v){
            ids.push(v.id);
        });
        return ids;
    }
    function doDelete(){
        var rows = $("#dg").datagrid('getChecked');
        if(rows.length==0){
            layer.open({content:"请先选中要删除的行"});
            return false;
        }
        layer.confirm("确定要删除么?",{btn:['确定','取消']}, function () {
            $.post("<%=basePath%>agent/delete",{ids:getIds().join(",")},function(data){
                if(data.status == 200) {
                    layer.confirm("Delete Success",{btn:['确定','取消']},function(){
                        window.location.href="<%=basePath%>handlebill/list";
                    })
                }else{
                    layer.open({content:"Delete Failed"});
                }
            },"json");

        });
    }
</script>
</body>
</html>