<%@ 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%;
        }
        .device-logo-img{
            border: 1px solid #e7e7e7;
            border-radius: 5px;
            padding: 10px;
            width: 100px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" enctype="multipart/form-data">
    <input name="id" value="${entity.id}" hidden/>
<%--    <div class="layui-form-item">--%>
<%--        <label class="layui-form-label">类型logo</label>--%>
<%--        <div class="layui-input-block">--%>
<%--            <button class="layui-btn layui-btn-sm" type="button" id="upload"><i class="layui-icon">&#xe681;</i>上传</button>--%>
<%--            <div class="device-logo" style="margin-top: 10px; display: ${empty entity.deviceLogo ? 'none' : ''}">--%>
<%--                <img alt="图片" class="device-logo-img" id="prevImg" src="${entity.deviceLogo}"/>--%>
<%--            </div>--%>
<%--            <input class="layui-input" type="hidden" name="deviceLogo" id="deviceLogo" value="${entity.deviceLogo}">--%>
<%--        </div>--%>
<%--    </div>--%>
    <div class="layui-form-item">
        <label class="layui-form-label">类型名称</label>
        <div class="layui-input-block">
            <input name="name" value="${entity.name}" 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="code" value="${entity.code}" 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="showFlag" autocomplete="off" lay-verify="required">
                <option value="">请选择</option>
                <option value="1" ${entity.showFlag eq '1' ? 'selected' : ''}>显示</option>
                <option value="2" ${entity.showFlag eq '2' ? '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="payCodeFlag" autocomplete="off" lay-verify="required">
                <option value="">请选择</option>
                <option value="0" ${entity.payCodeFlag eq '0' ? 'selected' : ''}>否</option>
                <option value="1" ${entity.payCodeFlag eq '1' ? 'selected' : ''}>是</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >类型描述</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入类型描述" name="desc" class="layui-textarea">${entity.desc}</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(){
        let form = layui.form;
        let 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}/deviceType/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('deviceType');
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2
                        });
                    }
                }
            })
            return false;
        });

        //初始化文件上传
        // let dialog = null;
        // let uploadInst = upload.render({
        //     elem: '#upload' //绑定元素
        //     ,acceptMime:'image/*'
        //     ,url: ctx + '/upload/ossUploadFile' //上传接口
        //     ,choose:function (obj){
        //         //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
        //         obj.preview(function(index, file, result){
        //             $("#prevImg").attr("src",result).parent("div").show();
        //         });
        //     }
        //     ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        //         dialog = layer.msg('上传中...', {icon: 16, time: 0, shade: [0.3, '#000', false]});
        //     }
        //     ,done: function(res){
        //         layer.close(dialog);
        //         if(res.code == 200){
        //             $("#deviceLogo").val(res.url);
        //         }else{
        //             layer.msg(res.msg,{icon:2});
        //         }
        //     }
        //     ,error: function(){
        //         layer.close(dialog);
        //         layer.msg("上传失败",{icon:2});
        //     }
        // });
    });
</script>
</body>
</html>
