xinzengmingyi.js 7.7 KB

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