entrustAllSocket.js
6.86 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
/**
* 买卖--全部商品
*/
var EntrustingAll = function() {
var _sock = null;
var _attentions = null; //用户关注列表
var _clickTag = 0;
var _searchText = '';
var _entrusts = null;
var _searchTip = '请输入代码或名称';
return {
init : function() {
EntrustingAll.userAttentions();
EntrustingAll.connect();
$('#txtSearch').val(_searchTip);
$('#txtSearch').focus(function() {
if ($('#txtSearch').val() == _searchTip) {
$('#txtSearch').val('');
}
});
$('#txtSearch').blur(function() {
if ($('#txtSearch').val() == '') {
$('#txtSearch').val(_searchTip);
}
});
$('#txtSearch').keyup(function() {
EntrustingAll.search();
});
},
/** 连接 */
connect : function() {
_sock = new SockJS("/sockjs/ec/entrust/all");
_sock.onopen = function() {
//console.log('open');
};
_sock.onmessage = function(event) {
_entrusts = $.parseJSON(event.data);
EntrustingAll.showEntrust();
};
_sock.onclose = function() {
EntrustingAll.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("EntrustingAll.connect()", 5000);
},
/**显示全部商品*/
showEntrust : function() {
var entrusts = _entrusts;
if (_attentions == null) {
setTimeout(function() {
EntrustingAll.showEntrust();
}, 1000);
return;
}
var text = new Array();
var attentions = _attentions.split(',');
$('#entrustList').html('');
if (entrusts == null || entrusts.length == 0) {
return;
}
for (var i = 0; i < entrusts.length; i++) {
var entrust = entrusts[i];
//alert("rrrr"+entrusts.length);
var attentioned = false;
var otcCode = entrust.otcCode;
var otcName = entrust.otcName;
var rose =EntrustingAll.toPercents(entrust.rose);
//var rose =entrust.rose;
var ups = entrust.ups;
//var businessAmount = entrust.businessAmount;
var businessBalance = entrust.businessBalance;
var openPrice = parseFloat(entrust.openPrice);
var lastPrice = parseFloat(entrust.lastPrice);
var trendClass = "";
businessBalance = Math.round((businessBalance /10000) * 100) / 100;
//businessBalance = businessBalance + "万";
//涨跌标识
if (openPrice > 0 && lastPrice > 0) {
if (openPrice < lastPrice) {
trendClass = " red-font";
} else if (openPrice > lastPrice) {
trendClass = " green-font";
}
}
if(rose>0){//涨跌幅颜色
trendClass = " red-font";
}else if(rose<0){
trendClass = " green-font";
}
if(ups>0){//涨跌颜色
trendClass = " red-font";
}else if(ups<0){
trendClass = " green-font";
}
//搜索
if (_searchText.length > 0) {
var searchText = isNaN(_searchText) ? otcName : otcCode;
if (searchText.indexOf(_searchText) < 0) {
continue;
}
}
lastPrice = entrust.lastPrice == null || entrust.lastPrice == 0.00 ? '--' : entrust.lastPrice.toMoney(2, "", ",");
rose=entrust.lastPrice == null || entrust.lastPrice == 0.00 ? '--' : rose;
ups=entrust.lastPrice == null || entrust.lastPrice == 0.00 ? '--' : ups.toFixed(2);
var buyPrice = entrust.buyPrice == null ? '--' : entrust.buyPrice.toMoney(2, "", ",");
var buyAmount = entrust.buyAmount == null || entrust.buyAmount == 0 ? '--' : entrust.buyAmount;
var sellPrice = entrust.sellPrice == null ? '--' : entrust.sellPrice.toMoney(2, "", ",");
var sellAmount = entrust.sellAmount == null || entrust.sellAmount == 0 ? '--' : entrust.sellAmount;
var businessAmount = entrust.businessAmount==null || entrust.businessAmount == 0 ? '--':entrust.businessAmount;
businessBalance=businessBalance==null || businessBalance == 0 ? '--':businessBalance;
if(entrust.businessAmount!=null || entrust.businessAmount != 0){
businessAmountOne = Math.round((businessAmount /10000) * 100) / 100;
businessAmount=(businessAmount.toString().length<5) ? businessAmount : businessAmountOne + "万";
}
text.push('<tr>');
text.push('<td>' + (i + 1) + '</a></td>');
text.push('<td class="clearHover"><a href="/ec/entrust/detail/' + otcCode + '">' + otcCode + '</td>');
text.push('<td style="width:150px" class="left-font padding-left clearHover"><a href="/ec/entrust/detail/' + otcCode + '">' + otcName + '</td>');
text.push('<td style="width:60px" class="right-font padding-right' + trendClass + '">' + lastPrice + '</td>');
text.push('<td style="width:60px" class="right-font padding-right' + trendClass + '">' +rose+ '</td>');
text.push('<td style="width:70px" class="right-font padding-right '+ trendClass +'">' + ups + '</td>');
text.push('<td style="width:60px" class="right-font padding-right">' + businessAmount + '</td>');
text.push('<td style="width:70px" class="right-font padding-right"> ' + businessBalance + '</td>');
text.push('<td style="width:80px" class="padding-left">');
for (var p in attentions) {
if (attentions[p] == otcCode) {
text.push('已关注');
attentioned = true;
break;
}
}
if (!attentioned) {
text.push('<a class="pay-attenion" onclick="EntrustingAll.attention(\'' +
otcCode + '\', \'' + otcName + '\', this)">+</a>');
}
text.push('</td>');
text.push('<td ><a href="/ec/entrust/detail/' + otcCode + '" class="trade-now">立即买卖</a></td>');
text.push('</tr>');
}
$('#entrustList').html(text.join(''));
},
toPercents : function (point){
var str=Number(point*100).toFixed(2);
str+="%";
return str;
},
/**关注*/
attention : function(otcCode, otcName, link) {
//防止重复点击
if (_clickTag == 1) {
return false;
}
_clickTag = 1;
$.post('/user/attention/save', { otcCode : otcCode, otcName : otcName },
function(data) {
if (data != '') {
$('#attentionsResult').html(data);
$(link).prop('outerHTML', '已关注');
$(link).onclick = function() {
EntrustingAll.attention(otcCode, otcName, link);
};
EntrustingAll.userAttentions();
easyDialog.open({
container : 'sureAttention'
});
}
_clickTag = 0;
}, 'text');
},
/**获取用户关注列表*/
userAttentions : function() {
$.get('/entrust/userAttentions', function(data) {
_attentions = data;
}, 'text');
},
search : function() {
_searchText = $('#txtSearch').val();
EntrustingAll.showEntrust();
}
}
}();
$(function() {
$("#navbar").find("a").removeClass("headBar-seleced");
$("#navbar").find(".em").css("display","none");
$("#deal").siblings(".em").css("display","block");
$("#deal").addClass("headBar-seleced");
EntrustingAll.init();
})