jiandangsousuo.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. mui.plusReady(function() {
  2. var page = 1,
  3. pagesize = 10;
  4. var self = plus.webview.currentWebview();
  5. var $searchbarInput = $('#searchPut'),
  6. $searchSuggest = $('#search_suggest_text'),// 搜索框下面悬浮的搜索提示
  7. search_keyword = "",//记录搜索框的内容
  8. $noResultWrap = $('#no_result_wrap'),
  9. $searchResult = $('#search_result');
  10. mui.init({
  11. pullRefresh : {
  12. container:'.mui-scroll-wrapper',
  13. up : {
  14. height:50,
  15. contentdown:"",
  16. contentrefresh : "正在加载...",
  17. contentnomore:'没有更多数据了',
  18. callback: function() {
  19. var self = this;
  20. page++;
  21. queryListData(function(value){
  22. setTimeout(function(){
  23. self.endPullupToRefresh(value);
  24. },500)
  25. })
  26. }
  27. }
  28. }
  29. })
  30. //监视输入
  31. $searchbarInput.on('input', function() {
  32. var text = $(this).val().trim();
  33. $searchResult.hide();
  34. $noResultWrap.hide();
  35. showSearchSuggest(text);
  36. }).on('keydown',function(e) {
  37. if (e.which === 13) {
  38. searchByPaging()
  39. }
  40. })
  41. //查询
  42. function searchByPaging(){
  43. $searchbarInput.blur();
  44. search_keyword = $searchbarInput.val();
  45. if(!$.trim(search_keyword)) {
  46. return ;
  47. }
  48. page = 1;
  49. $('#dest_list').empty();
  50. mui('.mui-scroll-wrapper').pullRefresh().refresh(true);
  51. plus.nativeUI.showWaiting();
  52. queryListData();
  53. $searchSuggest.hide();
  54. $noResultWrap.hide();
  55. }
  56. $searchSuggest.on('click',function() {
  57. searchByPaging()
  58. })
  59. // 控制搜索关键字悬浮提示的显示
  60. function showSearchSuggest(text) {
  61. var suggestText = '搜索“'+text+'”';
  62. // 如果text不为空,则显示;否则隐藏
  63. if(text&&text.trim().length) {
  64. $searchSuggest.text(suggestText);
  65. $searchSuggest.show();
  66. } else {
  67. $searchSuggest.text('');
  68. $searchSuggest.hide();
  69. }
  70. }
  71. //关键字变色
  72. function ellipsisText($elements, searchText) {
  73. _.each($elements,function(el) {
  74. var $textEl = $(el).find(".j-text-ellipsis");
  75. _.each($textEl, function(t){
  76. highlineKeyword($(t),searchText)
  77. })
  78. })
  79. }
  80. function highlineKeyword($el,searchText) {
  81. var text = $.trim($el.attr('data-text')),
  82. length = text.length,
  83. kws = $.trim(searchText).replace(/\s+/g," ").split(" ");
  84. $el.html(replaceAll(text, kws));
  85. }
  86. function replaceAll(text, arr) {
  87. var html = text;
  88. _.each(arr,function(kw) {
  89. var reg = new RegExp(kw+"(?!>)","gi");
  90. html = html.replace(reg,'<em>'+kw+'</em>');
  91. });
  92. return html;
  93. }
  94. //取消
  95. $('.searchbar-cancel').on('click',function() {
  96. mui.back();
  97. })
  98. //点击跳转
  99. $searchResult.on('tap','.j-detail',function(){
  100. mui.openWindow({
  101. id: "jiandangxiangqing",
  102. url: "jiandangxiangqing.html",
  103. extras: {
  104. code:$(this).attr('data-code')
  105. }
  106. })
  107. })
  108. function queryListData(fun){
  109. var params ={
  110. pageNo:page,
  111. pageSize:pagesize,
  112. keyWord:search_keyword
  113. }
  114. sendPost("doctor/archives/findArchivesList",params, function(){
  115. plus.nativeUI.closeWaiting();
  116. fun&&fun.call(this,false)
  117. mui.toast("请求失败");
  118. }, function(res){
  119. plus.nativeUI.closeWaiting();
  120. if(res.status == 200){
  121. var html = template('li_tmpl',{list:_.map(res.data,function(o){
  122. o.jsonStr = JSON.stringify(o);
  123. return o;})
  124. })
  125. if(page == 1 && res.data.length==0){
  126. $noResultWrap.show();
  127. $searchResult.hide();
  128. }else{
  129. $noResultWrap.hide();
  130. $searchResult.show();
  131. if(res.data.length < pagesize){
  132. fun&&fun.call(this,true)
  133. }else{
  134. fun&&fun.call(this,false)
  135. }
  136. $('#dest_list').append(html);
  137. ellipsisText($searchResult.find('.j-detail'),search_keyword)//变色
  138. }
  139. }else{
  140. fun&&fun.call(this,false)
  141. mui.toast("获取数据失败");
  142. }
  143. })
  144. }
  145. })
  146. template.helper('setTimeF',function(o){
  147. return o.substring(0,16)
  148. })