<!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">
        <input type="hidden" name="id" id="id">
        <div class="layui-form-item">
            <label class="layui-form-label">所属部门</label>
            <div class="layui-input-inline">
                <select name="tenantid" id="tenantid" lay-search="" lay-filter="tenant">
                    <option value="">全部</option>
                    <option th:each="item : ${tenant_list}" th:text="${item.name}" th:value="${item.id}"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属项目</label>
            <div class="layui-input-inline">
                <select name="project_id" id="projectid" lay-search="" lay-filter="project">
                    <option value="">全部</option>
                    <option th:each="item : ${project_list}" th:text="${item.project_id}" th:value="${item.project_id}"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设备编号</label>
            <div class="layui-input-inline">
                <input type="text" name="deviceid" id="deviceid" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">推送组</label>
            <div class="layui-input-inline">
                <select name="fwd_group_id" id="fwd_group_id" lay-verify="required" lay-reqtext="不能为空" lay-search="">
                    <option th:each="item : ${gnss_group_fwd_list}" th:text="${item.name}" th:value="${item.name}"></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">时间段</label>
            <div class="layui-input-inline">
                <input type="text" name="starttime" autocomplete="off" lay-verify="required" lay-reqtext="不能为空" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
            </div>
            <div class="layui-input-inline">
                <input type="text" name="endtime" autocomplete="off" lay-verify="required" lay-reqtext="不能为空" id="ID-laydate-end-date" class="layui-input" placeholder="结束日期">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>

    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                $ = layui.$,
                laydate = layui.laydate;
            var iframeIndex = parent.layer.getFrameIndex(window.name);

            laydate.render({
                elem: '#ID-laydate-start-date',
                type: 'datetime'
            });
            laydate.render({
                elem: '#ID-laydate-end-date',
                type: 'datetime'
            });
            // 所属部门下拉框改变，修改项目下拉框
            form.on('select(tenant)', function (data) {
                console.log(data.value);
                $.ajax({
                    type:"GET",
                    url:"/gnss/device/q_project",
                    data:{
                        'tenantid':data.value
                    },
                    success: function(result) {
                        $('#projectid').empty();
                        $('#projectid').append(new Option("全部", ""));
                        $('#deviceid').empty();
                        //console.log(result);
                        $.each(result.data, function (index, item) {
                            $('#projectid')
                                .append(new Option(item.project_id, item.project_id));
                        });
                        layui.form.render("select");
                    },
                    error: function () {
                        console.log("ajax error");
                    }
                });
            });

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                $.ajax({
                    type:"POST",
                    url:"/fwd/resend_records/add",
                    contentType: "application/json;charset=UTF-8",
                    data: JSON.stringify(data.field),
                    success: function (result) {
                        parent.onUpdated();
                        parent.layer.close(iframeIndex);
                    },
                    error: function () {
                        console.log("ajax error");
                        parent.layer.close(iframeIndex);
                    }
                });
                return false;
            });

        });

    </script>

</body>
</html>