perfectInfo.html
12.9 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
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
<!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>完善设备信息</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/style.css" />
</head>
<body class="perfect-info-view repair-view">
<div class="aui-content aui-margin-b-15">
<header class="aui-bar aui-bar-nav" id="header">
<a class="aui-btn aui-pull-left" tapmode onclick="cancelConfirm();">
<span class="aui-iconfont aui-icon-left"></span>
</a>
<div class="aui-title">完善设备信息</div>
<a class="aui-btn aui-pull-right" tapmode onclick="confirmEqu();">添加</a>
</header>
<p class="thing-small-title aui-margin-b-10" id="eqNum"><s></s>设备编号:</p>
<ul>
<li class="phone-input">
<label>姓名</label>
<input id="username" class="aui-pull-right" value="" type="text" />
</li>
<li class="deviceset-input" id="deviceset-input">
<label>设置密码</label>
<input id="setpwd" class="aui-pull-right" value="" type="password" maxlength="6" placeholder="请设置密码(最多六位)"/>
</li>
<li class="devicecheck-input" id="devicecheck-input">
<label>确认密码</label>
<input id="checkpwd" class="aui-pull-right" value="" type="password" maxlength="6" placeholder="请再次确认密码"/>
</li>
<li class="device-input" id="device-input">
<label>输入密码</label>
<input id="inputpwd" class="aui-pull-right" value="" type="password" maxlength="6" placeholder="请输入密码"/>
</li>
<li tapmode onclick="choseCity()">
<label>设备所在地址</label>
<span class="aui-pull-right" id="addr">所属城市</span>
<i></i>
</li>
<li>
<label>完善详细地址</label>
<input id="detail" type="text" placeholder="请填写详细地址" />
</li>
</ul>
</div>
</body>
</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/addr.js"></script>
<script type="text/javascript" src="../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
var header = $api.byId('header');
var code = "";
var qtstr = "";
var chose_pro = "";
var chose_city = "";
var fistadd = false;
fixStatusBar_API(header);
apiready = function() {
api.setStatusBarStyle({
style: 'dark',
color: 'rgba(0,0,0,0)'
});
api.parseTapmode();
var params = api.pageParam;
code = params.code;
qtstr = code;
var token = $api.getStorage('userToken');
$.ajax({
url: HOST + '/iot_api/v1/app/get_imei_by_qr?qrstr='+code,
type: 'GET',
dataType: 'json',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'token': token
},
success: function(ret) {
if (ret) {
if (ret.code == 0) {
code = ret.data;
$api.html($api.byId("eqNum"), "<s></s>设备编号:"+ code)
//获取设备绑定用户数量,判断该设备是否是首次添加,首次添加隐藏device-input,非首次隐藏deviceset-input devicecheck-input
$.ajax({
url: HOST + '/iot_api/v1/app/get_store_bind_user_count?imei='+ code,
type: 'GET',
dataType: 'json',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'token': token
},
success: function(ret) {
if (ret.data > 0) {
fistadd = false;
document.getElementById("deviceset-input").style.display = 'none';
document.getElementById("devicecheck-input").style.display = 'none';
} else {
fistadd = true;
document.getElementById("device-input").style.display = 'none';
}
},
error: function() {
api.toast({
msg: '服务器内部错误',
duration: 2000,
location: 'bottom'
});
setTimeout(function(){
openCanner(api.pageParam.isEmpty);
api.closeWin();
},2000);
}
});
}else{
api.toast({
msg: '设备编号不存在,请确认',
duration: 2000,
location: 'bottom'
});
setTimeout(function(){
api.closeWin();
openCanner(api.pageParam.isEmpty);
}, 2000);
}
}
},
error: function() {
api.toast({
msg: '获取设备编号失败,请重试',
duration: 2000,
location: 'bottom'
});
setTimeout(function(){
openCanner(api.pageParam.isEmpty);
api.closeWin();
},2000);
}
});
var username = $api.getStorage('userName');
$api.val($api.byId("username"), username);
// api.openWin({ slidBackEnabled:false,
// name: 'index',
// url: './html/index.html',
// pageParam: {}
// });
}
function choseCity() {
var UIActionSelector = api.require('UIActionSelector');
UIActionSelector.open({
datas: subjson,
layout: {
row: 5,
col: 3,
height: 30,
size: 12,
sizeActive: 14,
rowSpacing: 5,
colSpacing: 10,
maskBg: 'rgba(0,0,0,0.2)',
bg: '#fff',
color: '#888',
colorActive: '#f00',
colorSelected: '#f00'
},
animation: true,
cancel: {
text: '取消',
size: 12,
w: 90,
h: 35,
bg: '#fff',
bgActive: '#ccc',
color: '#888',
colorActive: '#fff'
},
ok: {
text: '确定',
size: 12,
w: 90,
h: 35,
bg: '#fff',
bgActive: '#ccc',
color: '#888',
colorActive: '#fff'
},
title: {
text: '选择所属城市',
size: 12,
h: 44,
bg: '#eee',
color: '#888'
},
fixedOn: api.frameName
}, function(ret, err) {
if (ret && ret['eventType'] == "ok") {
chose_pro = ret['level1'];
chose_city = ret['level2'];
$api.html($api.byId("addr"), ret['level1'] + " " + ret['level2']);
}
});
}
function cancelConfirm(){
if(api.pageParam.isEmpty){
openCanner(api.pageParam.isEmpty);
}else{
api.closeWin();
}
}
function login() {
api.openWin({ slidBackEnabled:false,
name: 'index',
url: 'index.html',
pageParam: {}
});
}
function confirmEqu(){
if(code==""){
api.toast({
msg: '添加设备失败,设备编号不存在',
duration: 3000,
location: 'bottom'
});
return false;
}
if(chose_pro=="" || chose_city==""){
api.toast({
msg: '添加设备失败,请选择设备地址',
duration: 3000,
location: 'bottom'
});
return false;
}
var detailAddr = $api.val($api.byId("detail"));
if(detailAddr==""){
api.toast({
msg: '添加设备失败,请填写详细地址',
duration: 3000,
location: 'bottom'
});
return false;
}
var setPwd = $api.val($api.byId("setpwd"));
var checkPwd = $api.val($api.byId("checkpwd"));
var inputPwd = $api.val($api.byId("inputpwd"));
if (setPwd != checkPwd) {
api.toast({ msg: "两次密码输入不一致"});
return false;
}
var password = '';
if (fistadd) {
if (setPwd == '') {
api.toast({ msg: "设置密码不可为空"});
return false;
}
password = setPwd
} else {
if (inputPwd == '') {
api.toast({ msg: "密码不可为空"});
return false;
}
password = inputPwd
}
api.showProgress({
style: 'default',
animationType: 'fade',
title: '正在绑定中...',
text: '',
modal: true
});
var token = $api.getStorage('userToken');
$.ajax({
url: HOST + '/iot_api/v1/app/bind_device',
type: 'POST',
dataType: 'json',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'token': token
},
data: JSON.stringify({
qrstr: qtstr,
user_id: $api.getStorage('userID'),
username: $api.getStorage('userName'),
province: chose_pro,
city: chose_city,
address:detailAddr,
password: password,
first_add: fistadd,
}),
complete: function() {
api.hideProgress();
},
success: function(ret) {
if (ret) {
if (ret.code == 0) {
api.toast({
msg: '绑定成功!',
duration: 4000,
location: 'bottom'
});
//添加新设备同步推送
var ajpush = api.require('ajpush');
initAndListenPush(ajpush, false);
setTimeout(function() {
api.openFrame({historyGestureEnabled :false,
reload: true,
name: 'root',
url: 'widget://html/index.html',
rect: {
x: 0,
y: 0,
w: 'auto',
h: 'auto'
}
});
api.sendEvent({
name: 'change_first'
});
api.sendEvent({
name: 'add_device'
});
var dest = $api.getStorage('defaultDevice');
api.sendEvent({
name: 'change_device',
extra: {
imei: dest?dest:code
}
});
api.closeWin({
name: 'scanner'
});
// api.closeWin({
// name: 'choseDevice'
// });
// api.closeWin({
// name: 'equipmentList'
// });
// api.closeWin({
// name: 'equipment'
// });
api.closeWin();
}, 3000);
} else {
api.toast({
msg: "绑定失败," + ajaxCodeCheck(ret.code, ret.msg, '请重试!')
});
}
}
},
error: function() {
api.toast({
msg: "绑定失败,请稍候再试"
});
}
});
}
</script>