perfectInfo.html
11.5 KB
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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>完善设备信息_frm</title>
<link rel="stylesheet" type="text/css" href="../../css/api.css" />
<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
<link rel="stylesheet" type="text/css" href="../../css/utils/addDevice.css" />
<link rel="stylesheet" type="text/css" href="../../css/style.css" />
<style>
html,
body{
background-color: #F4F6F9;
}
</style>
</head>
<body>
<div class="device-title">
<div style="margin-left:15px;margin-right:15.5px;">
<div class="aui-row aui-row-flex top-14">
<div class="aui-col aui-col-span-1" style="margin-top: 1rem;">
<div class="title-sign"></div>
</div>
<div class="aui-col aui-col-span-23">
<span class="device-name" id="device_imei">设备编号:000000000000000</span>
</div>
</div>
</div>
</div>
<div class="info-panel">
<div class="info-inside-panel">
<div class="aui-row aui-row-flex padding-top-21">
<div class="aui-col aui-col-span-9 aui-row-flex-start">
<span class="measure-obj">设备名称</span>
</div>
<div class="aui-col aui-col-span-15 aui-row-flex-end">
<input id="device_name" class="aui-input" placeholder="设备名不可超过12个字符" type="text" maxlength="12" style="height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
</div>
</div>
<div class="panel-line margin-top-21"></div>
<div class="check-hide aui-hide" id="input1">
<div class="aui-row aui-row-flex padding-top-21">
<div class="aui-col aui-col-span-9 aui-row-flex-start">
<span class="measure-obj">输入设备密码</span>
</div>
<div class="aui-col aui-col-span-15 aui-row-flex-end">
<input id="normal_pwd" class="aui-input" placeholder="请输入6位数字设备密码" type="tel" maxlength="6" style="-webkit-text-security:disc;height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
</div>
</div>
<div class="panel-line margin-top-21"></div>
</div>
<div class="check-hide aui-hide" id="input2">
<div class="aui-row aui-row-flex padding-top-21">
<div class="aui-col aui-col-span-9 aui-row-flex-start">
<span class="measure-obj">设置设备密码</span>
</div>
<div class="aui-col aui-col-span-15 aui-row-flex-end">
<input id="device_pwd" class="aui-input" placeholder="请设置6位数字设备密码" type="tel" maxlength="6" style="-webkit-text-security:disc;height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
</div>
</div>
<div class="panel-line margin-top-21"></div>
</div>
<div class="check-hide aui-hide" id="input3">
<div class="aui-row aui-row-flex padding-top-21">
<div class="aui-col aui-col-span-9 aui-row-flex-start">
<span class="measure-obj">确认设备密码</span>
</div>
<div class="aui-col aui-col-span-15 aui-row-flex-end">
<input id="pwd_check" class="aui-input" placeholder="请再次确认设备密码" type="tel" maxlength="6" style="-webkit-text-security:disc;height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
</div>
</div>
<div class="panel-line margin-top-21"></div>
</div>
<div class="aui-row aui-row-flex">
<div class="aui-col aui-col-span-8 aui-row-flex-start padding-top-21">
<span class="measure-obj">设备所在地址</span>
</div>
<!-- <div class="aui-col aui-col-span-3 aui-row-flex-end padding-top-21" tapmode onclick="chooseLocationType()">
</div> -->
<div class="aui-col aui-col-span-14 aui-row-flex-end padding-top-21" style="height:auto;vertical-align:middle;" tapmode onclick="chooseLocationType()">
<!-- <img src="../../image/icon-map-small.png" style="width:18px;height:18px;" /> -->
<span class="num-value" id="device_position">请添加设备所在位置</span>
</div>
<div class="aui-col aui-col-span-2 aui-row-flex-end padding-top-21" tapmode onclick="chooseLocationType()">
<i class="aui-iconfont aui-icon-right" style="color:#5B7FF8;font-size:16px;margin-top:-0.1rem;"></i>
</div>
</div>
<div class="panel-line margin-top-21"></div>
<div class="aui-row aui-row-flex padding-top-21">
<div class="aui-col aui-col-span-7 aui-row-flex-start">
<span class="measure-obj">完善详细地址</span>
</div>
<div class="aui-col aui-col-span-17 aui-row-flex-end">
<input id="detail_address" class="aui-input" placeholder="请输入详细地址" type="text" maxlength="15" style="height:1.26rem;text-align:right;font-weight:500;color:rgba(91,127,248,1);font-size:14px;" >
</div>
</div>
<div class="panel-line margin-top-21"></div>
</div>
</div>
<div class="confirm-btn" tapmode onclick="handleAddDevice();">确认</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
var userId;
var token;
var username;
var addImei;
var isFirstAdd;
var province;
var city;
var address;
var bmap;
apiready = function() {
api.parseTapmode();
var params = api.pageParam;
token = $api.getStorage('userToken');
username = $api.getStorage('userName');
userId = $api.getStorage('userID');
addImei = params.code;
bmap = api.require('bMap');
$api.html($api.byId('device_imei'), '设备编号:'+params.code);
api.addEventListener({
name: 'changeDeviceLocation'
}, function(ret, err){
if( ret ){
if (ret.value.info) {
$api.html($api.byId('device_position'), ret.value.info.address);
bindDeviceInfo(ret.value.info);
}
}
});
checkIsFirstAdd();
}
function bindDeviceInfo(param) {
bmap.getNameFromCoords({
lon: param.lon,
lat: param.lat
}, function(ret, err) {
if (ret.status) {
province = ret.province;
city = ret.city;
address = param.address;
}
});
}
function chooseLocationType() {
api.openWin({
name: 'map_win',
url: './map_win.html',
slidBackEnabled: false,
});
}
function checkIsFirstAdd() {
api.ajax({
url: HOST + '/iot_api/v1/app/get_store_bind_user_count?imei='+ addImei,
method: 'GET',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'token': token
},
}, function(ret, err) {
var dom1 = $api.byId('input1');
var dom2 = $api.byId('input2');
var dom3 = $api.byId('input3');
if (ret.data > 0) {
isFirstAdd = false;
$api.removeCls(dom1, 'aui-hide');
$api.addCls(dom2, 'aui-hide');
$api.addCls(dom3, 'aui-hide');
}else {
isFirstAdd = true;
$api.addCls(dom1, 'aui-hide');
$api.removeCls(dom2, 'aui-hide');
$api.removeCls(dom3, 'aui-hide');
}
});
}
function handleAddDevice() {
var device_name = $api.val($api.byId("device_name"));
if (device_name == '') {
api.toast({ msg: "设备名称不可为空"});
}
var password;
if (isFirstAdd) {
var setInput = $api.val($api.byId('device_pwd'));
var checkInput = $api.val($api.byId('pwd_check'));
if (setInput == '') {
api.toast({ msg: "设置密码不可为空"});
return;
}
if (checkInput == '' || setInput != checkInput) {
api.toast({ msg: "两次密码不一致"});
return;
}
password = setInput;
}else {
var normalInput = $api.val($api.byId('normal_pwd'));
if (normalInput == '') {
api.toast({ msg: "密码不可为空"});
return;
}
password = normalInput;
}
var mapAddress_ = $api.html($api.byId('device_position'));
if (mapAddress_ == '请添加设备所在位置') {
api.toast({ msg: "请进行初始化定位该设备"});
return;
}
var inputAddress_ = $api.val($api.byId('detail_address'));
if (inputAddress_ == '') {
api.toast({ msg: "请输入详细地址"});
return;
}
var allAddress = mapAddress_ + '--' + inputAddress_;
//开始绑定
api.showProgress({
style: 'default',
animationType: 'fade',
title: '正在绑定中...',
text: '',
modal: true
});
api.ajax({
url: HOST + '/iot_api/v1/app/bind_device',
method: 'post',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'token': token
},
data: {
body: {
qrstr: addImei,
user_id: userId,
username: username,
province: province,
city: city,
address: allAddress,
password: password,
first_add: isFirstAdd,
store_name: device_name
}
}
}, function(ret, err) {
api.hideProgress();
if (ret.code == 0) {
var devices = $api.getStorage('devices');
//添加新设备同步推送
var ajpush = api.require('ajpush');
initAndListenPush(ajpush, false);
api.sendEvent({
name: 'change_device'
});
api.sendEvent({
name: 'change_device_device_list'
});
// setTimeout(function() {
// console.log(JSON.stringify(devices));
// console.log(devices.length);
// console.log(ret.data);
// if (devices.length == 0) {//将添加的设备置成默认设备
// api.ajax({
// url: HOST + '/iot_api/v1/app/set_device_default',
// method: 'post',
// headers: {
// 'Content-Type': 'application/json;charset=utf-8',
// 'token': token
// },
// data: {
// body: {
// id: ret.data
// }
// }
// }, function(ret, err) {
// console.log(JSON.stringify(ret));
// if (ret.code == 0) {
// $api.setStorage('defaultDevice', addImei);
// api.toast({msg: '设备操作成功!',duration: 2000,location: 'bottom'});
// }
// });
// }
// }, 2000);
alert("绑定成功!");
api.sendEvent({
name: 'closeAddDevicePage',
extra: {
isAdd: true,
}
});
}else {
api.toast({
msg: "绑定失败," + ajaxCodeCheck(ret.code, ret.msg, '请重试!')
});
}
});
// api.hideProgress();
//----------
}
</script>
</html>