alone.js
5.78 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
/**
* 单线路调度
*/
var _alone = (function(){
var upCode = 0
,downCode = 1;
var aloneObject = {
init: function(cb){
_data.queryRealSchedule(lineCodes, function(schList){
var schTempList;
for(var lineCode in lineMap){
schTempList = schList[lineCode];
tab = $('#tab_line_' + lineCode);
tab.append(template('alone_main_temp', lineMap[lineCode]));
//有排班数据
if(schTempList){
var rs = splitDir(schTempList);
//填充表格数据
calculateLineNo(
//上行
tab.find('table[data-type=up] tbody').html(template('alone_plan_table_temp', {list: rs.up}))[0]
);
calculateLineNo(
//下行
tab.find('table[data-type=down] tbody').html(template('alone_plan_table_temp', {list: rs.down}))[0]
);
//滚动条
tab.find('._body').slimscroll({
height: 'calc(100% - 80px)',
alwaysVisible: true
});
}
//svg
_data.queryStationRoute(lineCode , 'lineSvg' + lineCode , drawSvg.initAloneSvg);
}
//初始化备注弹层
initRemarksPop();
cb && cb();
});
},
//刷新单个班次
refreshSchedule: function(schedule, isBatch){
//更新 _data
_data.updateSchedule(schedule);
var tab = '#tab_line_' + schedule.xlBm;
//xlBm
var $tr = $('tr[data-id='+schedule.id+']', tab)
,newTr = template('alone_plan_table_temp', {list: [schedule]});
$tr.replaceWith(newTr);
initRemarksPop();
var type = schedule.xlDir==0?'up':'down';
calculateLineNo($('.pb-table[data-type='+type+']', tab)[0]);
if(!isBatch)
goToSch(schedule);
},
//刷新多个班次,刷新完数据再统一计算行号
refreshScheduleArray: function(array){
if(!array || array.length == 0)
return;
$.each(array, function(){
aloneObject.refreshSchedule(this, 1);
});
var table = $('tr[data-id='+array[0].id+']').parents('table')[0];
calculateLineNo(table);
initRemarksPop();
},
//将班次所在的表格做全量更新
updateTableBySch: function(schedule){
//将该线路走向班次 全部从服务器同步一次
var xlDir = schedule.xlDir, xlBm = schedule.xlBm;
$.get('/realSchedule/findByLineAndUpDown', {line: xlBm, upDown: xlDir}
,function(list){
$.each(list, function(){
_data.pushSchedule(this);
});
/*var upDown = xlDir==0?'up':'down';
var tab = $('#tab_line_' + xlBm);
//重新渲染表格
var table = tab.find('.pb-table[data-type='+upDown+']');*/
var table = getTableBySch(sch);
var schArray = _data.findSchByLine(xlBm, xlDir);
calculateLineNo(
table.find('tbody').html(template('alone_plan_table_temp', {list: schArray}))[0]
);
//定位到新添加的班次
goToSch(schedule);
/*var currTr = table.find('tr[data-id='+schedule.id+']')
,top = parseInt(currTr.find('td[name=lineNo]').text()) * 37 - half;
top = top>0?top:0;
currTr.addClass('anim-delay animated flash');
currTr.parents('._body').slimScroll({ scrollTo: top + 'px' });*/
});
},
update2Table: function(xlBm, schedule){
//上行
$.get('/realSchedule/lineCode/' + xlBm, function(array){
//加入_data缓存
$.each(array, function(){
_data.pushSchedule(this);
});
var rs = splitDir(array)
,tab = $('#tab_line_' + xlBm)
/*,half = tab.find('._body').height() / 2*/;
//填充表格数据
calculateLineNo(
//上行
tab.find('table[data-type=up] tbody').html(template('alone_plan_table_temp', {list: rs.up}))[0]
);
calculateLineNo(
//下行
tab.find('table[data-type=down] tbody').html(template('alone_plan_table_temp', {list: rs.down}))[0]
);
//定位到指定的班次
goToSch(schedule);
/*var currTr = tab.find('tr[data-id='+schedule.id+']')
,top = parseInt(currTr.find('td[name=lineNo]').text()) * 37 - half;
top = top>0?top:0;
currTr.addClass('anim-delay animated flash');
currTr.parents('._body').slimScroll({ scrollTo: top + 'px' });*/
});
},
//重新计算行号
calculateLineNo: calculateLineNo
}
//获取班次所在table
function getTableBySch(sch){
var upDown = sch.xlDir==0?'up':'down';
var tab = $('#tab_line_' + sch.xlBm);
return tab.find('.pb-table[data-type='+upDown+']');
}
//定位到班次所在的行
function goToSch(sch){
var table = getTableBySch(sch);
if(!table.is(":visible"))
return;
//表格被锁定
if(table.parents('.sch_table_panel').hasClass('lock'))
return;
var currTr = table.find('tr[data-id='+sch.id+']')
,half = table.parents('._body').height() / 2
,top = parseInt(currTr.find('td[name=lineNo]').text()) * 37 - half;
top = top>0?top:0;
currTr.addClass('anim-delay animated flash').one(animationend, function(){
$(this).removeClass('anim-delay animated flash');
});
currTr.parents('._body').slimScroll({ scrollTo: top + 'px' });
}
//计算行号
function calculateLineNo(table){
var rows = table.rows;
$.each(rows,function(i, r){
if($(r).hasClass('child-task-list'))
return true;
var cells = r.cells;
$(cells[0]).text(i + 1);
$(r).data('no', (i + 1));
});
}
function splitDir(list){
/*list.sort(function(a, b){
return a.fcno - b.fcno;
});*/
var rs = {up: [], down: []};
$.each(list, function(){
if(this.xlDir == upCode)
rs.up.push(this);
else
rs.down.push(this);
});
return rs;
}
function initRemarksPop(){
//备注POPOVER
$('.remarks-popover', '.pb-table').popover({trigger: 'hover',container: '.portlet-fullscreen',placement:'bottom'});
}
countDown('alone.js');
return aloneObject;
})();