//var patient=""; var sortDate=""; var pageSize = 5; $(function() { // var self=plus.webview.getWebviewById("health-index-bloodsugar-chart"); // if(self.code){patient=self.code;} // console.log("bsh_patient:"+patient); clearHTML(); queryList(sortDate,pageSize); //点击加载更多 $("#view_more").on("tap", function() { queryList(sortDate,pageSize); console.log("加载更多"); }); }); function queryList(sortDate,pageSize) { //显示进度条 // plus.nativeUI.showWaiting(); //发送请求 queryListByType(1, sortDate, pageSize, queryListSuccesss); } /** * 健康指标图表查询成功处理方法 */ function queryListSuccesss(res) { if (res.status == 200) { if (res.list.length > 0) { //成功 showList(res.list); }else{ //无更多数据 document.querySelector("#view_more").innerText = "已无更多数据"; } } else { //非200则为失败 queryListFailed(res); } // plus.nativeUI.closeWaiting(); } /** * 显示查询结果 * @param {Object} list */ function showList(list) { // clearHTML(); for (var i = 0; i < list.length; i++) { var data = list[i]; if (!data) { continue; } addRow(data.date.substr(5, 5), toIntValue(data.value1), toIntValue(data.value2), toIntValue(data.value3), toIntValue(data.value4), toIntValue(data.value5), toIntValue(data.value6), toIntValue(data.value7)); sortDate = list[i].sortDate; } } function toIntValue(value){ if(parseInt(value) == value){ return parseInt(value); }else{ return Math.round(value*Math.pow(10, 1))/Math.pow(10, 1); } } /** * 清空tbody */ function clearHTML() { $("#table1 tbody").html(""); } /** * tbody添加一行tr * @param {Object} dateStr * @param {Object} value1 * @param {Object} value2 */ function addRow(dateStr, value1, value2, value3, value4, value5, value6, value7) { if(dateStr.length > 5){ dateStr = dateStr.substr(5, 5); } var tb = document.querySelector("#item"); var tr = document.createElement("tr"); var html = ''+dateStr+''; html += getTD(value1, 7.2, 4.4, "bb"); html += getTD(value2, 10, 4.4, "ba"); html += getTD(value3, 10, 4.4, "lb"); html += getTD(value4, 10, 4.4, "la"); html += getTD(value5, 10, 4.4, "db"); html += getTD(value6, 10, 4.4, "da"); html += getTD(value7, 10, 4.4, "sb"); tr.innerHTML = html; tb.appendChild(tr); } function getTD(value, max, min, styleName){ if(value == 0 || isNaN(value)){ return ''; } if(value > max){ return ''+value+''; }else if(value < min){ return ''+value+''; }else{ return ''+value+''; } } //添加数据添加监听 window.addEventListener("add-item", function(e) { //刷新列表 queryList(); //添加一行 // addRow(e.detail.date, e.detail.val_high, e.detail.val_low); //存储到本地 // plus.storage.setItem("bloodpressure_history", con); });