<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>私塾家</title>
    <script th:include="sys/common/metaCSS" th:remove="tag"></script>
    <script th:include="sys/common/metaJS" th:remove="tag"></script>
    <script src="sys/js/jquery.validate.min.js" th:src="@{/static/sys/js/jquery.validate.min.js}"></script>
    <script src="sys/js/jquery-validation/messages_zh.js" th:src="@{/static/sys/js/jquery-validation/messages_zh.js}"></script>

    <style>
        .clearfix:after {
            visibility: hidden;
            display: block;
            font-size: 0;
            content: " ";
            clear: both;
            height: 0;
        }
        .clearfix { display: inline-table; }
        * html .clearfix { height: 1%; }
        .clearfix { display: block; }
        .fl{display:inline;float:left}
        clearfix >control-label-error{display:inline;float:left;marign-left:10px}
        label.control-label-error {
            color: Red;
        }
        .lispan {line-height: 34px;}

        .select1{
            width:100%;
            height: 32px;
            line-height: 32px;
            border-top: solid 1px #a7b5bc;
            border-left: solid 1px #a7b5bc;
            border-right: solid 1px #ced9df;
            border-bottom: solid 1px #ced9df;
            opacity:1;
            margin-bottom: 10px;
        }

        textarea{
            width: 382px;
        }
    </style>
</head>

<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">系统管理</a></li>
        <li><a th:href="@{/sys/sconota/sconotaList.html}">版本控制</a></li>
    </ul>
</div>
<div class="formbody">
    <div class="formtitle"><span th:text="${entity.id} ? '修改版本控制' :'新增版本控制'">版本控制</span></div>
    <form id="submitFrom"   method="post" class="form-horizontal form-validate">
        <input type="hidden" name="id" th:if="${entity.id}" th:value="${entity.id}"/>
        <input type="hidden" name="isDelete" th:value="0"/>
        <ul class="forminfo">
            <li class="clearfix">
                <label>升级包名称：<b>*</b></label>
                <input type="text" id="updatePackName" name="updatePackName" class="dfinput fl" th:value="${entity.updatePackName}">
            </li>
            <li class="clearfix">
                <label>升级之前版本号：<b>*</b></label>
                <input type="text" id="currentVersion" name="currentVersion" class="dfinput fl" th:value="${entity.currentVersion}">
            </li>
            <li class="clearfix">
                <label>升级之后版本号：<b>*</b></label>
                <input type="text" id="updateVersion" name="updateVersion" class="dfinput fl" th:value="${entity.updateVersion}">
            </li>
            <li class="clearfix">
                <input type="hidden" name="fileKey" id="fileKey" th:value="${entity.fileKey}"/>
                <label class="upload-file"> 上传发版包：</label>
                <input type="file" id="upfile">
            </li>
            <li class="clearfix">
                <label>是否启用升级：<b>*</b></label>
                <div id="isUsing" class="vocation" style="margin-right: 5px; width: 346px">
                    <select class="scinput select_width" name="isUsing"  >
                        <option  value="0" th:selected="${entity.isUsing==0}" >未启用</option>
                        <option  value="1" th:selected="${entity.isUsing==1}" >已启用</option>
                    </select>
                </div>
            </li>
            <li class="clearfix">
                <label>是否测试：<b>*</b></label>
                <div id="isTest" class="vocation" style="margin-right: 5px; width: 346px">
                    <select class="select1" name="isTest" onchange="changeType()" >
                        <option  value="0" th:selected="${entity.isTest==0}" >正式</option>
                        <option  value="1" th:selected="${entity.isTest==1}" >测试</option>
                    </select>
                </div>
            </li>
            <li class="clearfix">
                <label>测试imei号：<b>*</b></label>
                <div id="testImei" class="vocation" style="margin-right: 5px; width: 346px">
                    <input type="text" id="testImei1" name="testImei" class="dfinput fl" th:value="${list[0]}">
                    <input type="text" id="testImei2" name="testImei" class="dfinput fl" th:value="${list[1]}">
                    <input type="text" id="testImei3" name="testImei" class="dfinput fl" th:value="${list[2]}">
                    <input type="text" id="testImei4" name="testImei" class="dfinput fl" th:value="${list[3]}">
                    <input type="text" id="testImei5" name="testImei" class="dfinput fl" th:value="${list[4]}">
                </div>

            </li>
            <li class="clearfix">
                <label>md5：<b>*</b></label>
                <input type="text" id="md5" name="md5" class="dfinput fl" th:value="${entity.md5}">
            </li>
            <li>
                <label>升级日志：</label>
                <textarea style="border: solid 1px #a7b5bc;width: 345px" rows="15" name="content">[[${entity.content}]]</textarea>
            </li>
            <li>
                <label>&nbsp;</label>
                <button type="submit" class="btn" id="onload">保存</button>
                <button type="button" class="btn" onclick="window.history.go(-1);">取消</button>
            </li>
        </ul>
    </form>
    <div id="dispaly-progress"></div>
</div>
</body>
<script th:include="sys/common/fileUpload" th:remove="tag"></script>
<script type="text/javascript">

    $(function(){

        $("#submitFrom").validate({

            ignore:"",
            rules : {
                currentVersion: {
                    required : true
                },
                updateVersion: {
                    required : true
                },
                content: {
                    required : true
                }
            },
            messages: {
                currentVersion: {
                    required : "升级前版本号不能为空"
                },
                updateVersion: {
                    required : "升级后版本号不能为空"
                },
                content: {
                    required : "升级日志不能为空"
                }
            },

            errorPlacement : function(error, element) {
                error.appendTo(element.parent());
            },
            submitHandler : function(form) {
                roleFrom();
            }
        });

    });
    function roleFrom(){
        var url="[[${sysUrl}]]/sys/sconota/sconotaSave";
        var params = $("#submitFrom").serialize();
        $.post(url,params,function(data){
            if(data != null){
                if(data.meta.success){
                    parent.layer.msg("操作成功!",{icon:1});
                    setTimeout(function(){
                        window.location.href ='[[${sysUrl}]]/sys/sconota/sconotaList.html';
                    },1000);
                }else{
                    parent.layer.msg(data.meta.message,{icon:11});
                }
            }

        });
    }
    function changeType(){
        var type = $(".select1 option:selected").val();
        var testImei=$("#testImei").val();
        debugger;
        if(type=="1"&&testImei==""){
            layer.msg("测试imei不能为空",{icon:11});
            return;
        }
        options.uploader= "[[${sysUrl}]]/sys/appinfo/upload/"+type;
        initUpload(options,"fileKey","");
    }
    var options = uploadOptions("upfile","上传发版包");
    $(function(){
        options.fileTypeExts = "*.*";
        options.fileSizeLimit= '200MB';
        options.uploader= "[[${sysUrl}]]/sys/sconota/upload";
        initUpload1(options,"fileKey","");
    });
    function initUpload1(uploadOptions,id,idImg){
        $("#" + uploadOptions.buttonId).uploadify({
            //开启调试
            'debug' : false,
            //是否自动上传
            'auto' : uploadOptions.auto,
            //超时时间
            'successTimeout' : 99999,
            //附带值
            'formData' : {

            },
            //flash
            'swf' : "[[${sysUrl}]]/static/sys/js/uploadify/v3/uploadify.swf",
            //文件选择后的容器ID
            'queueID' : uploadOptions.queueID,
            //服务器端脚本使用的文件对象的名称 $_FILES个['upload']
            'fileObjName' : 'upload',
            //上传处理程序
            'uploader' : uploadOptions.uploader,
            //
            'buttonText' : uploadOptions.buttonText,
            'buttonClass' : 'tms-btn',
            //浏览按钮的宽度
            'width' : '84',
            //浏览按钮的高度
            'height' : '30',
            //在浏览窗口底部的文件类型下拉菜单中显示的文本
            'fileTypeDesc' : '支持的格式',
            //允许上传的文件后缀
            'fileTypeExts' : uploadOptions.fileTypeExts,
            //上传文件的大小限制
            'fileSizeLimit' : uploadOptions.fileSizeLimit,
            //上传数量
            'queueSizeLimit' : uploadOptions.queueSizeLimit,
            //返回一个错误，选择文件的时候触发
            'onSelectError' : function(file, errorCode, errorMsg) {
                switch (errorCode) {
                    case -100:
                        // alert("上传的文件数量已经超出系统限制的");
                        break;
                    case -110:
                        //alert("文件 ["+file.name+"] 大小超出系统限制的大小！");
                        break;
                    case -120:
                        //alert("文件 ["+file.name+"] 大小异常！");
                        break;
                    case -130:
                        alert("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            },
            'onUploadProgress' : function (file, fileBytesLoaded, fileTotalBytes) {
                debugger;
                var percent = fileBytesLoaded / fileTotalBytes;
                var progress=percent*100+"%";
                if (percent == 0) {
                    $("#dispaly-progress").html("<label style='color: red;font-size: 22px;font-weight: bold'>上传中</label>");
                    $("#dispaly-progress").value=progress;
                }
                if (percent == 1) {
                    $("#dispaly-progress").html("<label style='color: red;font-size: 22px;font-weight: bold'>上传完成！</label>");
                }
            },
            //上传到服务器，服务器返回相应信息到data里
            'onUploadSuccess' : function(file, resData, resOk) {
                if(resData != null && resData != ""){
                    var obj = $.parseJSON(resData);
                    var filePath = obj.data.pics[0].filePath;
                    var fileThumPath = obj.data.pics[0].fileThumPath;
                    $("#"+id).val(filePath);
                    if($("#"+idImg)){
                        $("#"+idImg).attr("src", fileThumPath);
                    }
                }
            }
        });
    };
</script>
</html>