layui.extend({
    common    :   'js/common'
}).use(['jquery','table','common','util','laydate','form'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    var common=layui.common;
    var util=layui.util;
    var laydate=layui.laydate;
    var form = layui.form;
    common.layuiTable.render(table,{
         elem: '#table-id'
        , url: '/statistics/sysDeviceLog/showSysDeviceLogList' //模拟接口
        ,method:'post'
        , cellMinWidth: 80 //全局定义常规单元格的最小宽度，
        , cols: [[
             { field: 'serialNumber', title: '序列号',align:'center'}
            , { field: 'event', title: '事件',templet:'#tempLet_event',align:'center'}
            , { field: 'createDate', title: '事件时间' ,align:'center'}
            , { field: 'message', title: '信息',align:'center'}
        ]]
       , id: 'table-id'
        , page: true
        , limit: 10
    });

    var startMalfunctionDate,endMalfunctionDate;
    var queryTableFn=function(){
        var serialNumber = $('input[name="serialNumber"]').val();
        //执行重载
        table.reload('table-id', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: {
                serialNumber: serialNumber,
                startMalfunctionDate:startMalfunctionDate,
                endMalfunctionDate:endMalfunctionDate
            }
        });
    }

    //日期时间范围选择
    laydate.render({
        elem: '#laydate-range-datetime'
        ,type: 'datetime'
        ,range:true //或 range: '~' 来自定义分割字符
        ,done: function(value, date, endDate){
            if(value){
                var dates=value.split(" - ");
                startMalfunctionDate=dates[0];
                endMalfunctionDate=dates[1];
            }else{
                startMalfunctionDate="";
                endMalfunctionDate="";
            }
        }
    });

    //监听搜索
    form.on('submit(query)', function(){
        queryTableFn();
    });

    //监听重置查询
    form.on('submit(reset)', function(){
        //清空条件
        $('input[name="serialNumber"]').val("");
        startMalfunctionDate="";
        endMalfunctionDate="";
        $("#laydate-range-datetime").val("");
        queryTableFn();
    });
});

