<%@ page contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp"/>
</head>
<body>

<div class="row animated fadeInRight" style="margin: 0;">
    <!-- 表单数据 -->
    <div class="mb50 mt10">
        <div class="whitebg pl10 pr10">
            <table class="layui-hide" id="deviceOperateInfoTab" lay-filter="deviceOperateInfoTab"></table>
        </div>
    </div>
</div>

<script type="text/html" id="leftBar">
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="search"><i class="layui-icon">&#xe615;</i>查询
    </button>
</script>

<script type="text/html" id="toolBar">
    <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i
            class="layui-icon">&#xe640;</i>删除
    </button>
</script>

<script>
    layui.use(['table', 'layer', 'form'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;

        var tableIns = table.render({
            elem: '#deviceOperateInfoTab'
            , url: ctx + '/deviceOperateInfo/pageData'
            , id: 'deviceOperateInfo'
            ,where: {
                deviceNo:'${deviceNo}'
            }
            , response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , countName: 'count' //数据总数的字段名称，默认：count
                , dataName: 'data' //默数据列表的字段名称，认：data
                , statusCode: 200
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            , toolbar: '#leftBar' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter']
            , title: '设备操作详情表'
            , cols: [[
                {type: 'checkbox', fixed: 'left', hidden: true}
                , {field: 'numbers', title: '序号', fixed: 'left', unresize: true, minWidth: 80, type: 'numbers'}
                , {
                    field: 'deviceNo', title: '设备编号', minWidth: 150, templet: function (d) {
                        return "NO." + d.deviceNo;
                    }
                }
                , {field: 'typeDesc', title: '操作类型', minWidth: 100}
                , {field: 'remark', title: '备注', minWidth: 100}

                , {
                    field: 'createTime',
                    title: '操作时间',
                    minWidth: 160,
                    templet: "<div>{{layui.util.toDateString(d.createTime,'yyyy-MM-dd HH:mm')}}</div>"
                }
            ]]
            , request: {
                pageName: 'current' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , page: true
        });

        //监听头工具栏事件
        table.on('toolbar(deviceOperateInfoTab)', function (obj) {
            switch (obj.event) {
                case 'search':
                    var params = serialize($('#form1'));
                    params["deviceNo"] = '${deviceNo}';
                    table.reload('deviceOperateInfo', {
                        where: params
                        , page: {
                            size: 10
                            , current: 1
                        }
                    });
                    break;
            }
        });

        function del(obj) {
            $.ajax({
                url: '${ctx}/deviceOperateInfo/del/' + obj.id,
                method: 'DELETE',
                dataType: 'JSON',
                contentType: "application/json",
                success: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.message, {
                            icon: 1
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2
                        });
                    }
                }
            })
        }
    });
    jQuery.prototype.serializeObject = function () {
        var obj = new Object();
        $.each(this.serializeArray(), function (index, param) {
            if (!(param.name in obj)) {
                obj[param.name] = param.value;
            }
        });
        return obj;
    };
</script>
</body>
</html>
