123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- // TODO 医生列表示例数据
- //var doctorsData = {"msg":"获取医院医生列表成功!","list":[{"code":"D2016080002","jobName":" 全科医师","introduce":"我是全科医生","name":"大米全科1","deptName":"","photo":"http://172.19.103.85:8882/res/images/2016/08/12/20160812170142_901.jpg","id":1262,"expertise":"我是全科医生","hospitalName":"嘉莲社区医疗服务中心"},{"code":"D2016080005","jobName":" 全科医师","introduce":"我是全科医生","name":"大米全科2","deptName":"","photo":"","id":1271,"expertise":"我是全科医生","hospitalName":"嘉莲社区医疗服务中心"},{"code":"D2016080225","jobName":" 全科医师","introduce":"我是全科医生","name":"谭仁祝(全科)","deptName":"","photo":"","id":1274,"expertise":"我是全科医生","hospitalName":"嘉莲社区医疗服务中心"},{"code":"D2010080225","jobName":" 全科医师","introduce":"我是全科医生","name":"谭仁祝(全科1)","deptName":"","photo":"","id":1276,"expertise":"我是全科医生","hospitalName":"嘉莲社区医疗服务中心"}],"status":200};
- // TODO 临时构造plus对象,使得能够在浏览器中进行调试
- // var plus = null;
- // 登录者相关信息(包括userAgent)
- var baseInfo = null,
- // 基础环境信息(包括当前webview)
- baseEnv = null;
- var $orgTab = $('#org_tab'),
- $yishengWrapper = $('#yisheng_wrapper'),
- $yishengiList = $('#yisheng_list'),
- // 搜索输入框
- $searchbarInput = $('.searchbar input'),
- // 搜索无结果时显示
- $noResultWrap = $('#no_result_wrap');
- var curPage = 1,
- // iscroll 滚动条实例
- iscroller;
-
- // 获取基本信息(包括userAgent、上个页面传递的数据)
- var getBaseInfoPromise = function() {
- // 登录的相关信息
- 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;
- });
- },
- // 初始化医生列表
- initYiShengList = function(doctorsData) {
- var html = template("yisheng_li_tmpl", {list: doctorsData.list})
- $yishengiList.append(html);
- },
- // 分页查询列表
- searchByPaging = function () {
- // TODO 示例示例搜索参数
- // id: 上次搜索结果列表最后一条记录id,type:6(进行中),query:搜素关键字,pageSize:每页条数
- var url = "/doctor/findDoctorByDept",
- dept = baseInfo.accessData.dept,
- params = { page:curPage,pagesize:15, dept: dept};
- getReqPromise(url,params).then(function(res){
- var data = res;
- if(!iscroller) {
- iscroller = initScroller($yishengWrapper,url,
- function() { // 传递分页参数
- return $.extend({},params,{page:curPage+1});
- },function(data) {
- if(data.list && data.list.length) {
- curPage++;
- }
- initYiShengList(data);
- iscroller.refresh();
- });
- }
- if(!data.list || !data.list.length) {
- $searchtResult.hide();
- $noResultWrap.show();
- } else {
- $noResultWrap.hide();
- initYiShengList(data);
- if(data.list.length<15){
- $('.pullUp').hide();
- }
- }
-
- iscroller.refresh();
- }).catch(function(e) {
- console && console.error(e)
- });
- },
- // 滚动条分页实例初始化
- initScroller = function($el,url,getData,pullUpAction) {
- var 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);
- })
- }});
-
- return scroller;
- },
- // 更新分页上拉加载的提示文本
- updatePullUpText= function(scroller,list) {
- var $wrap = $(scroller.wrapper),
- $pullupLabel = $wrap.find('.pullUpLabel');
- if(!list || !list.length) {
- $pullupLabel.text('没有更多');
- } else if(list.length==15){
- $pullupLabel.text('上拉加载更多');
- }else{
- $wrap.find('.pullUp').hide();
- }
- scroller.on('refresh',function() {
-
- if(!list || !list.length) {
- $pullupLabel.text('没有更多');
- } else if(list.length==15){
- $pullupLabel.text('上拉加载更多');
- }
- if(list.length<15){
- $wrap.find('.pullUp').hide();
- }
- });
- },
- // 绑定页面事件
- bindEvents = function () {
- $yishengiList.on('tap','li',function() {
- var code = $(this).attr('data-code');
- openWebview("doctor-homepage.html",{
- accessData: {
- doctor: code
- }
- })
- });
- $searchbarInput.on('tap',function() {
- var toWebview = plus.webview.getWebviewById("sousuojigouyisheng");
- var createNew = !!toWebview;
- createNew && toWebview.close();
- mui.openWindow({
- url:"sousuojigouyisheng.html",
- id:"sousuojigouyisheng",
- createNew: true
- });
- });
- };
- // 页面业务处理流程开始
- 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);
- });
|