var self, classes; mui.plusReady(function(){ self = plus.webview.currentWebview(); classes = self.classes; var $searchbarInput = $('#searchPut'), $searchSuggest = $('#search_suggest_text'),// 搜索框下面悬浮的搜索提示 search_keyword = "",//记录搜索框的内容 $noResultWrap = $('#no_result_wrap'), $del = $('.u-icon-delete'), $ul = $('.lc-list'), $searchResult = $('#search_result'); $searchbarInput.focus(); //监视输入 $searchbarInput.on('input', function() { var text = $(this).val().trim(); if(text){ $del.show() }else{ $del.hide() } $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 ; } $searchSuggest.hide(); var params = { name:search_keyword, isinsulin:classes==0?1:2 } plus.nativeUI.showWaiting(); sendPost("doctor/prescriptionInfo/findDictByName",params, function(){ plus.nativeUI.closeWaiting(); mui.toast("获取数据失败"); }, function(res){ plus.nativeUI.closeWaiting(); if(res.status == 200){ if(res.data.length>0){ var html = template('result_tmp',{data:$.map(res.data,function(o,index){ o.isRefrigerate = o.storageConditions; o.physicAmountUnit = o.packUnit; o.physicAmountUnitName = o.packUnitName; o.jsonStr = JSON.stringify(o); return o }) }) $ul.empty().html(html) ellipsisText($searchResult.find('.yp-one'),search_keyword) $noResultWrap.hide(); $searchResult.show(); }else{ $noResultWrap.show() $ul.empty() $searchResult.hide() } }else{ mui.toast("获取数据失败"); } },'get') } $searchSuggest.on('click',function() { searchByPaging() }) mui('.mui-scroll-wrapper').scroll({ bounce: true }) // 控制搜索关键字悬浮提示的显示 function showSearchSuggest(text) { var suggestText = '搜索“'+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 props = getRowProps($el), chartWidth = props.chartWidth, rowHeight = props.rowHeight, rowWidth = props.rowWidth, // 每行显示字符数(以中文字符为标准计算) chartNum = Math.floor(rowWidth / chartWidth.zh), // 排除指定数量字符所占宽度 exceptNum = 0, // 行数 rowNum = 1, // 预计显示总字符数 expectedNum = chartNum * rowNum - exceptNum, $target = $el, // 目标文本 text = $.trim($target.attr('data-text')), length = text.length, // 关键字数组 kws = $.trim(searchText).replace(/\s+/g," ").split(" "); var fidx = 0,preFidx,diff = 0; $target.html(replaceAll(text, kws)); if(Math.floor($target.height() / rowHeight) <= rowNum) { return ; } } function getRowProps($el) { var $textEllipsis = $el, $text = $textEllipsis.eq(0), $chart = $text.text('a'), enWidth = $chart.width(), $chart = $text.text('中'), zhWidth = $chart.width(), lineHeight = parseFloat($chart.css("lineHeight"), 10), rowHeight = $chart.height(); $chart.text(''); return { chartWidth: { zh: zhWidth, en: enWidth }, rowHeight: Math.max(rowHeight, lineHeight), rowWidth: $el.width() }; } function replaceAll(text, arr) { var html = text; _.each(arr,function(kw) { var reg = new RegExp(kw+"(?!>)","gi"); html = html.replace(reg,''+kw+''); }); return html; } //清空 $del.click(function(){ $searchbarInput.val('') $del.hide() $noResultWrap.hide() $searchResult.hide() $searchSuggest.empty().hide() $searchbarInput.focus() }) //选取用药 $ul.on('click','.yp-one',function(){ var $val = $(this).attr('data-json'); plus.storage.setItem("chooseMedicineList",$val) plus.storage.setItem("medicineType",classes) //新增 var page = plus.webview.getWebviewById("drugs"); if(page){ mui.fire(page, "addMedicine"); } mui.back() }) })