$(function(){
var articleUrl = "/_wp3services/generalQuery?queryObj=teacherHome";
var siteId = 21; //站点Id
var pageIndex = 1; //从某页开始
var rows = 12; //每页显示多少篇文章
var zm = '';
var title = '';
var item = '';
var type = '0';
var columnId ='';
var field =[
{title:"Modern physics",name:"Modern physics",type:"4"},
{title:"Optical science and technology",name:"Optical science and technology",type:"4"},
{title:"Condensed matter and material physics",name:"Condensed matter and material physics",type:"4"},
{title:"Experimental teaching center",name:"Experimental teaching center",type:"4"},
];
var $listTable = $(".news-main");
var $wp_paging = $(".wp_paging");
var dataField = {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"}
var dataItem = dataField.children.split("+");
$listTable.before('
');
$.each(dataItem,function(index,val){
var html= "";
html = ''+
' '+val+''+
'';
$listTable.prev(".zm").append(html);
});
$(".news_wz").addClass("loading");
$listTable.children().remove();
$wp_paging.remove();
loadContents(pageIndex,siteId,rows,item,type);
var $zm = $(".col_news_con .zm");
$zm.find(".wp_column").eq(0).find("a").addClass("hover");
$zm.find(".wp_column").each(function(){
$(this).on("click",function(){
$(".news_wz").addClass("loading");
$(this).siblings().find("a").removeClass("hover");
$(this).find("a").addClass("hover");
var key = $(this).find("a").attr("title");
if(key == '不限')key = '';
loadContents(pageIndex,siteId,rows,item,key,type);
});
});
/**
* 通过ajax请求,向文章检索服务发送请求
* @param {type} pageIndex
* @returns {undefined}
*/
/*首页,站点,输出,值,数组个数,类型*/
function loadContents(pageIndex,siteId,rows,val,zm,i){
//排序
var orders = JSON.stringify(getOrders());
//查询条件
var conditions = JSON.stringify(getConditions(val,zm,i));
//返回属性,若没有,则返回默认属性
var returnInfos = JSON.stringify(getReturnInfos());
$.ajax({url: articleUrl,
type: 'POST',
contentType: "application/x-www-form-urlencoded; charset=utf-8",
async: true,
dataType: 'json',
data: {
siteId: siteId,
pageIndex: pageIndex,
rows: rows,
conditions: conditions,
orders: orders,
returnInfos: returnInfos,
articleType: 2,
level:1
},
success: function(result){
//window.console && console.log(result);
$listTable.children().remove();
$wp_paging.remove();
if (result != null){
$(".news_wz").removeClass("loading");
if(result.data.length>0){
var htmls = "";
for (var j = 0; j < result.data.length; j++) {
var art = result.data[j];
htmls +=''+
' '+
'
'+
' '+art.title+'
'+
' '+
'';
}
$listTable.html(htmls);
}else{
$listTable.html('未检索到相关信息!');
}
}
var total = result.total;
var pageCount = result.pageCount;
var pageHtml = "";
pageHtml += ('');
pageHtml += ('
');
pageHtml += ('
');
$("#wp_paging_w6").html(pageHtml);
}
});
}
initpageClick("wp_paging_w6",siteId,rows); //跳转页面
initFirstPageClick("wp_paging_w6",siteId,rows); //首页
initLastPageClick("wp_paging_w6",siteId,rows); //尾页
initPrevPageClick("wp_paging_w6",siteId,rows); //上一页
initNextPageClick("wp_paging_w6",siteId,rows); //下一页
for (j = 0; j < field.length; j++){
var html= "";
html = ''+
' '+field[j].title+''+
'';
$("#search_teach").append(html);
$("#search_teach > li.wp_column").eq(j).append('');
if(field[j].children !=='' && field[j].children !== undefined){
var items = (field[j].children).split("+");
$.each(items,function(index,val){
var subHtml=''+
' '+val+''+
'';
$("#search_teach > li.wp_column").eq(j).find("ul").append(subHtml);
});
}
}
$("#search_teach li").each(function(){
var _this = $(this);
$(this).children("a").on("click",function(){
$(".news_wz").addClass("loading");
$listTable.children().remove();
$wp_paging.remove();
_this.siblings("li").find("a").removeClass("hover");
$(this).addClass("hover");
item = $(this).attr("title");
title = $(this).find(".column-name").text();
type = $(this).attr("type");
$(".col_title h2").text(title);
$zm.find(".wp_column").siblings().find("a").removeClass("hover");
$zm.find(".wp_column").eq(0).find("a").addClass("hover");
loadContents(1,siteId,rows,item,'',type);
});
});
if($(".col_name_text").data("coltitle")=='全体教职工'){
$(".news_wz").addClass("loading");
$listTable.children().remove();
$wp_paging.remove();
loadContents(1,siteId,rows,'','','0');
}else{
$("#search_teach li.wp_column").each(function(){
if($(this).find(".names").text() == $(".col_name_text").data("coltitle")){
$(this).find("a.wp-main").trigger("click");
}
});
}
/**
* 文章检索服务的查询条件
*
*/
function getConditions(val,zm,i){
var conditdata = [];
var letterJson = [];
console.log(zm,i)
switch (i){
case '0':
if(val != ''){
var items = val.split("+");
$.each(items,function(index,el){
letterJson.push({field:"exField1", value:el, judge: "="});
});
}
if(zm != ''){
conditdata.push({field:"firstLetter", value:zm, judge: "="});
}
break;
case '1':
var items = val.split("+");
$.each(items,function(index,el){
letterJson.push({field:"firstLetter", value:el, judge: "="});
});
break;
case '2':
var items = val.split("+");
$.each(items,function(index,el){
letterJson.push({field:"exField4", value:'%'+el+'%', judge: "like"});
});
break;
case '3':
var items = val.split("+");
$.each(items,function(index,el){
letterJson.push({field:"exField7", value:'%'+el+'%', judge: "like"});
});
break;
case '4':
if(val != ''){
var items = val.split("+");
$.each(items,function(index,el){
letterJson.push({field:"exField4", value:el, judge: "like"});
});
}
if(zm != ''){
conditdata.push({field:"firstLetter", value:'%'+zm+'%', judge: "like"});
}
break;
default:
//letterJson.push({field:"exField2", value:val, judge: "="});
}
if (letterJson != null && letterJson.length > 0) {
conditdata.push({orConditions: letterJson});
}
conditdata.push({field:"published", value:1, judge: "="});
return conditdata;
}
/**
* 排序
*/
function getOrders(){
var orderData = [
{field: "letter", type: "asc"}
//{field: "firstLetter", type: "asc"}
];
return orderData;
}
/**
* 返回属性
* @returns {Array}
*/
function getReturnInfos() {
var returnInfosdata = [
{field: "title", name: "title"},
{field: "exField1", name: "exField1"}, // 职称
{field: "exField2", name: "exField2"}, // 招生专业
{field: "exField3", name: "exField3"}, // 研究生导师
{field: "exField4", name: "exField4"}, // 系别
{field: "exField5", name: "exField5"}, // 专业职称
{field: "department", name: "department"},
{field: "headerPic", name: "headerPic"},
{field: "cnUrl", name: "cnUrl"}
];
return returnInfosdata;
}
//初始化跳转页面
function initpageClick(idTag,siteId,rows) {
$(document).on('click', "#" + idTag + " .new_pagingJump", function(event) {
var letter=$(".zm .wp-main.hover span").text();
if(letter=="不限"){letter=""}
var exf1="";var type="0";
if($(".col_list .wp-main.hover span").length>0){
exf1=$(".col_list .wp-main.hover span").text();
type=$(".col_list .wp-main.hover").attr("type")
}
var pageNum = $(".new_page_jump .pageNum").val();
if (pageNum === "") {
alert("请输入页码!");
return;
}
var pageCount = $(".new_pages .all_pages").attr("pageCount");
if (isNaN(pageNum) || pageNum <= 0 || pageNum > pageCount) {
alert("请输入正确页码!");
return;
}
loadContents(pageNum,siteId,rows,exf1,letter,type);
});
}
//初始化首页
function initFirstPageClick(idTag,siteId,rows) {
$(document).on('click', "#" + idTag + " .new_page_nav .first", function(event) {
var letter=$(".zm .wp-main.hover span").text();
if(letter=="不限"){letter=""}
var exf1="";var type="0";
if($(".col_list .wp-main.hover span").length>0){
exf1=$(".col_list .wp-main.hover span").text();
type=$(".col_list .wp-main.hover").attr("type")
}
loadContents(1,siteId,rows,exf1,letter,type);
});
}
//初始化尾页
function initLastPageClick(idTag,siteId,rows) {
$(document).on('click', "#" + idTag + " .new_page_nav .last", function(event) {
var letter=$(".zm .wp-main.hover span").text();
if(letter=="不限"){letter=""}
var exf1="";var type="0";
if($(".col_list .wp-main.hover span").length>0){
exf1=$(".col_list .wp-main.hover span").text();
type=$(".col_list .wp-main.hover").attr("type")
}
var allPages = $(".new_pages .all_pages").attr("pageCount");
loadContents(allPages,siteId,rows,exf1,letter,type);
});
}
//初始化上一页
function initPrevPageClick(idTag,siteId,rows) {
$(document).on('click', "#" + idTag + " .new_page_nav .prev", function(event) {
var letter=$(".zm .wp-main.hover span").text();
if(letter=="不限"){letter=""}
var exf1="";var type="0";
if($(".col_list .wp-main.hover span").length>0){
exf1=$(".col_list .wp-main.hover span").text();
type=$(".col_list .wp-main.hover").attr("type")
}
var pageCount = $(".new_page_jump .curr_page").attr("curr_page");
var prev = --pageCount;
if (prev <= 0) {
return;
}
loadContents(prev,siteId,rows,exf1,letter,type);
});
}
//初始化下一页
function initNextPageClick(idTag,siteId,rows) {
$(document).on('click', "#" + idTag + " .new_page_nav .next", function(event) {
var letter=$(".zm .wp-main.hover span").text();
if(letter=="不限"){letter=""}
var exf1="";var type="0";
if($(".col_list .wp-main.hover span").length>0){
exf1=$(".col_list .wp-main.hover span").text();
type=$(".col_list .wp-main.hover").attr("type")
}
//console.log(letter,exf1,type)
var pageCount = $(".new_page_jump .curr_page").attr("curr_page");
var next = ++pageCount;
var allPages = $(".new_pages .all_pages").attr("pageCount");
if (allPages < next) {
return;
}
loadContents(next,siteId,rows,exf1,letter,type);
});
}
})