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 += '
检测时间: ' + item.receiveDate;
html += '
';
html += '
粮食温度
';
html += '
' + item.tempMax + ' ℃
';
html += '
粮高温
';
html += '
' + item.tempAve + ' ℃
';
html += '
粮均温
';
html += '
' + item.tempMin + ' ℃
';
html += '
粮低温
';
html += '
';
html += '
';
html += '
仓内温
';
if (item.tempIn <= -100) {
html += '备用
';
} else {
html += '
' + item.tempIn + '℃
';
}
html += '
仓内湿
';
if (item.humidityIn <= -100) {
html += '备用
';
} else {
html += '' + item.humidityIn + '%';
}
html += '';
html += '
仓外温
';
if (item.tempOut <= -100) {
html += '备用
';
} else {
html += '
' + item.tempOut + '℃
';
}
html += '仓外湿
';
if (item.humidityOut <= -100) {
html += '备用
';
} else {
html += '' + item.humidityOut + '%';
}
html += '';
})
} else {
html += '';
html += '
粮食温度
';
html += '
-- ℃
';
html += '
粮高温
';
html += '
-- ℃
';
html += '
粮均温
';
html += '
-- ℃
';
html += '
粮低温
';
html += '
';
}
$("#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
}
})
}
});