xufangsousuo.js 6.0 KB

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