sgj
6 小时以前 3a5e49666af1da441633b0a9bae4c3c2b18974b3
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="zh-cn" xmlns:th=http://www.thymeleaf.org>
<head>
    <meta charset="utf-8">
    <title>设备警告</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" th:href="@{/ajax/libs/mui/css/mui.min.css}">
    <style type="text/css">
        .mui-content{
            margin: 0 6px;
        }
        .mui-content>.mui-table-view:first-child {
            margin-top: -1px;
        }
        .mui-table-view-chevron .mui-table-view-cell {
            padding-right: 0px;
        }
        .mui-col-xs-10 {
            width: 100%;
        }
        .mui-h4, h4 {
            font-size: 17px;
            font-weight: 600;
        }
        .first1{
            color: #C7254E;
            float: right;
            margin-right: 50px;
            font-size: 15px;
        }
        .first2{
            float: right;
            margin-right: 50px;
            font-size: 15px;
        }
        .mui-h5, h5 {
            font-size: 14px;
            font-weight: 400;
            color: #333;
            margin: 10px 0;
        }
        .mui-table-view-cell p {
            color: #333;
        }
        .mui-scroll-wrapper {
            width: unset;
        }
        .head{
            margin-top: 44px;
        }
        .head1{
            margin-top: -44px;
        }
    </style>
</head>
 
<body>
<div id="head">
 
</div>
<div id="content" class="mui-content">
    <!--下拉刷新容器-->
    <div id="pullrefresh" class="mui-content mui-scroll-wrapper">
        <!--数据列表-->
        <ul class="mui-table-view mui-table-view-chevron"></ul>
    </div>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/wx/wx-common.js}"></script>
<script th:src="@{/ajax/libs/mui/js/mui.js}"></script>
<script th:inline="javascript">
    var loginType = [[${loginType}]];  //登录方式
    var deptList = [[${deptList}]];
    var userName = [[${userName}]];
    openid = [[${openid}]];  //用户的openid
    SERVE_URL = location.href.split("/wx/")[0];  //服务域名
    var pageSize = 10;  //每页条数
    var pageNo = 1;  //页码
    var total;
    var pageCount;  //总页码数
    var warnList;  //每页数据
    var deptListMap = {};
    $(function () {
        //所有库区
        if (deptList) {
            for (var i = 0; i < deptList.length; i++) {
                deptListMap[deptList[i].id] = deptList[i];
            }
        }
 
        // 监听页面显示事件(微信 H5 环境)
        window.addEventListener('pageshow', function() {
            if (localStorage.getItem('needRefresh') === 'true') {
                localStorage.removeItem('needRefresh');
                refreshData();
            }
        });
 
    });
 
 
    mui.init({
        pullRefresh: {
            container: '#pullrefresh',
            down: {
                // style: 'circle',
                // callback: pullupRefresh  //下拉刷新
            },
            up: {
                auto: true,
                contentrefresh: '正在加载...',
                callback: pullupRefresh  //上滑刷新
            },
            preventDefaultException: {
                className: /^mui-/
            }
        }
    });
 
 
    //初始出加载页面数据
    function pullupRefresh() {
        $("#pullrefresh").addClass("head1");
        //请求获取数据
        getWarnData();
    }
 
    function refreshData() {
        // 重置分页参数
        pageNo = 1;
 
        // 调用浏览器刷新
        location.reload();
    }
 
 
    //初始化页面数据
    function initData() {
        if(warnList == null || warnList.length<1){
            mui.toast("没有更多数据了!");
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
            return;
        }
        //初始化数据到页面
        mui('#pullrefresh').pullRefresh().endPullupToRefresh((pageNo>=pageCount));
        var table = document.body.querySelector('.mui-table-view');
        for (var i = 0; i < warnList.length; i++) {
            var deptName = deptListMap[warnList[i].deptId] ? deptListMap[warnList[i].deptId].kqmc : warnList[i].deptId;
            console.log(deptListMap);
            var li = document.createElement('li');
            li.className = 'mui-table-view-cell';
            var html = '';
            html += '<div onclick="toWarnDetail(\'' + warnList[i].id +'\',\'' + warnList[i].companyId + '\')" class="mui-table">';
            html += '<div class="mui-table-cell mui-col-xs-10"><h4 class="mui-ellipsis">' + warnList[i].id;
            html += '</span></h4><h5>所属库区:<span>' + deptName;
            html += '</span></h5><h5>警告时间:<span>' + warnList[i].createTime;
            html += '</span></h5><p class="mui-h6 mui-ellipsis">警告说明:' +warnList[i].content;
            li.innerHTML = html;
            table.appendChild(li);
        }
        pageNo += 1;
    }
 
    //请求获取警告数据
    function getWarnData() {
        var data = {
            "userName": userName,
            "loginType": loginType,
            "openid": openid,
            "pageSize": pageSize,
            "pageNo": pageNo
        };
        wxCommon.postJson("../wx/getSnapReplyPage", data,function (result) {
            if (result.code == "0000") {
                warnList = null;
                warnList = result.data.records;
                pageCount = getPageCount (result.data.total,pageSize);
                initData();
            } else {
                mui.toast("没有更多数据了!");
            }
        });
    }
 
    //计算总页码
    function getPageCount (total,limit){
        return total > 0 ? ((total < limit) ? 1 : ((total % limit) ? (parseInt(total / limit) + 1) : (total / limit))) : 0;
    }
 
    //查看警告详情页面
    function toWarnDetail(warnId,companyId) {
        location.href = SERVE_URL +
            '/wx/view-gateway?state=warn-detail&id='+ warnId + '&companyId=' + companyId + '&loginType=' + loginType + '&userName=' + userName;
    }
 
</script>
</body>
 
</html>