var flag = false; var d = dialog({contentType:'load', skin:'bk-popup'}); var sortDate = ""; var pageSize = 5; $(function() { clearHTML(); queryList(sortDate,pageSize); //点击加载更多 $("#view_more").on("tap", function() { queryList(sortDate,pageSize); }); document.getElementById("add").onclick = handleClick; setTimeout(function(){ flag = true; },500); }); function handleClick(){ if(!flag){ flag = true; return ; } window.location.href = "add-diet-record.html"; } function queryList(sortDate,pagesize) { //拼请求内容 d.show(); var params = {}; params.sortDate = sortDate; params.pagesize = pagesize; //发送ajax请求 sendPost("patient/health_record/list_diet", params, "json", "post", queryListFailed, queryListSuccesss); } /** * 健康指标图表查询成功处理方法 */ function queryListSuccesss(res) { if (res.status == 200) { d.close(); if (res.list.length > 0) { showList(res.list); }else{ document.querySelector("#view_more").innerText = "已无更多数据"; } } else { queryListFailed(res); } } function queryListFailed(res) { d.close().remove(); if (res && res.msg) { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show(); } } /** * 显示查询结果 * @param {Object} list */ function showList(list) { for (var i = 0; i < list.length; i++) { var data = list[i]; if (!data) { continue; } //data.date.substr(5, 5) --只有月-日 addRow(data.record_date, data.content,data.images); sortDate = list[i].sortDate; } } /** * 清空tbody */ function clearHTML() { $("#diet_list").html(""); } /** * tbody添加一行tr * @param {Object} dateStr * @param {Object} value1 * @param {Object} value2 */ function addRow(record_date, content,images) { // if(dateStr.length > 5){ // dateStr = dateStr.substr(5, 5); // } var tb = document.querySelector("#diet_list"); var tr = document.createElement("tr"); var pict= new Array(); //定义一数组 pict=images.split(","); //字符分割 var img_html=""; for (i=0;i"); //分割后的字符输出 img_html+="" } var html =""; html+="" html+= ""+record_date+"" html+= ""+img_html+content+"" html+="" tr.innerHTML = html; tb.appendChild(tr); } //查看图片 function viewImg(dom) { var $img = $(dom); var thissrc = $img.attr("src"); var mWid = $(window).width(); var mHei = $(window).height(); var nHtml = '
'; $("body").append(nHtml); $(".delimgpop").click(function() { $(this).remove() }); }; //添加数据添加监听 window.addEventListener("add-item", function(e) { clearHTML(); queryList(); });