health-record-drug.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. sendPost("patient/health_record/list_medication", params, "json", "post", queryListFailed, queryListSuccesss);
  19. }
  20. /**
  21. * 健康指标图表查询成功处理方法
  22. */
  23. function queryListSuccesss(res) {
  24. if (res.status == 200) {
  25. d.close();
  26. if (res.list.length > 0) {
  27. showList(res.list);
  28. }else{
  29. document.querySelector("#view_more").innerText = "已无更多数据";
  30. }
  31. } else {
  32. //非200则为失败
  33. queryListFailed(res);
  34. }
  35. }
  36. function queryListFailed(res) {
  37. d.close().remove();
  38. if (res && res.msg) {
  39. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  40. } else {
  41. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  42. }
  43. }
  44. /**
  45. * 显示查询结果
  46. * @param {Object} list
  47. */
  48. function showList(list) {
  49. for (var i = 0; i < list.length; i++) {
  50. var data = list[i];
  51. if (!data) {
  52. continue;
  53. }
  54. addRow(data.record_date, data.medicines);
  55. sortDate = list[i].sortDate;
  56. }
  57. }
  58. /**
  59. * 清空tbody
  60. */
  61. function clearHTML() {
  62. $("#drug_list").html("");
  63. }
  64. /**
  65. * tbody添加一行tr
  66. * @param {Object} dateStr
  67. * @param {Object} value1
  68. * @param {Object} value2
  69. */
  70. function addRow(date, medicines) {
  71. var tb = document.querySelector("#drug_list");
  72. var tr = document.createElement("tr");
  73. var html ="";
  74. html+="<tr>"
  75. html+= "<td class='width-30'>"+date+"</td>"
  76. html+= "<td class='width-70'>"+medicines+"</td>"
  77. html+="</tr>"
  78. tr.innerHTML = html;
  79. tb.appendChild(tr);
  80. }
  81. //添加数据添加监听
  82. window.addEventListener("add-item", function(e) {
  83. clearHTML();
  84. queryList();
  85. });