jiankangtijian.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // 基本信息(包括userAgent、上个页面传递的数据)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. var $eventListWrapper = $('#recent_event_list_wrap'),
  6. $eventList = $('#recent_event_list'),
  7. // 搜索无结果时显示
  8. $noResultWrap = $('#no_result_wrap');
  9. // 分页查询当前页数
  10. var curPage = 1,
  11. pagesize = 50, //实际接口并没有分页
  12. // iscroll 滚动条实例
  13. iscroller;
  14. template.helper("toJson", function(v, i) {
  15. return JSON.stringify(v);
  16. });
  17. // 获取基本信息(包括userAgent、上个页面传递的数据)
  18. var getBaseInfoPromise = function() {
  19. // 登录的相关信息
  20. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  21. return {
  22. userAgent: userAgent,
  23. patiInfo: baseEnv.webview.patiInfo
  24. }
  25. },
  26. // 获取基础环境信息
  27. getBaseEnvPromise = function () {
  28. var env = {
  29. webview: plus&&plus.webview.currentWebview()
  30. };
  31. return Promise.resolve().then(function(res) {
  32. return env;
  33. });
  34. },
  35. // 分页查询列表
  36. searchByPaging = function (isInit) {
  37. plus.nativeUI.showWaiting();
  38. var url = healthProfileServer+"doctor/health_record/list_medical",
  39. params = {
  40. patient: baseInfo.patiInfo.code,
  41. pageIndex: curPage,
  42. pageSize: pagesize
  43. };
  44. if(isInit){
  45. curPage = 1;
  46. }
  47. getReqPromise(url,params,'POST').then(function(res){
  48. if(res.status == 200) {
  49. var list = res.list;
  50. if(!list || !list.length) {
  51. $eventList.hide();
  52. $noResultWrap.show();
  53. checkIsReminded();
  54. } else {
  55. $noResultWrap.hide();
  56. $eventList.show();
  57. var html = template("recent_event_tmpl", {list: list});
  58. if(isInit){
  59. if(list.length > 0){
  60. var zuiyinTime = list[0].medicalTime.toString().split(" ")[0];
  61. var days = tab(zuiyinTime,new Date());
  62. if(days >= 365){
  63. checkIsReminded();
  64. }else{
  65. $("#jktj_tx").hide();
  66. }
  67. }
  68. $eventList.empty().append(html);
  69. }else{
  70. $eventList.append(html);
  71. }
  72. if(list.length == pagesize){
  73. curPage ++;
  74. }else{
  75. mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(true);
  76. }
  77. }
  78. } else {
  79. mui.toast(res.msg);
  80. }
  81. plus.nativeUI.closeWaiting();
  82. }).catch(function(e) {
  83. console && console.error(e)
  84. });
  85. },
  86. // 滚动条分页实例初始化
  87. initScroller = function() {
  88. //阻尼系数
  89. var deceleration = mui.os.ios?0.003:0.0009;
  90. mui('.mui-scroll-wrapper').scroll({
  91. bounce: false,
  92. indicators: true, //是否显示滚动条
  93. deceleration:deceleration
  94. });
  95. iscroller = mui('.mui-scroll-wrapper').pullRefresh({
  96. down: {
  97. callback: function() {
  98. var self = this;
  99. setTimeout(function() {
  100. searchByPaging(true);
  101. self.endPulldownToRefresh();
  102. }, 500);
  103. }
  104. },
  105. /* 实际接口并没有处理分页
  106. up:{
  107. callback: function(){
  108. var self = this;
  109. setTimeout(function(){
  110. searchByPaging();
  111. self.endPullupToRefresh();
  112. }, 500);
  113. }
  114. }*/
  115. });
  116. },
  117. //判断是否7天内提醒过居民
  118. checkIsReminded = function(){
  119. var url = "/doctor/patient_label_info/isRemind",
  120. params = {patient: baseInfo.patiInfo.code};
  121. sendGet(url, params, null, function(res){
  122. if(res.status==200){
  123. //data 0表示没提醒过,1表示7天内已提醒过 2年龄不到65岁
  124. if(res.data == 0){
  125. $("#jktj_tx").html("提醒体检");
  126. }else if(res.data == 1){
  127. $("#jktj_tx").html("已提醒");
  128. }else if(res.data == 2){
  129. $("#jktj_tx").hide()
  130. }
  131. } else {
  132. mui.toast(res.msg);
  133. }
  134. });
  135. },
  136. // 绑定页面事件
  137. bindEvents = function () {
  138. $eventList.on('tap','li',function() {
  139. var data = JSON.parse($(this).attr("data-json"));
  140. openWebview("jiankangtijianxiangqing.html",{eventInfo: data,patiInfo: baseInfo.patiInfo});
  141. });
  142. $('#jktj_tx').on("tap", function(e){
  143. var url = "/doctor/patient_label_info/isRemind",
  144. params = {patient: baseInfo.patiInfo.code};
  145. sendGet(url, params, null, function(res){
  146. if(res.status==200){
  147. //data 0表示没有提醒过 1表示7天内提醒过
  148. if(res.data == 0){
  149. mui.confirm("是否向居民发送体检提醒消息?", "提示", ["立即提醒", "不了,谢谢"], function(e){
  150. if(e.index == 0){
  151. tixingJm();
  152. }
  153. })
  154. }else{
  155. mui.toast("七天内已提醒过该居民,请不要重复提醒");
  156. }
  157. } else {
  158. mui.toast(res.msg);
  159. }
  160. });
  161. })
  162. };
  163. function tab(date1,date2){
  164. var time =0;
  165. var days =0;
  166. var oDate1 = new Date(date1);
  167. var oDate2 = new Date(date2);
  168. start =oDate1.getTime();
  169. end =oDate2.getTime();
  170. time = end - start;
  171. days = Math.floor(time/86400000);
  172. return days;
  173. };
  174. function tixingJm(){
  175. plus.nativeUI.showWaiting();
  176. sendPost("/doctor/patient_label_info/singleRemindPhyExam", {patient: baseInfo.patiInfo.code}, null, function(res){
  177. plus.nativeUI.closeWaiting();
  178. if(res.status == 200){
  179. mui.toast("提醒成功");
  180. $('#jktj_tx').html("已提醒");
  181. }
  182. else {
  183. mui.toast(res.msg);
  184. }
  185. })
  186. }
  187. // 页面业务处理流程开始
  188. new Promise(function(resolve, reject) {
  189. // TODO 临时放开
  190. //resolve(true);
  191. mui.plusReady(function() {
  192. // plus已经准备好,可以往下执行
  193. resolve(true);
  194. });
  195. }).then(function() {
  196. // plus.nativeUI.showWaiting();
  197. // 获取基础环境信息
  198. return getBaseEnvPromise().then(function(env) {
  199. baseEnv = env;
  200. }).then(function() {
  201. // 获取登录医生信息
  202. baseInfo = getBaseInfoPromise();
  203. initScroller();
  204. searchByPaging(true);
  205. // 绑定页面事件
  206. bindEvents();
  207. })
  208. }).catch(function(e) {
  209. plus.nativeUI.closeWaiting();
  210. console && console.error(e);
  211. });