123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- // TODO 社区列表示例数据
- //var hospitalData = {"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 baseInfo = null,
- // 基础环境信息(包括当前webview)
- baseEnv = null;
- var hasTnvite;
- var members = {};
- var isConsulted = false;
- var $tabs = $(".tab-hd"),
- $teamListWrapper = $("#team_doctor_list_wrap"),
- $famousListWrapper = $("#famous_doctor_list_wrap"),
- $zhuankeListWrapper = $("#zhuanke_list_wrap"),
- $teamDoctorList = $("#team_doctor_list"),
- $famousList = $("#famous_list"),
- $zhuankeList = $("#zhuanke_list"),
- // 搜索无结果时显示
- $teamNoResultWrap = $('#team_no_result_wrap'),
- $famouNoResultWrap = $('#famous_no_result_wrap'),
- $zhuankeNoResultWrap = $('#zhuanke_no_result_wrap'),
- $zhuankeSearchBar = $('#zhuanke_searchbar');
- // iscroll 滚动条实例
- var t_iscroller, //团队
- f_iscroller, //名医
- z_iscroller, //专科
- //当前选中tab
- curType,
- //保存页面数据
- teamDoctorObj,
- famousObj,
- zhuankeObj,
- f_lastPage = false,
- z_lastPage = false;
- var self;
- // 获取基本信息(包括userAgent、上个页面传递的数据)
- var getBaseInfoPromise = function() {
- self = plus.webview.currentWebview();
- // 登录的相关信息
- 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;
- });
- },
- //初始化
- initPage = function(){
- var self = plus.webview.currentWebview();
- var type = curType || self.type || 0;
- initTeamInfo(1);
- // $tabs.find(".sanp-flex").eq(type).click();
- //获得求助医生列表
- getGroupDoctors();
- },
- /*获得求助医生列表*/
- getGroupDoctors = function(){
- var url = "/doctor/consult/forHelpDocs",
- params = {consult: baseInfo.accessData.consultCode};
-
- getReqPromise(url, params).then(function(datas) {
- if(datas.status==200){
- members = datas.data;
- for(var k in members){
- isConsulted = true;
- break;
- }
- } else {
- mui.toast("程序开了点小差, 请稍后重试!");
- throw new Error("查询求助过的医生列表失败");
- }
- }).catch(function(e){
- console && console.error(e);
- });
- },
- /*团队医生处理*/
- initTeamInfo = function(curPage){
- var url = "/doctor/family_contract/consult_doctors",
- params = {sessionId : self.sessionId}; //不分页
- getReqPromise(url, params).then(function(res) {
- if(!t_iscroller) {
- t_iscroller = $teamListWrapper.initScroll({pullDown: false, pullUp: false});
- }
- if(!res.data || !res.data.teamDoctors.length) {
- $teamListWrapper.hide();
- $teamNoResultWrap.show();
- $('.posater-oper').eq(0).show();
- } else {
- $teamNoResultWrap.hide();
- $teamListWrapper.show();
- $('.posater-oper').eq(0).show();
- teamDoctorObj = res;
- //获得责任医生信息
- if(res.hasOwnProperty("dutyDoctor")){
- var tempList = [];
- tempList.push(res.dutyDoctor);
- var html = template('doctor_li_tmpl', {list : tempList});
- $teamDoctorList.append('<p class="c-f14 mt10 c-909090">责任医生</p>'+html);
- }
- var p = '<p class="c-f14 mt10 c-909090">团队内其他医生</p>';
- var html = template('doctor_li_tmpl',{list : res.data.teamDoctors});
- $teamDoctorList.append(p+html);
- }
-
- t_iscroller.refresh();
- plus.nativeUI.closeWaiting();
- }).catch(function(e){
- mui.toast(e.msg);
- });
- },
- /*名医处理*/
- initFamousInfo = function(curPage){
- // TODO 示例示例搜索参数
- // id: 上次搜索结果列表最后一条记录id,type:1(1:名医,0:非名医,key:搜素关键字,pagesize:每页条数
- var url = "doctor/consult/famousDoctorList",
- params = { type:1,page:curPage,pagesize:15};
- getReqPromise(url,params).then(function(res){
- if(!f_iscroller) {
- f_iscroller = $famousListWrapper.initScroll({pullDownAction: function(){
- initFamousInfo(1);
- },pullUp: false});
- }
- if(!res.list || !res.list.length) {
- f_lastPage = true;
- $famousListWrapper.hide();
- $famouNoResultWrap.show();
- } else {
- famousObj = res;
- $famouNoResultWrap.hide();
- $famousListWrapper.show();
- appendMembers({list: _.map(res.list,function(o) {
- if(members[o.code]){
- o.asked = true;
- }
- return o;
- })}, 'doctor_li_tmpl','famous_list',true);
- }
-
- f_iscroller.refresh();
- plus.nativeUI.closeWaiting();
- }).catch(function(e) {
- mui.toast(e.msg);
- });
- },
- /*专科医生处理*/
- initZhuankeInfo = function(curPage){
- var url = "/doctor/hospitals_list",
- params = { city:"350200",type:1,page:curPage,pagesize:15};
- getReqPromise(url,params).then(function(res){
- if(!z_iscroller) {
- z_iscroller = initScroller($zhuankeListWrapper,url,
- function() { // 传递分页参数
- return $.extend({},params,{page:curPage+1});
- },
- //下拉刷新处理
- function(){
- initZhuankeInfo(1);
- },
- function(data) {
- if(data.data && data.data.length) {
- curPage++;
- }
- if(data.data.length < 15){
- z_lastPage = true;
- }
- appendMembers(data, 'hospital_li_tmpl','zhuanke_list',false);
- z_iscroller.refresh();
- }, z_lastPage);
- }
- if(!res.data || !res.data.length) {
- $zhuankeListWrapper.hide();
- $zhuankeSearchBar.hide();
- $zhuankeNoResultWrap.show();
- } else {
- zhuankeObj = res;
- $zhuankeNoResultWrap.hide();
- $zhuankeSearchBar.show();
- $zhuankeListWrapper.show();
- appendMembers(res, 'hospital_li_tmpl','zhuanke_list',true);
- }
-
- z_iscroller.refresh();
- plus.nativeUI.closeWaiting();
- }).catch(function(e) {
- mui.toast(e.msg);
- });
- },
- // 滚动条分页实例初始化
- initScroller = function($el,url,getData,pullDownAction,pullUpAction,is_lastPage) {
- var scroller = $el.initScroll({pullDownAction: function(){
- if(pullDownAction && $.isFunction(pullDownAction)) {
- pullDownAction();
- }
- },pullUpAction: function() {
- if(!is_lastPage){
- var data = getData();
- getReqPromise(url,data).then(function(data) {
- if(pullUpAction && $.isFunction(pullUpAction)) {
- pullUpAction(data);
- updatePullUpText(scroller,data.list);
- }
- })
- }else{
- updatePullUpText(scroller,[]);
- return false;
- }
- }});
-
- return scroller;
- },
- // 更新分页上拉加载的提示文本
- updatePullUpText= function(scroller,list) {
- var $wrap = $(scroller.wrapper),
- $pullupLabel = $wrap.find('.pullUpLabel');
-
- if(!list || !list.length) {
- // $wrap.find(".pullUp").hide();
- $pullupLabel.text('没有更多');
- } else if(list.length<15){
- // $wrap.find(".pullUp").hide();
- $pullupLabel.text('没有更多');
- }else {
- $pullupLabel.text('上拉加载更多');
- }
- scroller.on('refresh',function() {
- if(!list || !list.length) {
- // $wrap.find(".pullUp").hide();
- $pullupLabel.text('没有更多');
- } else if(list.length<15){
- // $wrap.find(".pullUp").hide();
- $pullupLabel.text('没有更多');
- } else {
- $pullupLabel.text('上拉加载更多');
- }
- });
- },
- appendMembers = function(data, tmplId, ulId, isRefresh){
- var html = template(tmplId, data);
- if(isRefresh){
- $('#'+ulId).empty().html(html);
- } else{
- $('#'+ulId).append(html);
- }
- },
- //绑定事件
- bindEvents = function(){
- $tabs.on('click', '.sanp-flex', function(){
- $tabs.find(".sanp-flex").removeClass("curr");
- $(this).addClass("curr");
- curType = $(this).index();
- plus.nativeUI.showWaiting("加载中,请稍候...");
- $(".posater-oper").hide().eq(curType).show();
-
- switch (curType) {
- case 0:
- if (teamDoctorObj) {
- plus.nativeUI.closeWaiting();
- } else {
- initTeamInfo(1);
- }
- break;
- case 1:
- if (famousObj) {
- plus.nativeUI.closeWaiting();
- } else {
- initFamousInfo(1);
- }
- break;
- case 2:
- if (zhuankeObj) {
- plus.nativeUI.closeWaiting();
- } else {
- initZhuankeInfo(1);
- }
- break;
- }
- });
- $zhuankeList.on('click', 'li', function(){
- mui.openWindow({
- url:"hospital_dept.html",
- id: "hospital_dept",
- extras: {
- accessData:{
- hospitalId: $(this).attr("data-code"),
- consultCode: self.consultInfo.consult,
- patient: self.consultInfo.patient
- },
- aa: self.aa,
- members: members,
- consultInfo: self.consultInfo,
- isConsulted: isConsulted
- }
- });
- });
-
- $zhuankeSearchBar.on('click', 'input', function(){
- mui.openWindow({
- url:"search_doctor.html",
- id:"search_doctor",
- extras: {
- accessData:{
- consultCode: self.consultInfo.consult,
- patient: self.consultInfo.patient
- },
- aa: self.aa,
- members: members,
- consultInfo: self.consultInfo,
- isConsulted: isConsulted
- }
- });
- });
-
- $("#cy_btn").on('click',function(){
- mui.openWindow({
- url:"changyong_doctor.html",
- id:"changyong_doctor",
- extras: {
- openId: self.opener().id,
- type: 2,
- aa: self.aa,
- members: members,
- consultInfo: self.consultInfo,
- isConsulted: isConsulted
- }
- });
- });
- };
- // 页面业务处理流程开始
- new Promise(function(resolve, reject) {
- // TODO 临时放开
- //resolve(true);
- mui.plusReady(function() {
- // plus已经准备好,可以往下执行
- resolve(true);
- });
- }).then(function() {
- plus.nativeUI.showWaiting();
-
- // 获取基础环境信息
- return getBaseEnvPromise().then(function(env) {
- baseEnv = env;
- }).then(function() {
-
- // 获取登录医生信息
- baseInfo = getBaseInfoPromise();
- initPage();
- //绑定页面事件
- bindEvents();
- plus.nativeUI.closeWaiting();
- })
- }).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);
- });
|