<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>待发送指令</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

    <div class="layui-form layuimini-form">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>

    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

    <script type="text/html" id="currentTableBar">
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
    </script>

    <script th:inline="none">
        layui.use(['form', 'table'], function () {
            var $ = layui.$,
                form = layui.form,
                table = layui.table;
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            /**
             * 初始化表单，要加上，不然刷新部分组件可能会不加载
             */
            form.render();

            table.render({
                elem: '#currentTableId',
                url: '/gnss/cache_cmd/list',
                cols: [[
                    {field: 'deviceid', title: '设备编号'},
                    {field: 'updatetime', title: '更新时间', templet: "<div>{{layui.util.toDateString(d.updatetime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                    {field: 'syn', title: '已发送',templet: "<div>{{d.syn==1?'是':'否'}}</div>"},
                    {field: 'type', title: '类型',templet: '#typeTrans'},
                    {field: 'cmd', title: '指令',width:'35%'},
                    {title: '操作', toolbar: '#currentTableBar', fixed: "right", minWidth: 60}
                ]],
                limits: [10, 20, 50],
                limit: 10,
                page: true,
                skin: 'line'
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'delete') {
                    layer.confirm('确定删除该条指令？', function(index){
                        $.ajax({
                            type:"POST",
                            url:"/gnss/cache_cmd/delete",
                            data:{
                                'del_id':data.id
                            },
                            success: function (data) {
                                //data是cotroller相应处理函数的返回值
                                table.reload('currentTableId');
                            },
                            error: function () {
                                console.log("ajax error");
                            }
                        });
                        layer.close(index);
                    });
                }
            });
        });

    </script>

    <script type="text/html" id="typeTrans">
        {{#  if(d.type == 0){ }}
        <span>GNSS</span>
        {{# } else if(d.type == 1){ }}
        <span >DTU</span>
        {{# } else if(d.type == 2){ }}
        <span >MPU</span>
        {{# } else { }}
        <span >DEBUG</span>
        {{#  } }}
    </script>
</body>
</html>