indexSocket.js
4.25 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
/**
* 首页推送
*/
var EntrustInfo = function() {
var _sock = null;
var _lastEntrustRow = 0, _lastBarginRow = 0;
return {
init : function() {
EntrustInfo.connect();
},
/** 连接 */
connect : function() {
_sock = new SockJS("/sockjs/ec/entrust");
_sock.onopen = function() {
//console.log('open');
};
_sock.onmessage = function(event) {
var data = $.parseJSON(event.data);
if (data.flag == 'entrust') {
EntrustInfo.lastEntrust(data.data);
} else if (data.flag == 'bargin') {
EntrustInfo.lastBargin(data.data);
}
EntrustInfo.fillTab();
};
_sock.onclose = function() {
EntrustInfo.reconnect();
}
},
/** 发送消息 */
send : function() {
if (_sock != null) {
_sock.send($('#txtMessage').val());
}
},
/** 断开连接 */
disconnect : function() {
if (_sock != null) {
_sock.close();
_sock = null;
}
},
/** 断线重连 */
reconnect : function() {
// console.log('reconnect');
setTimeout("EntrustInfo.connect()", 5000);
},
/**最新发布*/
lastEntrust : function(entrusts) {
$('#tabLastEntrust').html('');
if (entrusts == null) {
return;
}
var text = new Array();
_lastEntrustRow = entrusts.length;
for (var i = 0; i < entrusts.length; i++) {
var entrust = entrusts[i];
var otcProp;
text.push('<tr>');
text.push('<td class="right-font"><a href="/ec/entrust/detail/'
+ entrust.otcCode + '" target="_blank">' + entrust.otcCode + '</td>');
text.push('<td class="left-font" style="padding-left:10px"><a href="/ec/entrust/detail/'
+ entrust.otcCode + '" target="_blank">' + entrust.otcName + '</td>');
switch (entrust.otcProp) {
case '0S0' :
otcProp = '<span class="green-font">卖出</span>';
break;
case '0B0' :
otcProp = '<span class="red-font">买入</span>';
break;
default:
otcProp = '';
}
text.push('<td class="left-font ">' + otcProp + '</td>');
text.push('<td class="right-font">' + entrust.entrustPrice.toMoney(2, "", ",") + '</td>');
text.push('<td class="right-font">' + entrust.entrustAmount + '</td>');
text.push('</tr>');
}
$('#tabLastEntrust').html(text.join(''));
},
/**最新成交*/
lastBargin : function(bargins) {
$('#tabLastBargin').html('');
if (bargins == null) {
return;
}
var text = new Array();
_lastBarginRow = bargins.length;
for (var i = 0; i < bargins.length; i++) {
var bargin = bargins[i];
text.push('<tr>');
text.push('<td class="right-font"><a href="/ec/entrust/detail/'
+ bargin.otcCode + '" target="_blank">' + bargin.otcCode + '</td>');
text.push('<td class="left-font" style="padding-left:10px"><a href="/ec/entrust/detail/'
+ bargin.otcCode + '" target="_blank">' + bargin.otcName + '</td>');
text.push('<td class=" right-font">' + bargin.businessPrice.toMoney(2, "", ",") + '</td>');
text.push('<td class=" right-font">' + bargin.businessAmount + '</td>');
text.push('<td class=" right-font">' + bargin.currTime + '</td>');
text.push('</tr>');
}
$('#tabLastBargin').html(text.join(''));
},
/**补齐表格:最少5行,并时最新发布和最新成交行数相同*/
fillTab : function() {
var fillRow = 0;
var tabLastEntrust, tabLastBargin;
if (_lastEntrustRow == _lastBarginRow && _lastEntrustRow >= 5) {
return;
}
if (_lastEntrustRow < 5 && _lastBarginRow < 5) {
EntrustInfo.fillingTab($('#tabLastEntrust'), 5 - _lastEntrustRow);
EntrustInfo.fillingTab($('#tabLastBargin'), 5 - _lastBarginRow);
_lastEntrustRow = 5;
_lastBarginRow = 5;
} else if (_lastEntrustRow < _lastBarginRow) {
EntrustInfo.fillingTab($('#tabLastEntrust'), _lastBarginRow - _lastEntrustRow);
_lastEntrustRow = _lastBarginRow;
} else if (_lastBarginRow < _lastEntrustRow){
EntrustInfo.fillingTab($('#tabLastBargin'), _lastEntrustRow - _lastBarginRow);
_lastBarginRow = _lastEntrustRow;
}
},
fillingTab : function(tab, row) {
var text = new Array();
for (var i = 0; i < row; i++) {
text.push('<tr>');
for (var j = 0; j < 5; j++) {
text.push('<td >--</td>');
}
text.push('</tr>');
}
tab.append(text.join(''));
}
}
}();
$(function() {
EntrustInfo.init();
})