<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<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" />
    <link rel="stylesheet" type="text/css" href="${ctx}/page/umeditor/themes/default/css/umeditor.css">
    <script type="text/javascript" src="${ctx}/page/umeditor/third-party/template.min.js"></script>
    <script type="text/javascript" src="${ctx}/page/umeditor/umeditor.config.js"></script>
    <script type="text/javascript" src="${ctx}/page/umeditor/umeditor.min.js"></script>
    <script type="text/javascript" src="${ctx}/page/umeditor/lang/zh-cn/zh-cn.js"></script>
    <style>
        .layui-input,.layui-textarea{
            border-color:#606060;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" style="width: 80%; margin-top: 20px" >
    <input name="id" value="${entity.id}" hidden/>
<div style="margin-left: 200px;margin-right: 200px">
    <div class="layui-form-item">
        <label class="layui-form-label" >设备名称:</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
                <input name="name" value="${entity.name}" placeholder="请输入设备名称" class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"  >设备详情:</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
<%--                <input name="phone" value="${entity.phone}" placeholder="请输入手机号" class="layui-input"/>--%>
                <textarea id="detail" name="detail" lay-verify="detail" style="width: 571px" placeholder="请输入内容" class="layui-textarea">${entity.detail}</textarea>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" >单价:</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block" >
                <input name="unitPrice" value="${entity.unitPrice}" placeholder="请输入单价" class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"  >厂家名称:</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block" >
                <input name="venderName" value="${entity.venderName}" placeholder="请输入厂家名称" class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" >厂家型号:</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block" >
                <input name="venderModel" value="${entity.venderModel}" placeholder="请输入厂家型号" class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" >通道机器型号:</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block" >
                <input name="aisleModel" value="${entity.aisleModel}" placeholder="请输入通道机器型号" class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" >设备简介:</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block" >
                <textarea placeholder="请输入设备简介" name="introDesc" id="introDesc" class="layui-textarea">${entity.introDesc}</textarea>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序:</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block" >
                <input name="seq" value="${entity.seq}" placeholder="请输入排序" class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">设备图片</label>
        <div class="layui-input-block" style="display: flex;justify-content: flex-start">
            <input name="fileKey" id="fileKey" hidden/>
            <input type="hidden" name="deviceLogo" value="${entity.deviceLogo}" id="url"/>
            <input name="fileName" id="fileName" class="layui-input layui-col-xs6 layui-disabled" disabled/>
        </div>
        <div class="layui-input-block" style="display: flex;justify-content: flex-start ; margin-top: 5px">
            <button type="button" class="layui-btn layui-btn layui-btn-normal  layui-col-xs3"  onclick="$('#file').click();">
                浏览...
            </button>
            <button type="button" class="layui-btn layui-btn-normal layui-col-xs3"  id="uploadParam">
                上传
            </button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <select name="status" id="status" lay-filter="aihao">
                <option value="">请选择</option>
                <option value="1" <c:if test="${entity.status eq '1' }">selected</c:if> >显示</option>
                <option value="0" <c:if test="${entity.status eq '0' }">selected</c:if> >不显示</option>
            </select>
        </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>
</div>
</form>

<form id="ajaxForm" class="layui-form" style="width: 70%" >
    <input type="hidden" name="OSSAccessKeyId" id="accessid" value="${uploadParam.accessid}">
    <input type="hidden" name="policy" id="policy" value="${uploadParam.policy}">
    <input type="hidden" name="signature" id="signature" value="${uploadParam.signature}">
    <input type="hidden" name="expire" id="expire" value="${uploadParam.expire}">
    <input type="hidden" name="success_action_status" id="success_action_status" value="200">
    <input type="hidden" name="key" id="key" value="${uploadParam.key}">
    <input type="hidden" name="callBack" id="key2_callBack" value="${uploadParam.callBack}">
    <input type="file" style="display: none" name="file" id="file" onchange="document.getElementById('fileName').value=this.files[0].name">
</form>

<script>
    //Demo
    layui.use(['form', 'layer'], function(){
        var form = layui.form;
        var layer = layui.layer;

        var um = UM.getEditor('detail');

        $('#close').click(function() {
            parent.layer.closeAll();
        });

        $("#uploadParam").click(function () {
            var fileName = $("#fileName").val();
            if(!fileName){
                layer.msg("请先选择文件！");
                return;
            }
            var suffix = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length); //
            var key = '${uploadParam.key}'+"."+suffix;
            $("#key").val(key);
            $("#fileKey").val(key);
            var index = layer.load(1,{shade: [0.1,'#000'] });
            $.ajax({
                url: '${uploadParam.host}',
                method: 'post',
                data: new FormData($('#ajaxForm')[0]),
                dataType:'json',
                processData: false,
                contentType: false,
                success: function(res) {
                    layer.close(index);
                    if (res.code == 200){
                        layer.msg("上传成功！")
                        $("#url").val(res.url);
                    }else{
                        layer.msg("上传失败！")
                    }
                },
                error: function (errorMsg) {
                    layer.close(index);
                    layer.msg("上传出错！")
                }
            })
        })

        //监听提交
        form.on('submit(formDemo)', function(data){
            var index = layer.load(1,{shade: [0.1,'#000'] });
            var params = data.field;
            params.detail = um.getContent();
            $.ajax({
                url: '${ctx}/device/saveOrUpdate',
                method: 'post',
                data: JSON.stringify(params),
                dataType: 'JSON',
                contentType:"application/json",
                success: function(res) {
                    layer.close(index);
                    if(res.code == 200) {
                        layer.alert(res.data,function(){
                            parent.location.reload();
                        })
                    } else {
                        layer.msg(res.message, {
                            icon: 5
                        });
                    }
                }
            })
            return false;
        });
    });

</script>
</body>
</html>