<!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">
    <style>
        .input-select-change-box {position: relative;}
        .input-select-change-btn {position: absolute; top: 0; right: 0;}
        .layui-form-select dl {max-height: 155px;}
        #selectChangeBtn {display: none;}
        #modelCategoryInputBox {display: none;}
    </style>
</head>
<body>
<div class="layui-anim layui-anim-fadein">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form layui-form-pane" lay-filter="dataForm">
                <div class="layui-form-item">
                    <label class="layui-form-label">模型名称 *</label>
                    <div class="layui-input-block">
                        <input type="text" id="modelName" name="modelName" class="layui-input" value="" placeholder="请输入模型名称" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">模型Key *</label>
                    <div class="layui-input-block">
                        <input type="text" id="modelKey" name="modelKey" class="layui-input" value="" placeholder="请输入模型Key，只能是字母与数字" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">模型描述 *</label>
                    <div class="layui-input-block">
                        <input type="text" id="modelDescription" name="modelDescription" class="layui-input" value="" placeholder="请输入模型描述" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">模型分类 *</label>
                    <div class="layui-input-block input-select-change-box">
                        <div id="modelCategoryInputBox">
                            <input type="text" id="modelCategoryInput" name="modelCategory" class="layui-input" value="" placeholder="请输入模型分类">
                        </div>
                        <div id="modelCategorySelectBox">
                            <select id="modelCategorySelect" name="modelCategory" lay-verify="required">
                                <option value="">请选择</option>
                                <option th:each="modelCategory:${modelCategories}" th:value="${modelCategory}" th:text="${modelCategory}"></option>
                            </select>
                        </div>
                        <button type="button" id="inputChangeBtn" class="layui-btn layui-btn-xs input-select-change-btn">输入</button>
                        <button type="button" id="selectChangeBtn" class="layui-btn layui-btn-xs input-select-change-btn">选择</button>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button type="button" class="layui-btn" lay-submit lay-filter="submitForm">确定</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: 'assets/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'laytpl'], function(){
        var $ = layui.$;
        var form = layui.form;

        function closeBox() {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

        // 提交表单
        form.on('submit(submitForm)', function(formData) {
            top.dialog.confirm(top.dataMessage.commit, function(index) {
                top.dialog.close(index);
                var loadLayerIndex;
                top.restAjax.post(top.restAjax.path('api/activiti/create', []), formData.field, null, function(code, data) {
                    top.dialog.msg(top.dataMessage.commitSuccess);
                    top.dialog.open({
                        url: top.restAjax.path('route/activiti/update?modelId={modelId}', [data.data]),
                        title: '编辑流程图',
                        width: '90%',
                        height: '90%',
                        onClose: function() {
                            closeBox();
                        }
                    });
                }, function(code, data) {
                    top.dialog.msg(data.msg);
                }, function() {
                    loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
                }, function() {
                    top.dialog.close(loadLayerIndex);
                });
            });
            return false;
        });

        $('#inputChangeBtn').click(function() {
            $(this).hide();
            $('#selectChangeBtn').show();
            $('#modelCategorySelectBox').hide();
            $('#modelCategorySelect').removeAttr('name');
            $('#modelCategorySelect').removeAttr('lay-verify');
            $('#modelCategoryInputBox').show();
            $('#modelCategoryInput').attr('name', 'modelCategory');
            $('#modelCategoryInput').attr('lay-verify', 'required');
        });

        $('#selectChangeBtn').click(function() {
            $(this).hide();
            $('#inputChangeBtn').show();
            $('#modelCategoryInputBox').hide();
            $('#modelCategoryInput').removeAttr('name');
            $('#modelCategoryInput').removeAttr('lay-verify');
            $('#modelCategorySelectBox').show();
            $('#modelCategorySelect').attr('name', 'modelCategory');
            $('#modelCategorySelect').attr('lay-verify', 'required');
        });

        // 校验
        form.verify({
        });
    });
</script>
</body>
</html>