; (function($){ $.fn.fwsSearch = function(opts){ var col_id = $(".col_title").data("id"); var defaults = { siteId: null, //站点Id columnId: col_id , //栏目Id url:'/_wp3services/generalQuery?queryObj=articles', //文章检索接口 lang: 1, //语言类型 level:1, //校级:0,,部门:1 displayType:'filter', //展示类型, 'list':栏目列表, 'select':下拉框, 'filter':条件筛选 category: true, nav:{ active: true, //是否显示导航 navCon: '.fws_nav' //导航放置位置 }, field: [ //导航数据,格式如下 {title:"字母",children:"A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z",type:"0"} ], fieldJson: [], //文章的json数据 pageIndex: 1, //默认第一页开始 rows: 999, //每页显示多少篇文章 orderData:[ //排序方式 {field: "letter", type: "asc"} ], conditFeild:[ //检索需要的字段||检索查询条件 {type:"0", field:"letter", judge:"like"}, {type:"0", field:"f4", judge:"like"} ], returnInfosdata:[ //检索返回的字段 {field: "title", name: "title"}, {field: "publishTime", name: "publishTime"}, {field: "content", name: "content"}, {field: "summary", name: "summary"}, {field: "mircImgPath", name: "mircImgPath"}, {field: "imgPath", name: "imgPath"}, {field: "link", name: "link"}, {field: "url", name: "url"}, {field: "letter", name: "letter"}, {field: "f4", name: "f4"}, {field: "visitCount", name: "visitCount"} ], showType: 1, //输出显示方式(以下面tpl参数设置优先) 1:人名+浏览次数 2:上图下文 tpl:function(data){ //输出结构 return '
  • ' + '
    ' + ' '+'' + art.title + '' + '
    ' + '
  • '; }, callback: function(){} //回调函数(参数为当前结构,检索结果,配置项) //paging: true, //isMobile: false }; var o = $.extend(true, {}, defaults, opts); return this.each(function(){ $('html').addClass("fws_searchs"); var c = $(this); c.wrapInner('
    '); var $listTable = c.find('.listTable'); var $wp_paging = c.find('.wp_paging'); var pageIndex = o.pageIndex,item = '',type = ''; url = o.url, rows = o.rows, showType= o.showType; /*pageCount = 0, loadBtn = true;*/ function getSearchData(url,complete,showType,rows,keyword,orgId,pageIndex){ complete.addClass("loading"); $(".listTable .news_list").children().remove(); var orders = JSON.stringify(getOrders()),conditions = JSON.stringify(getConditions(keyword,orgId)),returnInfos = JSON.stringify(getReturnInfos()); $.ajax({ url: url, type: 'POST', contentType: "application/x-www-form-urlencoded; charset=utf-8", async: true, dataType: 'json', data: { siteId: o.siteId, columnId: o.columnId, pageIndex: pageIndex, rows: rows, conditions: conditions, orders: orders, returnInfos: returnInfos, articleType: 1, scope:o.scope }, success: function(result){ //window.console && console.log(result); complete.children(".news_list").children().remove(); complete.next().remove(); if(result != null){ $listTable.removeClass("loading"); if(result.data.length > 0){ setTempTpl(result,complete,showType,rows); pageTpl(result,complete,pageIndex,rows); pageClick(rows,item,type); }else{ $listTable.children().html('
    未检索到相关信息!
    '); } } if(typeof o.callback === "function"){ o.callback.call(this, result, o); } } }); } /*模板结构*/ function setTempTpl(result,complete,showType,rows){ $(".listTable .news_list").children().remove(); var html = ""; var tecCount = Math.min(rows, result.data.length); var keyword = 'A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z'; var items = keyword.split("+"); if(o.category){ if(o.showType && o.showType !== null){ var html = "",nameHtml = ""; $.each(items,function(index,name){ nameHtml = '
    '+ '
    '+name+'
    '+ '
    '+ ' '+ '
    '+ '
    '; $listTable.children().append(nameHtml); //complete.children(".news_list").append(html); for (i = 0; i < tecCount; i++){ var art = result.data[i]; var tecUrl = art.cnUrl; art.cnUrl = checkMobileURL(tecUrl); if(name == $.trim(art[o.conditFeild[1].field])){ html = '
  • ' + '
    ' + ' '+'' + art.title + '' + '
    ' + '
  • '; complete.find(".news_item").eq(index).find(".news_con .news_lists").append(html); } } }); } }else{ for (i = 0; i < tecCount; i++){ var art = result.data[i]; var tecUrl = art.cnUrl; art.cnUrl = checkMobileURL(tecUrl); if(o.showType && o.showType !== null){ if(showType == 1){ html += '
  • ' + '
    ' + ' '+'' + art.title + '' + '
    ' + '
  • '; }else{ html += '
  • ' + '
    ' + ' '+'' + art.title + '' + '
    ' + '
  • '; } }else{ if(typeof o.tpl === "function" && o.tpl){ html += o.tpl(art); } } } //区分不同的输出结构 complete.children(".news_list").append(html); } $(document).ready(function(){ $('.news_item.list').each(function(){ $(this).find(".news_con .news_lists").each(function(){ if($(this).find("li").length == 0){ $(this).parents(".news_item").remove(); } }); }); if($(window).width() < 768){ $('.listzm a').click(function () { $('html, body').animate({ scrollTop: $($.attr(this, 'href')).offset().top - 440 }, 800); return false; }); }else{ $('.listzm a').click(function () { $('html, body').animate({ scrollTop: $($.attr(this, 'href')).offset().top - 65 }, 800); return false; }); } }); } /*分页结构*/ function pageTpl(result,complete,pageIndex,rows){ var pageCount = result.pageCount; var total = result.total; var pageHtml = '
    '+ ' '+ '
    '; $(complete).after(pageHtml); } //初始化 fwsSearchDate(showType,rows,item,type,pageIndex); //分页点击事件 function pageClick(rows,item,type){ $(document).off(); //移除所有元素上的 click 事件 initpageClick(rows,item,type); //跳转页面 initFirstPageClick(rows,item,type); //首页 initLastPageClick(rows,item,type); //尾页 initPrevPageClick(rows,item,type); //上一页 initNextPageClick(rows,item,type); //下一页 } //初始化跳转页面 function initpageClick(rows,item,type){ $(document).on('click','.new_pagingJump',function(event){ var pageNum = c.find(".pageNum").val(); if (pageNum === "") { alert("请输入页码!"); return; } var pageCount = c.find(".all_pages").attr("pageCount"); if (isNaN(pageNum) || pageNum <= 0 || pageNum > pageCount) { alert("请输入正确页码!"); return; } fwsSearchDate(showType,rows,item,type,pageNum); }); } //初始化首页 function initFirstPageClick(rows,item,type) { $(document).on('click', ".new_page_nav .first", function(event) { fwsSearchDate(showType,rows,item,type,1); }); } //初始化尾页 function initLastPageClick(rows,item,type){ $(document).off().on('click', ".new_page_nav .last", function(event) { var allPages = c.find(".all_pages").attr("pageCount"); fwsSearchDate(showType,rows,item,type,allPages); }); } //初始化上一页 function initPrevPageClick(rows,item,type){ $(document).on('click', ".new_page_nav .prev", function(event) { var pageCount = c.find(".curr_page").attr("curr_page"); var prev = --pageCount; if (prev <= 0){ alert("当前为第一页"); return; } fwsSearchDate(showType,rows,item,type,prev); }); } //初始化下一页 function initNextPageClick(rows,item,type) { $(document).on('click', ".new_page_nav .next", function(event) { var pageCount = c.find(".curr_page").attr("curr_page"); var next = ++pageCount; var allPages = c.find(".all_pages").attr("pageCount"); if (allPages < next) { alert("当前为最后一页"); return; } fwsSearchDate(showType,rows,item,type,next); }); } /*导航*/ if(o.nav.active && o.displayType === 'list'){ var html= "",subHtml = '',field = o.field; var $navCon = $(o.nav.navCon); $navCon.wrapInner('