entrustAttentionSocket.js
6.29 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
/**
* 买卖--用户关注商品
*/
var EntrustAttention = function() {
var _sock = null;
var _searchText = '';
var _entrusts = null;
var _searchTip = '请输入代码或名称';
return {
init : function() {
EntrustAttention.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() {
EntrustAttention.search();
});
$('#entrustList').html('<tr><td rowspan="4" colspan="10" width="100%" style="height:400px; background: #f2f2f2;" > <img src="./../resource/images/noData.png" width="500" height="300"> </td></tr> ');
},
/** 连接 */
connect : function() {
_sock = new SockJS("/sockjs/ec/entrust/attention");
_sock.onopen = function() {
//console.log('open');
EntrustAttention.send();
};
_sock.onmessage = function(event) {
_entrusts = $.parseJSON(event.data);
EntrustAttention.showEntrust();
};
_sock.onclose = function() {
EntrustAttention.reconnect();
}
},
/** 发送消息 */
send : function() {
if (_sock != null) {
_sock.send($('#hidUserId').val());
}
},
/** 断开连接 */
disconnect : function() {
if (_sock != null) {
_sock.close();
_sock = null;
}
},
/** 断线重连 */
reconnect : function() {
// console.log('reconnect');
setTimeout("EntrustAttention.connect()", 5000);
},
/**显示全部商品*/
showEntrust : function(entrusts) {
var text = new Array();
var entrusts = _entrusts;
//$('#entrustList').html('');
if (entrusts == null || entrusts.length == 0) {
return
}
for (var i = 0; i < entrusts.length; i++) {
var entrust = entrusts[i];
var attentioned = false;
var otcCode = entrust.otcCode;
var otcName = entrust.otcName;
var rose =EntrustAttention.toPercents(entrust.rose);
//var rose =entrust.rose;
var ups = entrust.ups;//保留两位小数四舍五入
//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 + "万";
//businessBalance=(businessBalance.toString().length<5) ? businessBalance : businessBalanceOne + "万";
//涨跌标识
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="padding-left clearHover"> ' + businessBalance + '</td>');
text.push('<td style="width:80px" class="padding-left">');
text.push('<a class="pay-attenion" onclick="EntrustAttention.beforeCacelAttention(\'' +
otcCode + '\')">×</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;
},
beforeCacelAttention : function(otcCode) {
easyDialog.open({
container : 'cancleAttention'
});
$('#btnYes').one('click', function() {
EntrustAttention.cacelAttention(otcCode);
});
},
/**取消关注*/
cacelAttention : function(otcCode) {
$.post('/user/attention/delete', { otcCode : otcCode }, function(data) {
if (data != '') {
EntrustAttention.send();
}
easyDialog.close();
}, 'text');
},
search : function() {
_searchText = $('#txtSearch').val();
EntrustAttention.showEntrust();
}
}
}();
$(function() {
EntrustAttention.init();
})