layui页面的自动上下滚动

核心代码

            /* 滚动条自动上下滚动 */
            scrollBar();
            function scrollBar() {
                var height = $('.layui-table-body').height();
                var number = 0;
                var length = 0;
                var time = setInterval(function () {
                    number += 1;
                    // 当滚动完后,从新开始
                    if (number == 2) {
                        clearInterval(time);
                        $('.layui-table-body').scrollTop('0');
                    } else {
                        // 设置这个高度滚动几次
                        length += height / 2;
                        $('.layui-table-body').scrollTop(length);  //只有此处有区别
                    }
                }, 3000);   // 设置时间,3秒滚动一次
            };

            setInterval(function () {
                table.reload('contentTable',{
                    method:'get'
                    ,page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
                scrollBar();
            }, 6000);    //全部滚动一次需要6秒

整体页面代码

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/5/14 0014
  Time: 13:23
  批量拆箱看板
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<head>
    <meta charset="utf-8">
    <title>倒箱品管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
    <script type="text/css">
        .layui-tab-item {
            display: none;
            height: 1000px;
        }
    </script>
    <%
        //页面每隔30秒自动刷新一遍
        response.setHeader("refresh","10");
    %>
</head>
<body>
    <div class="x-body fDiv">
        <table id="tableList" lay-filter="tableList"></table>
    </div>

    <div id="tableListDetailDiv" class="fDiv" hidden="hidden">
        <table id="tableListDetail" lay-filter="tableListDetail"></table>
    </div>

    <script type="text/javascript">
        layui.use(['table','layer','upload','form'], function(){
            var table = layui.table;
            var $ = layui.jquery, active = {
                reload:function () {
                    table.reload('contentTable',{
                        method:'get'
                        ,page: {
                            curr: 1//重新从第 1 页开始
                        }
                    });
                }
            };

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

            /* 这是行点击变色的函数,放到复选框点击事件上方,就是因为,单击用这个,如果是勾选复选框,就把这个事件覆盖了。 显示复选框的样式 */
            /* 关键点,在页面头部加class样式(.layui-table-view .layui-table-body),在table外加div层,id为fDiv */
            $(document).on('click', '.fDiv .layui-table-view .layui-table-body tr', function (event) {
                var trElem = $(this);
                var tableView = trElem.closest('.layui-table-view');
                tableView.find('.layui-table-body tr.table_tr_click').removeClass('table_tr_click');
                tableView.find('.layui-table-body tr[data-index="' + trElem.data('index') + '"]').addClass('table_tr_click');
            });

            /* 疑问:想在最后加一列备注,合并4行,但是失败,样式会乱,如果加在供应商名称后,就没问题*/
            table.render({
                elem: '#tableList'
                ,url:'${pageContext.request.contextPath }/kanban/piLiangChaiXiangKanBan.do'
                ,id :'contentTable'
                ,totalRow: true //开启合计行
                ,page : false
                ,height : 800
                ,cols: [
                    [
                        {title:'序号',width: 50,type:'numbers', align:'center', rowspan: 4}
                        ,{field: 'customer_name', title:'供应商名称', width:'150', align:'center', rowspan: 4, totalRowText: '合计:'}
                        ,{title:'倒箱品库存现况', align:'center', colspan: 14}
                        ,{title:'倒箱品作业现况', align:'center', colspan: 6}

                    ],
                    [
                        {title:'库存', align:'center', rowspan: 2, colspan: 2}
                        ,{title:'日发货计划', align:'center', colspan: 8}
                        ,{title:'下趟数', align:'center', colspan: 4}
                        ,{title:'今日计划', align:'center', rowspan: 2, colspan: 2}
                        ,{title:'完成数', align:'center', rowspan: 2, colspan: 2}
                        ,{title:'未完成', align:'center', rowspan: 2, colspan: 2}
                    ],
                    [
                        {title:'计划总数', align:'center', colspan: 2}
                        ,{title:'已发货', align:'center', colspan: 2}
                        ,{title:'未发货', align:'center', colspan: 2}
                        ,{title:'差额', align:'center', colspan: 2}
                        ,{title:'计划总数', align:'center', colspan: 2}
                        ,{title:'差额', align:'center', colspan: 2}
                    ],
                    [
                        {field: 'wuLiaoKuCun',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiKuCun',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoJiHuaFaHuo',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiJiHuaFaHuo',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoYiFa',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiYiFa',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoWeiFa',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiWeiFa',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoJiHuaCha',title: '物料',align:'center', width:'80',style:'color: #FF0000;', totalRow: true}
                        ,{field: 'rongQiJiHuaCha',title: '容器',align:'center', width:'60',style:'color: #FF0000;', totalRow: true}
                        ,{field: 'wuLiaoXiaGeJiHua',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiXiaGeJiHua',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoXiaGeJiHuaCha',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiXiaGeJiHuaCha',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoChaiJiHua',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiChaiJiHua',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoChaiYiZuo',title: '物料',align:'center', width:'80', totalRow: true}
                        ,{field: 'rongQiChaiYiZuo',title: '容器',align:'center', width:'60', totalRow: true}
                        ,{field: 'wuLiaoChaiWeiZuo',title: '物料',align:'center', width:'80',style:'color: #FF0000;', totalRow: true}
                        ,{field: 'rongQiChaiWeiZuo',title: '容器',align:'center', width:'60',style:'color: #FF0000;', totalRow: true}
                    ]
                ]
                ,done : function(res, curr, count){
                    $('th').css({
                        'background-color': '#009688', 'color': '#fff','font-weight':'bold'
                    });
                    var divArr = $(".layui-table-total div.layui-table-cell");
                    $.each(divArr,function (index,item) {
                        var _div = $(item);
                        var content = _div.html();
                        content = content.replace(".00","");
                        _div.html(content);
                    });
                    var that = this.elem.next();
                    res.data.forEach(function (item, index) {
                        // 所需的条件
                        if(item.wuLiaoJiHuaCha > 0){
                            // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                            that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='wuLiaoJiHuaCha']").css("background-color", "#FFFF66");
                        }
                        if(item.rongQiJiHuaCha > 0){
                            // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                            that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='rongQiJiHuaCha']").css("background-color", "#FFFF66");
                        }
                        if(item.wuLiaoChaiWeiZuo > 0){
                            // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                            that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='wuLiaoChaiWeiZuo']").css("background-color", "#FFFF66");
                        }
                        if(item.rongQiChaiWeiZuo > 0){
                            // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                            that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='rongQiChaiWeiZuo']").css("background-color", "#FFFF66");
                        }
                    });
                }
            });

            //行点击事件,显示明细表
            table.on('row(tableList)', function(obj){
                var customerId = obj.data.customerId;
                var customerName = obj.data.customer_name;
                console.log("canshu="+customerId);
                layer.open({
                    type: 1 					//Page层类型
                    ,area: ['1700px', '700px'] 	//宽  高
                    ,title: customerName
                    ,shade: 0.6 				//遮罩透明度
                    ,maxmin: true 				//允许全屏最小化
                    ,anim: 1 					//0-6的动画形式,-1不开启
                    ,content: $('#tableListDetailDiv')
                    ,end: function () {
                        var formDiv = document.getElementById('tableListDetailDiv');
                        formDiv.style.display = '';
                    }
                    ,success:function(layero, index){
                        table.render({
                            elem: '#tableListDetail'
                            ,url:'${pageContext.request.contextPath }/kanban/piLiangChaiXiangKanBanOnMateriel.do'
                            ,where: {"customerId":customerId}
                            ,id :'contentTableDetail'
                            ,totalRow: true //开启合计行
                            ,page : false
                            ,height : 600
                            ,cols: [
                                [
                                    {title:'序号',width: 50,type:'numbers', align:'center', rowspan: 4}
                                    ,{field: 'materiel_name', title:'物料名称', width:'150', align:'center', rowspan: 4, totalRowText: '合计:'}
                                    ,{field: 'materiel_num', title:'零件号', width:'150', align:'center', rowspan: 4}
                                    ,{title:'倒箱品库存现况', align:'center', colspan: 14}
                                    ,{title:'倒箱品作业现况', align:'center', colspan: 6}

                                ],
                                [
                                    {title:'库存', align:'center', rowspan: 2, colspan: 2}
                                    ,{title:'日发货计划', align:'center', colspan: 8}
                                    ,{title:'下趟数', align:'center', colspan: 4}
                                    ,{title:'今日计划', align:'center', rowspan: 2, colspan: 2}
                                    ,{title:'完成数', align:'center', rowspan: 2, colspan: 2}
                                    ,{title:'未完成', align:'center', rowspan: 2, colspan: 2}
                                ],
                                [
                                    {title:'计划总数', align:'center', colspan: 2}
                                    ,{title:'已发货', align:'center', colspan: 2}
                                    ,{title:'未发货', align:'center', colspan: 2}
                                    ,{title:'差额', align:'center', colspan: 2}
                                    ,{title:'计划总数', align:'center', colspan: 2}
                                    ,{title:'差额', align:'center', colspan: 2}
                                ],
                                [
                                    {field: 'wuLiaoKuCun',title: '物料',align:'center', width:'70', totalRow: true}
                                    ,{field: 'rongQiKuCun',title: '容器',align:'center', width:'60', totalRow: true}
                                    ,{field: 'wuLiaoJiHuaFaHuo',title: '物料',align:'center', width:'70', totalRow: true}
                                    ,{field: 'rongQiJiHuaFaHuo',title: '容器',align:'center', width:'60', totalRow: true}
                                    ,{field: 'wuLiaoYiFa',title: '物料',align:'center', width:'70', totalRow: true}
                                    ,{field: 'rongQiYiFa',title: '容器',align:'center', width:'60', totalRow: true}
                                    ,{field: 'wuLiaoWeiFa',title: '物料',align:'center', width:'70', totalRow: true}
                                    ,{field: 'rongQiWeiFa',title: '容器',align:'center', width:'60', totalRow: true}
                                    ,{field: 'wuLiaoJiHuaCha',title: '物料',align:'center', width:'70',style:'color: #FF0000;', totalRow: true}
                                    ,{field: 'rongQiJiHuaCha',title: '容器',align:'center', width:'60',style:'color: #FF0000;', totalRow: true}
                                    ,{field: 'wuLiaoXiaGeJiHua',title: '物料',align:'center', width:'70', totalRow: true}
                                    ,{field: 'rongQiXiaGeJiHua',title: '容器',align:'center', width:'60', totalRow: true}
                                    ,{field: 'wuLiaoXiaGeJiHuaCha',title: '物料',align:'center', width:'70', totalRow: true}
                                    ,{field: 'rongQiXiaGeJiHuaCha',title: '容器',align:'center', width:'60', totalRow: true}
                                    ,{field: 'wuLiaoChaiJiHua',title: '物料',align:'center', width:'70', totalRow: true}
                                    ,{field: 'rongQiChaiJiHua',title: '容器',align:'center', width:'60', totalRow: true}
                                    ,{field: 'wuLiaoChaiYiZuo',title: '物料',align:'center', width:'70', totalRow: true}
                                    ,{field: 'rongQiChaiYiZuo',title: '容器',align:'center', width:'60', totalRow: true}
                                    ,{field: 'wuLiaoChaiWeiZuo',title: '物料',align:'center', width:'70',style:'color: #FF0000;', totalRow: true}
                                    ,{field: 'rongQiChaiWeiZuo',title: '容器',align:'center', width:'60',style:'color: #FF0000;', totalRow: true}
                                ]
                            ]
                            ,done : function(res, curr, count){
                                $('th').css({
                                    'background-color': '#009688', 'color': '#fff','font-weight':'bold'
                                });
                                var divArr = $(".layui-table-total div.layui-table-cell");
                                $.each(divArr,function (index,item) {
                                    var _div = $(item);
                                    var content = _div.html();
                                    content = content.replace(".00","");
                                    _div.html(content);
                                });
                                var that = this.elem.next();
                                res.data.forEach(function (item, index) {
                                    // 所需的条件
                                    if(item.wuLiaoJiHuaCha > 0){
                                        // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                                        that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='wuLiaoJiHuaCha']").css("background-color", "#FFFF66");
                                    }
                                    if(item.rongQiJiHuaCha > 0){
                                        // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                                        that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='rongQiJiHuaCha']").css("background-color", "#FFFF66");
                                    }
                                    if(item.wuLiaoChaiWeiZuo > 0){
                                        // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                                        that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='wuLiaoChaiWeiZuo']").css("background-color", "#FFFF66");
                                    }
                                    if(item.rongQiChaiWeiZuo > 0){
                                        // 添加颜色--#1E9FFF ;'threeMonth'根据需要填充背景色的field进行更改
                                        that.find(".layui-table-box tbody tr[data-index='" + index + "'] td[data-field='rongQiChaiWeiZuo']").css("background-color", "#FFFF66");
                                    }
                                });
                            }
                        });
                    }
                })
            });

            /* 滚动条自动上下滚动 */
            scrollBar();
            function scrollBar() {
                var height = $('.layui-table-body').height();
                var number = 0;
                var length = 0;
                var time = setInterval(function () {
                    number += 1;
                    // 当滚动完后,从新开始
                    if (number == 2) {
                        clearInterval(time);
                        $('.layui-table-body').scrollTop('0');
                    } else {
                        // 设置这个高度滚动几次
                        length += height / 2;
                        $('.layui-table-body').scrollTop(length);  //只有此处有区别
                    }
                }, 3000);   // 设置时间,3秒滚动一次
            };

            setInterval(function () {
                table.reload('contentTable',{
                    method:'get'
                    ,page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
                scrollBar();
            }, 6000);    //全部滚动一次需要6秒

        });

        /*setTimeout(function(){  //使用  setTimeout()方法设定定时2000毫秒
            window.location.reload();
        },300000);*/

    </script>

</body>
</html>

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值