select_doctor.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. // TODO 社区列表示例数据
  2. //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};
  3. //// TODO 临时构造plus对象,使得能够在浏览器中进行调试
  4. //var plus = null;
  5. // 基本信息(包括userAgent、上个页面传递的数据)
  6. var baseInfo = null,
  7. // 基础环境信息(包括当前webview)
  8. baseEnv = null;
  9. var hasTnvite;
  10. var members = {};
  11. var isConsulted = false;
  12. var $tabs = $(".tab-hd"),
  13. $teamListWrapper = $("#team_doctor_list_wrap"),
  14. $famousListWrapper = $("#famous_doctor_list_wrap"),
  15. $zhuankeListWrapper = $("#zhuanke_list_wrap"),
  16. $teamDoctorList = $("#team_doctor_list"),
  17. $famousList = $("#famous_list"),
  18. $zhuankeList = $("#zhuanke_list"),
  19. // 搜索无结果时显示
  20. $teamNoResultWrap = $('#team_no_result_wrap'),
  21. $famouNoResultWrap = $('#famous_no_result_wrap'),
  22. $zhuankeNoResultWrap = $('#zhuanke_no_result_wrap'),
  23. $zhuankeSearchBar = $('#zhuanke_searchbar');
  24. // iscroll 滚动条实例
  25. var t_iscroller, //团队
  26. f_iscroller, //名医
  27. z_iscroller, //专科
  28. //当前选中tab
  29. curType,
  30. //保存页面数据
  31. teamDoctorObj,
  32. famousObj,
  33. zhuankeObj,
  34. f_lastPage = false,
  35. z_lastPage = false;
  36. var self;
  37. // 获取基本信息(包括userAgent、上个页面传递的数据)
  38. var getBaseInfoPromise = function() {
  39. self = plus.webview.currentWebview();
  40. // 登录的相关信息
  41. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  42. return {
  43. userAgent: userAgent,
  44. // 上一个页面传递的数据
  45. accessData: baseEnv.webview.accessData
  46. }
  47. },
  48. // 获取基础环境信息
  49. getBaseEnvPromise = function () {
  50. var env = {
  51. webview: plus&&plus.webview.currentWebview()
  52. };
  53. return Promise.resolve().then(function(res) {
  54. return env;
  55. });
  56. },
  57. //初始化
  58. initPage = function(){
  59. var self = plus.webview.currentWebview();
  60. var type = curType || self.type || 0;
  61. initTeamInfo(1);
  62. // $tabs.find(".sanp-flex").eq(type).click();
  63. //获得求助医生列表
  64. getGroupDoctors();
  65. },
  66. /*获得求助医生列表*/
  67. getGroupDoctors = function(){
  68. var url = "/doctor/consult/forHelpDocs",
  69. params = {consult: baseInfo.accessData.consultCode};
  70. getReqPromise(url, params).then(function(datas) {
  71. if(datas.status==200){
  72. members = datas.data;
  73. for(var k in members){
  74. isConsulted = true;
  75. break;
  76. }
  77. } else {
  78. mui.toast("程序开了点小差, 请稍后重试!");
  79. throw new Error("查询求助过的医生列表失败");
  80. }
  81. }).catch(function(e){
  82. console && console.error(e);
  83. });
  84. },
  85. /*团队医生处理*/
  86. initTeamInfo = function(curPage){
  87. var url = "/doctor/family_contract/consult_doctors",
  88. params = {sessionId : self.sessionId}; //不分页
  89. getReqPromise(url, params).then(function(res) {
  90. if(!t_iscroller) {
  91. t_iscroller = $teamListWrapper.initScroll({pullDown: false, pullUp: false});
  92. }
  93. if(!res.data || !res.data.teamDoctors.length) {
  94. $teamListWrapper.hide();
  95. $teamNoResultWrap.show();
  96. $('.posater-oper').eq(0).show();
  97. } else {
  98. $teamNoResultWrap.hide();
  99. $teamListWrapper.show();
  100. $('.posater-oper').eq(0).show();
  101. teamDoctorObj = res;
  102. //获得责任医生信息
  103. if(res.hasOwnProperty("dutyDoctor")){
  104. var tempList = [];
  105. tempList.push(res.dutyDoctor);
  106. var html = template('doctor_li_tmpl', {list : tempList});
  107. $teamDoctorList.append('<p class="c-f14 mt10 c-909090">责任医生</p>'+html);
  108. }
  109. var p = '<p class="c-f14 mt10 c-909090">团队内其他医生</p>';
  110. var html = template('doctor_li_tmpl',{list : res.data.teamDoctors});
  111. $teamDoctorList.append(p+html);
  112. }
  113. t_iscroller.refresh();
  114. plus.nativeUI.closeWaiting();
  115. }).catch(function(e){
  116. mui.toast(e.msg);
  117. });
  118. },
  119. /*名医处理*/
  120. initFamousInfo = function(curPage){
  121. // TODO 示例示例搜索参数
  122. // id: 上次搜索结果列表最后一条记录id,type:1(1:名医,0:非名医,key:搜素关键字,pagesize:每页条数
  123. var url = "doctor/consult/famousDoctorList",
  124. params = { type:1,page:curPage,pagesize:15};
  125. getReqPromise(url,params).then(function(res){
  126. if(!f_iscroller) {
  127. f_iscroller = $famousListWrapper.initScroll({pullDownAction: function(){
  128. initFamousInfo(1);
  129. },pullUp: false});
  130. }
  131. if(!res.list || !res.list.length) {
  132. f_lastPage = true;
  133. $famousListWrapper.hide();
  134. $famouNoResultWrap.show();
  135. } else {
  136. famousObj = res;
  137. $famouNoResultWrap.hide();
  138. $famousListWrapper.show();
  139. appendMembers({list: _.map(res.list,function(o) {
  140. if(members[o.code]){
  141. o.asked = true;
  142. }
  143. return o;
  144. })}, 'doctor_li_tmpl','famous_list',true);
  145. }
  146. f_iscroller.refresh();
  147. plus.nativeUI.closeWaiting();
  148. }).catch(function(e) {
  149. mui.toast(e.msg);
  150. });
  151. },
  152. /*专科医生处理*/
  153. initZhuankeInfo = function(curPage){
  154. var url = "/doctor/hospitals_list",
  155. params = { city:"350200",type:1,page:curPage,pagesize:15};
  156. getReqPromise(url,params).then(function(res){
  157. if(!z_iscroller) {
  158. z_iscroller = initScroller($zhuankeListWrapper,url,
  159. function() { // 传递分页参数
  160. return $.extend({},params,{page:curPage+1});
  161. },
  162. //下拉刷新处理
  163. function(){
  164. initZhuankeInfo(1);
  165. },
  166. function(data) {
  167. if(data.data && data.data.length) {
  168. curPage++;
  169. }
  170. if(data.data.length < 15){
  171. z_lastPage = true;
  172. }
  173. appendMembers(data, 'hospital_li_tmpl','zhuanke_list',false);
  174. z_iscroller.refresh();
  175. }, z_lastPage);
  176. }
  177. if(!res.data || !res.data.length) {
  178. $zhuankeListWrapper.hide();
  179. $zhuankeSearchBar.hide();
  180. $zhuankeNoResultWrap.show();
  181. } else {
  182. zhuankeObj = res;
  183. $zhuankeNoResultWrap.hide();
  184. $zhuankeSearchBar.show();
  185. $zhuankeListWrapper.show();
  186. appendMembers(res, 'hospital_li_tmpl','zhuanke_list',true);
  187. }
  188. z_iscroller.refresh();
  189. plus.nativeUI.closeWaiting();
  190. }).catch(function(e) {
  191. mui.toast(e.msg);
  192. });
  193. },
  194. // 滚动条分页实例初始化
  195. initScroller = function($el,url,getData,pullDownAction,pullUpAction,is_lastPage) {
  196. var scroller = $el.initScroll({pullDownAction: function(){
  197. if(pullDownAction && $.isFunction(pullDownAction)) {
  198. pullDownAction();
  199. }
  200. },pullUpAction: function() {
  201. if(!is_lastPage){
  202. var data = getData();
  203. getReqPromise(url,data).then(function(data) {
  204. if(pullUpAction && $.isFunction(pullUpAction)) {
  205. pullUpAction(data);
  206. updatePullUpText(scroller,data.list);
  207. }
  208. })
  209. }else{
  210. updatePullUpText(scroller,[]);
  211. return false;
  212. }
  213. }});
  214. return scroller;
  215. },
  216. // 更新分页上拉加载的提示文本
  217. updatePullUpText= function(scroller,list) {
  218. var $wrap = $(scroller.wrapper),
  219. $pullupLabel = $wrap.find('.pullUpLabel');
  220. if(!list || !list.length) {
  221. // $wrap.find(".pullUp").hide();
  222. $pullupLabel.text('没有更多');
  223. } else if(list.length<15){
  224. // $wrap.find(".pullUp").hide();
  225. $pullupLabel.text('没有更多');
  226. }else {
  227. $pullupLabel.text('上拉加载更多');
  228. }
  229. scroller.on('refresh',function() {
  230. if(!list || !list.length) {
  231. // $wrap.find(".pullUp").hide();
  232. $pullupLabel.text('没有更多');
  233. } else if(list.length<15){
  234. // $wrap.find(".pullUp").hide();
  235. $pullupLabel.text('没有更多');
  236. } else {
  237. $pullupLabel.text('上拉加载更多');
  238. }
  239. });
  240. },
  241. appendMembers = function(data, tmplId, ulId, isRefresh){
  242. var html = template(tmplId, data);
  243. if(isRefresh){
  244. $('#'+ulId).empty().html(html);
  245. } else{
  246. $('#'+ulId).append(html);
  247. }
  248. },
  249. //绑定事件
  250. bindEvents = function(){
  251. $tabs.on('click', '.sanp-flex', function(){
  252. $tabs.find(".sanp-flex").removeClass("curr");
  253. $(this).addClass("curr");
  254. curType = $(this).index();
  255. plus.nativeUI.showWaiting("加载中,请稍候...");
  256. $(".posater-oper").hide().eq(curType).show();
  257. switch (curType) {
  258. case 0:
  259. if (teamDoctorObj) {
  260. plus.nativeUI.closeWaiting();
  261. } else {
  262. initTeamInfo(1);
  263. }
  264. break;
  265. case 1:
  266. if (famousObj) {
  267. plus.nativeUI.closeWaiting();
  268. } else {
  269. initFamousInfo(1);
  270. }
  271. break;
  272. case 2:
  273. if (zhuankeObj) {
  274. plus.nativeUI.closeWaiting();
  275. } else {
  276. initZhuankeInfo(1);
  277. }
  278. break;
  279. }
  280. });
  281. $zhuankeList.on('click', 'li', function(){
  282. mui.openWindow({
  283. url:"hospital_dept.html",
  284. id: "hospital_dept",
  285. extras: {
  286. accessData:{
  287. hospitalId: $(this).attr("data-code"),
  288. consultCode: self.consultInfo.consult,
  289. patient: self.consultInfo.patient
  290. },
  291. aa: self.aa,
  292. members: members,
  293. consultInfo: self.consultInfo,
  294. isConsulted: isConsulted
  295. }
  296. });
  297. });
  298. $zhuankeSearchBar.on('click', 'input', function(){
  299. mui.openWindow({
  300. url:"search_doctor.html",
  301. id:"search_doctor",
  302. extras: {
  303. accessData:{
  304. consultCode: self.consultInfo.consult,
  305. patient: self.consultInfo.patient
  306. },
  307. aa: self.aa,
  308. members: members,
  309. consultInfo: self.consultInfo,
  310. isConsulted: isConsulted
  311. }
  312. });
  313. });
  314. $("#cy_btn").on('click',function(){
  315. mui.openWindow({
  316. url:"changyong_doctor.html",
  317. id:"changyong_doctor",
  318. extras: {
  319. openId: self.opener().id,
  320. type: 2,
  321. aa: self.aa,
  322. members: members,
  323. consultInfo: self.consultInfo,
  324. isConsulted: isConsulted
  325. }
  326. });
  327. });
  328. };
  329. // 页面业务处理流程开始
  330. new Promise(function(resolve, reject) {
  331. // TODO 临时放开
  332. //resolve(true);
  333. mui.plusReady(function() {
  334. // plus已经准备好,可以往下执行
  335. resolve(true);
  336. });
  337. }).then(function() {
  338. plus.nativeUI.showWaiting();
  339. // 获取基础环境信息
  340. return getBaseEnvPromise().then(function(env) {
  341. baseEnv = env;
  342. }).then(function() {
  343. // 获取登录医生信息
  344. baseInfo = getBaseInfoPromise();
  345. initPage();
  346. //绑定页面事件
  347. bindEvents();
  348. plus.nativeUI.closeWaiting();
  349. })
  350. }).catch(function(e) {
  351. plus.nativeUI.closeWaiting();
  352. console && console.error(e);
  353. });
  354. template.helper("setHosPhoto", function(p) {
  355. if(!p || p == ""){
  356. return '../images/hospital_default.png';
  357. }
  358. return getImgUrl(p);
  359. });