health-record-diet.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var flag = false;
  2. var d = dialog({contentType:'load', skin:'bk-popup'});
  3. var sortDate = "";
  4. var pageSize = 5;
  5. $(function() {
  6. clearHTML();
  7. queryList(sortDate,pageSize);
  8. //点击加载更多
  9. $("#view_more").on("tap", function() {
  10. queryList(sortDate,pageSize);
  11. });
  12. document.getElementById("add").onclick = handleClick;
  13. setTimeout(function(){
  14. flag = true;
  15. },500);
  16. });
  17. function handleClick(){
  18. if(!flag){
  19. flag = true;
  20. return ;
  21. }
  22. window.location.href = "add-diet-record.html";
  23. }
  24. function queryList(sortDate,pagesize) {
  25. //拼请求内容
  26. d.show();
  27. var params = {};
  28. params.sortDate = sortDate;
  29. params.pagesize = pagesize;
  30. //发送ajax请求
  31. sendPost("patient/health_record/list_diet", params, "json", "post", queryListFailed, queryListSuccesss);
  32. }
  33. /**
  34. * 健康指标图表查询成功处理方法
  35. */
  36. function queryListSuccesss(res) {
  37. if (res.status == 200) {
  38. d.close();
  39. if (res.list.length > 0) {
  40. showList(res.list);
  41. }else{
  42. document.querySelector("#view_more").innerText = "已无更多数据";
  43. }
  44. } else {
  45. queryListFailed(res);
  46. }
  47. }
  48. function queryListFailed(res) {
  49. d.close().remove();
  50. if (res && res.msg) {
  51. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  52. } else {
  53. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  54. }
  55. }
  56. /**
  57. * 显示查询结果
  58. * @param {Object} list
  59. */
  60. function showList(list) {
  61. for (var i = 0; i < list.length; i++) {
  62. var data = list[i];
  63. if (!data) {
  64. continue;
  65. }
  66. //data.date.substr(5, 5) --只有月-日
  67. addRow(data.record_date, data.content,data.images);
  68. sortDate = list[i].sortDate;
  69. }
  70. }
  71. /**
  72. * 清空tbody
  73. */
  74. function clearHTML() {
  75. $("#diet_list").html("");
  76. }
  77. /**
  78. * tbody添加一行tr
  79. * @param {Object} dateStr
  80. * @param {Object} value1
  81. * @param {Object} value2
  82. */
  83. function addRow(record_date, content,images) {
  84. // if(dateStr.length > 5){
  85. // dateStr = dateStr.substr(5, 5);
  86. // }
  87. var tb = document.querySelector("#diet_list");
  88. var tr = document.createElement("tr");
  89. var pict= new Array(); //定义一数组
  90. pict=images.split(","); //字符分割
  91. var img_html="";
  92. for (i=0;i<pict.length ;i++ )
  93. {
  94. // document.write(+"<br/>"); //分割后的字符输出
  95. img_html+="<img src='"+ getImgUrl(pict[i])+"' width='40' height='40' style='display:inline-block; vertical-align:middle; margin-right:10px;' onclick='viewImg(this)'/>"
  96. }
  97. var html ="";
  98. html+="<tr>"
  99. html+= "<td class='width-30'>"+record_date+"</td>"
  100. html+= "<td class='width-70' style='text-align:left;'>"+img_html+content+"</td>"
  101. html+="</tr>"
  102. tr.innerHTML = html;
  103. tb.appendChild(tr);
  104. }
  105. //查看图片
  106. function viewImg(dom) {
  107. var $img = $(dom);
  108. var thissrc = $img.attr("src");
  109. var mWid = $(window).width();
  110. var mHei = $(window).height();
  111. var nHtml = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
  112. $("body").append(nHtml);
  113. $(".delimgpop").click(function() {
  114. $(this).remove()
  115. });
  116. };
  117. //添加数据添加监听
  118. window.addEventListener("add-item", function(e) {
  119. clearHTML();
  120. queryList();
  121. });