rightMenu.js
18.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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/**
* 右键菜单
*/
var _menu = (function() {
$('#rightMenu .menu-item button').on('click', function(){
var method = $(this).data('method');
//被激活的行
var activeTrs = $('.pb-table tr._tr_active');
if(activeTrs.length == 0){
layer.alert('没有选择班次!', {icon: 2, title: '异常'});
return;
}
if($(this).data('multi') == 1){
//多选操作
var idArray = [];
$.each(activeTrs, function(){idArray.push($(this).data('id'))});
menuObject[method](idArray);
}
else{
//单选操作
var schedul = _data.getSchedulById(activeTrs.data('id'));
if(!schedul){
layer.alert('无法找到当前项对应的班次信息,请尝试刷新页面!', {icon: 2, title: '异常'});
return;
}
menuObject[method](schedul);
}
});
// 表格右键呼出菜单
var ac = 'active-menu'
,items = '.pb-table.data tr td[name!=lineNo][data-name!=lpName]';
$('.portlet-fullscreen').on('contextmenu', items,
function(e) {
e.preventDefault();
var item = $(this);
if(!$(this).parent().hasClass('active-line-no')){
resetAllState();
item.addClass(ac);
item.parent().addClass('_tr_active');
}
showMenu(e.pageX, e.pageY + 3);
$(document).one('click', function() {
$('#rightMenu').removeClass('show-menu');
//item.removeClass(ac);
});
})
// 点击选中
.on('click',items, function() {
resetAllState();
$(this).addClass(ac);
var $ctr = $(this).parent();
//选中关联班次
selCognateSch($ctr);
$ctr.removeClass('selected');
});
//点击序号
var nos = '.pb-table.data tr td[name=lineNo]', prveSelRow;
$('.portlet-fullscreen').on('click', nos, function(e){
var $tab = $(this).parents('table');
//当前表格是否存在选中项
var multiSel = $tab.find('tr._tr_active').length;
//按住了ctrl 或 shift
if((e.ctrlKey || e.shiftKey) && multiSel){
resetState();
//按住了shift 多选
if(e.shiftKey && prveSelRow){
var startNo = parseInt(prveSelRow.data('no'))
,endNo = parseInt($(this).parent().data('no'));
selectRange(startNo, endNo, $tab[0]);
}
}
else
resetAllState();
//选中一行
prveSelRow = selectOneRow(this);
});
function msg_ct(t){
layer.msg(t,{offset: 'ct', shift : 5});
}
//点击路牌
var lps = '.pb-table.data tr td[data-name=lpName]';
$('.portlet-fullscreen').on('click', lps, function(e){
var lp = $(this).text();
msg_ct('高亮路牌:' + lp);
var lineCode = $(this).parents('.tab-pane').data('id');
var schArray = _data.getLineLpMap()[lineCode][lp];
resetAllState();
$.each(schArray, function(){
$('.pb-table tr[data-id='+this.id+']').addClass('selected dir_' + this.xlDir);
});
});
function selectOneRow(firstCell){
return $(firstCell).addClass('selected').parent().addClass('_tr_active active-line-no');
}
//实发时间单元格事件
var layerTip;
$('.portlet-fullscreen').on('click', 'table.pb-table .sfsj-item', function(){
var id = $(this).parent().data('id');
var sch = _data.getSchedulById(id);
layerTip = layer.tips(template('sfsj_sch-detail-temp', sch), this, {
tips: [2, '#709d94'],shift:5, time: 5000
});
});
/*
$('.portlet-fullscreen').on('dbclick', 'table.pb-table .sfsj-item', function(){
alert(11);
});
*/
//选中关联班次
function selCognateSch($ctr){
//选中关联班次
var clnbbm = $ctr.find('td[data-name=clZbh]').text()
,schId = $ctr.data('id')
,sch = _data.getSchedulById(schId);
var scroll = false;
$.each(_data.findByCl(clnbbm), function(){
if(scroll){
var nextTr = $('tr[data-id='+this.id+']');
//不在同一个table才定位,避免滚动当前table,丢失焦点
if(sch.xlDir != this.xlDir){
//定位到下一个班次
var wrap = nextTr.parents('._body')
,top = parseInt(nextTr.find('td[name=lineNo]').text()) * 37 - wrap.height() / 2;
wrap.slimScroll({ scrollTo: top + 'px' });
}
scroll = false;
nextTr.addClass('next-sch');
$('.pb-table tr[data-id='+this.id+']').addClass('selected');
return false;
}
//$('.pb-table tr[data-id='+this.id+']').addClass('selected');
if(this.id == schId)
scroll = true;
});
}
//还原状态
function resetState(){
$('.pb-table tr td.' + ac).removeClass(ac);
$('.pb-table tr.selected').removeClass('selected');
$('.pb-table tr.next-sch').removeClass('next-sch');
$('.pb-table tr.dir_0').removeClass('dir_0');
$('.pb-table tr.dir_1').removeClass('dir_1');
if(layerTip){
layer.close(layerTip);
layerTip = null;
}
}
function resetAllState(){
$('.pb-table tr td.' + ac).removeClass(ac);
$('.pb-table tr.selected').removeClass('selected');
$('.pb-table tr.dir_0').removeClass('dir_0');
$('.pb-table tr.dir_1').removeClass('dir_1');
$('.pb-table tr._tr_active').removeClass('_tr_active active-line-no');
$('.pb-table tr.next-sch').removeClass('next-sch');
$('.pb-table.data tr td.selected[name=lineNo]').removeClass('selected');
prveSelRow = null;
if(layerTip){
layer.close(layerTip);
layerTip = null;
}
}
//根据起止行号选中多行
function selectRange(s , e, table){
var rows = table.rows;
if(s > e){
//交换位置
s = s + e;
e = s - e;
s = s - e;
}
var no;
$.each(rows, function(i, r){
no = parseInt($(r).data('no'));
if(no > s && no < e)
selectOneRow($(r).find('td[name=lineNo]')[0]);
if(no > e)
return false;
});
}
var menuObject = {
//待发调整
outgoAdjust: function(schedul){
var index = layer.open({
type: 1,
area: '630px',
maxmin: true,
content: template('outgo_adjust_body_temp', schedul),
shift: 5,
title: '待发调整',
success: function(){
dictionaryUtils.transformDom($('#outgoAdjustForm .nt-dictionary'));
//驾驶员
$.get('/realSchedule/driver', {lineCode: schedul.xlBm}, function(rs){
initPinYinSelect2('#outgoAdjustForm select[name=jsy]', rs, function(that){
//默认选中
that.val(schedul.jGh + '/' + schedul.jName).change();
});
});
//售票员
$.get('/realSchedule/conductor', {lineCode: schedul.xlBm}, function(rs){
initPinYinSelect2('#outgoAdjustForm select[name=spy]' , rs, function(that){
//默认选中
that.val(schedul.sGh + '/' + schedul.sName).change();
});
});
//车辆
$.get('/realSchedule/cars', {lineCode: schedul.xlBm}, function(rs){
$('#outgoAdjustForm select[name=clZbh]').select2({data: rs}).val(schedul.clZbh).change();
});
$('#outgoAdjustForm button.confirm').on('click', function(){
var check = customFormValidate('#outgoAdjustForm');
if(!check)return;
var params = $('#outgoAdjustForm').serializeJSON();
$post('/realSchedule/outgoAdjust', params, function(rs){
layer.close(index);
if(rs.t){
msg_ct('调整成功!');
_alone.refreshSchedule(rs.t);
}
});
});
}
});
},
//计划烂班
planDestroy: function(schedul){
if(schedul.status == -1){
layer.alert('没必要做重复烂班!', {icon: 2, title: '提示', shift: 5});
return;
}
var array = [];
//获取未烂班的班次
$.each(_data.getSchedulByVeh(schedul.clZbh),function(){
if(this.status != -1)
array.push(this);
});
var data = {item: schedul, array : array}
var index = layer.open({
type: 1,
area: ['370px', '645px'],
maxmin: true,
content: template('plan_destroy_body_temp', data),
shift: 5,
title: '计划烂班设置',
success: function(){
var f = $('#planDestroyForm');
//红色
$('.icheck', f).iCheck({
checkboxClass: 'icheckbox_square-red',
increaseArea: '20%'
});
//蓝色
$('.icheck-blue', f).iCheck({
checkboxClass: 'icheckbox_minimal-blue',
increaseArea: '20%'
});
$('[data-toggle="tooltip"]', f).tooltip();
//滚动到选中项
var cont = $('.custom-check-box', f)
,checked = $('.icheck:checked', f);
if(checked.length > 0){
cont.animate({
scrollTop: checked.offset().top - cont.offset().top + checked.scrollTop()
}, 500);
}
//确定
$('button.confirm', f).on('click', function(){
f.submit();
});
//调整说明
$('select[name=reason]', f).on('change', function(){
var t = $(this).val();
if(!t) return;
var textarea = $('textarea[name=remarks]', f);
textarea.val(textarea.val() + t + ',');
});
f.validate({
submitHandler : function(){
var params = f.serializeJSON()
,text = '确定烂掉部分班次['+schedul.clZbh+'] '
,idsStr = '';
$.each(params.ids, function(i, id){
var s = _data.getSchedulById(id);
text += (s.fcsj + ', ');
idsStr += (id + ',');
});
text = text.substr(0, text.length - 2);
if(params.spaceAdjust == 1){
text += '<br>并自动调整后续班次间隔 <span class="font-red">'+params.spaceNum+'</span>分钟'
}
layer.close(index);
//弹出确认框
index = layer.confirm(text, {
btn : [ '确定烂班' , '取消' ],
icon : 3,
shift: 5,
skin : 'layui-layer-cfm-delete'
}, function(){
params.idsStr = idsStr;
$post('/realSchedule/destroy', params, function(rs){
layer.close(index);
//刷新数据
_alone.refreshScheduleArray(rs.list);
msg_ct('计划烂班成功!');
});
});
return false;
}
});
}
});
},
//实发调整
realOutgoAdjust: function(schedul){
var index = layer.open({
type: 1,
area: ['350px', '455px'],
maxmin: true,
content: template('real_outgo_adjust_body_temp', schedul),
shift: 5,
title: '实发调整',
success: function(){
$('.confirm', '#realOutgoAdjust').on('click', function(){
var params = $('#realOutgoAdjust').serializeJSON();
if(!params.fcsjActual){
layer.msg('实发时刻不能为空');
return;
}
layer.close(index);
$post('/realSchedule/realOutAdjust', params
,function(rs){
if(rs.ts){
msg_ct('实发调整成功!');
//更新前端数据
_alone.refreshScheduleArray(rs.ts);
}
});
});
}
});
},
//撤销实发
revokeRealOutgo: function(schedul){
layer.confirm('确定要撤销实发?', {
btn : [ '撤销实发', '取消' ],
icon : 3,
shift :5,
}, function(){
$post('/realSchedule/revokeRealOutgo', {id: schedul.id}, function(rs){
console.log(rs);
if(rs.ts){
msg_ct('撤销实发成功!');
//更新前端数据
_alone.refreshScheduleArray(rs.ts);
}
});
});
},
//撤销烂班
revokeDestroy: function(schedul){
layer.confirm('确定要撤销烂班?', {
btn : [ '撤销烂班', '取消' ],
icon : 3,
shift :5,
}, function(){
$post('/realSchedule/revokeDestroy', {id: schedul.id}, function(rs){
if(rs.t){
msg_ct('撤销烂班成功!');
//更新前端数据
_alone.refreshSchedule(rs.t);
}
});
});
},
//间隔调整
spaceAdjust: function(idArray){
if(idArray && idArray.length == 1){
layer.msg('请选中多个班次!');
return;
}
layer.prompt({title: '请输入间隔(分钟)', formType: 0 , shift: 5
}, function(space){
if (!isNaN(space)) {
$.ajax({
url: '/realSchedule/spaceAdjust',
type: 'POST',
traditional: true,
data: {ids: idArray, space: space},
success:function(rs){
console.log(rs);
if(rs.status == 'SUCCESS'
|| rs.status == 200){
//刷新数据
_alone.refreshScheduleArray(rs.list);
msg_ct('调整间隔成功!');
}
},
error: errorHandle
});
} else
layer.alert('你必须输入一个数字!', {icon: 2, title: '操作失败'});
});
},
//子任务
childTask: function(schedul){
var layIndex = layer.msg('加载中...', {icon: 16});
$.get('/pages/control/line/child_pages/child_task.html', function(content){
layer.close(layIndex);
layer.open({
type: 1,
area: '930px',
maxmin: true,
content: content,
shift: 5,
title: '临加/子任务',
success: function(){
dictionaryUtils.transformDom($('#childTaskDiv .nt-dictionary'));
$('#childTaskDiv').trigger('init', {
selected: schedul,
_data: _data,
_alone: _alone
});
}
});
});
},
//调整人车
vehicAndPerAdjust: function(schedul){
$.get('/pages/control/line/child_pages/car_and_persion.html', function(content){
layer.open({
type: 1,
area: '730px',
maxmin: true,
content: content,
shift: 5,
title: '调整车辆/人员',
success: function(){
$('#vehicleAndPersionAdjustDiv').trigger('init', {
selected: schedul,
_data: _data,
_alone: _alone
});
}
});
});
},
//指令重发
directiveRepeat: function(schedul){
var text = '[路牌: '+schedul.lpName+' 计划时间:'+schedul.fcsj+' 待发时间:'+schedul.dfsj+']';
var index = layer.confirm(schedul.clZbh + '重发调度指令? ' + text, {
btn : [ '是' , '否' ],
icon : 3,
shift: 5
}, function(){
//走短语下发
layer.close(index);
layer.msg('正在下发指令', {icon: 16});
$.post('/directive/dispatch', {id: schedul.id},
function(code){
if(code == 0){
msg_ct('发送成功');
}
else if(code == -2){
layer.alert('该班次发车时间距离当前时间较远,系统阻止了该调度指令的下发。', {icon: 2, title: '被拦截的指令'});
}
else
layer.alert('发送调度指令失败', {icon: 2, title: '操作失败'});
});
});
},
//发车信息微调
schInfoFineTune: function(schedul){
var index = layer.open({
type: 1,
area: '680px',
maxmin: true,
content: template('schinfo_fine_tune_temp', schedul),
shift: 5,
title: '发车信息微调',
success: function(){
var ntds = $('#schinfoFineTune .nt-dictionary');
dictionaryUtils.transformDom(ntds);
//驾驶员
$.get('/realSchedule/driver', {lineCode: schedul.xlBm}, function(rs){
initPinYinSelect2('#schinfoFineTune select[name=jsy]', rs, function(that){
//默认选中
that.val(schedul.jGh + '/' + schedul.jName).change();
});
});
//售票员
$.get('/realSchedule/conductor', {lineCode: schedul.xlBm}, function(rs){
initPinYinSelect2('#schinfoFineTune select[name=spy]' , rs, function(that){
//默认选中
that.val(schedul.sGh + '/' + schedul.sName).change();
});
});
//车辆
$.get('/realSchedule/cars', {lineCode: schedul.xlBm}, function(rs){
$('#schinfoFineTune select[name=clZbh]').select2({data: rs}).val(schedul.clZbh).change();
});
//调整说明
$('#schinfoFineTune select[name=reason]').on('change', function(){
var t = $(this).val();
if(!t) return;
var textarea = $('#schinfoFineTune textarea[name=remarks]');
textarea.val(textarea.val() + t + ',');
});
//确定
$('#schinfoFineTune button.confirm').on('click', function(){
var params = $('form#schinfoFineTune').serializeJSON();
if(!customFormValidate('form#schinfoFineTune'))return;
$post('/realSchedule/schInfoFineTune', params, function(rs){
layer.close(index);
if(rs.ts)
_alone.refreshScheduleArray(rs.ts);
/*if(rs.nextSch)
_alone.refreshSchedule(rs.nextSch);*/
});
});
}
});
},
//基于车辆的待发调整
outgoAdjustAll: function(schedul){
$.get('/pages/control/line/child_pages/dfsj_batch.html', function(content){
layer.open({
type: 1,
area: '830px',
maxmin: true,
content: content,
shift: 5,
title: '待发调整(车辆)',
success: function(){
$('#outgoAdjustAllPanel').trigger('init', {
selected: schedul,
_data: _data,
_alone: _alone
});
}
});
});
}
}
function showMenu(x, y) {
var menu = $('#rightMenu'),
docWidth = $(document).width(), docHeight = $(document).height(),
menuHeight = menu.height(),
menuWidth = menu.width(),
offset = 12;
/* 边界 */
if (y > (docHeight - menuHeight)) {
y = docHeight - menuHeight - offset;
}
if (x > (docWidth - (menuWidth * 2))) {
x = docWidth - (menuWidth * 2) - offset;
}
menu.css('left', x + 'px')
.css('top', y + 'px')
.addClass('show-menu');
}
function errorHandle(){
layer.alert('服务器出现异常!', {icon: 2, title: '操作失败'});
}
/**
* 自定义表单校验
*/
function customFormValidate(f){
var rs = true;
//所有可见的项
var es = $('input,select', f);
for(var i = 0, e; e = es[i++];){
if($(e).attr('required') && ( $(e).val() == null || $(e).val() == '')){
if($(e).hasClass('select2-hidden-accessible'))
$(e).next().find('.select2-selection').addClass('custom-val-error');
else
$(e).addClass('custom-val-error');
rs = false;
}
else{
if($(e).hasClass('select2-hidden-accessible'))
$(e).next().find('.select2-selection').removeClass('custom-val-error');
else
$(e).removeClass('custom-val-error');
}
}
if(!rs){
layer.alert('数据完整性校验失败,请检查输入项', {icon: 2, title: '操作失败', shift: 5});
}
return rs;
}
return menuObject;
})();