123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- // TODO 社区列表示例数据
- //var data = {"msg":"查询成功","list":[{"code":"3502050100","name":"内科"},{"code":"3502050101","name":"儿科"},{"code":"3502050200","name":"妇科"},{"code":"3502050300","name":"肿瘤科"},{"code":"3502050301","name":"五官科"},{"code":"3502050302","name":"消化内科"}],"status":200};
- // TODO 临时构造plus对象,使得能够在浏览器中进行调试
- //var plus = null;
- // 基本信息(包括userAgent、上个页面传递的数据)
- var baseInfo = null,
- // 基础环境信息(包括当前webview)
- baseEnv = null;
- var self;
- var isConsulted = false;
- var $resultWrapper = $('#result_wrap'),
- $doctorList = $('#doctor_list'),
- // 搜索输入框
- $searchbarInput = $('.searchbar input'),
- // 搜索无结果时显示
- $noResultWrap = $('#no_result_wrap');
- var curPage = 1,
- pageSize = 15,
- // iscroll 滚动条实例
- iscroller,
- isLastPage = false;
-
- // 获取基本信息(包括userAgent、上个页面传递的数据)
- var getBaseInfoPromise = function() {
- self = plus.webview.currentWebview();
- isConsulted = self.isConsulted;
- // 登录的相关信息
- var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
- return {
- userAgent: userAgent,
- // 上一个页面传递的数据
- accessData: baseEnv.webview.accessData
- }
- },
- // 获取基础环境信息
- getBaseEnvPromise = function () {
-
- var env = {
- webview: plus&&plus.webview.currentWebview()
- };
- return Promise.resolve().then(function(res) {
- return env;
- });
- },
- // 初始化科室列表
- initDoctorList = function(data) {
- var html = template("doctor_li_tmpl", data);
- $doctorList.append(html);
- },
- // 分页查询列表
- searchByPaging = function () {
-
- plus.nativeUI.showWaiting();
- var url = "doctor/doctors_list",
- params = {
- hospital: baseInfo.accessData.hospitalId,
- dept: baseInfo.accessData.deptId,
- page: curPage,
- pagesize:pageSize
- };
- getReqPromise(url,params).then(function(res){
- if(res.status == 200) {
- var data = res;
- if(!iscroller) {
- iscroller = initScroller($resultWrapper,url,
- function() { // 传递分页参数
- return $.extend({},params,{page:curPage+1});
- },function(data) {
- initDoctorList(data);
- iscroller.refresh();
- });
- }
-
- if(!data.data || !data.data.length) {
- $resultWrapper.hide();
- $(".searchbar").hide();
- $noResultWrap.show();
- } else {
- if(res.data.length < pageSize){
- $('.pullUp').hide();
- isLastPage = true;
- }
- $noResultWrap.hide();
- $(".searchbar").show();
- $resultWrapper.show();
- initDoctorList(data);
- }
-
- iscroller.refresh();
- } else {
- mui.toast(res.msg);
- }
-
- plus.nativeUI.closeWaiting();
-
- }).catch(function(e) {
- plus.nativeUI.closeWaiting()
- // mui.toast(res.msg);
- });
- },
- // 滚动条分页实例初始化
- initScroller = function($el,url,getData,pullUpAction) {
- var scroller;
- if(!isLastPage){
- scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
- var data = getData();
- getReqPromise(url,data).then(function(data) {
- if(pullUpAction && $.isFunction(pullUpAction)) {
- pullUpAction(data);
- }
- updatePullUpText(scroller,data.list);
- });
- }});
- }else{
- scroller = $el.initScroll({pullDown: false, pullUp: false});
- }
-
- return scroller;
- },
- // 更新分页上拉加载的提示文本
- updatePullUpText= function(scroller,list) {
- var $wrap = $(scroller.wrapper),
- $pullupLabel = $wrap.find('.pullUpLabel');
- if(!list || !list.length) {
- $pullupLabel.text('没有更多');
- $wrap.find('.pullUp').hide();
- isLastPage = true;
- } else if(list.length == pageSize){
- $pullupLabel.text('上拉加载更多');
- }else{
- isLastPage = true;
- $wrap.find('.pullUp').hide();
- }
- scroller.on('refresh',function() {
-
- if(!list || !list.length) {
- isLastPage = true;
- $pullupLabel.text('没有更多');
- $wrap.find('.pullUp').hide();
- } else if(list.length == pageSize){
- $pullupLabel.text('上拉加载更多');
- }
-
- if(list.length < pageSize){
- isLastPage = true;
- $pullupLabel.text('没有更多');
- $wrap.find('.pullUp').hide();
- }
-
- });
- },
- // 绑定页面事件
- bindEvents = function () {
- $searchbarInput.on('click',function() {
-
- mui.openWindow({
- url:"search_doctor.html",
- id:"search_doctor",
- extras: {
- accessData:{
- consultCode: self.consultInfo.consult,
- patient: self.consultInfo.patient
- },
- aa: self.aa,
- members: self.members,
- consultInfo: self.consultInfo
- }
- });
- });
-
- $("#cy_btn").on('click',function(){
- mui.openWindow({
- url:"changyong_doctor.html",
- id:"changyong_doctor"
- });
- });
- };
- // 页面业务处理流程开始
- new Promise(function(resolve, reject) {
-
- // TODO 临时放开
- //resolve(true);
- mui.plusReady(function() {
- // plus已经准备好,可以往下执行
- resolve(true);
- });
- }).then(function() {
-
- // 获取基础环境信息
- return getBaseEnvPromise().then(function(env) {
- baseEnv = env;
- }).then(function() {
- // 获取登录医生信息
- baseInfo = getBaseInfoPromise();
- searchByPaging();
- // 绑定页面事件
- bindEvents();
- })
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e);
- });
- template.helper("setPhoto", function(p) {
- return getImgUrl(p);
- });
|