YYC
2023-05-29 397dbf892f842c834af17a91c788c94fd96003f8
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
var url = null;
var depotName;
var depotId;
var depotData = [];
var historyList = null;
var dateTime; //日期:yyyy-MM
//查询粮情历史数据参数
var data = {
    "interfaceId": "5302",
    "sign": "10302",
    "outId": "10302",
    "reqDateTime": new Date(),
    "tokenAuth": "",
    "data": {
        "deptId": "",
        "depotId": "",
        "dateTime": ''
    }
};
//查询仓库列表参数
var data0 = {
    "interfaceId": "5102",
    "sign": "10102",
    "outId": "10102",
    "reqDateTime": new Date(),
    "tokenAuth": "",
    "data": {
        "deptId": ""
    }
};
 
//初始化数据
function init() {
    var user = JSON.parse(localStorage.getItem('user'));
    var selectDeptId = JSON.parse(localStorage.getItem('selectDeptId'));
    url = user.url + "/api-phone/v35/gateway";
    data.tokenAuth = user.tokenAuth;
    data.data.deptId = selectDeptId;
    data0.tokenAuth = user.tokenAuth;
    data0.data.deptId = selectDeptId;
 
    //获取当前天时间
    dateTime = getDate(new Date());
    $("#dateTime").val(dateTime);
 
    //获取仓库参数信息
    var curr = plus.webview.currentWebview();
    depotId = curr.depotId;
    depotName = curr.depotName;
    $("#depot").val(depotName);
    //获取仓库列表
    getDepotList();
}
 
//查询历史数据
function getHistoryList() {
    historyList = null;
    if (!depotId) {
        mui.toast("请先选择仓库!");
        return;
    }
    data.data.depotId = depotId;
    data.data.dateTime = dateTime;
 
    //请求
    mui.ajax(url, {
        type: "POST",
        dataType: "json",
        crossDomain: true,
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(data),
        success: function(result) {
            if (result.code == "0000") {
                historyList = result.data;
                renderData();
            } else {
                renderData();
                mui.toast(result.mag);
            }
        },
        error: function() {
            mui.alert("系统繁忙,请重试!", "提示", ["确定"], function() {}, "div")
        }
    })
}
 
//渲染页面
function renderData() {
    var html = '';
    if (historyList != null && historyList.length > 0) {
        $.each(historyList, function(index, item) {
            html += '<li><div class="con"><div class="tit">检测时间: ' + item.receiveDate;
            html += '<a id="' + index + '" class="more"></a></div><div class="inner">';
            html += '<div class="info">粮食温度</div><div class="txt">';
            html += '<div class="num">' + item.tempMax + ' <span> ℃</span></div>';
            html += '<div class="desc">粮高温</div></div><div class="txt">';
            html += '<div class="num">' + item.tempAve + ' <span> ℃</span></div>';
            html += '<div class="desc">粮均温</div></div><div class="txt">';
            html += '<div class="num">' + item.tempMin + ' <span> ℃</span></div>';
            html += '<div class="desc">粮低温</div></div></div>';
            html += '<div class="m-tempre"><div class="group">';
            html += '<div class="tm" style="background-image: url(images/f5.png);">';
            html += '<div class="tem"><div class="left">仓内温 </div><div class="right">';
            if (item.tempIn <= -100) {
                html += '<span>备用</span></div></div>';
            } else {
                html += '<span>' + item.tempIn + '</span>℃</div></div>';
            }
            html += '<div class="tem"><div class="left">仓内湿 </div><div class="right">';
            if (item.humidityIn <= -100) {
                html += '<span>备用</span></div></div></div></div>';
            } else {
                html += '<span>' + item.humidityIn + '</span>%</div></div></div></div>';
            }
            html += '<div class="group"><div class="tm" style="background-image: url(images/f6.png);">';
            html += '<div class="tem"><div class="left">仓外温 </div><div class="right">';
            if (item.tempOut <= -100) {
                html += '<span>备用</span></div></div>';
            } else {
                html += '<span>' + item.tempOut + '</span>℃</div></div>';
            }
            html += '<div class="tem"><div class="left">仓外湿 </div><div class="right">';
            if (item.humidityOut <= -100) {
                html += '<span>备用</span></div></div></div></div>';
            } else {
                html += '<span>' + item.humidityOut + '</span>%</div></div></div></div>';
            }
            html += '</div></div></li>';
        })
    } else {
        html += '<li><div class="con"><div class="tit">检测时间: 暂无检测数据';
        html += '<a class="more"></a></div><div class="inner">';
        html += '<div class="info">粮食温度</div><div class="txt">';
        html += '<div class="num">-- <span> ℃</span></div>';
        html += '<div class="desc">粮高温</div></div><div class="txt">';
        html += '<div class="num">-- <span> ℃</span></div>';
        html += '<div class="desc">粮均温</div></div><div class="txt">';
        html += '<div class="num">-- <span> ℃</span></div>';
        html += '<div class="desc">粮低温</div></div></div>';
        html += '<div class="m-tempre"><div class="group">';
        html += '<div class="tm" style="background-image: url(images/f5.png);">';
        html += '<div class="tem"><div class="left">仓内温 </div>';
        html += '<div class="right"><span>--</span>℃</div></div>';
        html += '<div class="tem"><div class="left">仓内湿 </div>';
        html += '<div class="right"><span>--</span>%</div></div></div></div>';
        html += '<div class="group"><div class="tm" style="background-image: url(images/f6.png);">';
        html += '<div class="tem"><div class="left">仓外温 </div>';
        html += '<div class="right"><span>--</span>℃</div></div>';
        html += '<div class="tem"><div class="left">仓外湿 </div>';
        html += '<div class="right"><span>--</span>%</div></div></div></div></div></div></li>';
    }
    $("#hisList").html(html);
}
 
//默认获取当前日期(yyyy-MM)
function getDate(date) {
    var year = date.getFullYear();
    var month, day;
    month = date.getMonth() + 1;
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    return year + "-" + month;
}
 
//加减天
function addAndReduceMonth(tag) {
    var date = new Date(dateTime);
 
    date = date.setMonth(date.getMonth() + tag);
    date = new Date(date);
    dateTime = getDate(date);
    $("#dateTime").val(dateTime);
}
 
//选择日期
function chooseDate() {
    var dtpicker = new mui.DtPicker({
        type: "month", //设置日历初始视图模式 
    })
    dtpicker.show(function(e) {
        dateTime = e.value;
        $("#dateTime").val(dateTime);
    })
}
 
//选择仓库
function chooseDepot() {
    var groupPicker = new mui.PopPicker();
 
    groupPicker.setData(depotData);
 
    groupPicker.show(function(items) {
        depotId = items[0].value;
        depotName = items[0].text;
 
        $("#depot").val(depotName);
        mui.toast(depotId + "-" + dateTime);
    });
}
 
//获取仓库列表
function getDepotList() {
    mui.ajax(url, {
        type: "POST",
        dataType: "json",
        crossDomain: true,
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(data0),
        success: function(result) {
            if (result.code == "0000") {
                depotList = result.data;
                renderDepotData();
            } else {
                mui.toast("没有仓库信息!");
            }
        },
        error: function() {
            mui.alert('系统繁忙,请重试!', '提示', ["确定"], function() {}, "div");
        }
    })
}
 
//渲染仓库选择数据
function renderDepotData() {
    depotData = [];
    $.each(depotList, function(index, item) {
        depotData.push({
            value: item.depotId,
            text: item.depotName
        });
    })
}
 
mui('.mui-scroll-wrapper').scroll({
    indicators: false, //是否显示滚动条
    deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
    bounce: false, //是否启用回弹
    deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006
});
 
//功能模块跳转
mui(".mui-content").on("tap", ".mui-scroll-wrapper ul li a", function() {
    var index = this.getAttribute("id");
    if (index) {
        mui.openWindow({
            url: "grain-detail-his.html",
            id: "grain-detail-his",
            extras: {
                data: historyList[index],
                depotName: depotName
            }
        })
    }
});