123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- // 基本信息(包括userAgent)
- var baseInfo = null,
- //滚动条
- scroller1=null,
- // 基础环境信息(包括当前webview)
- baseEnv = null,
- page = 1,
- iscroller,
- patient = null;
-
- //搜索输入框
- var $searchbarInput = $('.search-input'),
- //文章列表
- $articleList = $("#jjts-category-ul");
- var self;
- var mscrolls = [];
- var pagesize = 10;
- var $eventListWrapper = $('#jjts-content');
- var $noResultWrap = $('#no_result_wrap');
- var $sliderSegmentedControl = $("#sliderSegmentedControl");
- // 获取登录相关信息
- var getBaseInfo = function() {
- // 登录的相关信息
- var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
- return {
- userAgent: userAgent
- }
- },
- // 获取基础环境信息
- getBaseEnvPromise = function () {
-
- var env = {
- webview: plus&&plus.webview.currentWebview()
- };
- var self = plus.webview.currentWebview();
- mui.back = function(){
- var opener = self.opener();
- if(opener.id=='p2dzixun'){
- mui.fire(opener, 'update');
- } else if(opener.id == 'fuwujilu') {
- mui.fire(opener, 'refresh');
- }
- self.close();
- }
- return Promise.resolve().then(function(res) {
- return env;
- });
- },
- refreshPage = function(){
- baseInfo = getBaseInfo();
- var index = $('.mui-control-item.mui-active').index();
- var view = $('.mui-table-view').eq(index);
- view.empty();
- var scroll = mscrolls[index];
- if(scroll) {
- scroll.pulldownLoading();
- }
- },
- //事件绑定
- bindEvents = function(){
- $articleList.on('tap','.content-tuisong',function() {
- var articleId = $(this).attr('data-id');
- openWebviewExtras("jianjiaotuisong-xiangqing.html",{articleId:articleId});
- return false;
- });
-
- $eventListWrapper.on('tap','.yituisong',function() {
- $("#slider").hide();
- $(".sucaiku").removeClass("show");
- $(".yituisong").addClass("show");
- getYituisongList(page,pagesize,true);
- $("#view_wrap").show();
- });
-
- $eventListWrapper.on('tap','.sucaiku',function() {
- $("#slider").show();
- $("#view_wrap").hide();
- $(".yituisong").removeClass("show");
- $(".sucaiku").addClass("show");
- });
-
- $sliderSegmentedControl.on('tap','.mui-control-item',function(){
- var index = $(this).index();
- var scroll = mscrolls[index];
- var view = $('.mui-table-view').eq(index);
- var isEmpty = view.find('li').length==0;
- if(scroll && isEmpty) {
- scroll.pullupLoading();
- }
- })
-
- $articleList.on('tap','.tuisong',function() {
- var articleId = $(this).attr('data-id');
- openWebviewExtras("tuisong_duixiang.html",{articleId:articleId});
- return false;
- });
-
- $searchbarInput.on('click',function() {
- openWebviewExtras("jianjiaotuisong_search.html");
- return false;
- });
-
- /*刷新事件*/
- window.addEventListener("refresh", function refresh(e) {
- refreshPage();
- });
- },
- loadListPromise = function(wheaType,page) {
- var url = "third/jkEdu/Article/getDoctorArticalList",
- params = {articleTitle: "",articleState:1,firstLevelCategoryId:wheaType,pageIndex:page,pageSize:pagesize};
- return new Promise(function(resolve, reject) {
- sendGet(url,params,function(res){
- if(res.msg){
- mui.toast(res.msg);
- }else{
- mui.toast("加载失败!");
- }
- },function(res){
- if(res.status==200){
- resolve(res.data)
- }else{
- if(res.msg){
- mui.toast(res.msg);
- }else{
- mui.toast("加载失败!");
- }
- }
- })
- });
- },
- initScroll = function () {
- //循环初始化所有下拉刷新,上拉加载。
- if(mscrolls.length == 0) {
- $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
- var page = 0;
- var wheaType= $(this).closest('.mui-slider-item').attr('data-type')||"";
- var pullRefresh = mui(pullRefreshEl).pullRefresh({
- down: {
- callback: function() {
- page = 0;
- var self = this;
- var ul = self.element.querySelector('.mui-table-view');
- var $scrollEl = $(ul).closest('.mui-scroll');
- var $noResult = $scrollEl.find('.no-result');
- $noResult.hide();
- loadListPromise(wheaType,page)
- .then(function(list) {
- plus.nativeUI.closeWaiting();
- if(list && list.length) {
- page++;
- setTimeout(function() {
- var html = template('jjts-article-list',{list: list});
- $(ul).html(html);
- self.endPulldownToRefresh(list.length < pagesize);
- }, 1000);
- } else {
- if(page == 0) {
- $noResult.show();
- self.endPulldownToRefresh(true);
- }
- self.endPulldownToRefresh(true);
- }
- })
- .catch(function(e) {
- console && console.error(e)
- })
- }
- },
- up: {
- callback: function() {
- var self = this;
- var ul = self.element.querySelector('.mui-table-view');
- var $scrollEl = $(ul).closest('.mui-scroll');
- var $noResult = $scrollEl.find('.no-result');
- loadListPromise(wheaType,page)
- .then(function(list) {
- if(list && list.length) {
- page++;
- setTimeout(function() {
- var html = template('jjts-article-list',{list: list});
- $(ul).append(html);
- self.endPullupToRefresh(list.length < pagesize);
- }, 1000);
- } else {
- if(page == 0) {
- $noResult.show();
- }
- self.endPullupToRefresh(true);
- }
- })
- .catch(function(e) {
- console && console.error(e)
- })
- }
- }
- });
- mscrolls.push(pullRefresh)
- });
- }
- }
- function initTuiSongScroller() {
- iscroller = mui("#view_wrap.mui-scroll-wrapper").pullRefresh({
- up: {
- callback: function() {
- page++;
- getYituisongList(page,10);
- this.endPullupToRefresh();
- }
- },
- down: {
- callback: function() {
- var self1 = this;
- page = 1;
- getYituisongList(1,pagesize,true);
- self1.endPulldownToRefresh();
- }
- }
- });
- }
- function getYituisongList(pageNum,pageSize,isInit){
- var url = "doctor/jkEdu/article/pushArticleList",
- params = {page: pageNum,pagesize: pageSize};
- plus.nativeUI.showWaiting();
- sendGet(url, params, null, function(res){
- if(res.status==10000){
- plus.nativeUI.closeWaiting();
- var list = res.result;
- if(list.length == 0) {
- if(isInit){
- $eventListWrapper.hide();
- $noResultWrap.show();
- }else{
- iscroller.endPullupToRefresh(true);
- }
- } else {
- $noResultWrap.hide();
- $eventListWrapper.show();
- var html = template('yituisong-tmp', {list:list});
- if(isInit) {
- $("#jktj_list").html(html);
- if(res.result.length == pageSize){
- iscroller.finished = false;
- }
- } else {
- $("#jktj_list").append(html)
- }
- if(res.result && res.result.length < pageSize) {
- iscroller.endPullupToRefresh(true);
- }else{
- iscroller.endPullupToRefresh(true);
- }
- }
- initTuiSongScroller();
- } else {
- plus.nativeUI.closeWaiting();
- mui.toast("数据获取失败");
- }
-
- });
- }
- // 页面业务处理流程开始
- new Promise(function(resolve, reject) {
- // TODO 临时放开
- //resolve(true);
- mui.plusReady(function() {
- // hrefhrefplus已经准备好,可以往下执行
- resolve(true);
- });
- }).then(function() {
- // 获取基础环境信息
- return getBaseEnvPromise().then(function(env) {
- baseEnv = env;
- }).then(function() {
- // 获取登录基本信息
- baseInfo = getBaseInfo();
- var self = plus.webview.currentWebview();
- getCategoryList();
- // 绑定页面事件
- bindEvents();
- $('.mui-control-item.mui-active').trigger('tap');
- })
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e);
- });
- template.helper("setPhoto", function(p) {
- return getImgUrl(p);
- });
- //获取文章分类(一级标题)
- getCategoryList = function () {
- var url = "third/jkEdu/Article/getCategoryList",
- params = {categoryLevel: 1};
- plus.nativeUI.showWaiting();
- sendGet(url, params, null, function(res){
- if(res.status==200){
- plus.nativeUI.closeWaiting();
- var list = res.data;
- if(list.length == 0) {
- $eventListWrapper.hide();
- $noResultWrap.show();
- } else {
- $noResultWrap.hide();
- $eventListWrapper.show();
- var html = template('categoryList', {list:list});
- $("#sliderSegmentedControl").html(html);
- var html2 = template('jjts-article-ul', {list:list});
- $("#jjts-category-ul").html(html2);
- initScroll();
- initTuiSongScroller();
- mui('#slider').slider({
- interval:0//自动轮播周期,若为0则不自动播放,默认为0;
- });
- }
- } else {
- $eventListWrapper.hide();
- $noResultWrap.show();
- mui.toast(res.msg);
- }
-
- });
- }
|