var d = dialog({ contentType: 'load', skin: 'bk-popup' }); var pagetype = 26; var $eventListWrapper = $('.main-content'); var $noResultWrap = $('#building'); var articleId,annoceId; var pagesize = [5,5,5], page = [1,1,0], //3个tab对应的分页的页数 loaded = [true, false, false]; //3个tab对应的页面是否加载过,第一个tab默认加载过 var userAgent = window.localStorage.getItem(agentName); var userInfo; var level1Type;//一键已读的类别 $(function(){ checkUserAgent(); }); function initScroller(){ //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; mui('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); mui.ready(function() { //循环初始化所有下拉刷新,上拉加载。 $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) { if(index == 0){ mui(pullRefreshEl).pullRefresh({ down: { callback: function() { var self = this; setTimeout(function() { getHealthArticle(index,articleId, true,1); self.endPulldownToRefresh(); }, 1000); } }, up: { callback: function() { var self = this; setTimeout(function(){ getHealthArticle(index,articleId, false,1); self.endPullupToRefresh(); }, 1000); } } }); }if(index == 1){ mui(pullRefreshEl).pullRefresh({ down: { callback: function() { var self = this; setTimeout(function() { getHealthArticle(index,annoceId, true,2); self.endPulldownToRefresh(); }, 1000); } }, up: { callback: function() { var self = this; setTimeout(function() { getHealthArticle(index,annoceId,false,2); self.endPullupToRefresh(); }, 1000); } } }); }if(index == 2){ mui(pullRefreshEl).pullRefresh({ down: { callback: function() { var self = this; setTimeout(function() { getMyCollection(index, true); self.endPulldownToRefresh(); }, 1000); } }, up: { callback: function() { var self = this; setTimeout(function() { getMyCollection(index); self.endPullupToRefresh(); }, 1000); } } }); } }); }); } //获取文章分类(一级标题) getCategoryList = function () { var url = "/third/jkEdu/Article/getCategoryList", params = { categoryLevel: "1" }; return new Promise(function(resolve, reject) { sendPost(url, params, 'json', 'GET', queryCategoryListFailed, function(res){ if(res.status == 200){ d.close(); var list = res.data; if(list.length == 0) { $eventListWrapper.hide(); $noResultWrap.show(); } else { $noResultWrap.hide(); $eventListWrapper.show(); var html = template('categoryList', {list:list}); $("#categoryBox").html(html); articleId = $("#tab0").attr('data-type'); annoceId = $("#tab1").attr('data-type'); initScroller(); } resolve(true) }else{ queryCategoryListFailed(res); } }); }) } function queryCategoryListFailed(res){ $eventListWrapper.hide(); $noResultWrap.show(); dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: res.msg }).show(); } function getHealthArticle(index,categoryId, isInit,type){ var tmpIndex = parseInt(index) + 1; if(isInit){ page[index] = 1; mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().scrollTo(0, 0, 1000); } var url = "/patient/jkEdu/article/fetchArticlePushedList", params = { page: page[index], pagesize: pagesize[index], level1Type: categoryId }; sendPost(url, params, 'json', 'GET', queryFailed, function(res){ d.close(); if(res.status == 200){ $('#read_all0').show(); $('#read_all1').show(); loaded[index] = true; //暂时默认数据是按年份group了的 [{year: 2017, list:[]}] if(res.data.length > 0){ if(type==1){ var temp = 'annoce_list_temp'; }else{ var temp = 'article_list_temp'; } // level1Type = res.data[0].level1Type; var html = template(temp, {list: res.data}); if(isInit){ $("#item"+tmpIndex+" .mui-scroll-wrapper").show(); $("#item"+tmpIndex+" .div-no-info").hide(); $("#recordList"+index).empty().append(html); }else{ $("#recordList"+index).append(html); } if(res.data.length < pagesize){ mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); }else{ page[index] ++; } }else{ if(isInit){ // $('#read_all').hide(); //type为1代表第一个tab栏 if(type==1){ //无数据 $("#item1 .mui-scroll-wrapper").hide(); $("#item1 .div-no-info").show(); $('#read_all0').hide(); }else{ //无数据 $("#item2 .mui-scroll-wrapper").hide(); $("#item2 .div-no-info").show(); $('#read_all1').hide(); } }else{ if(type==1){ mui("#item1 .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); }else{ mui("#item2 .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); } } } }else{ queryFailed(res); } }); } function getMyCollection(index, isInit){ var tmpIndex = parseInt(index) + 1; if(isInit){ page[index] = 0; mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().scrollTo(0, 0, 1000); } var url = "/third/jkEdu/Article/getCollectionArticalList", params = { pageIndex: page[index], pagesize: pagesize[index], articleState: "1", userType: '2' }; sendPost(url, params, 'json', 'GET', queryFailed, function(res){ d.close(); if(res.status == 200){ loaded[index] = true; //暂时默认数据是按年份group了的 [{year: 2017, list:[]}] if(res.data.length > 0){ var temp = 'myCollection_list_temp'; var html = template(temp, {list: res.data}); if(isInit){ $("#item"+tmpIndex+" .mui-scroll-wrapper").show(); $("#item"+tmpIndex+" .div-no-info").hide(); $("#recordList"+index).empty().append(html); }else{ $("#recordList"+index).append(html); } if(res.data.length < pagesize){ mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); }else{ page[index] ++; } }else{ if(isInit){ //无数据 $("#item3 .mui-scroll-wrapper").hide(); $("#item3 .div-no-info").show(); }else{ mui("#item3 .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); } } }else{ queryFailed(res); } }); } function queryFailed(res){ d.close(); if(res && res.msg) { dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: res.msg }).show(); } else { dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: '加载失败' }).show(); } } function bindEvents(){ document.querySelector('.mui-slider').addEventListener('slide', function(event) { var index = event.detail.slideNumber; if(!loaded[index]){ //tab未加载过,则加载数据 d.showModal(); if(index == 0){ getHealthArticle(index,articleId,true,1); }if(index == 1){ getHealthArticle(index,annoceId,true,2); }if(index == 2){ getMyCollection(index,true); } } }); //tab内item的点击事件 $("#recordList0").on('tap', 'li', function(){ var dataId = $(this).attr("data-code"); var articleId = $(this).attr("data-id"); $(this).find(".new-flag").hide(); window.location.href="article2.html?dataId="+dataId+'&articleId='+articleId+'&type='+'1';; }); //'健康文章'tab内item对应的点击事件 $("#recordList1").on('tap', 'li', function(){ var dataId = $(this).attr("data-code"); var articleId = $(this).attr("data-id"); $(this).find(".new-flag").hide(); window.location.href="article2.html?dataId="+dataId+'&articleId='+articleId+'&type='+'2';; }); //'我的收藏'tab内item对应的点击事件 $("#recordList2").on('tap', ' li', function(){ var dataId = $(this).attr("data-code"); var articleId = $(this).attr("data-id"); $(this).find(".new-flag").hide(); window.location.href="article2.html?dataId="+dataId+'&articleId='+articleId+'&type='+'3'; }); } function queryInit(){ getCategoryList().then(function() { //一键已读 $('#read_all0').on('click', function () { setReadTrue (articleId); }) //一键已读 $('#read_all1').on('click', function () { setReadTrue (annoceId); }) userInfo = JSON.parse(userAgent); if(!canPrescription){ $('#memberContainer').hide(); $("#slider").hide(); $("#building").show(); }else{ initFamilyData(); checkPatientInfo(); bindEvents(); } wxGetSign(); }).catch(function(e) { console && console.error(e) }); } //初始化家庭成员 function initFamilyData(){ appendFamilyMember($('#memberContainer'),function(){ loaded = [false, false, false]; page = [0,1,1]; checkPatientInfo(); },function(){ //判断有授权家人,修改样式 $("#slider").css({ 'top': '90px', 'height': 'calc(100% - 90px)' }); }); } //判断患者是否是慢病患者 function checkPatientInfo(){ d.showModal(); //显示3个tab mui('#slider').slider().gotoItem(0); $(".mui-slider-indicator .c-33").eq(1).show(); $(".mui-slider-indicator .c-33").eq(2).show(); mui('#slider').slider().setStopped(false); getHealthArticle(0,articleId,true,1); } //获取微信信息,并配置微信api接口 function wxGetSign(){ var params = {}; params.pageUrl = window.location.href; $.ajax(server + "weixin/getSign", { data: params, dataType: "json", type: "post", success: function(res){ if (res.status == 200) { var t = res.data.timestamp; var noncestr = res.data.noncestr; var signature = res.data.signature; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: appId, // 必填,公众号的唯一标识 timestamp: t, // 必填,生成签名的时间戳 nonceStr: noncestr, // 必填,生成签名的随机串 signature: signature,// 必填,签名,见附录1 jsApiList: [ 'closeWindow' ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); } } }); } template.helper("setPhoto", function(p) { return getImgUrl(p); }); template.helper('setTimer',function(o){ return o.substr(0,19) }); //设置已读 function setReadTrue (id) { d.show(); sendPost("patient/health/edu/readAllArticle",{firstLevelCategoryId:id},'json','get', function(res){ d.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}); }, function(res){ if(res.status == 200){ //隐藏所有的newicon $(".new-flag").hide(); } d.close(); }) }