device-physical-records.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. var now = new Date(),
  2. patiCode,
  3. deviceSn,
  4. type,
  5. unit;
  6. mui.init();
  7. mui.plusReady(function(){
  8. var self = plus.webview.currentWebview();
  9. patiCode = self.patiCode;
  10. deviceSn = self.deviceSn;
  11. type = self.type;
  12. $("#title").text(self.deviceName);
  13. if(type == 1){
  14. unit = "mmol/L";
  15. }else if(type == 2){
  16. unit = "mmHg";
  17. }
  18. //获取近半年的月份信息
  19. getMonth();
  20. bindEvents();
  21. templateHelper();
  22. });
  23. function getMonth(){
  24. var list = [];
  25. for(i=0; i<6; i++){
  26. var d = new Date();
  27. d.setMonth(now.getMonth() - i);
  28. list.push(d.format("yyyy-MM"));
  29. }
  30. var html = template("month-tmp", {list: list});
  31. $("#content").empty().append(html);
  32. }
  33. function getMonthDate(month){
  34. var lastDate = getMonthLastDate(month),
  35. days = lastDate.getDate(),
  36. dateList = [];
  37. if(now.getMonth() == lastDate.getMonth()){
  38. var days2 = now.getDate();
  39. for(i=0; i<days2; i++){
  40. var e = new Date(month);
  41. e.setDate(now.getDate() - i);
  42. dateList.push(e.format("yyyy-MM-dd"));
  43. }
  44. }else{
  45. for(i=0; i<days; i++){
  46. var e = new Date(month);
  47. e.setDate(lastDate.getDate() - i);
  48. dateList.push(e.format("yyyy-MM-dd"));
  49. }
  50. }
  51. var html = template("date-tmp", {list: dateList});
  52. $("#"+month).empty().append(html);
  53. }
  54. //获取当月的天数
  55. function getMonthLastDate(month){
  56. var d = new Date(month),
  57. year = d.getFullYear(),
  58. month = d.getMonth() + 1;
  59. var d2 = new Date(year, month, 0);
  60. return d2;
  61. }
  62. function getMonthDateData(month){
  63. var url = "doctor/health_index/getHealthDateAll",
  64. params = {
  65. patientCode: patiCode,
  66. deviceSn: deviceSn,
  67. choseMonth: month,
  68. type: type
  69. };
  70. plus.nativeUI.showWaiting();
  71. sendGet(url, params, null, function(res){
  72. if(res.status == 200){
  73. var list = res.data;
  74. if(list.length == 0){
  75. $("#"+month+" .no-record").show();
  76. }else{
  77. $("#"+month+" .no-record").hide();
  78. var html = template("date-tmp", {list: list});
  79. $("#"+month).append(html);
  80. }
  81. }else{
  82. mui.toast(res.msg);
  83. }
  84. plus.nativeUI.closeWaiting();
  85. }, true);
  86. }
  87. function getDateRecords(date){
  88. var url = "doctor/health_index/patientHealthIndexByDateAndDeviceSn",
  89. params = {
  90. patientCode: patiCode,
  91. deviceSn: deviceSn,
  92. choseDay: date,
  93. type: type
  94. };
  95. plus.nativeUI.showWaiting();
  96. sendGet(url, params, null, function(res){
  97. if(res.status == 200){
  98. var list = res.data,
  99. $ul = $(".record-list[data-date="+date+"]");
  100. if(list.length == 0){
  101. $ul.find(".no-record").show();
  102. }else{
  103. $ul.find(".no-record").hide();
  104. var html = "";
  105. if(type == "1"){
  106. html = template("record-tmp", {list: list, unit: unit});
  107. }else if(type == "2"){
  108. html = template("record2-tmp", {list: list, unit: unit});
  109. }
  110. $ul.append(html);
  111. }
  112. plus.nativeUI.closeWaiting();
  113. }else{
  114. plus.nativeUI.closeWaiting();
  115. mui.toast(res.msg);
  116. }
  117. }, true);
  118. }
  119. function bindEvents(){
  120. $("#content").on('click', ".month", function(){
  121. var $this = $(this),
  122. month = $this.attr("data-val");
  123. if($this.hasClass("active")){
  124. $this.removeClass("active");
  125. $this.find(".fa").removeClass("fa-angle-up").addClass("fa-angle-down");
  126. $this.parent().find(".date-list").hide();
  127. return false;
  128. }
  129. var $activeMonth = $(".month.active");
  130. if($activeMonth.length > 0){
  131. $activeMonth.removeClass("active");
  132. $activeMonth.find(".fa").removeClass("fa-angle-up").addClass("fa-angle-down");
  133. $activeMonth.parent().find(".date-list").hide();
  134. }
  135. $this.addClass("active");
  136. $this.find(".fa").removeClass("fa-angle-down").addClass("fa-angle-up");
  137. $this.parent().find(".date-list").show();
  138. if($this.parent().find(".date-panel").length > 0){
  139. return false;
  140. }
  141. getMonthDateData(month);
  142. });
  143. $("#content").on('click', ".date", function(){
  144. var $this = $(this),
  145. date = $this.attr("data-val");
  146. if($this.hasClass("active")){
  147. $this.removeClass("active");
  148. $this.find(".fa").removeClass("fa-angle-up").addClass("fa-angle-down");
  149. $this.parent().find(".record-list").hide();
  150. return false;
  151. }
  152. var $activeDate = $this.parent().parent().find(".date.active");
  153. if($activeDate.length > 0){
  154. $activeDate.removeClass("active");
  155. $activeDate.find(".fa").removeClass("fa-angle-up").addClass("fa-angle-down");
  156. $activeDate.parent().find(".record-list").hide();
  157. }
  158. $this.addClass("active");
  159. $this.find(".fa").removeClass("fa-angle-down").addClass("fa-angle-up");
  160. $this.parent().find(".record-list").show();
  161. if($this.parent().find(".record").length > 0){
  162. return false;
  163. }
  164. getDateRecords(date);
  165. });
  166. $(".header-link").on('click', function(){
  167. openWebview("../../huanzhe/html/huanzhexinxi.html",{
  168. patiCode: patiCode
  169. });
  170. })
  171. }
  172. function templateHelper(){
  173. template.helper("getTime", function(str){
  174. var s = str.replace(/\-/g, "/");
  175. var d = new Date(s);
  176. return d.format("hh:mm");
  177. });
  178. template.helper("getTypeName", function(gi_type){
  179. switch(gi_type){
  180. case "1":
  181. return "早餐前";
  182. break;
  183. case "2":
  184. return "早餐后";
  185. break;
  186. case "3":
  187. return "午餐前";
  188. break;
  189. case "4":
  190. return "午餐后";
  191. break;
  192. case "5":
  193. return "晚餐前";
  194. break;
  195. case "6":
  196. return "晚餐后";
  197. break;
  198. case "7":
  199. return "睡前";
  200. break;
  201. }
  202. });
  203. template.helper("getXTValue", function(val, type){
  204. val = parseFloat(val);
  205. var min = 0,
  206. max = 0;
  207. switch(type){
  208. case "1":
  209. case "3":
  210. case "5":
  211. case "7":
  212. min = 4,
  213. max = 7;
  214. break;
  215. case "2":
  216. case "4":
  217. case "6":
  218. min = 4,
  219. max = 11.1;
  220. break;
  221. }
  222. if(val < min){
  223. return '<i class="fa fa-long-arrow-down c-green"></i><span class="c-green ml10">'+val+unit+'</span>';
  224. }else if(val > max){
  225. return '<i class="fa fa-long-arrow-up c-red"></i><span class="c-red ml10">'+val+unit+'</span>';
  226. }else{
  227. return val+unit;
  228. }
  229. });
  230. template.helper("getXYValue", function(val, type){
  231. val = parseFloat(val);
  232. var min, max;
  233. if(type = 1){
  234. min = 90;
  235. max = 140;
  236. }else{
  237. min = 60;
  238. max = 90;
  239. }
  240. if(val < min){
  241. return '<i class="fa fa-long-arrow-down c-green"></i><span class="c-green ml10">'+val+unit+'</span>';
  242. }else if(val > max){
  243. return '<i class="fa fa-long-arrow-up c-red"></i><span class="c-red ml10">'+val+unit+'</span>';
  244. }else{
  245. return val+unit;
  246. }
  247. })
  248. }