coupon.js 8.13 KB
var tipMessage = $('#tipMessage').html();
var activityID = $('#activityID').html();
$('#phone').bind('input propertychange', function() {
	if ($(this).val().length === 11) {
		$('.input-content div').eq('0').addClass('verification-code');
	} else {
		$('.input-content div').eq('0').removeClass();
		if ($(this).val().length >= 1) {
			$('.input-content i').eq('0').removeClass('hidden');
		} else {
			$('.input-content i').eq('0').addClass('hidden');
		}
	}
});
$('#verification').bind('input propertychange', function() {
	if ($(this).val().length === 4) {
		$('.input-content div').eq('1').addClass('get');
	} else {
		$('.input-content div').eq('1').removeClass();
		if ($(this).val().length >= 1) {
			$('.input-content i').eq('1').removeClass('hidden');
		} else {
			$('.input-content i').eq('1').addClass('hidden');
		}
	}
});

if ($('#activityEnded').html()) {
	$('.tip-wrap').removeClass('hidden');
	$('.tip-wrap .title').html(tipMessage);
}


function showToast(messages, time) {
	$('#dialog').removeClass('hidden');
	$('.mask').removeClass('hidden');
	$('#dialog .content').html('<p class="phone-error">' + messages + '<p>');
	setTimeout(function() {
		$('.messages').addClass('hidden');
		$('.mask').addClass('hidden');
		$('#dialog .content').html(' ');
	}, time);
}

$(function() {

	$("#phone").val("");

	$.ajax({
		url: '/union/tencentMkt/TencentMktController/getActivityInfo',
		data: {
			activityCode: activityCode
		},
		success: function(data) {
			data = getPageInfo(data);
			if (data.code === 200 || data.code === 502 || data.code === 503) {
				/*if (window._yas) {
					window._yas.sendCustomInfo({
						activityID: activityID,
						returnCode: data.returnCode
					}, false);
				}*/
				if (data.code === 200) {
					$.extend(activityInfo, data);
					$('.receive-coupon-page .bg-contain .img1').attr('src', data.bgImg);
					if (data.secondScreenPic) {
						$('.receive-coupon-page .bg-contain .img2').attr('src', data.secondScreenPic);
					} else {
						$('.receive-coupon-page .bg-contain .img2').addClass('hidden');
					}
					if (data.buttomTextPic) {
						$('.receive-coupon-page .coupon-centent .coupon-description .img3').attr('src', data.buttomTextPic);
					}
					$('.gain-coupon-centent .coupon img').attr('src', data.couponPic);
					$('#activityEnded').text(data.ended);
					$('#newUser').text(data.newUser);
					$('#tipMessage').text(data.message);
					$('#activityID').text(data.activityID);
					$('#shareTitle').val(data.shareTitle);
					$('#shareDesc').val(data.shareDesc);
					$('#shareImg').val(data.shareImg);
					$('#shareLink').val(data.shareLink);
					$('#activityCode').val(data.activityCode);
					$(document).attr("title",data.title);

					$('.gain-coupon-centent .use-coupon-btn .use-coupon').attr('href', data.buttonLink);
					$('.gain-coupon-centent .go-wep').attr('href', data.pcLink);
					$('.tip .title').html(data.message);
					$('#activityDesc .message').html(data.formatActivityDesc);


					if(data.oldUserPopupContent){
						$('#oldUserSpan .message').html("<p>"+data.oldUserPopupContent+"</p>");
					}
					if (data.oldUserButtonName){
						$('#oldUserSpan .oldUserButton').html("<a href="+data.oldUserButtonLink+">"+data.oldUserButtonName+"</a>");
					}

					if (data.ended) {
						var img = $("<img>");
						img.attr("src", data.bgImg).css({"width":"100%","height":"100%"});
						$('.tip-wrap').append(img).css({"background":"none"});
						$('.tip-wrap .tip').css({"background":"none"});
						$('.tip-wrap').removeClass('hidden');
						$('.tip-wrap .title').html(data.message);
					}
				} else {
					showToast(data.message, 1600);
				}
			} else {
				showToast('网络错误,稍后再试!', 1600);
			}
		},
		error: function() {
			showToast('网络错误,稍后再试!', 1600);
		},
		dataType: "json"
	});
});

$('#getCoupon').on('click', function() {
	phone = $(this).siblings('input').val();
	reg = /[0-9]{11}/;
	if (!reg.test(phone)) {
		showToast('手机号错误,请重新输入。', 1600);
		return;
	}
	$.ajax({
		url: '/union/tencentMkt/TencentMktController/sendSms',
		data: {
			mobile: $('#phone').val(),
			activityCode: activityCode
		},
		success: function(data) {
			if (data.code === 200 || data.code === 502 || data.code === 503 || data.code === 404 || data.code === 504 || data.code == 505) {
				if (window._yas && window._yas.sendCustomInfo) {
					
				}
				if (data.code === 200) {

					$('.coupon-centent .phone-input-content').addClass('hidden');
					$('.coupon-centent .vertify-input-content').removeClass('hidden');

				} else if(data.code == 505){

					$('#oldUserDiv').removeClass('hidden');
					$('.mask').removeClass('hidden');
				}else {
					showToast(data.message, 1600);
				}
			} else {
				showToast('网络错误,稍后再试!', 1600);
			}
		},
		error: function() {
			showToast('网络错误,稍后再试!', 1600);
		},
		dataType: "json"
	});
});
$('.input-content').on('click', '.get', function() {
	$('.input-content div').eq('1').removeClass('get');
	if ($(this).siblings('input').val().length === 4) {
		$.ajax({
			url: '/union/tencentMkt/TencentMktController/validRegCodeAndSendCode',
			data: {
				code: $('#verification').val(),
				mobile: $('#phone').val(),
				activityCode: activityCode
			},
			dataType: 'json',
			success: function(data) {
				if (data.code === 200) {
					/*if (window._yas) {
						window._yas.sendCustomInfo({
							activityID: activityID,
							returnCode: data.returnCode
						}, false);
					}*/
					$('.coupon-centent').addClass('hidden');
					$('.gain-coupon-centent').removeClass('hidden');

				} else {
					showToast(data.message, 1600);
				}
			},
			error: function() {
				showToast('网络错误,稍后再试!', 1600);
			},
			dataType: "json"
		});
	} else {
		showToast('网络错误,稍后再试!', 1600);
	}
});
$('.close').on('click', function() {
	$('.dialog').addClass('hidden');
	$('.mask').addClass('hidden');
	$('#dialog .content').html(' ');
});
$('.description-btn').on('click', function() {
	$('#message').removeClass('hidden');
	$('.mask').removeClass('hidden');
});

$('.gain-description-btn').on('click', function() {
	$('#message').removeClass('hidden');
	$('.mask').removeClass('hidden');
});
$('.description').on('click', function() {
	$('#message').removeClass('hidden');
	$('.mask').removeClass('hidden');
});

// 下载按钮,增加埋点
$('.use-coupon-btn').on('click', function() {
	if (window._yas) {
		window._yas.sendCustomInfo({
			op : "YB_DOWNLOAD_C",
			param : JSON.stringify({
				TO_URL: activityInfo.buttonLink
			})
		}, true);
	}
});

$('.input-content .clear-mobile').on('click', function() {
	$('.input-content input').eq('0').val('');
	$(this).addClass('hidden');
	$('.input-content div').eq('0').removeClass();
});

$('.input-content .clear-verify').on('click', function() {
	$('.input-content input').eq('1').val('');
	$(this).addClass('hidden');
	$('.input-content div').eq('1').removeClass();
});

/**
 * 分享页面基础参数
 * @param  {object} sizeInfo [接口原始数据]
 * @return {object}          [description]
 */
function getPageInfo(pageInfo) {
	var dest = {};

	dest.shareTitle = pageInfo.data.shareTitle;
	dest.shareDesc = pageInfo.data.shareContent;
	dest.shareImg = pageInfo.data.shareImgUrl;
	dest.shareLink = pageInfo.data.shareUrl;
	dest.code = pageInfo.code;
	dest.activityID = pageInfo.id;
	dest.title = pageInfo.data.h5Title;
	dest.activityDesc = pageInfo.data.activityDesc;
	dest.couponPic = pageInfo.data.couponPic;
	dest.oldUserCouponPic = pageInfo.data.oldUserCouponPic;
	dest.mobile = pageInfo.data.mobile;
	dest.pcLink = pageInfo.data.pcLink;
	dest.buttonLink = pageInfo.data.buttonLink;
	dest.secondScreenPic = pageInfo.data.secondScreenPic;
	dest.formatActivityDesc =  pageInfo.data.formatActivityDesc;

	if (pageInfo.data.flag === 1) {
		dest.bgImg = pageInfo.data.activityNormalPic;
	} else {
		dest.bgImg = pageInfo.data.activityEndPic;
		dest.ended = true;
	}
	dest.message=pageInfo.data.returnMsg;
	dest.buttomTextPic = pageInfo.data.buttomTextPic;
	dest.oldUserPopupContent = pageInfo.data.oldUserPopupContent;
	dest.oldUserButtonName = pageInfo.data.oldUserButtonName;
	dest.oldUserButtonLink = pageInfo.data.oldUserButtonLink;

	// 清空变量,释放内存
	pageInfo = {};
	return dest;
};