<%@ 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>
        .layui-card{box-shadow: none;}
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab  layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="JSZL_JSZL_PJSZL_T" html='<li class="layui-this sf-tab"><a href="${ctx}/notification/technicalData">技术资料</a></li>'/>
                <%--<button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " id="searchBtn" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>
                    查询
                </button>--%>
            </ul>
        </div>
        <%--  <div class="layui-card-body" id="searchForm">
              <div class="layui-form-item">
                  <div class="layui-col-lg2 layui-col-sm3">
                      <label class="layui-form-label">标题：</label>
                      <div class="layui-input-block">
                          <input type="text" id="form-name" autocomplete="off" class="layui-input">
                      </div>
                  </div>
              </div>
          </div>--%>
    </div>

    <div class='layui-card'>
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test-table-reload" lay-filter="test-table-reload" ></table>

        </div>
    </div>
</div>

<div  id="toolbarDemo" class="layui-form-item layui-hide">
    <sfTags:pagePermission authFlag="PLATEM_JSZL_XZ_B" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
    <sfTags:pagePermission authFlag="PLATEM_JSZL_SC_B" html='<button class="layui-btn layui-btn-sm" id="delBtn" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>'/>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<%--<script type="text/html" id="table-toolbar">
    <sfTags:pagePermission authFlag="JSZL_SC_B" html='<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>'/>
</script>--%>
<script src="${ctxPlugin}/lib/base64.js"></script>
<script type="text/javascript">
    var $
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer'], function(){
        var tableExt = layui.tableExt;
        var layer = layui.layer;
       $ = layui.jquery;

        tableExt.render({
            elem: '#test-table-reload'
            ,toolbar : '#toolbarDemo'
            ,defaultToolbar : false
            ,url: '${ctx}/notification/ajaxTechnicalData?type=1'
            ,cols: [[
                {type: 'numbers', title: '序号'}
                , {field: 'id', type: 'checkbox'}
                ,{field:'href', title: '技术资料' , align : 'center', templet: function(d){
                        return  "<a href=\"${commonStaticImgPath}"+d.href+"\" target='_blank' class=\"layui-table-link\" >"+d.name+"</a>";
                  //  return '<a target="_blank" style="color:#D9B589;cursor:pointer;" href="${commonStaticImgPath}'+d.href+'">'+d.name+'</a>'
                }}
                ,{field:'description', title: '资料说明', align : 'center',width: 600}
                ,{field:'create_time', title: '创建时间', align : 'center'}
            ]]
            ,page:true
        });

        var table = tableExt.getLayTable();

        //监听行工具事件
        table.on('toolbar(test-table-reload)', function(obj){
            if(obj.event === 'add'){
                layer.open({
                    title:'新增技术资料',
                    type: 2,
                    area: ["750px", "550px"],
                    fixed: false,
                    content: '${ctx}/notification/technicalDataForm',
                    end:function(){
                        location.reload();
                    }
                })
            }
            if(obj.event === 'del'){
                var delData = table.checkStatus("test-table-reload");
                var ids = [];
                if (delData.data.length < 1) {
                    layer.msg("请勾选一条择待处理数据！", {icon: 2});
                    return;
                }
                var datas = delData.data;
                $.each(datas, function(i, d) {
                    ids.push(d.id);
                });
                layer.confirm('真的删除所选资料吗？',{icon: 3}, function(index){
                    $.post('${ctx}/notification/delTechnicalData', {id: ids.join(",")}, function(result){
                        if("ok" == result){
                            layer.msg("删除成功！", {icon: 1});
                            table.reload('test-table-reload');
                            /*   obj.del();
                               layer.close(index);*/
                        }else{
                            layer.msg("删除失败");
                        }
                    });
                });
            }

        });

        var active = {
            reload: function(){
                table.reload('test-table-reload', {
                    where: {
                        name: $('#form-name').val()
                    }
                });
            }
        };

        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });
    function previewUrl(_url){
        if (!checkUrl(_url)) {
            return false;
        }
        var base = new Base64();
        var b64Encoded =  base.encode(_url);
        if(_url.endsWith('pdf')){
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded)+'&officePreviewType=pdf');
        }else{
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded));
        }
    }
    function checkUrl(url) {
        //url= 协议://(ftp的登录信息)[IP|域名](:端口号)(/或?请求参数)
        var strRegex = '^((https|http|ftp)://)'//(https或http或ftp)
            + '(([\\w_!~*\'()\\.&=+$%-]+: )?[\\w_!~*\'()\\.&=+$%-]+@)?' //ftp的user@  可有可无
            + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 3位数字.3位数字.3位数字.3位数字
            + '|' // 允许IP和DOMAIN（域名）
            + '(localhost)|'	//匹配localhost
            + '([\\w_!~*\'()-]+\\.)*' // 域名- 至少一个[英文或数字_!~*\'()-]加上.
            + '\\w+\\.' // 一级域名 -英文或数字  加上.
            + '[a-zA-Z]{1,6})' // 顶级域名- 1-6位英文
            + '(:[0-9]{1,5})?' // 端口- :80 ,1-5位数字
            + '((/?)|' // url无参数结尾 - 斜杆或这没有
            + '(/[\\w_!~*\'()\\.;?:@&=+$,%#-]+)+/?)$';//请求参数结尾- 英文或数字和[]内的各种字符
        var re = new RegExp(strRegex, 'i');//i不区分大小写
        //将url做uri转码后再匹配，解除请求参数中的中文和空字符影响
        if (re.test(encodeURI(url))) {
            return (true);
        } else {
            return (false);
        }
    }

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