health-index-waistline-history.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. //点击加载更多
  12. $("#view_more").on("tap", function() {
  13. queryList(sortDate,pageSize);
  14. console.log("加载更多");
  15. });
  16. });
  17. function queryList(sortDate,pageSize) {
  18. //显示进度条
  19. // plus.nativeUI.showWaiting();
  20. //发送请求
  21. queryListByType(4, sortDate, pageSize, queryListSuccesss);
  22. }
  23. /**
  24. * 健康指标图表查询成功处理方法
  25. */
  26. function queryListSuccesss(res) {
  27. if (res.status == 200) {
  28. d.close();
  29. if (res.list.length > 0) {
  30. //成功
  31. showList(res.list);
  32. }else{
  33. //无更多数据
  34. document.querySelector("#view_more").innerText = "已无更多数据";
  35. }
  36. }else {
  37. //非200则为失败
  38. queryListFailed(res);
  39. }
  40. // plus.nativeUI.closeWaiting();
  41. }
  42. /**
  43. * 显示查询结果
  44. * @param {Object} list
  45. */
  46. function showList(list) {
  47. // clearHTML();
  48. for (var i = 0; i < list.length; i++) {
  49. var data = list[i];
  50. if (!data) {
  51. continue;
  52. }
  53. addRow(data.date.substr(5, 5), toIntValue(data.value1));
  54. sortDate = list[i].sortDate;
  55. }
  56. }
  57. function toIntValue(value) {
  58. if (parseInt(value) == value) {
  59. return parseInt(value);
  60. } else {
  61. return Math.round(value * Math.pow(10, 1)) / Math.pow(10, 1);
  62. }
  63. }
  64. /**
  65. * 清空tbody
  66. */
  67. function clearHTML() {
  68. $("#item").html("");
  69. }
  70. /**
  71. * tbody添加一行tr
  72. * @param {Object} dateStr
  73. * @param {Object} value1
  74. * @param {Object} value2
  75. */
  76. function addRow(dateStr, value1) {
  77. if (dateStr.length > 5) {
  78. dateStr = dateStr.substr(5, 5);
  79. }
  80. var tb = document.querySelector("#item");
  81. var tr = document.createElement("tr");
  82. var html = '<td class="width-30">' + dateStr + '</td>';
  83. html += '<td class="width-70">' + value1 + '</td>';
  84. tr.innerHTML = html;
  85. tb.appendChild(tr);
  86. }
  87. //添加数据添加监听
  88. window.addEventListener("add-item", function(e) {
  89. clearHTML();
  90. //刷新列表
  91. queryList();
  92. //添加一行
  93. // addRow(e.detail.date, e.detail.val_high, e.detail.val_low);
  94. //存储到本地
  95. // plus.storage.setItem("bloodpressure_history", con);
  96. });