陈战涛
2023-03-14 c29ed2aa867b00eccfdc7c3a68f431008b13ea7d
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>门禁控制</title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link href="./css/mui.min.css" rel="stylesheet" />
 
        <style>
            .mui-bar-nav {
                background: #245ca7;
                -webkit-box-shadow: none;
                box-shadow: none;
            }
 
            .mui-title {
                color: #FFFFFF;
            }
 
            .mui-icon-back:before,
            .mui-icon-left-nav:before {
                color: #FFFFFF;
            }
 
            .mui-grid-view.mui-grid-9 .mui-media .mui-icon {
                font-size: 2.4em;
                position: relative;
                border-radius: 50px;
                padding: 12px;
            }
 
            .mui-grid-view.mui-grid-9 .mui-media {
                background: #ddd;
                height: 130px;
                width: 33.3333%;
            }
 
            .mui-grid-view.mui-grid-9 {
                padding: 5px 5px;
                border-top: none;
                border-left: none;
            }
 
            .mui-table-view.mui-grid-view .mui-table-view-cell .mui-media-body {
                color: #0062cc;
                margin-top: unset;
            }
 
            .img_ico {
                width: 70px;
                height: auto;
                display: block;
                margin: auto;
                margin-top: 10px;
            }
 
            .title {
                background-color: #FFFFFF;
                display: block;
                padding: 0 15px;
                box-sizing: border-box;
                color: #333;
                height: 40px;
                line-height: 40px;
            }
 
            /*操作弹出窗*/
            .mark_one {
                background: rgba(0, 0, 0, .8);
                position: fixed;
                left: 0px;
                top: 0px;
                right: 0px;
                bottom: 0px;
                z-index: 10000;
                display: flex;
            }
 
            .mark_one_layer {
                background: #fff;
                width: 85%;
                margin: auto;
                border-radius: 5px;
            }
 
            .mark_one_layer .title {
                background: #245ca7;
                line-height: 40px;
                padding: 0 15px;
                box-sizing: border-box;
                color: #fff;
                border-radius: 5px 5px 0 0;
            }
 
            .mark_one_layer .title a {
                line-height: 40px;
                font-size: 2.5rem;
                float: right;
            }
 
            .mark_one_layer .btn {
                display: block;
                font-size: 1.5rem;
                text-align: center;
            }
 
            .mark_one_layer .btn button {
                color: #fff;
                border-radius: 5px;
                line-height: 35px;
                font-size: 16px;
                margin: 10px 10px;
            }
 
            .mark_one_btn1 {
                background: #2f64ab;
                width: 40%;
            }
 
            .mark_one_btn2 {
                background: #e4606d;
                width: 40%;
            }
 
            a {
                text-decoration: none;
                color: #f7f7f7;
            }
        </style>
    </head>
    <body>
        <header class="mui-bar mui-bar-nav">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title"><span id="depotName"></span>门禁设备</h1>
        </header>
        <div class="mui-content">
            <div id="deviceList1">
                <!-- <div class="title"><strong>仓库正面</strong></div>
                <ul class="mui-table-view mui-grid-view mui-grid-9">
                    <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
                        <a href="javascript:void(0)" onclick="openDialog(1)">
                            <div class="mui-media-body">##1</div>
                            <img class="img_ico" src="./images/device-status/lock.png">
                        </a>
                    </li>
                </ul> -->
            </div>
            <div id="deviceList2">
                <!-- <div class="title"><strong>仓库背面</strong></div>
                <ul class="mui-table-view mui-grid-view mui-grid-9">
                    <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
                        <a href="javascript:void(0)" onclick="openDialog(1)">
                            <div class="mui-media-body">##1</div>
                            <img class="img_ico" src="./images/device-status/lock_open.png">
 
                        </a>
                    </li>
                </ul> -->
            </div>
 
            <!--弹窗-->
            <div class="mark_one" id="openOne" style="display: none;">
                <div class="mark_one_layer">
                    <div class="title">
                        <span style="font-size: 16px;" id="markName1">设备操作</span>
                        <a onclick="closeDialog()" class="close">&times;</a>
                    </div>
                    <div class="btn">
                        <button class="mark_one_btn1 mb-3" onclick="toExecute('OPEN')">
                            开门
                        </button>
                        <button class="mark_one_btn2 mb-3" onclick="toExecute('CLOSE')">
                            关门
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <script src="./js/mui.js"></script>
        <script src="./js/jquery.min.js"></script>
        <script src="./js/echarts.min.js"></script>
 
        <script type="text/javascript" charset="utf-8">
            var url; //接口路径
            var deviceList; //设备集合
            var indexTag = null; //设备操作时的标记
            //获取仓库下的门禁设备请求参数
            var data1 = {
                "interfaceId": "5402",
                "sign": "10402",
                "outId": "10402",
                "reqDateTime": new Date(),
                "tokenAuth": "",
                "data": {
                    "depotId": "",
                    "type": "0E" //门禁
                }
            };
            //控制设备参数
            var data2 = {
                "interfaceId": "5405",
                "sign": "10405",
                "outId": "",
                "reqDateTime": new Date(),
                "tokenAuth": "",
                "data1": []
            };
            mui.init()
            mui.plusReady(function() {
                //获取参数
                var curr = plus.webview.currentWebview();
                var user = JSON.parse(localStorage.getItem('user'));
                $("#depotName").html(curr.depotName);
                //参数赋值
                data1.tokenAuth = user.tokenAuth;
                data1.data.depotId = curr.depotId;
                //设置门禁权限码
                data2.outId = curr.doorToken;
                
                data2.tokenAuth = user.tokenAuth;
                url = user.url + "/api-phone/gateway";
                getDeviceList();
            })
 
            //获取仓库信息
            function getDeviceList() {
                //发送请求获取仓库信息
                mui.ajax(url, {
                    type: "POST",
                    dataType: "json",
                    crossDomain: true,
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data1),
                    success: function(result) {
                        if (result.code == "0000") {
                            deviceList = result.data;
                            if (deviceList != null && deviceList.length > 0) {
                                renderDeviceList();
                            } else {
                                mui.alert('暂无设备!', '提示',["确定"],function(){},"div");
                            }
                        } else {
                            mui.alert('无相关设备信息!', '提示',["确定"],function(){},"div");
                        }
                    },
                    error: function() {
                        mui.alert('系统繁忙,请重试!', '提示',["确定"],function(){},"div");
                    }
                })
            }
 
            //渲染
            function renderDeviceList() {
                //标记仓库正反面的设备数
                var count1 = 0;
                var count2 = 0;
 
                var html1 = '';
                var html2 = '';
                html1 += '<div class="title"><strong>仓库正面</strong></div><ul class="mui-table-view mui-grid-view mui-grid-9">';
                html2 += '<div class="title"><strong>仓库背面</strong></div><ul class="mui-table-view mui-grid-view mui-grid-9">';
                var img_url;
                $.each(deviceList, function(index, item) {
                    img_url = '';
                    //设置设备图片路径
                    if (item.type == "0E") {
                        if (item.status == "OPEN") {
                            img_url = './images/device-status/lock_open.png';
                        } else {
                            img_url = './images/device-status/lock.png';
                        }
                    }
 
                    //仓库正面
                    if (item.location == '01') {
                        html1 += '<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3"><a href="javascript:void(0)" ' +
                            'onclick="openDialog(\'' + index + '\')">';
                        html1 += '<div class="mui-media-body">' + item.name + '</div><img class="img_ico" ';
                        html1 += 'src="' + img_url + '">';
                        html1 += '</a></li>';
                        count1++;
                    }
                    //仓库背面
                    if (item.location == '02') {
                        html2 += '<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3"><a href="javascript:void(0)" ' +
                            'onclick="openDialog(\'' + index + '\')">';
                        html2 += '<div class="mui-media-body">' + item.name + '</div><img class="img_ico" ';
                        html2 += 'src="' + img_url + '">';
                        html2 += '</a></li>';
                        count2++;
                    }
                })
                html1 += '</ul>';
                html2 += '</ul>';
                if (count1 > 0) {
                    $("#deviceList1").html(html1);
                } else {
                    $("#deviceList1").html("");
                }
                if (count2 > 0) {
                    $("#deviceList2").html(html2);
                } else {
                    $("#deviceList2").html("");
                }
            }
 
            //设备操作
            function toExecute(targetStatus) {
                if (indexTag != null && indexTag >= 0) {
                    var batchTag = false;
                    //判断是否是批量
                    if (targetStatus == 'W_OPEN_ALL') {
                        targetStatus = 'OPEN';
                        batchTag = true;
                    }
                    if (targetStatus == 'W_CLOSE_ALL') {
                        targetStatus = 'CLOSE';
                        batchTag = true;
                    }
                    //参数清空
                    data2.data1 = [];
                    if (batchTag) { //批量操作
                        $.each(deviceList, function(index, item) {
                            if (deviceList[indexTag].type == item.type) {
                                data2.data1.push({
                                    "id": item.id,
                                    "depotId": item.depotId,
                                    "passCode": item.passCode,
                                    "name": item.name,
                                    "serId": item.serId,
                                    "link": item.link,
                                    "type": item.type,
                                    "targetStatus": targetStatus
                                })
                            }
                        })
                    } else { //单设备操作
                        data2.data1.push({
                            "id": deviceList[indexTag].id,
                            "depotId": deviceList[indexTag].depotId,
                            "passCode": deviceList[indexTag].passCode,
                            "name": deviceList[indexTag].name,
                            "serId": deviceList[indexTag].serId,
                            "link": deviceList[indexTag].link,
                            "type": deviceList[indexTag].type,
                            "targetStatus": targetStatus
                        })
                    }
                    //发送操作请求
                    toControlDevice();
 
                    //关闭弹窗
                    closeDialog();
                }
            }
 
            //设备操作请求
            function toControlDevice() {
                mui.ajax(url, {
                    type: "POST",
                    dataType: "json",
                    crossDomain: true,
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data2),
                    success: function(result) {
                        if (result.code == "0000") {
                            mui.alert('操作命令发送成功,请等待30秒后重新打开此页面!', '提示',["确定"],function(){},"div");
                        } else {
                            mui.alert(result.msg, '提示',["确定"],function(){},"div");
                        }
                    },
                    error: function() {
                        mui.alert('系统繁忙,请重试!', '提示',["确定"],function(){},"div");
                    }
                })
            }
 
            //打开弹窗
            function openDialog(index) {
                indexTag = index;
                $("#markName1").html("设备操作 - " + deviceList[index].name);
                $('#openOne').css('display', 'flex');
            }
 
            //关闭弹窗
            function closeDialog() {
                indexTag = null;
                $("#openOne").css('display', 'none');
            }
        </script>
    </body>
</html>