123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- mui.plusReady(function() {
- var page = 1,
- pagesize = 10;
- var self = plus.webview.currentWebview();
- var $searchbarInput = $('#searchPut'),
- $searchSuggest = $('#search_suggest_text'),// 搜索框下面悬浮的搜索提示
- search_keyword = "",//记录搜索框的内容
- $noResultWrap = $('#no_result_wrap'),
- $searchResult = $('#search_result');
- mui.init({
- pullRefresh : {
- container:'.mui-scroll-wrapper',
- up : {
- height:50,
- contentdown:"",
- contentrefresh : "正在加载...",
- contentnomore:'没有更多数据了',
- callback: function() {
- var self = this;
- page++;
- queryListData(function(value){
- setTimeout(function(){
- self.endPullupToRefresh(value);
- },500)
- })
- }
- }
- }
- })
- //监视输入
- $searchbarInput.on('input', function() {
- var text = $(this).val().trim();
- $searchResult.hide();
- $noResultWrap.hide();
- showSearchSuggest(text);
- }).on('keydown',function(e) {
- if (e.which === 13) {
- searchByPaging()
- }
- })
-
- //查询
- function searchByPaging(){
- $searchbarInput.blur();
- search_keyword = $searchbarInput.val();
- if(!$.trim(search_keyword)) {
- return ;
- }
- page = 1;
- $('#dest_list').empty();
- mui('.mui-scroll-wrapper').pullRefresh().refresh(true);
- plus.nativeUI.showWaiting();
- queryListData();
- $searchSuggest.hide();
- $noResultWrap.hide();
- }
-
- $searchSuggest.on('click',function() {
- searchByPaging()
- })
-
- // 控制搜索关键字悬浮提示的显示
- function showSearchSuggest(text) {
- var suggestText = '搜索“'+text+'”';
- // 如果text不为空,则显示;否则隐藏
- if(text&&text.trim().length) {
- $searchSuggest.text(suggestText);
- $searchSuggest.show();
- } else {
- $searchSuggest.text('');
- $searchSuggest.hide();
- }
- }
-
- //关键字变色
- function ellipsisText($elements, searchText) {
- _.each($elements,function(el) {
- var $textEl = $(el).find(".j-text-ellipsis");
- _.each($textEl, function(t){
- highlineKeyword($(t),searchText)
- })
- })
- }
- function highlineKeyword($el,searchText) {
- var text = $.trim($el.attr('data-text')),
- length = text.length,
- kws = $.trim(searchText).replace(/\s+/g," ").split(" ");
- $el.html(replaceAll(text, kws));
- }
- function replaceAll(text, arr) {
- var html = text;
- _.each(arr,function(kw) {
- var reg = new RegExp(kw+"(?!>)","gi");
- html = html.replace(reg,'<em>'+kw+'</em>');
- });
- return html;
- }
-
- //取消
- $('.searchbar-cancel').on('click',function() {
- mui.back();
- })
- //点击跳转
- $searchResult.on('tap','.j-detail',function(){
- mui.openWindow({
- id: "jiandangxiangqing",
- url: "jiandangxiangqing.html",
- extras: {
- code:$(this).attr('data-code')
- }
- })
- })
-
- function queryListData(fun){
- var params ={
- pageNo:page,
- pageSize:pagesize,
- keyWord:search_keyword
- }
- sendPost("doctor/archives/findArchivesList",params, function(){
- plus.nativeUI.closeWaiting();
- fun&&fun.call(this,false)
- mui.toast("请求失败");
- }, function(res){
- plus.nativeUI.closeWaiting();
- if(res.status == 200){
- var html = template('li_tmpl',{list:_.map(res.data,function(o){
- o.jsonStr = JSON.stringify(o);
- return o;})
- })
- if(page == 1 && res.data.length==0){
- $noResultWrap.show();
- $searchResult.hide();
- }else{
- $noResultWrap.hide();
- $searchResult.show();
- if(res.data.length < pagesize){
- fun&&fun.call(this,true)
- }else{
- fun&&fun.call(this,false)
- }
- $('#dest_list').append(html);
- ellipsisText($searchResult.find('.j-detail'),search_keyword)//变色
- }
- }else{
- fun&&fun.call(this,false)
- mui.toast("获取数据失败");
- }
- })
- }
- })
- template.helper('setTimeF',function(o){
- return o.substring(0,16)
- })
|