searchxufangdingdan.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. mui.plusReady(function() {
  2. var page = 1,
  3. pagesize = 10;
  4. var self = plus.webview.currentWebview();
  5. var teamCode = self.teamCode;
  6. var type = self.type;
  7. var docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  8. var $searchbarInput = $('#searchPut'),
  9. $searchSuggest = $('#search_suggest_text'),// 搜索框下面悬浮的搜索提示
  10. search_keyword = "",//记录搜索框的内容
  11. $noResultWrap = $('#no_result_wrap'),
  12. $searchResult = $('#search_result');
  13. $searchbarInput.focus();
  14. mui.init({
  15. pullRefresh : {
  16. container:'.mui-scroll-wrapper',
  17. up : {
  18. height:50,
  19. contentdown:"",
  20. contentrefresh : "正在加载...",
  21. contentnomore:'没有更多数据了',
  22. callback: function() {
  23. var self = this;
  24. page++;
  25. queryListData(function(value){
  26. setTimeout(function(){
  27. self.endPullupToRefresh(value);
  28. },500)
  29. },'up')
  30. }
  31. }
  32. }
  33. })
  34. //监视输入
  35. $searchbarInput.on('input', function() {
  36. var text = $(this).val().trim();
  37. $searchResult.hide();
  38. $noResultWrap.hide();
  39. showSearchSuggest(text);
  40. }).on('keydown',function(e) {
  41. if (e.which === 13) {
  42. searchByPaging()
  43. }
  44. })
  45. //查询
  46. function searchByPaging(){
  47. $searchbarInput.blur();
  48. search_keyword = $searchbarInput.val();
  49. if(!$.trim(search_keyword)) {
  50. return ;
  51. }
  52. page = 1;
  53. $('#dest_list').empty();
  54. mui('.mui-scroll-wrapper').pullRefresh().refresh(true);
  55. plus.nativeUI.showWaiting();
  56. queryListData();
  57. $searchSuggest.hide();
  58. $noResultWrap.hide();
  59. }
  60. $searchSuggest.on('click',function() {
  61. searchByPaging()
  62. })
  63. // 控制搜索关键字悬浮提示的显示
  64. function showSearchSuggest(text) {
  65. var suggestText = '搜索“'+text+'”';
  66. // 如果text不为空,则显示;否则隐藏
  67. if(text&&text.trim().length) {
  68. $searchSuggest.text(suggestText);
  69. $searchSuggest.show();
  70. } else {
  71. $searchSuggest.text('');
  72. $searchSuggest.hide();
  73. }
  74. }
  75. //关键字变色
  76. function ellipsisText($elements, searchText) {
  77. _.each($elements,function(el) {
  78. var $textEl = $(el).find(".j-text-ellipsis");
  79. _.each($textEl, function(t){
  80. highlineKeyword($(t),searchText)
  81. })
  82. })
  83. }
  84. function highlineKeyword($el,searchText) {
  85. var props = getRowProps($el),
  86. chartWidth = props.chartWidth,
  87. rowHeight = props.rowHeight,
  88. rowWidth = props.rowWidth,
  89. // 每行显示字符数(以中文字符为标准计算)
  90. chartNum = Math.floor(rowWidth / chartWidth.zh),
  91. // 排除指定数量字符所占宽度
  92. exceptNum = 0,
  93. // 行数
  94. rowNum = 1,
  95. // 预计显示总字符数
  96. expectedNum = chartNum * rowNum - exceptNum,
  97. $target = $el,
  98. // 目标文本
  99. text = $.trim($target.attr('data-text')),
  100. length = text.length,
  101. // 关键字数组
  102. kws = $.trim(searchText).replace(/\s+/g," ").split(" ");
  103. var fidx = 0,preFidx,diff = 0;
  104. $target.html(replaceAll(text, kws));
  105. if(Math.floor($target.height() / rowHeight) <= rowNum) {
  106. return ;
  107. }
  108. }
  109. function getRowProps($el) {
  110. var $textEllipsis = $el,
  111. $text = $textEllipsis.eq(0),
  112. $chart = $text.text('a'),
  113. enWidth = $chart.width(),
  114. $chart = $text.text('中'),
  115. zhWidth = $chart.width(),
  116. lineHeight = parseFloat($chart.css("lineHeight"), 10),
  117. rowHeight = $chart.height();
  118. $chart.text('');
  119. return {
  120. chartWidth: {
  121. zh: zhWidth,
  122. en: enWidth
  123. },
  124. rowHeight: Math.max(rowHeight, lineHeight),
  125. rowWidth: $el.width()
  126. };
  127. }
  128. function replaceAll(text, arr) {
  129. var html = text;
  130. _.each(arr,function(kw) {
  131. var reg = new RegExp(kw+"(?!>)","gi");
  132. html = html.replace(reg,'<em>'+kw+'</em>');
  133. });
  134. return html;
  135. }
  136. //取消
  137. $('.searchbar-cancel').on('click',function() {
  138. mui.back();
  139. })
  140. template.helper('setSex',function(item){
  141. if(item == 1){
  142. return '男'
  143. }else{
  144. return '女'
  145. }
  146. })
  147. template.helper('dispensaryTypeName',function(type){
  148. if(type == 1){
  149. return '自取'
  150. } else if(type == 2){
  151. return '快递配送'
  152. } else if(type == 3){
  153. return '健管师配送'
  154. }
  155. return ''
  156. })
  157. //点击展开
  158. $('#medi_list').on('click','.patient-type',function(){
  159. var $this = $(this),
  160. $parent = $this.parent(),
  161. $sibling = $this.siblings('.n-list');
  162. if($parent.hasClass('current')){
  163. $parent.removeClass('current');
  164. $sibling.hide()
  165. }else{
  166. $parent.addClass('current');
  167. $sibling.show()
  168. }
  169. })
  170. //点击跳转
  171. $('#dest_list').on('tap','li',function(){
  172. var data = JSON.parse($(this).attr('data-json')),
  173. prescriptionCode = data.code;
  174. mui.openWindow({
  175. id: "dingdangenzong",
  176. url: "dingdangenzong.html",
  177. extras: {
  178. teamCode: teamCode?teamCode:$(this).attr('data-team'),
  179. prescriptionCode: prescriptionCode
  180. }
  181. })
  182. })
  183. function queryListData(fun){
  184. var params ={}
  185. var url = "";
  186. if(docInfo.level == 2) {
  187. url = "/doctor/prescriptionInfo/getDoctorPrescriptionExpressage";
  188. var params ={
  189. page:page,
  190. size:pagesize,
  191. nameKey:search_keyword,
  192. teamCode:teamCode
  193. }
  194. } else if(docInfo.level == 3) {
  195. url = "/doctor/prescriptionInfo/getHDoctorPrescriptionExpressage";
  196. var params ={
  197. page:page,
  198. size:pagesize,
  199. nameKey:search_keyword,
  200. type:type,
  201. teamCode:teamCode
  202. }
  203. }
  204. sendPost(url,params, function(){
  205. plus.nativeUI.closeWaiting();
  206. fun&&fun.call(this,false)
  207. mui.toast("获取数据失败!");
  208. }, function(res){
  209. plus.nativeUI.closeWaiting();
  210. if(res.status == 200){
  211. var html = template('li_tmpl',{list:_.map(res.data,function(o){
  212. o.jsonStr = JSON.stringify(o);
  213. return o;})
  214. })
  215. if(page == 1 && res.data.length==0){
  216. $noResultWrap.show();
  217. $searchResult.hide();
  218. }else{
  219. $noResultWrap.hide();
  220. $searchResult.show();
  221. if(res.data.length < pagesize){
  222. fun&&fun.call(this,true)
  223. }else{
  224. fun&&fun.call(this,false)
  225. }
  226. $('#dest_list').append(html);
  227. ellipsisText($searchResult.find('.j-li'),search_keyword)//变色
  228. }
  229. }else{
  230. fun&&fun.call(this,false)
  231. mui.toast("获取数据失败!");
  232. }
  233. },'get')
  234. }
  235. })
  236. template.helper("setPhoto", function(p) {
  237. return getImgUrl(p);
  238. });