<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../../common.jsp" />
    <style>
        .layui-form-item{
            margin-top: 10px;
        }
        .layui-form{
            width: 70%;
            margin-left: 10%;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <input name="id" value="${entity.id}" hidden/>
    <div class="layui-form-item">
        <label class="layui-form-label">类型名称</label>
        <div class="layui-input-block">
            <select class="layui-select" name="code" autocomplete="off" lay-filter="code" lay-verify="required">
                <option value="">请选择</option>
                <c:forEach items="${codeList}" var="c">
                    <option value="${c.code}" ${c.code == entity.code ? 'selected' : ''}>${c.name}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">规格名称</label>
        <div class="layui-input-block">
            <input name="specName" value="${entity.specName}" autocomplete="off" maxlength="20" placeholder="请输入规格名称" class="layui-input" lay-verify="required" />
        </div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label">规格Code</label>
        <div class="layui-input-block">
            <input name="spec" value="${entity.spec}" autocomplete="off" maxlength="20" placeholder="请输入规格Code" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select class="layui-select" name="type" autocomplete="off" lay-verify="required">
                <option value="">请选择</option>
                <option value="1" ${entity.type eq '1' ? 'selected' : ''}>主扫设备（商户扫顾客）</option>
                <option value="2" ${entity.type eq '2' ? 'selected' : ''}>被扫设备（顾客扫商户）</option>
                <option value="3" ${entity.type eq '3' ? 'selected' : ''}>其他</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否包邮</label>
        <div class="layui-input-block">
            <select class="layui-select" name="postageFlag" autocomplete="off" lay-verify="required">
                <option value="">请选择</option>
                <option value="00" ${entity.postageFlag eq '00' ? 'selected' : ''}>包邮</option>
                <option value="01" ${entity.postageFlag eq '01' ? 'selected' : ''}>不包邮</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">重量(kg)</label>
        <div class="layui-input-block">
            <input type="number" name="weight" value="${entity.weight}" autocomplete="off" maxlength="20" placeholder="请输入重量(kg)" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >规格描述</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入规格描述" name="specDesc" class="layui-textarea">${entity.specDesc}</textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="button" id="close" class="layui-btn layui-btn-primary">关闭</button>
        </div>
    </div>
</form>

<script>
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer = layui.layer;
        $('#close').click(function() {
            parent.layer.closeAll();
        });
            //监听提交
        form.on('submit(formDemo)', function(data){
            var index = layer.load(1,{shade: [0.1,'#000'] });
            $.ajax({
                url: '${ctx}/deviceSpec/save',
                method: 'post',
                data: JSON.stringify(data.field),
                dataType: 'JSON',
                contentType:"application/json",
                success: function(res) {
                    layer.close(index);
                    if(res.code == 200) {
                        layer.msg(res.message, { icon: 1, time: 1000 }, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layui.table.reload('deviceSpec');
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2
                        });
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
