rationNewConfig.js 1.69 KB
/**
 * 
 */
var rationNewConfig = function() {
	return {

		formatNumberRgx : function(num) {
			var parts = num.toString().split(".");
			parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
			return parts.join(".");
		},

		/** 配售信息 */
		rationConfig : function(otcCode, otcName, num, price, rationNewConfigId) {
			$.ajax({
				url : '/user/ration/queryRationUserById',
				type : 'post',
				dataType : 'json',
				data : {
					id : rationNewConfigId
				},
				success : function(data) {
					$("#otcCode").html(otcCode);
					$("#otcName").html(otcName);
					$("#stockNum").html(num);
					$("#price").html((price * 1).toFixed(2) + "元");
					var totalPercent = 0;
					for (var i = 0; i < data.length; i++) {
						totalPercent += data[i].percent;
					}
					var position = Math.round(num * totalPercent / 100);
					$("#saleNum").html(position);
					$("#totalPrice").html((price * (position)).toFixed(2) + "元");
					$("#position").html(num - position);
					$("#rationConfigId").val(rationNewConfigId);
				}
			});
			easyDialog.open({
				container : 'easyDialogConfig'
			});
		},
		

		agreeRation : function() {
			var isSubmit = false;
			if (isSubmit == true) {
				showMessage('请勿重复提交。');
				return;
			}
			isSubmit = true;
			$.ajax({
				url : '/user/ration/toAgreeRation',
				type : 'post',
				dataType : 'json',
				data : {
					otcCode : $("#otcCode").html(), id:$("#rationConfigId").val()
				},
				success : function(data) {
					if (data == 1) {
						easyDialog.close();
						window.location.reload();
					}else if(data == 0){
						isSubmit = false;
						alert("对不起,此次配售已结束");
						easyDialog.close();
					}
				}
			});
		}

	}
}();