groupManage_win.html
11.6 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
<!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">
<meta name="referrer" content="no-referrer">
<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: #F4F6F9;
height: 100%;
}
</style>
</head>
<body>
<div id="app">
<template>
<header class="aui-header-bar alarm-title" >
<div class="aui-header-left" tapmode onclick="closeWin();">
<i class="aui-iconfont aui-icon-left" style="color:#FFFFFF;font-size:16px;">返回</i>
</div>
<div class="aui-title title-font">分组管理</div>
<div class="aui-header-right" tapmode @click="handleGroup();">
<div style="color: #FFFFFF;">{{ editTitle }}</div>
</div>
</header>
<div style="background:linear-gradient(90deg,rgba(91,127,248,1) 0%,rgba(75,175,239,1) 100%);height:50%;width:auto;"></div>
<div v-if="groupList.length > 0" class="group-panel" v-for="(list_d, list_i) in groupList">
<div class="group-list-panel" tapmode @click= "chooseGroup(list_d, list_i)">
<el-row>
<el-col :span=spanImg>
<img src="../../image/alarm/icon-unselected.png" class="group-choose-area" :id="'select_'+ list_i" style="width:18px;height:18px;margin-top:1.3rem;margin-left:15px;" />
</el-col>
<el-col :span=spanV>
<div class="group-list-inside-panel">
<el-row style="padding-bottom: 14px;">
<el-col :span=23>
<p>{{ list_d.group_name }}</p>
<span class="group-list-panel-subtitle">{{ list_d.total }}个设备</span>
</el-col>
<el-col :span=1 style="margin-top: 0.5rem;">
<i v-if="!editVisable" class="aui-iconfont aui-icon-right" ></i>
</el-col>
</el-row>
</div>
</el-col>
</el-row>
</div>
</div>
<div v-if="!editVisable" class="group-panel group-manage-btn" tapmode @click="addGroup()">添加分组</div>
</template>
</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" src="../../script/fastclick.js "></script>
<script type="text/javascript">
var vm,that;
apiready = function(){
api.parseTapmode();
$(function() {
FastClick.attach(document.body);
});
//---------初始化vue
vm = new Vue({
el: '#app',
data: {
groupList: [],
userId: api.getPrefs({sync: true,key: 'userID'}),
editVisable: false,
editTitle: '编辑',
spanImg: 0,
spanV: 24,
choosedGroups: [],
},
mounted() {
//window.chooseProduct = this.chooseProduct;
},
created() {
that = this
api.addEventListener({
name: 'groupSelectAll'
}, function(ret, err){
that.choosedGroups = []
//group-choose-area
var chooseDoms = $api.domAll('.group-choose-area');
if (ret.value.chooseAll) {
for (var j = 0; j < chooseDoms.length; j++) {
chooseDoms[j].src = '../../image/alarm/icon-selected.png';
}
that.groupList.forEach(d => {
that.choosedGroups.push(d.id)
});
}else {
for (var j = 0; j < chooseDoms.length; j++) {
chooseDoms[j].src = '../../image/alarm/icon-unselected.png';
}
}
});
api.addEventListener({
name: 'group_bach_del'
}, function(ret, err){
that.batchRemove()
});
api.addEventListener({
name: 'init_group_list2'
}, function(ret, err){
that.initUserGroups()
});
this.initUserGroups()
},
methods: {
async initUserGroups() {
let dataRes = await get_user_groups(this.userId)
this.groupList = dataRes.data.List
api.sendEvent({
name: 'init_group_list',
});
},
handleGroup() {
if (this.editTitle === '编辑') {
this.editVisable = true
this.editTitle = '取消'
this.spanImg = 2
this.spanV = 22
//打开底部操作栏
api.openFrame({
name: 'group_tool',
url: './group_footer.html',
rect: {
x: 0,
y: api.winHeight - 60,
w: api.winWidth,
h: 65
},
pageParam: {
from: 'groupManage_win'
}
});
}else {
this.editTitle = '编辑'
this.editVisable = false
this.spanImg = 0
this.spanV = 24
api.closeFrame({
name: 'group_tool'
});
var chooseDoms = $api.domAll('.group-choose-area');
for (var j = 0; j < chooseDoms.length; j++) {
chooseDoms[j].src = '../../image/alarm/icon-unselected.png';
}
this.choosedGroups = []
}
},
async addGroup() {
let text_ = parseTime(new Date(),'{y}-{m}-{d}')
api.prompt({
title: '新建分组',
text: text_,
buttons: ['取消', '创建']
},async function(ret, err) {
var index = ret.buttonIndex;
var text = ret.text;
if (index == 2) {
if (text.length <= 15 && text != '') {
that.groupList.forEach(d => {
if (d.group_name === text) {
api.toast({msg: '当前组名已存在!'});
return;
}
});
let params = {
user_id: that.userId,
group_name: text
}
let result = await post_create_user_groups(params)
if (result && result.message === '成功') {
api.toast({msg: '创建成功!'});
}
that.initUserGroups()
}else if (text == '') {
api.toast({msg: '设备名称不可为空'});
}else if (text.length > 15) {
api.toast({msg: '设备名称最多15个字符!'});
}
}
});
},
chooseGroup(row, i) {
if (this.editVisable) {//编辑状态
let imgPath = $api.byId('select_' + i).src
if (imgPath.indexOf("unselected") != -1) { //点击前是未选择状态(点击选择)
$api.byId('select_' + i).src = '../../image/alarm/icon-selected.png'
//handle...
this.choosedGroups.push(row.id)
}else {
$api.byId('select_' + i).src = '../../image/alarm/icon-unselected.png'
//handle...
let index = this.choosedGroups.indexOf(row.id);
this.choosedGroups.splice(index,1)
}
}else {
api.openWin({
name: 'groupDetail',
url: './groupDetail.html',
bounces: false,
pageParam: {row : row}
});
}
},
batchRemove() {
var dialogBox = api.require('dialogBox');
dialogBox.alert({
texts: {
title: '',
content: '确定删除已选择的分组吗?',
leftBtnTitle: '取消',
rightBtnTitle: '确定'
},
styles: {
bg: '#fff',
w: 300,
corner:2,
title: {
marginT: 20,
icon: '../../image/mine/img-signOut.png',
iconSize: 74,
titleSize: 14,
titleColor: '#000'
},
content: {
color: '#37394E',
size: 14
},
left: {
marginB: 0,
marginL: 0,
w: 150,
h: 47,
corner: 10,
bg: '#FFFFFF',
color: '#818295',
size: 16
},
right: {
marginB: 0,
marginL: 0,
w: 150,
h: 47,
corner: 10,
bg: '#FFFFFF',
color: '#5B7FF8',
size: 16
},
horizontalLine:{
color:'rgba(240,245,255,1)',
height:1
},
verticalLine:{
color:'rgba(240,245,255,1)',
width:1 //(可选项)数字类型;左右边按钮竖线的高度;默认:0
}
}
},async function(ret) {
dialogBox.close({
dialogName: 'alert'
});
if (ret.eventType == 'right') {
let params = {
ids: that.choosedGroups
}
let delRes = await post_del_groups(params)
if (delRes.code === 200) {
api.toast({msg: '删除成功!',duration: 2000,location: 'bottom'});
}else {
api.toast({msg: '删除失败!',duration: 2000,location: 'bottom'});
}
that.initUserGroups()
}
});
}
}
})
};
</script>
</html>