<!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">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label required">设备编号</label>
                <div class="layui-input-block">
                    <input type="number" name="deviceid" id="deviceid" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入设备编号" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required">设备名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" placeholder="请输入设备名称" value="" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label required">设备类型</label>
                <div class="layui-input-inline">
                    <select name="devicetype" id="devicetype" lay-verify="required" lay-search="">
                        <option value="0">监测站</option>
                        <option value="1">基准站</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">父设备号</label>
                <div class="layui-input-block">
                    <input type="number" name="parentid" id="parentid" placeholder="请输入关联基准站编号" value="" class="layui-input">
                </div>
            </div>


        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label required">基本参数组</label>
                <div class="layui-input-inline">
                    <select name="group_id" id="group_id" lay-verify="required" lay-search="">
                        <option th:each="item : ${gnss_group_list}" th:text="${item.id}" th:value="${item.id}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required">解算参数组</label>
                <div class="layui-input-inline">
                    <select name="calc_group_id" id="calc_group_id" lay-verify="required" lay-search="">
                        <option th:each="item : ${gnss_group_calc_list}" th:text="${item.id}" th:value="${item.id}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label required">所属部门</label>
                <div class="layui-input-inline">
                    <select name="tenantname" id="tenantname" lay-verify="required" lay-search="">
                        <option th:each="item : ${tenant_list}" th:text="${item.name}" th:value="${item.name}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">项目号</label>
                <div class="layui-input-block">
                    <input type="text" name="project_id" id="project_id" placeholder="请输入项目编号" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">项目2号</label>
                <div class="layui-input-block">
                    <input type="text" name="project2_id" id="project2_id" placeholder="请输入项目编号" value="" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label required">使用状态</label>
                <div class="layui-input-inline">
                    <select name="opmode" id="opmode" lay-verify="required" lay-search="">
                        <option value="0">正常</option>
                        <option value="1">维护</option>
                        <option value="2">停用</option>
                    </select>
                </div>
            </div>
        </div>

        <hr>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">推送至</label>
                <div class="layui-input-inline">
                    <select name="fwd_group_id" id="fwd_group_id" lay-search="">
                        <option value="不推送">不推送</option>
                        <option th:each="item : ${gnss_group_fwd_list}" th:text="${item.name}" th:value="${item.name}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline" th:if="${role=='SUPER_ADMIN' || role=='ADMIN'}">
                <label class="layui-form-label">推送2</label>
                <div class="layui-input-inline">
                    <select name="fwd_group_id2" id="fwd_group_id2" lay-search="">
                        <option value="不推送">不推送</option>
                        <option th:each="item : ${gnss_group_fwd_list}" th:text="${item.name}" th:value="${item.name}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">推送名称</label>
                <div class="layui-input-block">
                    <input type="text" name="fwddeviceid" id="fwddeviceid" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">初始位置(mm) 东</label>
                <div class="layui-input-block">
                    <input type="text" name="ipose" id="ipose" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">北</label>
                <div class="layui-input-block">
                    <input type="text" name="iposn" id="iposn" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">天</label>
                <div class="layui-input-block">
                    <input type="text" name="iposd" id="iposd" class="layui-input">
                </div>
            </div>
        </div>

        <hr>
        <div class="layui-form-item">
            <div class="layui-input-block" style="float:right" >
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="initLocBtn">取初值</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.$;
            var iframeIndex = parent.layer.getFrameIndex(window.name);

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

                return false;
            });

            form.on('submit(initLocBtn)', function (data) {
                layer.confirm('确定重新取初值？', function(index){
                    $.ajax({
                        type:"POST",
                        url:"/gnss/device/init_loc",
                        data:{
                            'deviceid':$('#deviceid').val()
                        },
                        success: function (result) {
                            $('#ipose').val(result.ipose);
                            $('#iposn').val(result.iposn);
                            $('#iposd').val(result.iposd);
                        },
                        error: function () {
                            console.log("ajax error");
                        }
                    });
                });

                return false;
            });


        });

        function setParams(data){
            var form = layui.form,
                $ = layui.$;
            var device_id = $('#deviceid');
            device_id.val(data.deviceid);
            device_id.attr('readonly',true);
            $('#name').val(data.name);
            $('#devicetype').val(data.devicetype);
            $('#parentid').val(data.parentid);
            $('#tenantname').val(data.tenantname);
            $('#project_id').val(data.project_id);
            $('#project2_id').val(data.project2_id);
            $('#group_id').val(data.group_id);
            $('#calc_group_id').val(data.calc_group_id);
            $('#fwd_group_id').val(data.fwd_group_id);
            $('#fwd_group_id2').val(data.fwd_group_id2);
            $('#opmode').val(data.opmode);
            $('#fwddeviceid').val(data.fwddeviceid);
            $('#ipose').val(data.ipose);
            $('#iposn').val(data.iposn);
            $('#iposd').val(data.iposd);
            form.render();
        }
    </script>

</body>
</html>