prescription-selection.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. var listPage = function(){
  2. var d = dialog({contentType:'load', skin:'bk-popup'});
  3. //设置变量标记选项的值
  4. var deseaseType = 0,
  5. startDate = '',
  6. endDate = '';
  7. var page = 0,
  8. pagesize = 10,
  9. recipeNo = 0; // 记录
  10. function pageInit(){
  11. getPrescriptionList(true);
  12. initScroller();
  13. bindEvents();
  14. }
  15. function getPrescriptionList(isInit){
  16. d.show();
  17. if(isInit){
  18. page = 0;
  19. //mui(".mui-scroll-wrapper").pullRefresh().scrollTo(0, 0, 1);
  20. }
  21. var url = 'patient/prescriptionInfo/getRecipeMasterList',
  22. params = {
  23. type: 1, //type: 1-查询处方,2-我的续方, 3-续方记录
  24. isRenewal: 1, //1: 可续方,2: 无过滤
  25. diagnosisCode: deseaseType, //0: 全部,1:高血压,2: 糖尿病
  26. startDate: startDate?startDate+' 00:00:00':startDate,
  27. endDate: endDate?endDate+' 23:59:59':endDate,
  28. page: page,
  29. size: pagesize
  30. // recipeNo:recipeNo
  31. };
  32. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  33. if(res.status == 200){
  34. d.close();
  35. if(res.data.list.length >0){
  36. $("#next").removeClass("disabled")
  37. $(".mui-scroll-wrapper").show();
  38. $(".div-no-info").hide();
  39. var list = _.map(res.data.list, function(o){
  40. o.jsonStr = JSON.stringify(o);
  41. var canXF = getXFStatus(o.prescriptionDt, o.createTime);
  42. o.canXF = canXF;
  43. recipeNo = o.code;
  44. return o;
  45. });
  46. var html = template("prescription_tmp", {list: list});
  47. if(!isInit){
  48. $("#prescriptionList").append(html);
  49. }else{
  50. $("#prescriptionList").empty().append(html);
  51. }
  52. if(res.data.list.length < pagesize){
  53. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  54. }else{
  55. page ++;
  56. }
  57. }else{
  58. if(isInit){ //初始请求,无数据
  59. $(".mui-scroll-wrapper").hide();
  60. $(".div-no-info").show();
  61. $("#next").hide();
  62. }else{
  63. $("#next").addClass("disabled");
  64. }
  65. }
  66. }else{
  67. queryFailed(res);
  68. }
  69. });
  70. }
  71. function getXFStatus(arr, date){
  72. var isXFDesease = true,
  73. statusName = '',
  74. canXF = false;
  75. if(arr){
  76. for(i=0; i<arr.length; i++){
  77. var item = arr[i];
  78. //HP0093 - 高血压 , HP0047 - 糖尿病
  79. if((item.healthProblem != 'HP0093') && (item.healthProblem != 'HP0047')){
  80. isXFDesease = false;
  81. break;
  82. }
  83. }
  84. if(isXFDesease){
  85. //判断时间是否是在6个月内的
  86. // var d = new Date(date),
  87. // now = new Date();
  88. // now.setMonth(now.getMonth() - 2);
  89. //
  90. // if(d > now){ //6个月内的时间
  91. statusName = '续方';
  92. canXF = true;
  93. // }
  94. }
  95. }
  96. return canXF;
  97. }
  98. /**
  99. * 根据选择的时间类型获取开始和结束时间
  100. */
  101. function getDate(type){
  102. var now = new Date(),
  103. d = new Date();
  104. switch (type){
  105. case 'all':
  106. startDate = '';
  107. endDate = "";
  108. break;
  109. case 'week':
  110. d.setDate(d.getDate() - 6);
  111. break;
  112. case 'month':
  113. d.setMonth(d.getMonth() - 1);
  114. d.setDate(d.getDate() + 1);
  115. break;
  116. case 'half-year':
  117. d.setMonth(d.getMonth() - 2);
  118. d.setDate(d.getDate() + 1);
  119. break;
  120. }
  121. if(type != 'all'){
  122. endDate = now.Format('yyyy-MM-dd');
  123. startDate = d.Format('yyyy-MM-dd');
  124. }
  125. }
  126. function bindEvents(){
  127. $(".c-lab-mor").on("click","li",function(){
  128. var index = $(this).index();
  129. $(".c-lab-mor li i").removeClass("active");
  130. $(this).find("i").addClass("active");
  131. if(index==0){//所有诊断
  132. $(".div-diagnosis").show();
  133. $(".div-dates").hide();
  134. }else{
  135. $(".div-diagnosis").hide();
  136. $(".div-dates").show();
  137. }
  138. $(".modal-overlay").show();
  139. });
  140. //所有诊断-tab点击事件
  141. $(".div-diagnosis").on("click","li",function(){
  142. $(".div-diagnosis li").removeClass("active");
  143. $(this).addClass("active");
  144. $(".c-lab-mor li i").removeClass("active");
  145. $(".modal-overlay").hide();
  146. $(".div-diagnosis").hide();
  147. $(".c-lab-mor li").eq(0).find("span").html($(this).find("label").html());
  148. //TODO 搜索数据处理
  149. deseaseType = $(this).attr("data-val");
  150. page = 1;
  151. getPrescriptionList(true);
  152. });
  153. //全部时间-tab点击事件
  154. $(".div-dates").on("click","li",function(){
  155. $(".div-dates li").removeClass("active");
  156. $(this).addClass("active");
  157. $(".c-lab-mor li i").removeClass("active");
  158. $(".modal-overlay").hide();
  159. $(".div-dates").hide();
  160. $(".c-lab-mor li").eq(1).find("span").html($(this).find("label").html());
  161. //TODO 搜索数据处理
  162. var value = $(this).attr("data-val");
  163. getDate(value);
  164. page = 1;
  165. getPrescriptionList(true);
  166. });
  167. //点击遮罩事件
  168. $(".modal-overlay").on("click",function(){
  169. $(".div-diagnosis").hide();
  170. $(".div-dates").hide();
  171. $(".c-lab-mor li i").removeClass("active");
  172. $(".modal-overlay").hide();
  173. });
  174. //申请续方按钮事件
  175. $(".ul-consultation").on("tap",".div-sqxf-btn",function(e){
  176. e.stopPropagation();
  177. var $this = $(this);
  178. if($this.hasClass('appy-btn')){
  179. var code = $this.closest("li").attr("data-code");
  180. window.localStorage.setItem("prescriptionCode", code);
  181. viewApi.back();
  182. }else{
  183. return false;
  184. }
  185. })
  186. //域跳转处方详情页
  187. .on("tap","li",function(){
  188. var code = $(this).attr("data-code");
  189. window.location.href = "../../prescription/html/prescription_detail.html?code="+code;
  190. });
  191. //显示下一条数据
  192. $("#next").on('tap', function(){
  193. if($(this).hasClass("disabled")){
  194. return false;
  195. }
  196. getPrescriptionList(false);
  197. })
  198. }
  199. function initScroller(){
  200. //阻尼系数
  201. var deceleration = mui.os.ios?0.003:0.0009;
  202. mui('.mui-scroll-wrapper').scroll({
  203. bounce: false,
  204. indicators: true, //是否显示滚动条
  205. deceleration:deceleration
  206. });
  207. mui(".mui-scroll-wrapper").pullRefresh({
  208. down: {
  209. callback: function() {
  210. var self = this;
  211. setTimeout(function() {
  212. getPrescriptionList(true);
  213. self.endPulldownToRefresh();
  214. }, 1000);
  215. }
  216. },
  217. up: {
  218. callback: function() {
  219. var self = this;
  220. setTimeout(function(){
  221. getPrescriptionList();
  222. self.endPullupToRefresh();
  223. }, 1000);
  224. }
  225. }
  226. });
  227. }
  228. function queryFailed(res){
  229. d.close();
  230. if(res && res.msg) {
  231. dialog({
  232. contentType: 'tipsbox',
  233. skin: 'bk-popup',
  234. content: res.msg
  235. }).show();
  236. } else {
  237. dialog({
  238. contentType: 'tipsbox',
  239. skin: 'bk-popup',
  240. content: '加载失败'
  241. }).show();
  242. }
  243. }
  244. return {
  245. initPage: pageInit
  246. };
  247. }