mingyiguanli.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // TODO 列表示例数据
  2. //var data = {"msg":"查询成功","list":[
  3. //{"id":"3502050100","consult":"",patient:"P123",photo:"",title:"",name:"张敏敏",jobName:"主任医师",expertise:"中医内科疾病,糖尿病慢性并发症;肿瘤手术后及放、化疗后中医药调理;脾肿瘤手术后及放、化疗中医药调理。",introduce:"无",deptName:"骨科",hospitalName:"厦门市第一医院",age:23,comment:"激光治疗红血丝治疗部位保持清洁,避免感染和摩擦;部位有痂皮的会自行脱落,不要手动进行抠除。",star:3,type:5,time:"2016-09-12 16:49:17",status:"",sex:0,doctorRead:""},
  4. //{"id":"3502050101","consult":"",patient:"P124",photo:"",title:"",name:"李佳佳",jobName:"主任医师",expertise:"中医内科疾病,糖尿病慢性并发症;肿瘤手术后及放、化疗后中医药调理;脾肿瘤手术后及放、化疗中医药调理。",introduce:"无",deptName:"骨科",hospitalName:"厦门市第一医院",age:23,age:23,comment:"激光治疗红血丝治疗部位保持清洁,避免感染和摩擦;部位有痂皮的会自行脱落,不要手动进行抠除。",star:3,type:5,time:"2016-09-13 16:49:17",status:"",sex:0,doctorRead:""},
  5. //{"id":"3502050102","consult":"",patient:"P124",photo:"",title:"",name:"李佳敏",jobName:"主任医师",expertise:"中医内科疾病,糖尿病慢性并发症;肿瘤手术后及放、化疗后中医药调理;脾肿瘤手术后及放、化疗中医药调理。",introduce:"无",deptName:"骨科",hospitalName:"厦门市第一医院",age:23,age:23,comment:"激光治疗红血丝治疗部位保持清洁,避免感染和摩擦;部位有痂皮的会自行脱落,不要手动进行抠除。",star:3,type:5,time:"2016-09-13 16:49:17",status:"",sex:0,doctorRead:""},
  6. //{"id":"3502050103","consult":"",patient:"P124",photo:"",title:"",name:"赵六",jobName:"主任医师",expertise:"中医内科疾病,糖尿病慢性并发症;肿瘤手术后及放、化疗后中医药调理;脾肿瘤手术后及放、化疗中医药调理。",introduce:"无",deptName:"骨科",hospitalName:"厦门市第一医院",age:23,age:23,comment:"激光治疗红血丝治疗部位保持清洁,避免感染和摩擦;部位有痂皮的会自行脱落,不要手动进行抠除。",star:3,type:5,time:"2016-09-13 16:49:17",status:"",sex:0,doctorRead:""}],"status":200};
  7. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  8. // var plus = null;
  9. // 基本信息(包括userAgent、上个页面传递的数据)
  10. var baseInfo = null,
  11. // 基础环境信息(包括当前webview)
  12. baseEnv = null;
  13. var $doctorListWrapper = $('#doctor_list_wrap'),
  14. $doctorList = $('#doctor_list'),
  15. $addMingyiBtn = $('#addMingyi_btn'),
  16. // 搜索无结果时显示
  17. $noResultWrap = $('#no_result_wrap');
  18. // 分页查询当前页数
  19. var curPage = 1,
  20. // iscroll 滚动条实例
  21. iscroller;
  22. // 获取基本信息(包括userAgent、上个页面传递的数据)
  23. var getBaseInfoPromise = function() {
  24. // 登录的相关信息
  25. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  26. return {
  27. userAgent: userAgent
  28. }
  29. },
  30. // 获取基础环境信息
  31. getBaseEnvPromise = function () {
  32. var env = {
  33. webview: plus&&plus.webview.currentWebview()
  34. };
  35. return Promise.resolve().then(function(res) {
  36. return env;
  37. });
  38. },
  39. ellipsisText = function ($el) {
  40. $el.ellipsis({ row: 2 });
  41. },
  42. // 初始化医生列表
  43. initDoctorList = function(data) {
  44. var html = template("yisheng_li_tmpl", {list: data.list})
  45. $doctorList.append(html);
  46. ellipsisText($doctorList.find('.c-dest-content'))
  47. },
  48. // 分页查询列表
  49. searchByPaging = function () {
  50. // TODO 示例示例搜索参数
  51. // id: 上次搜索结果列表最后一条记录id,type:1(1:名医,0:非名医,key:搜素关键字,pagesize:每页条数
  52. var url = "doctor/findFamousDoctor",
  53. params = { type:1,page:curPage,pagesize:15};
  54. getReqPromise(url,params).then(function(res){
  55. var data = res;
  56. if(!iscroller) {
  57. iscroller = initScroller($doctorListWrapper,url,
  58. function() { // 传递分页参数
  59. return $.extend({},params,{page:curPage+1});
  60. },function(data) {
  61. if(data.list && data.list.length) {
  62. curPage++;
  63. }
  64. initDoctorList(data);
  65. iscroller.refresh();
  66. });
  67. }
  68. if(!data.list || !data.list.length) {
  69. $doctorListWrapper.hide();
  70. $noResultWrap.show();
  71. } else {
  72. $noResultWrap.hide();
  73. $doctorListWrapper.show();
  74. initDoctorList(data);
  75. }
  76. iscroller.refresh();
  77. }).catch(function(e) {
  78. console && console.error(e)
  79. });
  80. },
  81. // 滚动条分页实例初始化
  82. initScroller = function($el,url,getData,pullUpAction) {
  83. var scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
  84. var data = getData();
  85. getReqPromise(url,data).then(function(data) {
  86. if(pullUpAction && $.isFunction(pullUpAction)) {
  87. pullUpAction(data);
  88. updatePullUpText(scroller,data.list);
  89. }
  90. })
  91. }});
  92. return scroller;
  93. },
  94. // 更新分页上拉加载的提示文本
  95. updatePullUpText= function(scroller,list) {
  96. var $wrap = $(scroller.wrapper),
  97. $pullupLabel = $wrap.find('.pullUpLabel');
  98. if(!list || !list.length) {
  99. $pullupLabel.text('没有更多');
  100. } else {
  101. $pullupLabel.text('上拉加载更多');
  102. }
  103. scroller.on('refresh',function() {
  104. if(!list || !list.length) {
  105. $pullupLabel.text('没有更多');
  106. } else {
  107. $pullupLabel.text('上拉加载更多');
  108. }
  109. });
  110. },
  111. // 绑定页面事件
  112. bindEvents = function () {
  113. $doctorList.on('click','.list-item',function() {
  114. var code = $(this).attr('data-code')||"";
  115. mui.openWindow({
  116. url: "doctor-homepage.html",
  117. id:"doctor-homepage",
  118. // 跳转页面传参
  119. extras: {
  120. accessData:{ // 传递数据
  121. doctor: code
  122. }
  123. }
  124. });
  125. });
  126. $addMingyiBtn.on('tap',function() {
  127. mui.openWindow({
  128. url: "xinzengmingyi.html",
  129. id:"xinzengmingyi"
  130. });
  131. });
  132. /*刷新事件*/
  133. window.addEventListener("refreshPage", function group(e) {
  134. $doctorList.empty();
  135. curPage = 1;
  136. searchByPaging();
  137. });
  138. };
  139. // 页面业务处理流程开始
  140. new Promise(function(resolve, reject) {
  141. // TODO 临时放开
  142. //resolve(true);
  143. mui.plusReady(function() {
  144. // plus已经准备好,可以往下执行
  145. resolve(true);
  146. });
  147. }).then(function() {
  148. // 获取基础环境信息
  149. return getBaseEnvPromise().then(function(env) {
  150. baseEnv = env;
  151. }).then(function() {
  152. // 获取登录医生信息
  153. baseInfo = getBaseInfoPromise();
  154. searchByPaging();
  155. // 绑定页面事件
  156. bindEvents();
  157. })
  158. }).catch(function(e) {
  159. plus.nativeUI.closeWaiting();
  160. console && console.error(e);
  161. });
  162. template.helper("setPhoto", function(p) {
  163. return getImgUrl(p);
  164. });