health-record-sport.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var sortDate = "";
  3. var pageSize = 5;
  4. $(function() {
  5. clearHTML();
  6. queryList(sortDate,pageSize);
  7. //点击加载更多
  8. $("#view_more").on("tap", function() {
  9. queryList(sortDate,pageSize);
  10. });
  11. });
  12. function queryList(sortDate,pagesize) {
  13. //拼请求内容
  14. d.show();
  15. var params = {};
  16. params.sortDate = sortDate;
  17. params.pagesize = pagesize;
  18. //发送ajax请求
  19. sendPost("patient/health_record/list_sports", params, "json", "post", queryListFailed, queryListSuccesss);
  20. }
  21. /**
  22. * 健康指标图表查询成功处理方法
  23. */
  24. function queryListSuccesss(res) {
  25. if (res.status == 200) {
  26. d.close();
  27. if (res.list.length > 0) {
  28. //成功
  29. showList(res.list);
  30. }else{
  31. //无更多数据
  32. document.querySelector("#view_more").innerText = "已无更多数据";
  33. }
  34. } else {
  35. queryListFailed(res);
  36. }
  37. }
  38. function queryListFailed(res) {
  39. d.close().remove();
  40. if (res && res.msg) {
  41. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  42. } else {
  43. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  44. }
  45. }
  46. /**
  47. * 显示查询结果
  48. * @param {Object} list
  49. */
  50. function showList(list) {
  51. for (var i = 0; i < list.length; i++) {
  52. var data = list[i];
  53. if (!data) {
  54. continue;
  55. }
  56. addRow(data.record_date, data.sports_time,data.sports_type,data.sports);
  57. sortDate = list[i].sortDate;
  58. }
  59. }
  60. /**
  61. * 清空tbody
  62. */
  63. function clearHTML() {
  64. $("#sport_list").html("");
  65. }
  66. /**
  67. * tbody添加一行tr
  68. * @param {Object} dateStr
  69. * @param {Object} value1
  70. * @param {Object} value2
  71. */
  72. function addRow(dateStr, sports_time,sports_type,sports) {
  73. var tb = document.querySelector("#sport_list");
  74. var tr = document.createElement("tr");
  75. var html ="";
  76. html+= "<td class='width-20 '>"+dateStr+"</td>";
  77. html+= "<td class='width-20 '>"+sports_time+"</td>";
  78. html+= "<td class='width-30 '>"+sports_type+"</td>";
  79. html+= "<td class='width-30 '>"+sports+"</td>";
  80. tr.innerHTML = html;
  81. tb.appendChild(tr);
  82. }
  83. //添加数据添加监听
  84. window.addEventListener("add-item", function(e) {
  85. clearHTML();
  86. queryList();
  87. });