health-record-drug.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_medication", 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.medicines);
  56. sortDate = list[i].sortDate;
  57. }
  58. document.getElementById("view_more").style.display="";
  59. }
  60. /**
  61. * 清空tbody
  62. */
  63. function clearHTML() {
  64. $("#drug_list").html("");
  65. }
  66. /**
  67. * tbody添加一行tr
  68. * @param {Object} dateStr
  69. * @param {Object} value1
  70. * @param {Object} value2
  71. */
  72. function addRow(date, medicines) {
  73. // if(dateStr.length > 5){
  74. // dateStr = dateStr.substr(5, 5);
  75. // }
  76. var tb = document.querySelector("#drug_list");
  77. var tr = document.createElement("tr");
  78. var html = "";
  79. html += "<tr>"
  80. html += "<td class='width-30'>" + date + "</td>"
  81. html += "<td class='width-70'>" + medicines + "</td>"
  82. html += "</tr>"
  83. tr.innerHTML = html;
  84. tb.appendChild(tr);
  85. $("#view_more").css("display"," ");
  86. }
  87. //添加数据添加监听
  88. window.addEventListener("add-item", function(e) {
  89. clearHTML();
  90. queryList();
  91. });