<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<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,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/favicon.ico}"/>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/common.css}">
    <link rel="stylesheet" th:href="@{/css/animate.min.css}">
    <link rel="stylesheet" th:href="@{/iconfont/iconfont.css}">
</head>


<body>

    <div class="page-loading">
        <div class="rubik-loader"></div>
    </div>

    <div class="z-body animated fadeIn">

        <table class="layui-hide" id="user-table"></table>
    </div>

    <script type="text/html" id="column-toolbar">
            <a lay-event="edit">
                <i class="zadmin-icon zadmin-icon-edit-square zadmin-oper-area zadmin-blue" title="编辑"></i>
            </a>

    </script>



    <script type="text/html" id="statusTpl">
            <input type="checkbox" name="name" value="{{d.name}}" lay-skin="switch" lay-text="正常|锁定" lay-filter="name" {{d.name== '1' ? 'checked' : '' }}>

    </script>

    <script th:src="@{/lib/jquery/jquery.min.js}"></script>
    <script th:src="@{/lib/layui/layui.js}"></script>
    <script th:src="@{/js/common.js}"></script>

    <script>
        layui.config({
            base: '/lib/layui/extend/'
        }).use(['table', 'element', 'form', 'dtree', 'tablePlug'], function () {
            var table = layui.table;
            var $ = layui.$;
            var form = layui.form;
            var dtree = layui.dtree;
            var tablePlug = layui.tablePlug;
            tablePlug.smartReload.enable(true);

            table.render({
                elem: '#user-table'
                , url: '/code/list/4'
                , page: true
                , toolbar: '#toolbar'
                , smartReloadModel: true
                , cols: [
                    [
                        {type: 'numbers', title: '序号', width: "5%"}
                        , {field: 'name', title: '是否开启手动推送', templet: "#statusTpl", width: "12%"}
                        , {field: 'alarmlevel', title: '延迟推送时长（s）', width: "15%"}
                        , {title: '操作', fixed: 'right', align: 'center', toolbar: '#column-toolbar'}

                    ]
                ]
            });

            // 账号状态(正常/锁定)点击事件
            form.on('switch(name)', function(data){
                if (data.elem.checked) {
                    $.post('/code/send/enable', function (data) {
                        handlerResult(data, enableDone);
                    });
                } else {
                    $.post('/code/send/disable', function (data) {
                        handlerResult(data, disableDone);
                    });
                }
            });

            // 行点击事件 重置密码
            table.on('tool', function (obj) {
                var data = obj.data;
                var event = obj.event;
                if (event === 'edit') {
                    edit(data);
                }
            });




            function disableDone(data) {
                layer.msg("禁用成功", {icon: 6});
            }

            function enableDone(data) {
                layer.msg("激活成功", {icon: 6});
            }
            function edit(data) {
                layer.open({
                    content: '/user/update/' + data.name+"/"+data.alarmlevel,
                    title: "编辑",
                    area: ['40%', '85%'],
                    type: 2,
                    maxmin: true,
                    shadeClose: true,
                    end: function () {
                        table.reload('user-table');
                    }
                });
            }

        });
    </script>
</body>

</html>