<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <meta name="decorator" content="base" />
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        body{
            height: 450px !important;
        }
    </style>

</head>
<body style="">

<div class="" id="" style="height: 100%;">
    <div class="layui-card" style="height: 100%;padding: 20px;">
        <div class="layui-card-body">
            <form class="layui-form" action="" lay-filter="component-form-element">
                <input type="hidden" name="id" value="">
                <input type="hidden" name="type" value="${type}">
                <input type="hidden" name="url" id="fileUrl" value="">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="line-height: 100px;"><span class="mark">*</span></label>
                    <div class="layui-input-inline">
                        <div style="padding: 25px;margin: 10px;border: 1px dotted #716666;width: 100%;">
                            <button type="button" class="layui-btn" id="uploadBtn" style="width: 100%;height: 40px;">
                                <i class="layui-icon">&#xe67c;</i>选择资料文件
                            </button>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="mark">*</span>标题：</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" id="title" readonly="readonly" required lay-verify="required" placeholder="选择文件自动关联" autocomplete="off" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">文件描述：</label>
                    <div class="layui-input-block">
                        <textarea name="description" placeholder="请输入文件描述内容" class="layui-textarea"></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="color: darkorange;">温馨提示：</label>
                    <div class="layui-input-block" style="padding-top: 5px;color: darkorange;">
                        <p>1.您可以上传需要用到的文件资料，每份最大30MB，支持格式：jpg、png、gif、doc、docx、ppt、pdf、xls、xlsx、txt、mp4、mp3、avi、mov、rmvb、rm、flv、3gp</p>
                        <p>2.禁止上传违反能辉相关规定的内容，一切风险均由本人承担！</p>
                    </div>
                </div>

                <div class="layui-form-item text-c mt-40" style="text-align: center;">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="component-form-element">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>

<script type="text/javascript">
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'jquery', 'layer', 'upload'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,form = layui.form
            ,index = parent.layer.getFrameIndex(window.name); //获取窗口索引;

        var laydate = layui.laydate;

        $(".sf-ly-date").each(function(){
            laydate.render({
                elem: this,
                trigger: 'click'
            });
        });

        var checkAdd = false;
        var DISABLED = 'layui-btn-disabled';
        form.on('submit(component-form-element)', function(data){
            //var postData = JSON.stringify(data.field);
            $(':button').addClass(DISABLED);
            $(':button').attr('disabled', 'disabled');

            if(checkAdd){
                layer.msg("不可重复点击!", {icon:2});
                return false;
            }
            checkAdd = true;
            var postData = data.field;
            if(postData.title == "" || postData.title == undefined || postData.url == "" || postData.url == undefined){
                layer.msg("请选择资料文件!", {icon:2});
                checkAdd = false;
                $(':button').removeClass(DISABLED);
                $(':button').removeAttr('disabled');
                return false;
            }

            $.post('${ctx}/notification/saveTechnicalData', postData, function(result){

                if("ok" == result){
                    layer.msg("保存成功", {icon:1,time:1000}, function(){
                        parent.layer.close(index);
                        checkAdd = false;
                        $(':button').removeClass(DISABLED);
                        $(':button').removeAttr('disabled');
                    });
                }else{
                    if("err" == result){
                        layer.msg("保存失败，请刷新重试!", {icon:2});
                        checkAdd = false;
                        $(':button').removeClass(DISABLED);
                        $(':button').removeAttr('disabled');
                    }
                }
            });
            return false;
        });

        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#uploadBtn' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            ,size: 10*1024*3
            ,number: 1
            ,accept:'file'
            ,exts: 'jpg|png|gif|doc|docx|ppt|pdf|xls|xlsx|txt|mp4|mp3|avi|mov|rmvb|rm|flv|3gp|apk'
            , done: function (res) {
                //上传完毕回调
                $("#title").val(res.filename);
                $("#fileUrl").val(res.path);
            }, error: function () {
                return layer.msg("上传失败！",{icon:2});
            }
        });

        $(function(){
            //parent.layer.iframeAuto(index);
        })
    });

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