health-index-bloodpressure-history.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. var sortDate="";
  2. var pageSize = 10;
  3. $(function() {
  4. //加载本地数据
  5. // var temp = plus.storage.getItem("bloodpressure_history");
  6. // if (temp) {
  7. // document.getElementById("item").innerHTML = temp;
  8. // }
  9. clearHTML();
  10. queryList(sortDate,pageSize);
  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(2,sortDate, pageSize, queryListSuccesss);
  21. }
  22. /**
  23. * 健康指标图表查询成功处理方法
  24. */
  25. function queryListSuccesss(res) {
  26. if (res.status == 200) {
  27. d.close();
  28. if (res.list.length > 0) {
  29. showList(res.list);
  30. }else{
  31. //无更多数据
  32. document.querySelector("#view_more").innerText = "已无更多数据";
  33. }
  34. } else {
  35. //非200则为失败
  36. queryListFailed(res);
  37. }
  38. }
  39. /**
  40. * 显示查询结果
  41. * @param {Object} list
  42. */
  43. function showList(list) {
  44. // clearHTML();
  45. for (var i = 0; i < list.length; i++) {
  46. var data = list[i];
  47. if (!data) {
  48. continue;
  49. }
  50. addRow(data.date.substr(5, 5), toIntValue(data.value1), toIntValue(data.value2));
  51. sortDate = list[i].sortDate;
  52. }
  53. }
  54. function toIntValue(value){
  55. if(parseInt(value) == value){
  56. return parseInt(value);
  57. }else{
  58. return Math.round(value*Math.pow(10, 1))/Math.pow(10, 1);
  59. }
  60. }
  61. /**
  62. * 清空tbody
  63. */
  64. function clearHTML() {
  65. $("#item").html("");
  66. }
  67. /**
  68. * tbody添加一行tr
  69. * @param {Object} dateStr
  70. * @param {Object} value1
  71. * @param {Object} value2
  72. */
  73. function addRow(dateStr, value1, value2) {
  74. if (dateStr.length > 5) {
  75. dateStr = dateStr.substr(5, 5);
  76. }
  77. var tb = document.querySelector("#item");
  78. var tr = document.createElement("tr");
  79. var html = '<td class="width-30">' + dateStr + '</td>';
  80. html += getTD(value1, 139, 90);
  81. html += getTD(value2, 89, 60);
  82. tr.innerHTML = html;
  83. tb.appendChild(tr);
  84. }
  85. function getTD(value, max, min) {
  86. if(value == 0 || isNaN(value)){
  87. return '<td class="width-35"></td>';
  88. }
  89. if (value > max) {
  90. return '<td class="width-35 c-f00">' + value + '</td>';
  91. } else if (value < min) {
  92. return '<td class="width-35 c-007cd9">' + value + '</td>';
  93. } else {
  94. return '<td class="width-35">' + value + '</td>';
  95. }
  96. }
  97. //添加数据添加监听
  98. window.addEventListener("add-item", function(e) {
  99. clearHTML();
  100. //刷新列表
  101. queryList();
  102. //添加一行
  103. // addRow(e.detail.date, e.detail.val_high, e.detail.val_low);
  104. //存储到本地
  105. // plus.storage.setItem("bloodpressure_history", con);
  106. });