<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Open Park</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,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="<%=path%>/static/css/font.css">
    <link rel="stylesheet" href="<%=path%>/static/css/xadmin.css">
    <script type="text/javascript" src="<%=path%>/static/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=path%>/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=path%>/static/js/xadmin.js"></script>
    <script>
        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        $(function () {
            var flag = "${flag }";
            if (flag == 1) {
                parent.layer.alert("增加成功", {icon: 6}, function () {
                    parent.location.reload();
                    parent.layer.close(index); //执行关闭
                });
            }
        });
    </script>
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="addForm" action="<%=path %>/moduleProject/add" method="post">
        <input type="hidden" name="projectId" value="${moduleProject.projectId}">
        <div class="layui-form-item">
            <label for="moduleId" class="layui-form-label">
                <span class="x-red">*</span>功能模块
            </label>
            <div class="layui-input-inline">
                <select id="moduleId" name="moduleId" class="valid">
                    <c:forEach items="${moduleList}" var="item">
                        <option value="${item.id}">${item.moduleName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tableId" class="layui-form-label">
                <span class="x-red">*</span>对应数据表
            </label>
            <div class="layui-input-inline">
                <select id="tableId" name="tableId" class="valid" lay-filter="tableSelect">
                    <option value="">选择对应数据表</option>
                    <c:forEach items="${tableList}" var="item">
                        <option value="${item.id}">${item.tableName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tableId" class="layui-form-label">
                <span class="x-red">*</span>参数1
            </label>
            <div class="layui-input-inline">
                <select id="param1" name="param1" class="valid">
                    <option value="">选择字段</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tableId" class="layui-form-label">
                <span class="x-red">*</span>参数2
            </label>
            <div class="layui-input-inline">
                <select id="param2" name="param2" class="valid">
                    <option value="">选择字段</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tableId" class="layui-form-label">
                <span class="x-red">*</span>参数3
            </label>
            <div class="layui-input-inline">
                <select id="param3" name="param3" class="valid">
                    <option value="">选择字段</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form'], function () {
        $ = layui.jquery;
        var form = layui.form;

        form.on('select(tableSelect)', function (data) {
            $("#param1").empty()
            $("#param2").empty()
            $("#param3").empty()
            $("#param1").append("<option value=''>选择字段</option>")
            $("#param2").append("<option value=''>选择字段</option>")
            $("#param3").append("<option value=''>选择字段</option>")
            if (data.value == "") {
                //重新渲染表单
                form.render();
                return false;
            }
            $.ajax({
                type: "GET",
                url: "<%=path %>/moduleProject/getColunm",
                data: {
                    tableId: data.value
                },
                success: function (result) {
                    var colunmList = result.data;
                    for (var i = 0; i < colunmList.length; i++) {
                        $("#param1").append("<option value='" + colunmList[i].id + "'>" + colunmList[i].colunmName + "</option>")
                        $("#param2").append("<option value='" + colunmList[i].id + "'>" + colunmList[i].colunmName + "</option>")
                        $("#param3").append("<option value='" + colunmList[i].id + "'>" + colunmList[i].colunmName + "</option>")
                    }
                    //重新渲染表单
                    form.render();
                }
            });
        });
    });
</script>
</body>
</html>