health-index-bloodsugar-history(2).js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //var patient="";
  2. var sortDate="";
  3. var pageSize = 5;
  4. $(function() {
  5. // var self=plus.webview.getWebviewById("health-index-bloodsugar-chart");
  6. // if(self.code){patient=self.code;}
  7. // console.log("bsh_patient:"+patient);
  8. clearHTML();
  9. queryList(sortDate,pageSize);
  10. //点击加载更多
  11. $("#view_more").on("tap", function() {
  12. queryList(sortDate,pageSize);
  13. console.log("加载更多");
  14. });
  15. });
  16. function queryList(sortDate,pageSize) {
  17. //显示进度条
  18. // plus.nativeUI.showWaiting();
  19. //发送请求
  20. queryListByType(1, sortDate, pageSize, queryListSuccesss);
  21. }
  22. /**
  23. * 健康指标图表查询成功处理方法
  24. */
  25. function queryListSuccesss(res) {
  26. if (res.status == 200) {
  27. if (res.list.length > 0) {
  28. //成功
  29. showList(res.list);
  30. }else{
  31. //无更多数据
  32. document.querySelector("#view_more").innerText = "已无更多数据";
  33. }
  34. } else {
  35. //非200则为失败
  36. queryListFailed(res);
  37. }
  38. // plus.nativeUI.closeWaiting();
  39. }
  40. /**
  41. * 显示查询结果
  42. * @param {Object} list
  43. */
  44. function showList(list) {
  45. // clearHTML();
  46. for (var i = 0; i < list.length; i++) {
  47. var data = list[i];
  48. if (!data) {
  49. continue;
  50. }
  51. addRow(data.date.substr(5, 5), toIntValue(data.value1), toIntValue(data.value2), toIntValue(data.value3), toIntValue(data.value4), toIntValue(data.value5), toIntValue(data.value6), toIntValue(data.value7));
  52. sortDate = list[i].sortDate;
  53. }
  54. }
  55. function toIntValue(value){
  56. if(parseInt(value) == value){
  57. return parseInt(value);
  58. }else{
  59. return Math.round(value*Math.pow(10, 1))/Math.pow(10, 1);
  60. }
  61. }
  62. /**
  63. * 清空tbody
  64. */
  65. function clearHTML() {
  66. $("#table1 tbody").html("");
  67. }
  68. /**
  69. * tbody添加一行tr
  70. * @param {Object} dateStr
  71. * @param {Object} value1
  72. * @param {Object} value2
  73. */
  74. function addRow(dateStr, value1, value2, value3, value4, value5, value6, value7) {
  75. if(dateStr.length > 5){
  76. dateStr = dateStr.substr(5, 5);
  77. }
  78. var tb = document.querySelector("#item");
  79. var tr = document.createElement("tr");
  80. var html = '<td class="date">'+dateStr+'</td>';
  81. html += getTD(value1, 7.2, 4.4, "bb");
  82. html += getTD(value2, 10, 4.4, "ba");
  83. html += getTD(value3, 10, 4.4, "lb");
  84. html += getTD(value4, 10, 4.4, "la");
  85. html += getTD(value5, 10, 4.4, "db");
  86. html += getTD(value6, 10, 4.4, "da");
  87. html += getTD(value7, 10, 4.4, "sb");
  88. tr.innerHTML = html;
  89. tb.appendChild(tr);
  90. }
  91. function getTD(value, max, min, styleName){
  92. if(value == 0 || isNaN(value)){
  93. return '<td class="'+styleName+'"></td>';
  94. }
  95. if(value > max){
  96. return '<td class="'+styleName+' c-f00">'+value+'</td>';
  97. }else if(value < min){
  98. return '<td class="'+styleName+' c-007cd9">'+value+'</td>';
  99. }else{
  100. return '<td class="'+styleName+'">'+value+'</td>';
  101. }
  102. }
  103. //添加数据添加监听
  104. window.addEventListener("add-item", function(e) {
  105. //刷新列表
  106. queryList();
  107. //添加一行
  108. // addRow(e.detail.date, e.detail.val_high, e.detail.val_low);
  109. //存储到本地
  110. // plus.storage.setItem("bloodpressure_history", con);
  111. });