xinzengmingyi.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. // 登录者相关信息(包括userAgent)
  2. var loginerInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. var $orgTab = $('#org_tab'),
  6. $orgList = $('#org_list'),
  7. $views = $('.dest-view'),
  8. $yiyuanView = $('#yiyuan_view'),
  9. $shequView = $('#shequ_view'),
  10. $yiyuanList = $('#yiyuan_list'),
  11. $shequList = $('#shequ_list'),
  12. // 搜索输入框
  13. $searchbarInput = $('.searchbar input'),
  14. // 搜索无结果时显示
  15. $noResultWrap = $('#no_result_wrap');
  16. // ”医院”列表分页查询最后一条记录Id
  17. var yiyuanLastId = 0,
  18. // ”社区”列表分页查询最后一条记录Id
  19. shequLastId = 0,
  20. // ”医院”列表iscroll 滚动条实例
  21. yiyuanIscroller,
  22. // ”社区”列表iscroll 滚动条实例
  23. shequIscroller;
  24. // 获取登录相关信息
  25. var getLoginerInfo = function() {
  26. // 登录的相关信息
  27. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  28. return {
  29. userAgent: userAgent
  30. }
  31. },
  32. // 获取基础环境信息
  33. getBaseEnvPromise = function () {
  34. var env = {
  35. webview: plus&&plus.webview.currentWebview()
  36. };
  37. return Promise.resolve().then(function(res) {
  38. return env;
  39. });
  40. },
  41. // 初始化医院列表
  42. initYiYuanViewList = function(data) {
  43. var html = template("org_li_tmpl", {list: data.list})
  44. $yiyuanList.append(html);
  45. },
  46. // 初始化社区列表
  47. initSheQuViewList = function(data) {
  48. var html = template("org_li_tmpl", {list: data.list})
  49. $shequList.append(html);
  50. },
  51. // "医院"分页查询列表
  52. searchYiYuanByPaging = function () {
  53. plus.nativeUI.showWaiting();
  54. // TODO 示例示例搜索参数
  55. // id: 上次搜索结果列表最后一条记录id,type:1(医院),query:搜素关键字,pagesize:每页条数
  56. var url = "doctor/hospitals",
  57. params = { id:0, pagesize:15,type:1 };
  58. getReqPromise(url,params).then(function(res){
  59. // TODO 测试示例数据
  60. //data = communitiesData;
  61. if(res.status == 200) {
  62. var data = res;
  63. yiyuanLastId = getLastId(data);
  64. if(!yiyuanIscroller) {
  65. yiyuanIscroller = initScroller($yiyuanView,url,
  66. function() { // 传递分页参数
  67. return $.extend({},params,{id:yiyuanLastId});
  68. },function(data) {
  69. yiyuanLastId = getLastId(data) || yiyuanLastId;
  70. initYiYuanViewList(data);
  71. yiyuanIscroller.refresh();
  72. });
  73. }
  74. if(!data.list || !data.list.length) {
  75. $yiyuanView.hide();
  76. $noResultWrap.show();
  77. } else {
  78. $noResultWrap.hide();
  79. initYiYuanViewList(data);
  80. }
  81. yiyuanIscroller.refresh();
  82. } else {
  83. mui.toast(res.msg);
  84. }
  85. plus.nativeUI.closeWaiting();
  86. }).catch(function(e) {
  87. plus.nativeUI.closeWaiting();
  88. console && console.error(e)
  89. });
  90. },
  91. // "社区"分页查询列表
  92. searchSheQuByPaging = function () {
  93. plus.nativeUI.showWaiting();
  94. // TODO 示例示例搜索参数
  95. // id: 上次搜索结果列表最后一条记录id,type:2(社区),query:搜素关键字,pagesize:每页条数
  96. var url = "doctor/hospitals",
  97. params = { id:0, pagesize:15,type:2 };
  98. getReqPromise(url,params).then(function(res){
  99. // TODO 测试示例数据
  100. // data = communitiesData;
  101. if(res.status == 200) {
  102. var data = res;
  103. shequLastId = getLastId(data);
  104. if(!shequIscroller) {
  105. shequIscroller = initScroller($shequView,url,
  106. function() { // 传递分页参数
  107. return $.extend({},params,{id:shequLastId});
  108. },function(data) {
  109. shequLastId = getLastId(data) || shequLastId;
  110. initSheQuViewList(data);
  111. shequIscroller.refresh();
  112. });
  113. }
  114. if(!data.list || !data.list.length) {
  115. $shequView.hide();
  116. $noResultWrap.show();
  117. } else {
  118. $noResultWrap.hide();
  119. initSheQuViewList(data);
  120. }
  121. shequIscroller.refresh();
  122. } else {
  123. mui.toast(res.msg);
  124. }
  125. plus.nativeUI.closeWaiting();
  126. }).catch(function(e) {
  127. plus.nativeUI.closeWaiting();
  128. console && console.error(e)
  129. });
  130. }
  131. // 滚动条分页实例初始化
  132. initScroller = function($el,url,getData,pullUpAction) {
  133. var scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
  134. var data = getData();
  135. getReqPromise(url,data).then(function(data) {
  136. if(pullUpAction && $.isFunction(pullUpAction)) {
  137. pullUpAction(data);
  138. }
  139. updatePullUpText(scroller,data.list);
  140. })
  141. }});
  142. return scroller;
  143. },
  144. // 获取分页搜索返回的最后一条记录的id
  145. getLastId = function(data) {
  146. var lastObj = data.list && data.list.length && data.list[data.list.length-1];
  147. // 最后一条记录
  148. if(lastObj) {
  149. return lastObj.id;
  150. } else {
  151. return null
  152. }
  153. },
  154. // 更新分页上拉加载的提示文本
  155. updatePullUpText= function(scroller,list) {
  156. var $wrap = $(scroller.wrapper),
  157. $pullupLabel = $wrap.find('.pullUpLabel');
  158. if(!list || !list.length) {
  159. $pullupLabel.text('没有更多');
  160. } else if(list.length==15){
  161. $pullupLabel.text('上拉加载更多');
  162. }
  163. if(list.length<15){
  164. $wrap.find('.pullUp').hide();
  165. }
  166. scroller.on('refresh',function() {
  167. if(!list || !list.length) {
  168. $pullupLabel.text('没有更多');
  169. } else if(list.length==15){
  170. $pullupLabel.text('上拉加载更多');
  171. }
  172. if(list.length<15){
  173. $wrap.find('.pullUp').hide();
  174. }
  175. });
  176. },
  177. // 绑定页面事件
  178. bindEvents = function () {
  179. $orgTab.on('click','li',function() {
  180. var type = $(this).attr('data-type');
  181. $orgTab.find('li').removeClass('curr');
  182. $('.dest-view').hide();
  183. $(this).addClass('curr');
  184. $('#'+type).show();
  185. });
  186. $views.on('tap','li',function() {
  187. mui.openWindow({
  188. url:"xuanzekeshi.html",
  189. id:"xuanzekeshi",
  190. // 跳转页面传参
  191. extras: {
  192. accessData:{ // 传递数据
  193. hospital: $(this).attr('data-code') || ""
  194. }
  195. }});
  196. });
  197. $searchbarInput.on('tap',function() {
  198. var toWebview = plus.webview.getWebviewById("sousuojigouyisheng");
  199. var createNew = !!toWebview;
  200. createNew && toWebview.close();
  201. mui.openWindow({
  202. url:"sousuojigouyisheng.html",
  203. id:"sousuojigouyisheng",
  204. createNew: true
  205. });
  206. });
  207. };
  208. // 页面业务处理流程开始
  209. new Promise(function(resolve, reject) {
  210. // TODO 临时放开
  211. // resolve(true);
  212. mui.plusReady(function() {
  213. // TODO 此处返回重写为"mingyiguanli",发现其有时会back到"xinzengmingyi",导致出错无法返回
  214. mui.back = function () {
  215. var myglWebview = plus.webview.getWebviewById("mingyiguanli");
  216. if(myglWebview) {
  217. mui.fire(myglWebview,"refreshPage");
  218. }
  219. return backToWebviewById('mingyiguanli');
  220. }();
  221. // plus已经准备好,可以往下执行
  222. resolve(true);
  223. });
  224. }).then(function() {
  225. // 获取基础环境信息
  226. return getBaseEnvPromise().then(function(env) {
  227. baseEnv = env;
  228. }).then(function() {
  229. // 获取登录医生信息
  230. loginerInfo = getLoginerInfo();
  231. searchYiYuanByPaging();
  232. searchSheQuByPaging();
  233. // 绑定页面事件
  234. bindEvents();
  235. })
  236. }).catch(function(e) {
  237. plus.nativeUI.closeWaiting();
  238. console && console.error(e);
  239. });
  240. template.helper("setHosPhoto", function(p) {
  241. if(!p || p == ""){
  242. return '../images/hospital_default.png';
  243. }
  244. return getImgUrl(p);
  245. });