health-record-new.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. var d = dialog({contentType:'load', skin:'bk-popup'}).show();
  2. var dd = dialog({contentType:'load', skin:'bk-popup'});
  3. var $tizhengList = $('#tizhengList'),
  4. $baojianList = $('#baojianList');
  5. var xuetangRecord = null,
  6. xuyaRecord = null,
  7. tizhongRecord = null,
  8. yaoweiRecord = null,
  9. yundongRecord = null,
  10. yongyaoRecord = null,
  11. yinshiRecord = null,
  12. tzSta = false,
  13. xtdt = '',
  14. xydt = '',
  15. tzdt = '',
  16. ywdt = '',
  17. yddt = '',
  18. yydt = '',
  19. ysdt = '';
  20. var xuetangDuring = ['','早餐前', '早餐后', '午餐前', '午餐后', '晚餐前', '晚餐后', '睡前'];
  21. function checkDate (v) {
  22. return (v < 10 ? '0' + v : v);
  23. }
  24. //获取最新的体征记录
  25. function getRecentDataPromise() {
  26. var user = JSON.parse(localStorage.getItem(agentName));
  27. return new Promise(function(resolve, reject) {
  28. sendPost("patient/health_index/last", {}, "json", "get", function() {
  29. d.close();
  30. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  31. }, function(res) {
  32. d.close();
  33. if(res.status == 200) {
  34. console.log(res)
  35. // res.data.xt = JSON.parse(res.data.xt);
  36. // var xtD = new Date(res.data.xt.czrq);
  37. // res.data.xt.czrq = xtD.getFullYear() + '-' +
  38. // checkDate(xtD.getMonth() + 1) +
  39. // '-' + checkDate(xtD.getDate());
  40. resolve(res)
  41. } else {
  42. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  43. }
  44. });
  45. })
  46. }
  47. //获取最新保健记录
  48. function getBJRecentDataPromise () {
  49. return new Promise(function( resolve, reject){
  50. sendPost("patient/health_record/recent", {}, "json", "get", function() {
  51. dd.close();
  52. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  53. }, function(res) {
  54. dd.close();
  55. if(res.status == 200) {
  56. console.log(res);
  57. resolve(res)
  58. } else {
  59. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  60. }
  61. });
  62. });
  63. }
  64. function getLevelClazz(value,max,min) {
  65. if(!value||(!max && !min)) {
  66. return '';
  67. }
  68. if(value < min) {
  69. return 'low';
  70. } else if(value > max) {
  71. return 'high';
  72. } else {
  73. return ''
  74. }
  75. }
  76. function bindEvents() {
  77. //标签切换
  78. $(".pt-tab li").click(function(){
  79. var id = $(this).attr("id");
  80. $(".pt-tab li").removeClass("hit");
  81. $(this).addClass("hit");
  82. if(id=="tizhengLi"){
  83. $("#tizhengList").show();
  84. $("#baojianList").hide();
  85. }else{
  86. $("#tizhengList").hide();
  87. $("#baojianList").show();
  88. }
  89. });
  90. $('#tizhengList').on('click','li',function() {
  91. var index = $(this).index();
  92. var dat = new Date(),
  93. nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
  94. if(index == 0) {
  95. window.location.href = 'xuetang-view.html?dateT=' + (xtdt || nowD);
  96. }
  97. if(index == 1) {
  98. window.location.href = 'xueya-view.html?dateT=' + (xydt || nowD);
  99. }
  100. if(index == 2) {
  101. window.location.href = 'tizhong-view.html?dateT=' + (tzdt || nowD);
  102. }
  103. if(index == 3) {
  104. window.location.href = 'yaowei-view.html?dateT=' + (ywdt || nowD);
  105. }
  106. })
  107. $('#baojianList').on('click','li',function() {
  108. var index = $(this).index();
  109. var dat = new Date(),
  110. nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
  111. if(index == 0) {
  112. window.location.href = 'yundong-view.html?dateT=' + (yddt || nowD);
  113. }
  114. if(index == 1) {
  115. window.location.href = 'yongyao-view.html?dateT=' + (yydt || nowD);
  116. }
  117. if(index == 2) {
  118. window.location.href = 'yinshi-view.html?dateT=' + (ysdt || nowD);
  119. }
  120. })
  121. //点击新增事件
  122. $(".div-add-btn").click(function(){
  123. $(".modal-overlay").css("background","transparent");
  124. $("#footer").css("z-index",4).hide();
  125. var activeItem = $(".pt-tab li.hit").attr("id");
  126. if(activeItem=="tizhengLi"){
  127. if($(this).hasClass("active")){
  128. $(".div-dialog-content.div-tizhengtezheng").hide();
  129. }else{
  130. $(".div-dialog-content.div-tizhengtezheng").show();
  131. }
  132. }else{
  133. if($(this).hasClass("active")){
  134. $(".div-dialog-content.div-baojianjilu").hide();
  135. }else{
  136. $(".div-dialog-content.div-baojianjilu").show();
  137. }
  138. }
  139. if($(this).hasClass("active")){
  140. $(".modal-overlay").removeClass("modal-overlay-visible");
  141. $(this).removeClass("active");
  142. }else{
  143. $(this).addClass("active");
  144. $(".modal-overlay").addClass("modal-overlay-visible");
  145. }
  146. });
  147. //点击遮罩事件
  148. $(".modal-overlay").on("click",function(){
  149. $(".div-add-btn").removeClass("active");
  150. $(".div-dialog-content").hide();
  151. $(".modal-overlay").removeClass("modal-overlay-visible");
  152. $("#footer").show();
  153. });
  154. //新增血糖
  155. $(".addxuetang").on("click",function(){
  156. $(this).addClass("active");
  157. window.open('health-index-add-bloodsugar.html');
  158. });
  159. //新增血压
  160. $(".addxueya").on("click",function(){
  161. $(this).addClass("active");
  162. window.open('health-index-add-bloodpressure.html');
  163. });
  164. //新增体重
  165. $(".addtizhong").on("click",function(){
  166. $(this).addClass("active");
  167. window.open('health-index-add-weight.html');
  168. });
  169. //新增腰围
  170. $(".addyaowei").on("click",function(){
  171. $(this).addClass("active");
  172. window.open('health-index-add-waistline.html');
  173. });
  174. //新增设备管理
  175. $(".addshebei").on("click",function(){
  176. $(this).addClass("active");
  177. window.open('../../wdsb/html/my-equipments.html');
  178. });
  179. //新增运动
  180. $(".addyundong").on("click",function(){
  181. $(this).addClass("active");
  182. window.open('add-sport-record.html');
  183. });
  184. //新增用药
  185. $(".addyongyao").on("click",function(){
  186. $(this).addClass("active");
  187. window.open('add-drug-record.html');
  188. });
  189. //新增饮食
  190. $(".addyinshi").on("click",function(){
  191. $(this).addClass("active");
  192. // 修复bug#2724
  193. window.location.href = 'add-diet-record.html';
  194. });
  195. }
  196. function getRecordType(isDevice) {
  197. return isDevice === null ? "手动记录" : isDevice !== null ? "设备上传" : '';
  198. // return isDevice == "0"?"手动记录":(isDevice=="1"?"设备上传":"");
  199. }
  200. //var html = template('tizheng_list_temp',{
  201. // xuetang:{},
  202. // xueya:{},
  203. // tizhong:{},
  204. // yaowei:{}
  205. //});
  206. //$tizhengList.html(html);
  207. //体征记录
  208. getRecentDataPromise()
  209. .then(function(res) {
  210. xuetangRecord = _.find(res.data,function(o) {
  211. var d = new Date(o.recordDate.replace(/\-/g, "/"));
  212. o.recordDate = d.getFullYear() + '-' + checkDate(d.getMonth() + 1) + '-' + checkDate(d.getDate());
  213. return o.type =="1";
  214. }) || {};
  215. xuyaRecord = _.find(res.data,function(o) {
  216. return o.type =="2";
  217. }) || {};
  218. tizhongRecord = _.find(res.data,function(o) {
  219. return o.type =="3";
  220. }) || {};
  221. yaoweiRecord = _.find(res.data,function(o) {
  222. return o.type =="4";
  223. }) || {};
  224. var xuetangValue = "";
  225. var xuetangValueIndex;
  226. var during = _.find(xuetangDuring,function(v,i){
  227. xuetangValue = xuetangRecord['value'+[i]];
  228. xuetangValueIndex = i;
  229. return i>0&&xuetangValue;
  230. });
  231. xtdt = xuetangRecord.recordDate;
  232. xydt = xuyaRecord.recordDate;
  233. tzdt = tizhongRecord.recordDate;
  234. ywdt = yaoweiRecord.recordDate;
  235. return {
  236. xuetang: $.extend({},xuetangRecord,{
  237. during: during,
  238. value: xuetangValue,
  239. levelClazz: (function() {
  240. // 不同时间段对应不同的血糖范围
  241. var levels = [[],[6.1, 3.9],[7.8, 4.4],
  242. [6.1, 3.9],[7.8, 4.4],
  243. [6.1, 3.9],[7.8, 4.4],
  244. [6.1, 3.9]][xuetangValueIndex];
  245. return getLevelClazz(xuetangValue, levels[0],levels[1])
  246. })(),
  247. recordType: getRecordType(xuetangRecord.deviceSn)
  248. }),
  249. xueya: $.extend({},xuyaRecord,{
  250. levelClazz: getLevelClazz(xuyaRecord.value1, 139, 90)||getLevelClazz(xuyaRecord.value2, 89, 60),
  251. recordType: getRecordType(xuyaRecord.deviceSn)
  252. }),
  253. tizhong: $.extend({},tizhongRecord,{
  254. recordType: getRecordType(tizhongRecord.deviceSn)
  255. }),
  256. yaowei: $.extend({},yaoweiRecord,{
  257. recordType: getRecordType(yaoweiRecord.deviceSn)
  258. })
  259. }
  260. })
  261. .then(function(data) {
  262. var html = template('tizheng_list_temp',data);
  263. $tizhengList.html(html)
  264. })
  265. .then(function() {
  266. bindEvents();
  267. })
  268. .catch(function(e) {
  269. d.close();
  270. console && console.error(e)
  271. });
  272. //保健记录
  273. getBJRecentDataPromise()
  274. .then(function (res) {
  275. yundongRecord = res.data.sprot;
  276. yongyaoRecord = res.data.medication;
  277. yinshiRecord = res.data.diet;
  278. yddt = yundongRecord.sortDate;
  279. yydt = yongyaoRecord.recordDate;
  280. ysdt = yinshiRecord.recordDate;
  281. return {
  282. yundong: yundongRecord,
  283. yongyao: yongyaoRecord,
  284. yinshi: yinshiRecord
  285. };
  286. }).then(function (data) {
  287. var html = template('baojian_list_tmp',data);
  288. $baojianList.html(html)
  289. });