mui.init(); var $searchbarInput = $('#searchPut'), $searchSuggest = $('#search_suggest_text'),// 搜索框下面悬浮的搜索提示 search_keyword = "",//记录搜索框的内容 $noResultWrap = $('#no_result_wrap'), $searchResult = $('#search_result'); $searchbarInput.focus(); var page = 1, pageSize =10; mui.plusReady(function(){ initScroller(); bindEvents(); }); function getList(isInit){ if(isInit){ page = 1; $searchSuggest.text(''); $searchSuggest.hide(); } var url = "/doctor/prescriptionInfo/getPrescriptionByKeyWord", keyword = $.trim($("#searchPut").val()), params = { keyWord: keyword, pageNo: page, pageSize: pageSize }; plus.nativeUI.showWaiting(); sendGet(url, params, null, function(res){ if(res.status == 200){ if(isInit){ mui('.mui-scroll-wrapper').scroll().scrollTo(0,0); if(res.data.length == 0){ $("#iScroll").hide(); $("#no_result_wrap").show(); }else{ $("#iScroll").show(); $("#no_result_wrap").hide(); var html = template("list-tmp", {list: res.data.list, keyword: keyword}); $("#listPanel").empty().append(html); if(res.data.length < pageSize){ mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(true); }else{ mui('.mui-scroll-wrapper').pullRefresh().refresh(true); page ++; } } }else{ var html = template("list-tmp", {list: res.data.list, keyword: keyword}); $("#listPanel").append(html); if(res.data.length < pageSize){ mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(true); }else{ mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(); page ++; } } }else{ mui.toast(res.msg); } plus.nativeUI.closeWaiting(); }, true); } function initScroller(){ //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; mui('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); mui(".mui-scroll-wrapper").pullRefresh({ up: { callback: function(){ var self = this; setTimeout(function(){ getList(false); // self.endPullupToRefresh(); }, 500); } } }) } function bindEvents(){ //监视输入 $searchbarInput.on('input', function() { var text = $(this).val().trim(); $searchResult.hide(); $noResultWrap.hide(); showSearchSuggest(text); }).on('keydown',function(e) { if (e.which === 13) { getList(true) } }); $searchSuggest.on('click',function() { getList(true) }); //取消 $('.searchbar-cancel').on('click',function() { mui.back(); }); $("#listPanel").on('tap', ".order", function(){ var code = $(this).attr("data-code"); openWebview("xufangxiangqing2.html", {prescriptionCode: code}); }); template.helper("getStatusName", function(status){ status = parseInt(status); if(status == 100){ return "已完成"; }else if(status == -2){ return "居民取消"; }else if(status == -1){ return "审核不通过"; }else if(status <= -3){ return "其他原因取消"; }else if(status >=0 && status<100){ return "进行中"; } }); template.helper("hightlightKeyword", function(str, kw){ var reg = new RegExp(kw+"(?!>)","gi"); return str.replace(reg,''+kw+''); }); template.helper("getExpressName", function(type){ switch(type){ case 1: return '自取'; break; case 3: return "健管师配送"; break; case 2: return "快递配送"; break; default: return ""; break; } }); template.helper("formatDate", function(str){ if(!str){ return ""; } var timeStm = parseInt(str), d = new Date(timeStm); return d.format("yyyy-MM-dd hh:mm") }) } // 控制搜索关键字悬浮提示的显示 function showSearchSuggest(text) { var suggestText = '搜索“'+text+'”'; // 如果text不为空,则显示;否则隐藏 if(text&&text.trim().length) { $searchSuggest.text(suggestText); $searchSuggest.show(); } else { $searchSuggest.text(''); $searchSuggest.hide(); } }