trade.js 2.01 KB
/**
 * 行情信息
 */

$(function() {
	// 30秒刷新一次行情
	setInterval(trade.search, 1000 * 30);
});


var trade = function() {
	var timer;
	return {
		search : function() {
			$('#data-grid').datagrid({
				url : '/trade/exchaneInfo'
			});
		},

		mclosePrice : function(value, row) {
			return parseFloat(value).toFixed(2);
		},

		openPrice : function(value, row) {
			return parseFloat(value).toFixed(2);
		},

		lastPrice : function(value, row) {
			return parseFloat(value).toFixed(2);
		},

		trend : function(value, row) {
			var mclose_price = parseFloat(row.mclose_price);
			var last_price = parseFloat(row.last_price); // 最新价
			var trend = (last_price - mclose_price) / mclose_price * 100;
			if (last_price < 0.05) {
				trend = 0;
			}
			if (isNaN(trend)) {
				trend = 0;
			}
			if (trend > 0) {
				style = ' style="color: #d0111a;"';
			} else if (trend < 0) {
				style = ' style="color: #009e0a;"';
			}
			return trend.toFixed(2) + "%";
		},

		businessAmount : function(value, row) {
			return parseFloat(value).toFixed(2);
		},

		highPrice : function(value, row) {
			return parseFloat(value).toFixed(2);
		},

		lowPrice : function(value, row) {
			return parseFloat(value).toFixed(2);
		},

		businessBalance : function(value) {
			return (parseFloat(value) / 10000).toFixed(2);
		},
		
		otcentrustInfo : function(otcCode) {
			$('#info-grid').datagrid({
				url : '/trade/otcentrustInfo?otcCode=' + otcCode
			});

			$("#otc-dialog").dialog("open");

			// 10秒刷新一次委托单详情
			timer=setInterval(function() {
				$('#info-grid').datagrid({
					url : '/trade/otcentrustInfo?otcCode=' + otcCode
				});
			}, 1000 * 10);
		},
		
		closeInterval:function(){
			 clearInterval(timer);
		},
		

		otcInfo : function(value, row) {
			return "<a href='#' onclick='trade.otcentrustInfo(" + row.mch_code
					+ ")'>查看委托详情单</a>";
		},

		otcProp : function(value, row) {
			if (value == '0B0') {
				return '买入';
			}
			if (value == '0S0') {
				return '卖出';
			}
		}

	}
}();