var d = dialog({contentType:'load', skin:'bk-popup'}); var page = 1, pageSize = 100; $(function(){ initScroller(); getDeptList(true); bindEvents(); }) function getDeptList(isInit){ d.show(); if(isInit){ page = 1; } var url = "patient/consult/dept_list", params = { page: page, pagesize: pageSize }; sendPost(url, params, 'json', 'get', queryFailed, function(res){ if(res.status == 200){ d.close(); var list = res.data; if(list.length > 0){ var html = template('dept_tmp', {list: list}); if(isInit){ var all = '
  • 全部
  • '; $("#deptList").empty().append(all+html); }else{ $("#deptList").append(html); } if(list.length < pageSize){ mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); }else{ mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(false); } }else{ if(isInit){ $(".c-main").hide(); $(".div-no-info").show(); }else{ mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); } } }else{ queryFailed(res); } }); } function bindEvents(){ $("#deptList").on('tap', 'li', function(){ var deptId = $(this).attr("data-code"), deptName = $(this).attr("data-name") || ''; var url = "select-consult-doctor.html?deptId="+deptId+"&deptName="+deptName; window.location.replace(url); }) } 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() { mui(".mui-scroll-wrapper").pullRefresh({ down:{ callback: function(){ getDeptList(true); this.endPulldownToRefresh(); } }, up: { callback: function() { var self = this; setTimeout(function() { getDeptList(false); }, 1000); } } }); }); } //请求失败处理事件 function queryFailed(res, message){ d.close(); if(message){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show(); }else{ if (res && res.msg) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show(); } } }