health-record-diet.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var patient = "";
  2. var sortDate = "";
  3. var pageSize = 10;
  4. mui.plusReady(function() {
  5. var self = plus.webview.currentWebview();
  6. if (self.pCode) {
  7. patient = self.pCode;
  8. }
  9. clearHTML();
  10. queryList(patient, sortDate, pageSize);
  11. //点击加载更多
  12. document.getElementById('view_more').addEventListener("tap", function() {
  13. queryList(patient, sortDate, pageSize);
  14. });
  15. });
  16. function queryList(patient, sortDate, pageSize) {
  17. //拼请求内容
  18. var params = {};
  19. params.patient = patient;
  20. params.sortDate = sortDate;
  21. params.pagesize = pageSize;
  22. //发送ajax请求
  23. sendPost("doctor/health_record/list_diet", params, queryListFailed, queryListSuccesss);
  24. }
  25. /**
  26. * 健康指标图表查询成功处理方法
  27. */
  28. function queryListSuccesss(res) {
  29. if (res.status == 200) {
  30. if (res.list.length > 0) {
  31. //成功
  32. showList(res.list);
  33. } else {
  34. //无更多数据
  35. document.querySelector("#view_more").innerText = "已无更多数据";
  36. }
  37. } else {
  38. //非200则为失败
  39. queryListFailed(res);
  40. }
  41. plus.nativeUI.closeWaiting();
  42. }
  43. /**
  44. * 显示查询结果
  45. * @param {Object} list
  46. */
  47. function showList(list) {
  48. // clearHTML();
  49. for (var i = 0; i < list.length; i++) {
  50. var data = list[i];
  51. if (!data) {
  52. continue;
  53. }
  54. //data.date.substr(5, 5) --只有月-日
  55. addRow(data.record_date, data.content, data.images);
  56. sortDate = list[i].sortDate;
  57. }
  58. document.getElementById("view_more").style.display="";
  59. }
  60. /**
  61. * 清空tbody
  62. */
  63. function clearHTML() {
  64. $("#diet_list").html("");
  65. }
  66. /**
  67. * tbody添加一行tr
  68. * @param {Object} dateStr
  69. * @param {Object} value1
  70. * @param {Object} value2
  71. */
  72. function addRow(record_date, content, images) {
  73. // if(dateStr.length > 5){
  74. // dateStr = dateStr.substr(5, 5);
  75. // }
  76. var tb = document.querySelector("#diet_list");
  77. var tr = document.createElement("tr");
  78. var imgs=[];
  79. if (images) {
  80. imgs=images.split(",");
  81. }
  82. var html = "";
  83. html += "<tr>"
  84. html += "<td class='width-30'>" + record_date + "</td>"
  85. html += "<td class='width-70' style='text-align:left;'>";
  86. var tempHtml="";
  87. for (var i = 0; i <imgs.length; i++) {
  88. var temp=imgs[i];
  89. tempHtml+="<img src='" + temp + "' width='40' height='40' style='display:inline-block; vertical-align:middle; margin-right:10px;' />";
  90. }
  91. html +=tempHtml;
  92. html +=content + "</td>";
  93. // <img src='" + images + "' width='40' height='40' style='display:inline-block; vertical-align:middle; margin-right:10px;' />" + content + "</td>"
  94. html += "</tr>"
  95. tr.innerHTML = html;
  96. tb.appendChild(tr);
  97. $("#view_more").css("display"," ");
  98. }
  99. //添加数据添加监听
  100. window.addEventListener("add-item", function(e) {
  101. clearHTML();
  102. queryList();
  103. });