<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>航班日期修改</title>
    <%-- <link href="<%=basePath %>static/css/login.css" rel="stylesheet"> --%>
    <script src="<%=basePath %>static/easyui/jquery.min.js"></script>
    <link href="<%=basePath %>static/layui2.4.5/css/layui.css" rel="stylesheet">
    <script src="<%=basePath %>static/layui2.4.5/layui.js"></script>
    <script type="text/javascript" src="<%=basePath %>static/layer-v3.0.3/layer/layer.js"></script>
</head>
<body>
<div class="demoTable">
    航班号:
    <div class="layui-inline">
        <input class="layui-input" style="text-transform:uppercase;" name="flightno" id="flightno" autocomplete="off" onkeyup="if (this.value != this.value.toUpperCase()) this.value=this.value.toUpperCase();">
    </div>
   <button class="layui-btn" lay-submit="" id="searchBtn" data-type="getInfo">查询</button>
    <button class="layui-btn" data-type="reload" id="add">新增</button>
</div>
<table class="layui-hide" id="flight" lay-filter="flight"></table>
 <%--
<script type="text/html" id="toolbar">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" >新增</button>
	<input id="searchInput"  type="text"  placeholder="请输入关键字">
    <button class="layui-btn layui-btn-sm" >查询</button>
  </div>
</script> --%>
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
              
 
<script>
layui.use('table', function(){
  var table = layui.table;
  
  table.render({
    elem: '#flight'
    ,url:'<%=basePath %>/flight/getList'
   /*  ,toolbar: '#toolbar' */
    ,title: '航班跨天配置'
    ,page: true //开启分页
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'flightno', title:'航班号', width:90, fixed: 'left', unresize: true, sort: true}
      ,{field:'crossdatys', title:'跨天数', width:120, edit: 'text'}
      ,{field:'originatingstation', title:'起始站', width:80, edit: 'text', sort: true}
      ,{field:'week', title:'星期', width:100}
      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
    ]]
  });
  
  $('#searchBtn').on('click',function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
  });
  // 点击获取数据
  var  active = {
      getInfo: function () {
          var flightno=$('#flightno').val();
          /* if (flightno) { */
              var index = layer.msg('查询中,请稍候...',{icon: 16,time:false,shade:0});
              setTimeout(function(){
                  table.reload('flight', { //表格的id
                      url:'<%=basePath %>/flight/selectByFlightno',
                      page:{
                          curr:1  //从第一页开始
                      },
                      where: {
                          'flightno':$.trim(flightno)
                      }
                  });
                  layer.close(index);
              },800);
         /*  } else {
              layer.msg("请输入航班号");
          } */
      },
  };
  $("#flightno").bind("keyup", function (e) {
      if (e.keyCode == 13) {
          var type = "getInfo";
          active[type] ? active[type].call(this) : '';
      }
  });
  
  //监听行工具事件
  table.on('tool(flight)', function(obj){
    var data = obj.data;
    console.log(obj)
    if(obj.event === 'del'){
      layer.confirm('您确定要删除吗', function(index){
    	  $.ajax({  
              type : "post",
              url : "<%=basePath %>/flight/del",
              data : data,
              success: function(data){ 
	        	   	if(data.success){
	        	   		layer.alert( data.msg, function () {
                          window.parent.location.reload(); //刷新父页面
                          parent.layer.close(index); //关闭当前弹窗
                   	});
	        	}
	       },  
	       error: function() {    
	    	   layer.alert("删除失败,请重试");  
	       }  
          });
      });
    } else if(obj.event === 'edit'){
            if (data) {
            	var id = data.id;
                layer.open({
                	type: 2,
                    title: "航班跨天编辑", //不显示标题栏
                    closeBtn: 2,
                    shade: 0.8,
                    id: (new Date()).valueOf(), //设定一个id,防止重复弹出 时间戳1280977330748
                    moveType: 1, //拖拽模式,0或者1
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                   /*  area: [window.screen.width / 2 + 'px', window.screen.height / 2 + 'px'], //宽高 */
                    area: ['700px', '260px'],
                    maxmin: true, //开启最大化最小化按钮
                    content: "<%=basePath %>/flight/edit?id="+id,
                    success: function (layero, index) {
                        // 获取子页面的iframe
                        var iframe = window['layui-layer-iframe' + index];
                        // 向子页面的全局函数child传参
                        iframe.child(data);
                        
                    }
                })
            } else {
                alert("先选择行")
           }
    }
    
  });
  
});
 $("#add").click(function(){
	 layer.open({
     	type: 2,
         title: "航班跨天添加", //不显示标题栏
         closeBtn: 2,
         shade: 0.8,
         id: (new Date()).valueOf(), //设定一个id,防止重复弹出 时间戳1280977330748
         moveType: 1, //拖拽模式,0或者1
         type: 2,
         skin: 'layui-layer-rim', //加上边框
        /*  area: [window.screen.width / 2 + 'px', window.screen.height / 2 + 'px'], //宽高 */
         area: ['700px', '260px'],
         maxmin: true, //开启最大化最小化按钮
         content: "<%=basePath %>/flight/edit",
         success: function (layero, index) {
             // 获取子页面的iframe
             var iframe = window['layui-layer-iframe' + index];
             // 向子页面的全局函数child传参
             iframe.child(data);
             
         }
     })
 })
</script>


</body>
</html>