<%@ 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="margin-top:20px; width: 98%;" >
    <input name="id" value="${entity.id}" hidden/>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >设备类型:</label>
            <div class="layui-input-inline">
                <select class="layui-select" name="code" autocomplete="off" lay-filter="deviceType" lay-verify="required">
                    <option value="">请选择</option>
                    <c:forEach items="${deviceTypeDict}" var="dict">
                        <option value="${dict.code}" ${dict.code == entity.code ? 'selected' : ''}>${dict.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >设备规格:</label>
            <div class="layui-input-inline">
                <select class="layui-select" lay-filter="typeSelect" autocomplete="off" id="type" lay-verify="required">
                    <option value="">请选择</option>
                    <c:if test="${not empty subDeviceType}">
                        <c:forEach items="${subDeviceType}" var="sub">
                            <c:if test="${sub.spec == entity.type}">
                                <c:set var="typeDesc" value="${sub.specName}" />
                            </c:if>
                            <option value="${sub.spec}" data-weight="${sub.weight}" data-postageFlag="${sub.postageFlag}" ${sub.spec == entity.type ? 'selected' : ''}>${sub.specName}</option>
                        </c:forEach>
                    </c:if>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span style="color: red">* 若需要添加新的版本，可以在以下编码和名称中自定义</span>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">规格code</label>
            <div class="layui-input-inline">
                <input type="text" name="type" placeholder="建议使用纯英文串" value="${entity.type}" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">规格名称</label>
            <div class="layui-input-inline">
                <input type="text" name="typeDesc" placeholder="规格名称" value="${typeDesc}" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">重量(kg)</label>
            <div class="layui-input-inline">
                <input type="number" name="weight" id="weight" placeholder="请输入重量" value="${weight}" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >设备分组:</label>
            <div class="layui-input-inline" style="margin-left:0">
                <select class="layui-select" lay-filter="groupNoSelect" autocomplete="off" lay-verify="required">
                    <option value="">请选择</option>
                    <c:forEach items="${deviceGroupDict}" var="dict">
                        <c:if test="${dict.groupCode == entity.groupNo}">
                            <c:set var="groupNoDesc" value="${dict.groupName}" />
                        </c:if>
                        <option value="${dict.groupCode}" ${dict.groupCode == entity.groupNo ? 'selected' : ''}>${dict.groupName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span style="color: red">* 若需要添加新的分组，可以在以下编码和名称中自定义</span>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">分组编码</label>
            <div class="layui-input-inline">
                <input type="text" name="groupNo" placeholder="建议使用纯英文串" value="${entity.groupNo}" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">分组名称</label>
            <div class="layui-input-inline">
                <input type="text" name="groupNoDesc" placeholder="版本名称" value="${groupNoDesc}" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >厂家名称:</label>
            <div class="layui-input-inline">
                <input name="venderName" value="${entity.venderName}" autocomplete="off" placeholder="请输入厂家名称" class="layui-input"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >厂家型号:</label>
            <div class="layui-input-inline">
                <input name="venderModel" value="${entity.venderModel}" autocomplete="off"  placeholder="请输入厂家型号" class="layui-input"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >通道型号:</label>
            <div class="layui-input-inline">
                <input name="aisleModel" value="${entity.aisleModel}" autocomplete="off" placeholder="请输入通道型号" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >单价:</label>
            <div class="layui-input-inline">
                <input type="number" name="unitPrice" value="${entity.unitPrice}" autocomplete="off" lay-verify="required" placeholder="请输入单价" class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >批发价:</label>
            <div class="layui-input-inline">
                <input type="number" name="wholesalePrice" value="${entity.wholesalePrice}" autocomplete="off" placeholder="请输入批发单价" class="layui-input"/>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" >批发最低数:</label>
            <div class="layui-input-block">
                <input type="number" name="wholesaleMinNum" value="${entity.wholesaleMinNum}" autocomplete="off" placeholder="请输入批发最低数" class="layui-input"/>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >状态:</label>
            <div class="layui-input-inline">
                <select class="layui-select" autocomplete="off" name="status" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="1" ${entity.status eq '1' or  empty entity.status ? 'selected' : '' } >显示</option>
                    <option value="0" ${entity.status eq '0' ? 'selected' : '' } >不显示</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >排序:</label>
            <div class="layui-input-inline">
                <input name="seq" value="${entity.seq}" autocomplete="off" 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:0">
            <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">
        <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>

<%--<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','upload'], function(){
        var form = layui.form;
        var layer = layui.layer;
        /*var upload = layui.upload;*/

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

        /*//创建监听函数
        var xhrOnProgress = function (fun) {
            xhrOnProgress.onprogress = fun; //绑定监听
            //使用闭包实现监听绑
            return function () {
                //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
                var xhr = $.ajaxSettings.xhr();
                //判断监听函数是否为函数
                if (typeof xhrOnProgress.onprogress !== 'function')
                    return xhr;
                //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
                if (xhrOnProgress.onprogress && xhr.upload) {
                    xhr.upload.onprogress = xhrOnProgress.onprogress;
                }
                return xhr;
            }
        }*/

        /*var openIndex = "";
        upload.render({
            elem: '#chooseFile', // 文件选择
            accept: 'images',
            acceptMime: 'image/!*',
            url: '${uploadParam.host}',
            exts: 'jpg|png|gif|bmp|jpeg',
            method: 'POST',
            auto: false, // 设置不自动提交
            bindAction: '#uploadBtn', // 提交按钮
            before: function () {
                element.progress('js_upload_progress', '0%');//设置页面进度条
                openIndex = layer.open({
                    type: 1,
                    title: '上传进度',
                    closeBtn: 1, //不显示关闭按钮
                    area: ['300', '130'],
                    shadeClose: false, //开启遮罩关闭
                    content: $("#uploadLoadingDiv").html(),
                    offset: '100'
                });
            }
            , xhr: xhrOnProgress
            , progress: function (value) {//上传进度回调 value进度值
                element.progress('js_upload_progress', value + '%');//设置页面进度条
            }
            , choose: function (obj) {
                var loading = layer.load(1, {shade: [0.1, '#000']});
                var data = {};
                obj.preview(function (index, file, result) {
                    var fileName = file.name;
                    $("#chooseFile").val(fileName);
                    var suffix = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length);
                    var key = '${uploadParam.key}' + "." + suffix;
                    $("#key").val(key);
                    $("#fileKey").val(key);
                    data.OSSAccessKeyId = $('#accessid').val();
                    data.policy = $('#policy').val();
                    data.signature = $('#signature').val();
                    data.expire = $('#expire').val();
                    data.success_action_status = $('#success_action_status').val();
                    data.callBack = $("#key2_callBack").val();
                    data.key = key;
                    layer.close(loading);
                });
                this.data = data;
            },
            done: function (res) {
                layer.close(openIndex);
                if (res.code == 200) {
                    layer.msg("上传成功！")
                    $("#url").val(res.url);
                } else {
                    layer.msg("上传失败！")
                }
            },
            error: function (res) {
                layer.msg(res.msg);
            }
        });*/
        form.on('select(deviceType)',function (data) {
            var dataType = data.value;
            $.ajax({
                url: ctx + '/deviceDetail/getDeviceSubVersionType/'+dataType,
                method: 'get',
                dataType: 'json',
                success: function(res) {
                    if(res.code == 200) {
                        var dom = $("#type");
                        var html = "<option value=''>请选择</option>";
                        dom.empty();
                        if(res.data.length > 0){
                            $.each(res.data,function (k,v) {
                                html+= "<option data-weight='"+v.weight+"' value='"+v.spec+"'>"+v.specName+"</option>";
                            })
                            dom.append(html);
                        }
                        form.render('select');
                    } else {
                        layer.msg(res.message, {
                            icon: 5
                        });
                    }
                }
            })

        })

        //监听提交
        form.on('submit(formDemo)', function(data){
            var index = layer.load(1,{shade: [0.1,'#000'] });
            var params = data.field;
            $.ajax({
                url: ctx + '/deviceDetail/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.message,function(){
                            parent.location.reload();
                        })
                    } else {
                        layer.msg(res.message, {
                            icon: 2
                        });
                    }
                }
            })
            return false;
        });

        form.on('select(typeSelect)', function(data) {
            $('input[name="type"]').val(data.value);
            if (data.value != "") {
                let obj = $(data.elem).find("option:selected").data();
                $("input[name = 'typeDesc']").val(data.elem[data.elem.selectedIndex].text);
                $("#weight").val(obj.weight.toFixed(2));
            } else {
                $("input[name = 'typeDesc']").val("");
            }
        });

        form.on('select(groupNoSelect)', function(data) {
            $('input[name="groupNo"]').val(data.value);
            if (data.value != "") {
                $("input[name = 'groupNoDesc']").val(data.elem[data.elem.selectedIndex].text);
            } else {
                $("input[name = 'groupNoDesc']").val("");
            }
        });
    });

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