yongyaojilu.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. // 基本信息(包括userAgent、上个页面传递的数据)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. var $zhenliaoListWrapper = $('#zhenliao_list_wrap'),
  6. $zhenliaoList = $('#zhenliao_list'),
  7. $zixingListWrapper = $('#zixing_list_wrap'),
  8. $zixingList = $('#zixing_list'),
  9. $tabs = $('.sign-comonhd'),
  10. // 搜索无结果时显示
  11. $noResultWrap = $('#no_result_wrap');
  12. // 分页查询当前页数
  13. var curPage = 1,
  14. // iscroll 滚动条实例
  15. zhenLiaoIscroller,
  16. zixingIscroller;
  17. template.helper("toJson", function(v, i) {
  18. return JSON.stringify(v);
  19. });
  20. // 获取基本信息(包括userAgent、上个页面传递的数据)
  21. var getBaseInfoPromise = function() {
  22. // 登录的相关信息
  23. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  24. return {
  25. userAgent: userAgent,
  26. patiInfo: baseEnv.webview.patiInfo
  27. }
  28. },
  29. // 获取基础环境信息
  30. getBaseEnvPromise = function () {
  31. var env = {
  32. webview: plus&&plus.webview.currentWebview()
  33. };
  34. return Promise.resolve().then(function(res) {
  35. return env;
  36. });
  37. },
  38. // 初始化诊疗用药列表
  39. initZhenLiaoYongYaoList = function(list) {
  40. var html = template("zhenliao_tmpl", {list: _.map(list,function(v) {
  41. v.belongCatalogName = (_.values(v.CATALOG)[0] || "").slice(0,2);
  42. return v;
  43. })})
  44. $zhenliaoList.append(html);
  45. },
  46. // 初始化自行用药列表
  47. initZiXingYongYaoList = function(list) {
  48. var html = template("zixing_tmpl", {list: list})
  49. $zixingList.append(html);
  50. },
  51. // 诊疗用药分页查询列表
  52. searchZhenLiaoYongYaoByPaging = function () {
  53. var url = healthProfileServer+"doctor/archives/event/drug",
  54. curPage = 1,
  55. pagesize = 50,
  56. // params = {
  57. // strSSID: baseInfo.patiInfo.ssc,
  58. // startNum: (curPage-1) * pagesize,
  59. // endNum: curPage * pagesize
  60. // };
  61. params = {
  62. patient: baseInfo.patiInfo.code,
  63. page: curPage,
  64. pageSize: pagesize
  65. }
  66. getReqPromise(url,params,'GET').then(function(res){
  67. plus.nativeUI.closeWaiting();
  68. if(res.status == 200) {
  69. curPage++;
  70. var data = JSON.parse(res.data),
  71. list = data.EhrList;
  72. if(!list|| !list.length) {
  73. $zhenliaoListWrapper.hide();
  74. if($tabs.find('.sanp-flex.curr').index() == 0) {
  75. $noResultWrap.show();
  76. }
  77. } else {
  78. if($tabs.find('.sanp-flex.curr').index() == 0) {
  79. $noResultWrap.hide();
  80. }
  81. if(!zhenLiaoIscroller) {
  82. zhenLiaoIscroller = initScroller($zhenliaoListWrapper,url,
  83. function() { // 传递分页参数
  84. return $.extend({},params,{page: curPage});
  85. },function(res) {
  86. if(res.status == 200) {
  87. if(res.data.length==0){ //cy
  88. $(".pullUp").hide()
  89. }else{
  90. var data = JSON.parse(res.data),
  91. list = data.EhrList;
  92. if(list && list.length) {
  93. curPage++;
  94. }
  95. initZhenLiaoYongYaoList(list);
  96. zhenLiaoIscroller.refresh();
  97. }
  98. } else {
  99. mui.toast(res.msg);
  100. }
  101. });
  102. }
  103. $zhenliaoListWrapper.show();
  104. initZhenLiaoYongYaoList(list);
  105. }
  106. } else {
  107. mui.toast(res.msg);
  108. }
  109. zhenLiaoIscroller && zhenLiaoIscroller.refresh();
  110. }).catch(function(e) {
  111. plus.nativeUI.closeWaiting();
  112. console && console.error(e)
  113. });
  114. },
  115. // 自行用药分页查询列表
  116. searchZiXingYaoByPaging = function () {
  117. var url = "doctor/health_record/list_medication",
  118. curPage = 1,
  119. pagesize = 20,
  120. params = {
  121. // patient: "03b4965a075048f2a667652d5aea7b6f",
  122. patient: baseInfo.patiInfo.code,
  123. page: curPage,
  124. pagesize: pagesize,
  125. sortDate: (function() {
  126. var date = new Date();
  127. return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' 23:59:59';
  128. })()
  129. },
  130. laseSortDate = params.sortDate;
  131. getReqPromise(url,params,'GET').then(function(res){
  132. if(res.status == 200) {
  133. var list = res.list;
  134. if(!list|| !list.length) {
  135. $zixingListWrapper.hide();
  136. if($tabs.find('.sanp-flex.curr').index() == 1) {
  137. $noResultWrap.show();
  138. }
  139. } else {
  140. laseSortDate = list[list.length -1].sortDate;
  141. if($tabs.find('.sanp-flex.curr').index() == 1) {
  142. $noResultWrap.hide();
  143. }
  144. if(!zixingIscroller) {
  145. zixingIscroller = initScroller($zixingListWrapper,url,
  146. function() { // 传递分页参数
  147. return $.extend({},params,{page: curPage+1,sortDate: laseSortDate});
  148. },function(res) {
  149. if(res.status == 200) {
  150. var list = res.list;
  151. if(list && list.length) {
  152. laseSortDate = list[list.length -1].sortDate;
  153. curPage++;
  154. }
  155. initZiXingYongYaoList(list);
  156. if(list.length < pagesize){
  157. $(".pullUp").hide();
  158. }else{
  159. $(".pullUp").show();
  160. }
  161. zixingIscroller.refresh();
  162. } else {
  163. mui.toast(res.msg);
  164. }
  165. });
  166. }
  167. initZiXingYongYaoList(list);
  168. }
  169. if(list.length < pagesize){
  170. $(".pullUp").hide();
  171. }else{
  172. $(".pullUp").show();
  173. }
  174. zixingIscroller && zixingIscroller.refresh();
  175. } else {
  176. mui.toast(res.msg);
  177. }
  178. }).catch(function(e) {
  179. console && console.error(e)
  180. });
  181. },
  182. // 滚动条分页实例初始化
  183. initScroller = function($el,url,getData,pullUpAction) {
  184. var scroller = $el.initScroll({pullDown: false,pullUpAction: function() {
  185. var data = getData();
  186. getReqPromise(url,data,'GET').then(function(data) {
  187. if(pullUpAction && $.isFunction(pullUpAction)) {
  188. pullUpAction(data);
  189. updatePullUpText(scroller,data.list);
  190. }
  191. })
  192. }});
  193. return scroller;
  194. },
  195. // 更新分页上拉加载的提示文本
  196. updatePullUpText= function(scroller,list) {
  197. var $wrap = $(scroller.wrapper),
  198. $pullupLabel = $wrap.find('.pullUpLabel');
  199. if(!list || !list.length) {
  200. $pullupLabel.text('没有更多');
  201. } else {
  202. $pullupLabel.text('上拉加载更多');
  203. }
  204. scroller.on('refresh',function() {
  205. if(!list || !list.length) {
  206. $pullupLabel.text('没有更多');
  207. } else {
  208. $pullupLabel.text('上拉加载更多');
  209. }
  210. });
  211. },
  212. // 绑定页面事件
  213. bindEvents = function () {
  214. $zhenliaoList.on('click','li',function() {
  215. var data = JSON.parse($(this).attr("data-json"));
  216. openWebview("single-profile.html",{eventInfo: {
  217. id: data.EVENT,
  218. catalogCode: data.CATALOG_CODE,
  219. type: (function() {
  220. if(data.TYPE=="1"){
  221. return "门诊";
  222. } else if(data.TYPE=="2"){
  223. return "住院";
  224. }
  225. })(),
  226. serial: data.SERIAL
  227. },patiInfo: baseInfo.patiInfo});
  228. });
  229. $tabs.on('click','.sanp-flex',function() {
  230. var index = $(this).index();
  231. $(this).siblings().removeClass('curr');
  232. $(this).addClass('curr');
  233. if(index==0) {
  234. $zixingListWrapper.hide();
  235. if($zhenliaoList.find('li').length == 0) {
  236. $noResultWrap.show();
  237. } else {
  238. $noResultWrap.hide();
  239. }
  240. $zhenliaoListWrapper.show();
  241. } else if(index == 1) {
  242. $zhenliaoListWrapper.hide();
  243. if($zixingList.find('li.li-item').length == 0) {
  244. $zixingListWrapper.hide();
  245. $noResultWrap.show();
  246. } else {
  247. $noResultWrap.hide();
  248. $zixingListWrapper.show();
  249. }
  250. }
  251. });
  252. };
  253. // 页面业务处理流程开始
  254. new Promise(function(resolve, reject) {
  255. // TODO 临时放开
  256. //resolve(true);
  257. mui.plusReady(function() {
  258. // plus已经准备好,可以往下执行
  259. resolve(true);
  260. });
  261. }).then(function() {
  262. plus.nativeUI.showWaiting();
  263. // 获取基础环境信息
  264. return getBaseEnvPromise().then(function(env) {
  265. baseEnv = env;
  266. }).then(function() {
  267. // 获取登录医生信息
  268. baseInfo = getBaseInfoPromise();
  269. searchZhenLiaoYongYaoByPaging();
  270. searchZiXingYaoByPaging();
  271. // 绑定页面事件
  272. bindEvents();
  273. })
  274. }).catch(function(e) {
  275. plus.nativeUI.closeWaiting();
  276. console && console.error(e);
  277. });