YYC
2023-06-19 0b27b9263ce721844d124ec4541a83b0f6db6c13
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
var url = null;
var pestData;
var data = {
    "interfaceId": "5306",
    "sign": "10306",
    "outId": "10306",
    "reqDateTime": new Date(),
    "tokenAuth": "",
    "data": {
        "deptId": ""
    }
};
//虫害采集参数
var data0 = {
    "interfaceId": "5307",
    "sign": "10307",
    "outId": "10307",
    "reqDateTime": new Date(),
    "tokenAuth": "",
    "data": {
        "deptId": "",
        "depotId": ""
    }
};
 
//初始化数据
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;
 
    getPestData();
}
 
//获取仓库最新虫害采集信息
function getPestData() {
    //发送请求获取仓库信息
    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") {
                pestData = result.data;
                renderPest();
            } else {
                mui.alert(result.msg, '提示', ["确定"], function() {}, "div");
            }
        },
        error: function() {
            mui.alert('系统繁忙,请重新登录尝试!', '提示', ["确定"], function() {}, "div");
        }
    })
}
 
//渲染虫害数据
function renderPest() {
    var html = '';
    if (pestData != null && pestData.length > 0) {
        $.each(pestData, function(index, item) {
            html += '<li><div class="con"><div class="tit">';
            html += '仓库名称: <span>' + item.depotName + '</span>';
            html += '<a id="' + item.depotId + '" class="more">虫害采集</a></div>';
            html += '<div class="txt"><div class="box">';
            if (index % 2 == 0) {
                html += '<div class="group out">';
            } else {
                html += '<div class="group in">';
            }
            html += '<div class="desc">' + item.depotStatusName + '</div>';
            html += '<div class="ort">仓库状态</div></div></div>';
            html += '<div class="box">';
            if (item.pestNum == null) {
                html += '<div class="group no"><div class="desc">--</div>';
            } else if (item.pestNum > 0) {
                html += '<div class="group y"><div class="desc">有</div>';
            } else {
                html += '<div class="group no"><div class="desc">无</div>';
            }
            html += '<div class="ort">是否有虫</div></div>';
            html += '</div></div><div class="time">检测时间: ';
            html += (item.receiveDate == null ? '暂无检测记录' : item.receiveDate) + '</div></li>';
        })
    }
    $("#pestList").html(html);
}
 
//滑动
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 depotId = this.getAttribute("id");
    gatherPest(depotId);
});
 
//气体采集
function gatherPest(depotId) {
    data0.data.depotId = depotId;
    //发送获取粮情请求
    mui.ajax(url, {
        type: "POST",
        dataType: "json",
        crossDomain: true,
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(data0),
        success: function(data) {
            if (data.code == "0000") {
                mui.alert('采集命令发送成功,请等待10秒重新打开此页面查看采集数据!', '提示', ["确定"], function() {}, "div");
            } else {
                mui.alert(data.msg, '提示', ["确定"], function() {}, "div");
            }
        },
        error: function() {
            mui.alert('系统繁忙,请重试!', '提示', ["确定"], function() {}, "div");
        }
    })
}