<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/'} ">
    <meta charset="utf-8">
    <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.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="assets/js/vendor/viewer/viewer.min.css">
</head>
<body>
<div class="layui-anim layui-anim-fadein">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form">
                    <table class="layui-table">
                            <col width="60">
                            <col>
                            <col width="80">
                            <col width="80">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>字段名</th>
                            <th>可见</th>
                            <th>可操作</th>
                        </tr>
                        </thead>
                        <tbody id="tBody"></tbody>
                    </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
<script>
    layui.config({
        base: 'assets/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'table', 'laydate', 'common'], function() {
        var $ = layui.$;
        var $win = $(window);
        var laydate = layui.laydate;
        var common = layui.common;
        var form = layui.form;
        var queryParams = top.restAjax.params(window.location.href);
        var deploymentId = queryParams.deploymentId;
        var flowNodeId = queryParams.flowNodeId;

        function initData() {
            var loadLayerIndex;
            top.restAjax.get(top.restAjax.path('api/node-field/list/deployment-id/{deploymentId}/flow-node-id/{flowNodeId}', [deploymentId, flowNodeId]), {}, null, function(code, data) {
                var trs = ''
                for(var i = 0, item; item = data[i++];) {
                    var tr = '<tr>' +
                        '<td>'+ i +'</td>' +
                        '<td>'+ item.fieldName +'</td>' +
                        '<td><input type="checkbox" lay-skin="switch" lay-text="是|否" '+ (item.isVisible ? 'checked' : '') +' lay-filter="isVisibleFilter" data-node-field-id="'+ item.nodeFieldId +'"></td>' +
                        '<td><input type="checkbox" lay-skin="switch" lay-text="是|否" '+ (item.isEditable ? 'checked' : '') +' lay-filter="isEditableFilter" data-node-field-id="'+ item.nodeFieldId +'"></td>' +
                        '</tr>';
                    trs += tr;
                }
                $('#tBody').append(trs);
                form.render();
            }, function(code, data) {
                top.dialog.msg(data.msg);
            }, function() {
                loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
            }, function() {
                top.dialog.close(loadLayerIndex);
            });
        }
        initData();

        form.on('switch(isVisibleFilter)', function(obj) {
            var nodeFieldId = obj.elem.dataset.nodeFieldId;
            var loadLayerIndex;
            top.restAjax.put(top.restAjax.path('api/node-field/update-visible/{nodeFieldId}', [nodeFieldId]), {
                isVisible: obj.elem.checked ? 1 : 0
            }, null, function(code, data) {
                top.dialog.msg('操作成功');
            }, function(code, data) {
                top.dialog.msg(data.msg);
                obj.elem.checked = !checked;
                form.render('checkbox')
            });
        });

        form.on('switch(isEditableFilter)', function(obj) {
            var nodeFieldId = obj.elem.dataset.nodeFieldId;
            var loadLayerIndex;
            top.restAjax.put(top.restAjax.path('api/node-field/update-editable/{nodeFieldId}', [nodeFieldId]), {
                isVisible: obj.elem.checked ? 1 : 0
            }, null, function(code, data) {
                top.dialog.msg('操作成功');
            }, function(code, data) {
                top.dialog.msg(data.msg);
                obj.elem.checked = !checked;
                form.render('checkbox')
            });
        });
    });
</script>
</body>
</html>