coupon.js 7.12 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(){

			$.ajax({
				url: '/activity/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) {
							$('.receive-coupon-page .bg-contain img').attr('src', data.bgImg);
							$('.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);
							$('.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').html(data.activityDesc);
							if(data.ended) {
								$('.tip-wrap').removeClass('hidden');
								$('.tip-wrap .title').html(data.message);
							}
						} else {
							showToast(data.message, 1400);
						}
					} else {
						showToast('网络错误,稍后再试!', 1400);
					}
				},
				error: function() {
					showToast('网络错误,稍后再试!', 1400);
				},
				dataType : "json"
			});
		});

		$('#getCoupon').on('click', function() {
			phone = $(this).siblings('input').val();
			reg = /[0-9]{11}/;
			if (!reg.test(phone)) {
				showToast('手机号错误,请重新输入。', 1400);
				return;
			}
			$.ajax({
				url: '/activity/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) {
						if (window._yas) {
							window._yas.sendCustomInfo({
								activityID: activityID,
								returnCode: data.returnCode
							}, false);
						}
						if (data.code === 200) {

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

						} else {
							showToast(data.message, 1400);
						}
					} else {
						showToast('网络错误,稍后再试!', 1400);
					}
				},
				error: function() {
					showToast('网络错误,稍后再试!', 1400);
				},
				dataType : "json"
			});
		});
		$('.input-content').on('click', '.get', function() {
			$('.input-content div').eq('1').removeClass('get');
			if ($(this).siblings('input').val().length === 4) {
				$.ajax({
					url: '/activity/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, 1400);
						}
					},
					error: function() {
						showToast('网络错误,稍后再试!', 1400);
					},
					dataType : "json"
				});
			} else {
				showToast('网络错误,稍后再试!', 1400);
			}
		});
		$('.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({
					activityID: activityID
				}, 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;

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

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