placingAmount.js 7.16 KB
var img = new Image();
img.src = "/resource/images/guajiang.png";

$(document).ready(
	function() {
		// 判断当前的浏览器是否ie9以下
		// grayCanvas();
		var flag = InternetExplorer()
		if (!flag) {
			$("#reward-msg").css("display", 'none');
		}
		function InternetExplorer() {
			var browser = navigator.appName;
			var b_version = navigator.appVersion;
			var version = b_version.split(";");
			if (version.length > 1) {
				var trim_Version = parseInt(version[1].replace(/[ ]/g, "")
						.replace(/MSIE/g, ""));
				if (trim_Version < 9) {
					return false;
				}
			}
			return true;
		}
		$(".youpiao-list").find(".youpiao-detail").each(function(index) {
			var i = index;
			$(this).mouseenter(function() {
				$(this).find(".detail-left").find("img").animate({
					width : '155px',
					height : '113px'
				}, "normal");
			})
			$(this).mouseleave(function() {
				$(this).find(".detail-left").find("img").animate({
					width : '150px',
					height : '110px'
				}, "normal");
			});
		});
		/** 立刻配售 */
		var isSubmit = false;
		$(".submitForm").click(
				function() {
					var rationCount = $("#ration_count").val();// 配售数量
					if (isNaN(rationCount)) {
						PlacingAmount.showMessage("请输入数字");
						return;
					}
					if (rationCount == '' || parseInt(rationCount) <= 0) {
						PlacingAmount.showMessage("请输入正确的配售数量");
						return;
					}
					if (isSubmit == true) {
						PlacingAmount
								.showMessage('请勿重复提交。如需继续配售,请刷新页面后重试。');
						return;
					}
					isSubmit = true;
					$.post('/user/goods/buy', $('#configForm')
							.serializeArray(), function(data) {
						if (data.success) {
							$("#dialog-success-content").html(data.data);
							easyDialog.open({
								container : 'buttonSuccessPopup'
							});
						} else {
							PlacingAmount.showMessage(data.data);
							isSubmit = false;
						}
	
					});
				});
	});

function grayCanvas() {
	var canvas = document.getElementById("canvas");
	var cxt = canvas.getContext("2d");
	var i = 0;

	cxt.globalCompositeOperation = 'copy';
	cxt.drawImage(img, 0, 0, 400, 55);
	cxt.globalCompositeOperation = "destination-out";

	function mousemove(e) {
		e.preventDefault();
		var top = document.documentElement.scrollTop || window.pageYOffset
				|| document.body.scrollTop;
		var left = document.documentElement.scrollLeft || window.pageXOffset
				|| document.body.scrollLeft;
		var offsetTop = $("#canvas").offset().top - top;
		var offsetLeft = $("#canvas").offset().left - left;
		cxt.beginPath();
		cxt.fillStyle = "#00f";
		cxt.arc(e.clientX - offsetLeft, e.clientY - offsetTop, 10, 0,
				Math.PI * 2);
		cxt.fill();
		cxt.closePath();
		i++;
		if (i > 20) {
			cxt.clearRect(0, 0, img, 400, 55);
			PlacingAmount.lottery();
			canvas.removeEventListener("mousemove", mousemove, false);
			canvas.removeEventListener("mousedown", mousedown, false);
			i = 0;
		}

	}

	function mousedown() {
		canvas.addEventListener("mousemove", mousemove);
	}

	canvas.addEventListener("mousedown", mousedown);

}

var PlacingAmount = function() {
	return {
		showPopUp : function(id) {
			PlacingAmount.loadConfig(id);
			easyDialog.open({
				container : 'placingAmountPopup'
			});
		},
		showLotteryUp : function(id) {

			PlacingAmount.loadLotteryCount(id);
			easyDialog.open({
				container : 'drawRewardPopup'
			});
			grayCanvas();
		},
		checkNumber : function() {
			var price = $("#price").html();
			var point = $("#point").val();
			var rationCount = $("#ration_count").val();
			if (isNaN(rationCount)) {
				return false;
			}
			$("#record_fare").html((price * rationCount).toFixed(2));
			$("#pointSpan").html((point * rationCount).toFixed(2))
		},
		/** 充值 */
		payButton : function() {
			location.href = "/user/charge";
		},
		showMessage : function(text) {
			easyDialog.open({
				container : 'buttonOnePopup'
			});
			$("#dialog-error-content").html(text);
		},
		// 再次刮奖的信息
		showLotteryMes : function(text) {
			easyDialog.open({
				container : 'buttonThreePopup'
			});
			$("#dialog-lottery-content").html(text);

		},
		// 根据id查询配置信息
		loadConfig : function(id) {
			$.ajax({
				url : "/user/goods/queryById?id=" + id,
				type : "post",
				success : function(data) {
					if (data != null) {
						var config = data.data;
						if (config != undefined && config != null) {
							$("#ration_count").val("")
							$("#record_fare").html("0");
							$("#pointSpan").html("0");
							$("#otcCode").html(config.otcCode);
							$("#otcName").html(config.otcName);
							$("#price").html(config.price.toFixed(2));
							$("#goodsRemain").html(config.goodsRemain);
							$("#point").val(config.point.toFixed(2));
							$("#goodsId").val(config.id);
							$("#userGoodsPointAmount").html(config.pointAmount.toFixed(2));
						}
					}
				}
			});
		},
		// 加载刮奖信息
		loadLotteryCount : function(id) {
			$.ajax({
				url : "/user/goods/lotteryCount?id=" + id,
				type : "post",
				success : function(data) {
					if (data != null) {
						var config = data.data;
						if (config != undefined && config != null) {
							$("#goodsId").val(config.id);
							$("#ration_count").val("1");
							$("#otcDetail").html(
									config.otcCode + "&nbsp;&nbsp;&nbsp;"
											+ config.otcName);
							$("#lotteryCountSpan").html(config.lotteryCount);
							$("#qualityCountSpan").html(config.qualityCount);
							$("#lotteryPointSpan").html(
									config.lotteryPoint.toFixed(2));
							$("#lotteryCountPoint").html(
									config.lotteryCountPoint.toFixed(2));
							$("#goods_remain_span").html(config.goodRemain);
							$("#lotteryExpireSpan").html(config.lotteryExpire);
							$("#buyExpireSpan").html(config.buyExpire);
						}
					}
				}
			});
		},
		// 刮奖
		lottery : function() {
			$.ajax({
				url : "/user/goods/lottery?id=" + $("#goodsId").val(),
				type : "post",
				success : function(data) {
					if (data.success) {
						easyDialog.open({
							container : 'buttonFourPopup'
						});

						$("#potteryInfo").html(data.data);
						$("#dialog-lottery-success").html(data.data);
					} else {
						$("#potteryInfo").html("");
						if (data.data.length > 10) {
							PlacingAmount.showMessage(data.data);
						} else {
							PlacingAmount.showLotteryMes(data.data);
						}
					}
				}
			});
		},
		// 再次刮奖
		lotteryAgain : function() {
			PlacingAmount.loadLotteryCount($("#goodsId").val());
			// window.location.reload();
			easyDialog.open({
				container : 'drawRewardPopup'
			});
			grayCanvas();
		},
		// 立即配售
		goodsBuy : function() {
			$.ajax({
				url : "/user/goods/queryById?id=" + $("#goodsId").val(),
				type : "post",
				success : function(data) {
					if (data != null) {
						var config = data.data;
						if (config != undefined && config != null) {
							$("#ration_count").val("1");
							$(".otcCode").html(config.otcCode);
							$(".otcName").html(config.otcName);
							$(".price").html(config.price.toFixed(2) + "元");
							$(".goodsRemain").html(config.goodsRemain);
							$(".point").html(config.point.toFixed(2));
							$("#goodsId").val(config.id);
							easyDialog.open({
								container : 'confirmPopup'
							});
						}
					}
				}
			});
		}
	}
}();