123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- mui.plusReady(function(){
- var page =0,
- pagesize = 10;
- var self = plus.webview.currentWebview();
- //可获得相关的参数
- // var firstLevelCategoryId= self.firstLevelCategoryId;
- var currentUserRole = self.currentUserRole;
- var currentUserRoleLevel = self.currentUserRoleLevel;
-
-
- var $searchbarInput = $('#searchPut'),
- $searchSuggest = $('#search_suggest_text'),
- search_keyword = "",//记录搜索框的内容
- $noResultWrap = $('#no_result_wrap'),
- $searchResult = $('#search_result');
- $searchbarInput.focus();
-
- 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);
- })
- },'up')
- }
- }
- }
- })
-
- //监视输入
- $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 = 0;
- $('#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 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,'<em>'+kw+'</em>');
- });
- return html;
- }
- //取消
- $('.searchbar-cancel').on('click',function(){
- mui.back();
- })
-
- function queryListData(fun){
- var params = {
- firstLevelCategoryId: self.firstLevelCategoryId,
- currentUserRole: self.currentUserRole,
- currentUserRoleLevel: self.currentUserRoleLevel,
- articleTitle: search_keyword,
- iDisplayStart: page,
- iDisplayLength: pagesize,
- currentUserRoleLevel: 4,
- roleType:1,
- isMyArticle:true
- };
- var url="/doctor/jkEdu/article/queryArticleAPPList";
- sendPost(url,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:res.data.aaData});
- if(page == 0 && res.data.aaData.length==0){
- $noResultWrap.show();
- $searchResult.hide();
- }else{
- $noResultWrap.hide();
- $searchResult.show();
- if(res.data.aaData.length < pagesize){
- fun&&fun.call(this,true)
- }else{
- fun&&fun.call(this,false)
- }
- $('#dest_list').append(html);
- ellipsisText($searchResult.find('.j-li'),search_keyword)//变色
-
- }
- }else{
- fun&&fun.call(this,false);
- mui.toast("获取数据失败!");
- }
- },'get')
- }
- $('#dest_list').on('tap','li.article-li',function(){
- var articleId = $(this).attr('data-id');
- mui.openWindow({
- id: "articleDetail",
- url: "articleDetail.html",
- extras: {
- articleId:articleId
- }
- })
- })
- //点击跳转
- $('#dest_list').on('tap','.tuisong-common',function(e){
- e.stopPropagation();
- var $this = $(this);
- var articleId = $this.attr("data-code");
- var articleTitle = $this.attr("data-title");
- mui.openWindow({
- id: "xuanzejumin_more",
- url: "xuanzejumin_more.html",
- extras: {
- article:articleId,origin:'jiaoyu',articleTitle:articleTitle
- }
- })
- })
- $('#dest_list').on('tap','.edit-common',function(e){
- e.stopPropagation();
- var $this = $(this);
- var articleId = $this.attr("data-id");
- mui.openWindow({
- id: "article-edit",
- url: "article-edit.html",
- extras: {
- articleId:articleId
- }
- })
- })
- })
- //取消
- $('.searchbar-cancel').on('click',function() {
- mui.back();
- })
- template.helper("setPhoto", function(p) {
- return getImgUrl(p);
- });
|