success.js 3.79 KB
Newer Older
hanpeng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
define(['zepto', 'medtap', 'mui'], function($, medtap, mui) {
	var main = {
		url: 'https://devgw.medtap.cn',
		lessonId: medtap.getRequest('lessonId'),
		linkUrl:'https://devgw.medtap.cn/wechat/oauth_stepEnd?type=COURSE_HOME&lessonId=',
		portType:getEnvironment(),
		name:'',
		init: function() {
			main.linkUrl += main.lessonId;
			main.getShareUser();
			main.bind();
			main.getShareInfo();
		},
		bind: function() {
			var mask = mui.createMask(function() {});
			$('.submit').unbind().bind('click', function() {
				window.location.replace('myCourse.html');
			});
			$('.share').unbind().bind('click', function() {
				window.location.replace('new_success.html?lessonId=' + main.lessonId);
			});
			$('.share_01').unbind().bind('click',function(){
				window.location.replace('new_success.html?lessonId=' + main.lessonId);
			})
			$('.close').unbind().bind('click', function() {
				$('.shareContent').hide();
			});
		},
		getShareUser:function(){
			medtap._ajax({
				url: '/common/share/getSharerByToken',
				type: 'post',
				contentType: 'application/json',
				portType:main.portType,
				async: false,
				data: {
			
				},
				success: function(res) {
					if (res.success == true) {
						if (res.content.clientType == 'USER') {
							var userShareId = res.content.clientId;
							main.linkUrl += '&userId=' + userShareId;
						} else if (res.content.clientType == 'AGENCY') {
							var agencyId = res.content.clientId;
							main.linkUrl += '&agencyId=' + agencyId;
						} else {
			
						}
					}
				}
			})
		},
		getShareInfo: function() {
			medtap._ajax({
				url: '/service/course/getCourseHome',
				type: 'get',
				portType:main.portType,
				data: {
					courseId:main.lessonId
				},
				success: function(res) {
					if (res.success == true) {
						var data = res.content;
						var status = data.signUpStatus;
						main.name = data.courseName;
						if(status == 1){
							//审核中
							$('.tip').html('报名成功!');
							$('.tip_desc').show();
							$('.share_01').show();
						}else if(status == 2){
							//报名成功
							$('.tip').html('审核成功!');
							$('.tip_desc').hide();
							$('.button_warp').show();
							$('.course_tip').show();
							$('.share_01').hide();
						}
						main.share(data);
					}
				}
			})
		},
		share: function(data) {
			console.log(data);
			var title = data.shareTitle;
			var content = data.shareDesc || '';
			var imgUrl = data.sharePic;
			medtap._ajax({
				url: '/wechat/fetchWechatTicket',
				type: 'GET',
				async: false,
				portType:main.portType,
				data: {
					url: window.location.href
				},
				success: function(res) {
					var data = res.content;
					wx.config({
						debug: false,
						appId: data.appId, // 必填,公众号的唯一标识
						timestamp: data.timestamp, // 必填,生成签名的时间戳
						nonceStr: data.nonceStr, // 必填,生成签名的随机串
						signature: data.signature, // 必填,签名,见附录1
						jsApiList: [
							'updateTimelineShareData',
							'updateAppMessageShareData'
						]
					})

					//微信分享
					wx.ready(function() {
						//分享给朋友
						wx.updateAppMessageShareData({
							title: title,
							desc: content, // 分享描述
							link: main.linkUrl,
							imgUrl: imgUrl, // 分享图标
							type: 'link', // 分享类型,music、video或link,不填默认为link
							dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
							success: function() {

							},
							cancel: function() {

							}
						});
						//分享到朋友圈
						wx.updateTimelineShareData({
							title: title, // 分享标题
							link: main.linkUrl,
							imgUrl: imgUrl, // 分享图标
							success: function() {

							},
							cancel: function() {

							}
						});
					});
				}
			})

		}
	}
	main.init();
})