123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- // TODO 社区列表示例数据
- //var communitiesData = {"msg":"查询成功","list":[{"code":"3502050100","name":"海沧区嵩屿街道社区卫生服务中心",address:"升平路40号"},{"code":"3502050101","name":"海沧社区卫生服务站",address:"升平路40号"},{"code":"3502050200","name":"石塘社区卫生服务中心",address:"升平路40号"},{"code":"3502050300","name":"东孚卫生院",address:"升平路40号"},{"code":"3502050301","name":"天竺社区卫生服务站",address:"升平路40号"},{"code":"3502050302","name":"国营厦门第一农场社区卫生服务站",address:"升平路40号"},{"code":"3502050400","name":"新阳社区卫生服务中心",address:"升平路40号"},{"code":"0a11148d-5b04-11e6-8344-fa163e8aee56","name":"厦门市海沧医院","photo":"",address:"升平路40号"}],"status":200};
- // TODO 临时构造plus对象,使得能够在浏览器中进行调试
- //var plus = null;
- // 登录者相关信息(包括userAgent)
- var loginerInfo = null,
- // 基础环境信息(包括当前webview)
- baseEnv = null;
- var $orgTab = $('#org_tab'),
- $orgList = $('#org_list'),
- $views = $('.dest-view'),
- $yiyuanView = $('#yiyuan_view'),
- $shequView = $('#shequ_view'),
- $yiyuanList = $('#yiyuan_list'),
- $shequList = $('#shequ_list'),
- // 搜索输入框
- $searchbarInput = $('.searchbar input'),
- // 搜索无结果时显示
- $noResultWrap = $('#no_result_wrap');
- // ”医院”列表分页查询最后一条记录Id
- var yiyuanLastId = 0,
- // ”社区”列表分页查询最后一条记录Id
- shequLastId = 0,
- // ”医院”列表iscroll 滚动条实例
- yiyuanIscroller,
- // ”社区”列表iscroll 滚动条实例
- shequIscroller;
- // 获取登录相关信息
- var getLoginerInfo = function() {
- // 登录的相关信息
- var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
- return {
- userAgent: userAgent
- }
- },
- // 获取基础环境信息
- getBaseEnvPromise = function () {
-
- var env = {
- webview: plus&&plus.webview.currentWebview()
- };
- return Promise.resolve().then(function(res) {
- return env;
- });
- },
- // 初始化医院列表
- initYiYuanViewList = function(data) {
- var html = template("org_li_tmpl", {list: data.list})
- $yiyuanList.append(html);
- },
- // 初始化社区列表
- initSheQuViewList = function(data) {
- var html = template("org_li_tmpl", {list: data.list})
- $shequList.append(html);
- },
- // "医院"分页查询列表
- searchYiYuanByPaging = function () {
-
- plus.nativeUI.showWaiting();
- // TODO 示例示例搜索参数
- // id: 上次搜索结果列表最后一条记录id,type:1(医院),query:搜素关键字,pagesize:每页条数
- var url = "doctor/hospitals",
- params = { id:0, pagesize:15,type:1 };
-
- getReqPromise(url,params).then(function(res){
- // TODO 测试示例数据
- //data = communitiesData;
- if(res.status == 200) {
- var data = res;
- yiyuanLastId = getLastId(data);
- if(!yiyuanIscroller) {
- yiyuanIscroller = initScroller($yiyuanView,url,
- function() { // 传递分页参数
- return $.extend({},params,{id:yiyuanLastId});
- },function(data) {
- yiyuanLastId = getLastId(data) || yiyuanLastId;
- initYiYuanViewList(data);
- yiyuanIscroller.refresh();
- });
- }
-
- if(!data.list || !data.list.length) {
- $yiyuanView.hide();
- $noResultWrap.show();
- } else {
- $noResultWrap.hide();
- initYiYuanViewList(data);
- }
-
- yiyuanIscroller.refresh();
- } else {
- mui.toast(res.msg);
- }
-
- plus.nativeUI.closeWaiting();
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e)
- });
- },
- // "社区"分页查询列表
- searchSheQuByPaging = function () {
- plus.nativeUI.showWaiting();
- // TODO 示例示例搜索参数
- // id: 上次搜索结果列表最后一条记录id,type:2(社区),query:搜素关键字,pagesize:每页条数
- var url = "doctor/hospitals",
- params = { id:0, pagesize:15,type:2 };
- getReqPromise(url,params).then(function(res){
- // TODO 测试示例数据
- // data = communitiesData;
- if(res.status == 200) {
- var data = res;
- shequLastId = getLastId(data);
- if(!shequIscroller) {
- shequIscroller = initScroller($shequView,url,
- function() { // 传递分页参数
- return $.extend({},params,{id:shequLastId});
- },function(data) {
- shequLastId = getLastId(data) || shequLastId;
- initSheQuViewList(data);
- shequIscroller.refresh();
- });
- }
- if(!data.list || !data.list.length) {
- $shequView.hide();
- $noResultWrap.show();
- } else {
- $noResultWrap.hide();
- initSheQuViewList(data);
- }
-
- shequIscroller.refresh();
- } else {
- mui.toast(res.msg);
- }
-
- plus.nativeUI.closeWaiting();
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- 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;
- },
- // 获取分页搜索返回的最后一条记录的id
- getLastId = function(data) {
- var lastObj = data.list && data.list.length && data.list[data.list.length-1];
- // 最后一条记录
- if(lastObj) {
- return lastObj.id;
- } else {
- return null
- }
- },
- // 更新分页上拉加载的提示文本
- 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('上拉加载更多');
- }
- if(list.length<15){
- $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 () {
- $orgTab.on('click','li',function() {
- var type = $(this).attr('data-type');
- $orgTab.find('li').removeClass('curr');
- $('.dest-view').hide();
- $(this).addClass('curr');
- $('#'+type).show();
- });
-
- $views.on('tap','li',function() {
- mui.openWindow({
- url:"xuanzekeshi.html",
- id:"xuanzekeshi",
- // 跳转页面传参
- extras: {
- accessData:{ // 传递数据
- hospital: $(this).attr('data-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() {
- // TODO 此处返回重写为"mingyiguanli",发现其有时会back到"xinzengmingyi",导致出错无法返回
- mui.back = function () {
- var myglWebview = plus.webview.getWebviewById("mingyiguanli");
- if(myglWebview) {
- mui.fire(myglWebview,"refreshPage");
- }
- return backToWebviewById('mingyiguanli');
- }();
- // plus已经准备好,可以往下执行
- resolve(true);
- });
- }).then(function() {
-
- // 获取基础环境信息
- return getBaseEnvPromise().then(function(env) {
- baseEnv = env;
- }).then(function() {
- // 获取登录医生信息
- loginerInfo = getLoginerInfo();
- searchYiYuanByPaging();
- searchSheQuByPaging();
- // 绑定页面事件
- bindEvents();
- })
- }).catch(function(e) {
- plus.nativeUI.closeWaiting();
- console && console.error(e);
- });
- template.helper("setHosPhoto", function(p) {
- if(!p || p == ""){
- return '../images/hospital_default.png';
- }
- return getImgUrl(p);
- });
|