| 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(); | 
|     getHistoryList(); | 
| } | 
|   | 
| //查询历史数据 | 
| 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); | 
|     getHistoryList() | 
| } | 
|   | 
| //选择日期 | 
| function chooseDate() { | 
|     var dtpicker = new mui.DtPicker({ | 
|         type: "month", //设置日历初始视图模式  | 
|         value: dateTime | 
|     }) | 
|     var time = dateTime | 
|     dtpicker.show(function(e) { | 
|         dateTime = e.value; | 
|         $("#dateTime").val(dateTime); | 
|     }) | 
|     if(time != dateTime){ | 
|         getHistoryList() | 
|     } | 
| } | 
|   | 
| //选择仓库 | 
| function chooseDepot() { | 
|     var groupPicker = new mui.PopPicker(); | 
|     console.log(JSON.stringify(depotData)) | 
|     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; | 
|                 // console.log(JSON.stringify(depotList)) | 
|                 renderDepotData(); | 
|             } else { | 
|                 mui.toast("没有仓库信息!"); | 
|             } | 
|         }, | 
|         error: function() { | 
|             mui.alert('系统繁忙,请重试!', '提示', ["确定"], function() {}, "div"); | 
|         } | 
|     }) | 
| } | 
|   | 
| //渲染仓库选择数据 | 
| function renderDepotData() { | 
|     var fenl = {}; | 
|     $.each(depotList, function(index, item) { | 
|         fenl = { | 
|             value: item.id, | 
|             text: item.name, | 
|         } | 
|         depotData.push(fenl); | 
|     }) | 
| } | 
|   | 
| mui('.mui-scroll-wrapper').scroll({ | 
|     indicators: true, //是否显示滚动条 | 
|     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 | 
|             } | 
|         }) | 
|     } | 
| }); |