perfectInfo_frm.html
11.3 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
<!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/home.css"/>
<link rel="stylesheet" type="text/css" href="../../css/element.css"/>
<link rel="stylesheet" type="text/css" href="../../css/style.css"/>
<style>
html,
body{
background-color: #F4F6F9;
}
</style>
</head>
<body>
<div id="app">
<div class="perfect-header-area">
<div class="perfect-header-area-inside">
<el-row>
<el-col :span=5>
<div style="border:1px solid rgba(174,184,206,1);">
<img :src="productInfos.pic_url" />
</div>
</el-col>
<el-col :span=18 :offset="1">
<div class="perfect-header-title">
<p class="hidden-font-one-line">设备类型: <span style="font-weight: bold;">{{ productInfos.name }} {{ productInfos.remark }}</span></p>
<p class="hidden-font-one-line">设备编号: <span style="font-weight: bold;">{{ imei }}</span></p>
</div>
</el-col>
</el-row>
</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 v-model="formData.storeName" id="device_name" class="aui-input" placeholder="设备名不可超过12个字符" type="text" maxlength="12" style="height:1.26rem;text-align:right;font-weight:500;color:rgba(174,184,206,1);font-size:14px;" >
</div>
</div>
<div class="panel-line margin-top-21"></div>
<div v-if="!formData.firstAdd">
<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" 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 v-if="formData.firstAdd">
<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 v-if="formData.firstAdd">
<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-14 aui-row-flex-end padding-top-21" style="height:auto;vertical-align:middle;" tapmode @click="chooseLocationType">
<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 @click="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 v-model="formData.address" 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 @click="handleAddDevice">确认</div>
</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/element.js"></script>
<script type="text/javascript" src="../../script/ctrl.js"></script>
<script type="text/javascript">
var vm,
selectedAddress;
var locationInfos = {
province: "",
city: "",
address: "",
}
apiready = function(){
api.parseTapmode();
var bmap = api.require('bMap');
api.addEventListener({
name: 'changeDeviceLocation'
}, function(ret, err){
if( ret ){
if (ret.value.info) {
$api.html($api.byId('device_position'), ret.value.info.address);
selectedAddress = ret.value.info
bindDeviceInfo();
}
}
});
//---------初始化vue
vm = new Vue({
el: '#app',
data: {
imei: api.pageParam.imei,
productInfos: api.pageParam.productInfos,
userId: api.getPrefs({sync: true,key: 'userID'}),
token: api.getPrefs({sync: true,key: 'userToken'}),
userName: api.getPrefs({sync: true,key: 'userName'}),
formData: {
password: "",
firstAdd: false,
storeName: "",
address: "", //详细地址
}
},
created() {
this.checkIsFirstAdd();
},
mounted() {
// window.bindDeviceInfo = this.bindDeviceInfo;
},
methods: {
async checkIsFirstAdd() {
let res_ = await get_check_is_first_add(this.imei, this.token)
if (res_ && res_.data > 0) {
this.formData.firstAdd = false
}else {
this.formData.firstAdd = true
}
},
chooseLocationType() {
api.openWin({
name: 'map_win',
url: './map_win.html',
slidBackEnabled: false,
});
},
async handleAddDevice() {
if (locationInfos.city != "") {
this.formData.province = locationInfos.province
this.formData.city = locationInfos.city
}else {
api.alert({
title: '提示',
msg: '请定位设备当前位置!'
});
return;
}
if (this.formData.storeName == "") {
api.toast({ msg: "设备名称不可为空"});
return;
}
if (this.formData.province == "") {
api.toast({ msg: "设备所在省份不可为空"});
return;
}
if (this.formData.city == "") {
api.toast({ msg: "设备所在城市不可为空"});
return;
}
if (this.formData.address == "") {
api.toast({ msg: "详细地址不可为空"});
return;
}
if (this.formData.firstAdd) {
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;
}
this.formData.password = setInput
}else {
var normalInput = $api.val($api.byId('normal_pwd'));
if (normalInput == '') {
api.toast({ msg: "密码不可为空"});
return;
}
this.formData.password = normalInput
}
var params = {
qrstr: this.imei,
user_id: this.userId,
username: this.userName,
province: this.formData.province,
city: this.formData.city,
address: selectedAddress.address + '--' + this.formData.address,
password: this.formData.password,
first_add: this.formData.firstAdd,
store_name: this.formData.storeName
}
console.log(JSON.stringify(params));
let bind_result = await post_user_bind_device(params, this.token)
console.log(JSON.stringify(bind_result));
if (bind_result.code === 0) {
//添加新设备同步推送
var ajpush = api.require('ajpush');
initAndListenPush(ajpush, false);
api.sendEvent({
name: 'change_device'
});//更新报警数量标记
alert("绑定成功!");
api.sendEvent({
name: 'closeAddDevicePage',
});
}else {
api.toast({
msg: "绑定失败," + ajaxCodeCheck(bind_result.code, bind_result.msg, '请重试!')
});
}
//接口!!
}
}
})
function bindDeviceInfo() {
bmap.getNameFromCoords({
lon: selectedAddress.extra_lon,
lat: selectedAddress.extra_lat
}, function(rett, err) {
if (rett.status) {
let info_ = {
"province": rett.province,
"city": rett.city,
"address": rett.address
}
locationInfos = info_
console.log(JSON.stringify(locationInfos));
}
});
}
};
</script>
</html>