liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html>
 
    <head>
        <meta charset="utf-8">
        <title>Hello WEUI</title>
        <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
 
        <link rel="stylesheet" href="css/mui.min.css">
    </head>
 
    <body>
        <!--下拉刷新容器-->
        <div id="pullrefresh" class="mui-content mui-scroll-wrapper">
            <div class="mui-scroll">
                <!--数据列表-->
                <ul class="mui-table-view mui-table-view-chevron">
 
                </ul>
            </div>
        </div>
        <script src="js/mui.min.js"></script>
        <script src="js/common.js" ></script>
        <script>
//        if(sessionCache.getSessionCashe("userToken") == null){
//            location.href="login.html";
//        }
            mui.init({
                pullRefresh: {
                    container: '#pullrefresh',
                    down: {
                        callback: pulldownRefresh
                    },
                    up: {
                        contentrefresh: '正在加载...',
                        callback: pullupRefresh
                    }
                }
            });
            
            if (mui.os.plus) {
                mui.plusReady(function() {
                    setTimeout(function() {
                        mui('#pullrefresh').pullRefresh().pullupLoading();
                    }, 1000);
 
                });
            } else {
                mui.ready(function() {
                    mui('#pullrefresh').pullRefresh().pullupLoading();
                });
            }
            
            var count = 0;
            /**
             * 上拉加载具体业务实现
             */
            function pullupRefresh() {
                setTimeout(function() {
                    mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。
                    var table = document.body.querySelector('.mui-table-view');
                    var cells = document.body.querySelectorAll('.mui-table-view-cell');
                    for (var i = cells.length, len = i + 20; i < len; i++) {
                        var li = document.createElement('li');
                        li.className = 'mui-table-view-cell';
                        li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>';
                        table.appendChild(li);
                    }
                }, 1500);
            }
            
            /**
             * 下拉刷新具体业务实现
             */
            function pulldownRefresh() {
                setTimeout(function() {
                    var table = document.body.querySelector('.mui-table-view');
                    var cells = document.body.querySelectorAll('.mui-table-view-cell');
                    getMassCommuniqueList(table);
                    mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
                }, 1500);
            }
 
            function getMassCommuniqueList(table) {
                mui.ajax(
                    "http://36.110.115.116:8082/lsnt/rest/massCommunique/getMassCommuniqueList", {
                        data: JSON.stringify({
                            "menuCode": "11",
                            "currentPage": "1",
                            "pageSize": "10"
                        }),
                        dataType: 'json',
                        type: 'post', //HTTP请求类型
                        headers: {
                            'Content-Type': 'application/json'
                        },
                        success: function(data) {
                            var noticeList = data.result;
                            for (var i = 0; i < noticeList.length; i++) {
                                var li = document.createElement('li');
                                li.className = 'mui-table-view-cell';
                                li.innerHTML = '<a class="mui-navigate-right">' + noticeList[i].commName + '</a>';
                                //下拉刷新,新纪录插到最前面;
                                table.insertBefore(li, table.firstChild);
                            }
                        },
                        error: function(xhr, type, errorThrown) {
                            //异常处理;
                            console.log(type);
                        }
                    });
            }
        </script>
    </body>
 
</html>