areasite.js
22.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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
// 加载vue
require.config({
paths: {
"vue": "../js/vue",
}
});
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'vue'], function ($, undefined, Backend, Table, Form, Vue) {
var Controller = {
index: function () {
require(['jstree'], function () {
Table.api.init();
// 巡检点列表
var table1 = $("#table1");
table1.bootstrapTable({
toolbar: '#toolbar1',
url: "inspection/areasite/index",
extend: {
index_url: 'inspection/areasite/index',
add_url: 'inspection/areasite/add',
edit_url: 'inspection/areasite/edit',
del_url: 'inspection/areasite/del',
multi_url: 'inspection/areasite/multi',
table: 'inspection_areasite',
},
sortName: 'id',
pageSize:10,
search: false,
columns: [
[
{field: '',radio: true},
{field: 'id', title: __('Id'),operate:false},
{field: 'site_name', title: __('巡检点名称'),operate:'like'},
{field: 'verify', title: __('验证方式'),operate:false,formatter: Controller.api.formatter.verify},
{field: 'lnglat', title: __('经纬度'),operate:false},
{field: 'distance', title: __('有效距离(米)'),operate:false},
{field: 'createtime', title: __('添加时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table1, events: Table.api.events.operate,
buttons: [
{
name: 'qrcode',
title: __('二维码'),
text:'二维码',
classname: 'btn btn-xs btn-default btn-dialog qrcode',
icon: 'fa fa-file-text',
url:'inspection/areasite/qrcode',
extend:' data-area=["30%","64%"]',
click: function (e, data) {
alert(123)
}
}
// ,{
// name: 'item',
// title: __('检查项管理'),
// text:'检查项管理',
// classname: 'btn btn-xs btn-default btn-click',
// icon: 'fa fa-file-text',
// click: function (e, data) {
//
// }
// }
],
formatter: Table.api.formatter.operate}
]
]
});
// 为表格1绑定事件
Table.api.bindevent(table1);
//当表格数据加载完成时
table1.on('load-success.bs.table', function (e, data) {
//这里可以获取从服务端获取的JSON数据data
//设置添加和编辑弹出大小
$(".btn-add").data("area",["66%","77%"]);
$(".btn-edit").data("area",["66%","77%"]);
});
//列表中编辑按钮调整弹框大小
table1.on('post-body.bs.table',function(){
$(".btn-editone").data("area",["66%","77%"]);
})
// 表格2
var table2 = $("#table2");
table2.bootstrapTable({
url: "inspection/areaitem/index",
extend: {
index_url: 'inspection/areaitem/index',
add_url: 'inspection/areaitem/add',
edit_url: 'inspection/areaitem/edit',
del_url: 'inspection/areaitem/del',
multi_url: 'inspection/areaitem/multi',
table: 'inspection_areaitem',
},
toolbar: '#toolbar2',
sortName: 'id',
pageSize:5,
search: false,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'item_name', title: __('检查项名称')},
{field: 'weigh', title: __('排序')},
{field: 'operate', title: __('Operate'), table: table2, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格2绑定事件
Table.api.bindevent(table2);
table1.on('click-row.bs.table', function (e, data) {
table2.bootstrapTable('refreshOptions',{url: "inspection/areaitem/index?areasite_id="+data.id,pageNumber:1, extend: {
index_url: 'inspection/areaitem/index?areasite_id='+data.id,
add_url: 'inspection/areaitem/add?areasite_id='+data.id,
edit_url: 'inspection/areaitem/edit',
del_url: 'inspection/areaitem/del',
multi_url: 'inspection/areaitem/multi',
table: 'inspection_areaitem',
},pageSize:5})
$("#toolbar2").find(".btn-add").removeClass("btn-disabled").removeClass("disabled");
});
$('#channeltree').on("changed.jstree", function (e, data) {
if(data.node){
node_id = data.node.id;
table1.bootstrapTable('refresh', {url: "inspection/areasite/index?area_id="+node_id,pageNumber:1});
table2.bootstrapTable('refreshOptions',{url: "inspection/areaitem/index?areasite_id="+data.id,pageNumber:1, extend: {
index_url: 'inspection/areaitem/index?areasite_id='+data.id,
add_url: 'inspection/areaitem/add?areasite_id='+data.id,
edit_url: 'inspection/areaitem/edit',
del_url: 'inspection/areaitem/del',
multi_url: 'inspection/areaitem/multi',
table: 'inspection_areaitem',
}})
$("#toolbar2").find(".btn-add").addClass("btn-disabled").addClass("disabled");
}
return false;
});
$('#channeltree').jstree({
"checkbox": {"keep_selected_style": false,},
"types": {
"total": {"icon": "fa fa-folder-o",},
"folder": {"icon": "fa fa-folder",},
"disabled": {"check_node": false,"uncheck_node": false}
},
'plugins': ["types",'contextmenu'],
"core": {
"themes": {
"stripes": false,
"dots": false,//是否显示树连接线
"icons": true,//是否显示节点的图标
},
'check_callback': true,
'data':{
'url' : 'inspection/area/tree',
'data' : function (node) {
return { 'id' : node.id};
}
}
},
'contextmenu':{
'items' : {
'add':{
'label':'添加',
'action':function(obj){
//reference获取当前选中节点的引用
var inst = jQuery.jstree.reference(obj.reference);
//通过get_node方法获取节点的信息,类似于实例对象
var clickedNode = inst.get_node(obj.reference);
let title = '添加区域'
let reservoir_id = parseInt(clickedNode.original.reservoir_id);
Fast.api.open("inspection/area/add?pid=" + clickedNode.id + '&reservoir_id=' + reservoir_id, title, {
area:["50%", "50%"],
callback:function(value){
setTimeout(function () {
$('#channeltree').jstree(true).refresh(); // 刷新树
},500)
}
});
},
},
'edit':{
'label':'编辑',
'action':function(obj){
//reference获取当前选中节点的引用
var inst = jQuery.jstree.reference(obj.reference);
//通过get_node方法获取节点的信息,类似于实例对象
var clickedNode = inst.get_node(obj.reference);
if (clickedNode.id === '#' || !clickedNode.id || clickedNode.id< 0){
layer.msg('不能编辑全部');
return;
}
let title = '编辑区域'
Fast.api.open("inspection/area/edit?ids=" + clickedNode.id, title, {
area:["50%", "50%"],
callback:function(value){
setTimeout(function () {
$('#channeltree').jstree(true).refresh(); // 刷新树
},500)
}
});
},
},
'del':{
'label':'删除',
'action':function(obj){
//reference获取当前选中节点的引用
var inst = jQuery.jstree.reference(obj.reference);
//通过get_node方法获取节点的信息,类似于实例对象
var clickedNode = inst.get_node(obj.reference);
if (clickedNode.id === '#' || !clickedNode.id || clickedNode.id< 0){
layer.msg('不能删除全部');
return;
}
//弹出确认提示
layer.confirm(`确认删除区域【${clickedNode.text}】吗?`,{icon: 3, title:'提示'},function (index) {
Fast.api.ajax({
url:"inspection/area/del?ids=" + clickedNode.id,
data:{ids:clickedNode.id},
loading:false,
success:function (res) {
if (res.code === 1){
Toastr.success('删除成功')
}else{
Toastr.error(res.msg)
}
},
error:function (res) {
layer.msg('网络错误')
},
complete:function (res) {
setTimeout(function () {
$('#channeltree').jstree(true).refresh(); // 刷新树
},500)
}
})
layer.close(index); //关闭当前弹窗
})
},
},
'refresh':{
'label':'刷新',
'action':function(obj){
$('#channeltree').jstree(true).refresh(); // 刷新树
}
}
}
}
});
})
},
add: function () {
var vmAdd = new Vue({
el: '#item-vue',
data: {
formData:{
item_name:'',
type:1,
weigh:'0',
},
cItemJson:'',//当前检查项表单json值
cItemList:[],//当前的检查项列表
},
created() {},
methods: {
//添加检查项
addItem:function () {
if (!this.formData.item_name){
layer.msg('请填写名称');
return;
}
if (!this.formData.weigh){
layer.msg('请填写排序值');
return;
}
// 检查是否重名
for (let i=0; i<this.cItemList.length; i++){
if (this.cItemList[i].item_name === this.formData.item_name){
layer.msg('检查项:' + this.formData.item_name + ' 已存在')
return;
}
}
this.cItemList.push({...this.formData});
// 根据排序值从小到大排序
this.cItemList.sort((a,b) => a.weigh - b.weigh);
// 更新cItemJson
this.cItemJson = JSON.stringify(this.cItemList);
},
//删除检查项
delItem:function (obj) {
let index = this.cItemList.findIndex(item => item.item_name === obj.item_name);
if (index > -1) {
this.cItemList.splice(index, 1); // 删除找到的对象
}
// 更新cItemJson
this.cItemJson = JSON.stringify(this.cItemList);
}
}
})
var timer;
$("input[type='radio']").on("click",function () {
if($("input[name='row[verify]']:checked").val()=="1"){
$(".lnglat").show()
timer = setInterval(function () {
$.ajax({
url:'inspection/areasite/getLnglat',
data:{id:0,distance:$("#c-distance").val()},
success:function (response) {
if(response.code){
// if(response.data.lng && response.data.lat){
// $("#c-lnglat").val(response.data.lng+","+response.data.lat);
// }
}
}
})
},2000)
}else{
$(".lnglat").hide()
clearInterval(timer)
}
})
$(".btn-getlnglat").click(function () {
Fast.api.open("inspection/areasite/ercode?id=0", __('扫码获取精确定位'), {
area:["250px","300px"],
callback:function (data) {
$("#c-audio_id").val(data.MediaId);
$("#c-audio_title").val(data.AudioTitle);
}
});
})
Controller.api.bindevent();
},
edit: function () {
var vmEdit = new Vue({
el: '#item-vue',
data: {
formData:{
item_name:'',
type:1,
weigh:'0',
},
cItemJson:'',//当前检查项表单json值
cItemList:Config.itemsForVue ? Config.itemsForVue : [],//当前的检查项列表
},
created() {
// 更新cItemJson
this.cItemJson = JSON.stringify(this.cItemList);
},
methods: {
//添加检查项
addItem:function () {
if (!this.formData.item_name){
layer.msg('请填写名称');
return;
}
if (!this.formData.weigh){
layer.msg('请填写排序值');
return;
}
// 检查是否重名
for (let i=0; i<this.cItemList.length; i++){
if (this.cItemList[i].item_name === this.formData.item_name){
layer.msg('检查项:' + this.formData.item_name + ' 已存在')
return;
}
}
this.cItemList.push({...this.formData});
// 根据排序值从小到大排序
this.cItemList.sort((a,b) => a.weigh - b.weigh);
// 更新cItemJson
this.cItemJson = JSON.stringify(this.cItemList);
},
//删除检查项
delItem:function (obj) {
let index = this.cItemList.findIndex(item => item.item_name === obj.item_name);
if (index > -1) {
this.cItemList.splice(index, 1); // 删除找到的对象
}
// 更新cItemJson
this.cItemJson = JSON.stringify(this.cItemList);
}
}
})
var timer;
$("input[type='radio']").on("click",function () {
if($("input[name='row[verify]']:checked").val()=="1"){
$(".lnglat").show()
timer = setInterval(function () {
$.ajax({
url:'inspection/areasite/getLnglat',
data:{id:$("#c-id").val(),distance:$("#c-distance").val()},
success:function (response) {
if(response.code){
// if(response.data.lng && response.data.lat){
// $("#c-lnglat").val(response.data.lng+","+response.data.lat);
// }
}
}
})
},2000)
}else{
$(".lnglat").hide()
clearInterval(timer)
}
})
if($("input[name='row[verify]']:checked").val()=="1"){
timer = setInterval(function () {
$.ajax({
url:'inspection/areasite/getLnglat',
data:{id:$("#c-id").val(),distance:$("#c-distance").val()},
success:function (response) {
if(response.code){
// if(response.data.lng && response.data.lat){
// $("#c-lnglat").val(response.data.lng+","+response.data.lat);
// }
}
}
})
},2000)
}
$(".btn-getlnglat").click(function () {
Fast.api.open("inspection/areasite/ercode?id="+$("#c-id").val(), __('扫码获取精确定位'), {
area:["250px","300px"],
callback:function (data) {
$("#c-audio_id").val(data.MediaId);
$("#c-audio_title").val(data.AudioTitle);
}
});
})
Controller.api.bindevent();
},
api: {
formatter:{
verify: function (value, row, index) {
switch (value) {
case 0:
return "不验证";
case 1:
return "定位";
}
},
},
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});