index.js 2.7 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
define(['zepto','medtap'],function($,medtap){
	var main = {
		wechatId:medtap.getRequest('wechatId'),
		agencyId:medtap.getRequest('agencyId'),
		operationType:medtap.getRequest('operationType'),
		token:'',
		msgId:medtap.getRequest('wechatMsgId'),
		init:function(){
			main.getTokenByWechatId();
			
			if(!main.msgId){
				
			}else{
				main.msgRecord();
			}
		},
		bind:function(){
			$('.filterBox').on('click', 'p', function(){
				$('.filter').text('筛选:' + $(this).text());
				$('.filter, .filterBox').removeClass('on');
				var type = $(this).attr('key');
				main.getBook(type)
			});
			$('.filter').on('click', function(){
				var elFilter = $('.filter');
				!!elFilter.hasClass('on') 
					? $('.filter, .filterBox').removeClass('on')
					: $('.filter, .filterBox').addClass('on');
			});
			$('.lectureWrap').on('click',function(){
				window.location.href = 'https://mp.weixin.qq.com/mp/homepage?__biz=MzA3NTk5NjEwMQ==&hid=15&sn=97b35926097a72407b476e086c5dee82&scene=18'
			})
		},
		//获取患教手册内容
		getBook:function(type){
			medtap.loading(1);
			medtap.submitAjax({
				url:'https://testdevgw.medtap.cn/common/category/listEduBook',
				type:'get',
				data:{
					type:type
				},
				success:function(res){
					if(res.success == true){
						medtap.loading(0);
						var bookList = res.content.categoryList;
						var str = '';
						for(var i = 0;i < bookList.length;i++){
							str += '<div class="bookItem" data-bookId="'+ bookList[i].node +'-'+ bookList[i].categoryId+'" data-title="'+bookList[i].content+'">'+
										'<div class="bookbanner"><img src="'+bookList[i].picUrl+'" ></div>'+
										'<div class="bookName">'+bookList[i].content+'</div>'+
									'</div>';
						}
						$('.bookList').html(str);
						main.goToBookDetail();
						
					}
				}
			})
		},
		//跳转至书籍详情
		goToBookDetail:function(){
			$('.bookList').on('click','.bookItem',function(){
				var bookId = $(this).attr('data-bookId');
				var title = $(this).attr('data-title');
				medtap.pushWindow('pages/bookDetail.html?bookId=' + bookId + '&title=' + title + '&wechatId=' + main.wechatId + '&agencyId=' + main.agencyId + '&operationType=' + main.operationType);
			})
		},
		
		getTokenByWechatId:function(){
			localStorage.wxLungToken = '';
			medtap.submitAjax({
				url:'https://testdevgw.medtap.cn/user/auth/token',
				type:'POST',
				async:false,
				contentType: "application/json",
				data:{
					wechatId:main.wechatId
				},
				success:function(res){
					if(res.success == true){
						var token = res.content.token;
						main.token = token;
						localStorage.setItem('wxLungToken',token);
						main.getBook('0');//初始化时获取患教手册
					}
				}
			})
		}
	}
	main.init();
	main.bind();
})