alone.js
7.2 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
/**
* 单线路调度
*/
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();
//初始化信使
initMessenger(lineCodes);
//消息框滚动条
$('.console-log .log-item-list').slimscroll({
height: '100%'
});
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)
,half = table.parents('._body').height() / 2
,currTr = table.find('tr[data-id='+sch.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' });
}
//计算行号
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 changeTGStatus(){
var status = $(this).data('status');
if(status == 0)
status = 1;
else
status = 0;
$(this).data('status', status);
var lineCode = $(this).data('linecode');
$.post('/realSchedule/trustStatus/change', {lineCode: lineCode, status: status}
,function(rs){
if(rs == 200){
layer.msg('切换成功!');
changeTgHtml(lineCode, status);
}
});
}
$('.portlet-fullscreen').on('click', '.tg_tools', changeTGStatus);
var tgHtml = ['托管状态,计算机自动处理 <i class="fa fa-question-circle tgQuestion" style="cursor: pointer;"></i>', '非托管状态,手动处理!'];
var tgPopoverOps = {content: template('tg_question_info_temp', {}),html: true,placement: 'left',trigger: 'hover',container: '.portlet-fullscreen'};
function initMessenger(lineCodes){
//查询线路托管状态
$.get('/realSchedule/trustStatus', {lineCodes: lineCodes},function(rs){
for(var line in rs)
changeTgHtml(line, rs[line]);
});
}
function changeTgHtml(line, status){
var tgTools = $('#tgTools_' + line);
tgTools.html(tgHtml[status]).data('status', status);
var array = $('#top-tabs-wrap a[data-id='+line+'] span zz');
if(status == 0){
//托管Question
$('.tgQuestion', tgTools).popover(tgPopoverOps);
tgTools.removeClass('hand');
$(array[2]).text('托管');
}
else{
tgTools.addClass('hand');
$(array[2]).text('');
}
//tab 头改变
}
function initRemarksPop(){
//备注POPOVER
$('.remarks-popover', '.pb-table').popover({trigger: 'hover',container: '.portlet-fullscreen',placement:'bottom'});
}
return aloneObject;
})();