/*
* @author:liting
* @update:2018/09/07
*
*/
// import 'css/bootstrap.less';
// import 'bootstrap/dist/js/bootstrap.js';
import 'css/newMenu/public.css';
import 'css/newMenu/header.css'
import 'css/newMenu/adviserList.css';
import 'js/public.js';
"use strict";
$(function () {
var thePageNo = 1,
thePageLength = 1,
dataList = {},
pageSize = 6;
init();
function init() {
pages();
inpFun();
search();
jump();
};
//一级界面跳转此页面
function jump() {
let hash = window.location.search;
if (hash) {
if (hash.indexOf('name') > -1 || hash.indexOf('topId') > -1 || hash.indexOf('secondId') > -1) {
let newHash = hash.substr(1, hash.length)
if (newHash.indexOf('name') > -1) {
let names = newHash.split('=')
dataList.name = decodeURIComponent(names[1])
$('.demandSearch').val(dataList.name);
}
loadDate()
}
} else {
dataList.name = "",
loadDate();
}
}
function loadDate(pageNo) {
$('.loading').show();
$.ajax({
method: "get",
dataType: "json",
url: globalConfig.context + "/api/portal/identity/consultantList",
data: {
pageNo: pageNo || 1,
pageSize: pageSize,
name: dataList.name,
sortType:dataList.sortType
},
success: function (data) {
var theArrs = [];
if (data && data.error.length) {
msg(data.error[0].message)
};
if (data.data && data.data.list.length) {
let nub = data.data.list.length;
for (let i = 0; i < nub; i++) {
let thisdata = data.data.list[i],txtCont='';
switch(thisdata.consultantType){
case 0:
txtCont='专利代理人';
break;
case 1:
txtCont='专利顾问';
break;
case 2:
txtCont='版权顾问';
break;
case 3:
txtCont='商标顾问';
break;
default:
txtCont="暂无";
}
theArrs.push(`
`);
};
};
$('.loading').hide().stop(true, true);
$('.adviserList ul').empty();
$('.adviserList ul').append(theArrs.join(''));
$('.pagination_box').css('display', 'block');
$('.inp').css('display', 'block');
if (data.data.list.length === 0) {
$('.adviserList ul').html("");
$('.pagination_box').css('display', 'none');
$('.inp').css('display', 'none');
};
thePageLength = data.data.totalCount ? Math.ceil(data.data.totalCount / pageSize) : 1;
$('.totalCount').html(`共${data.data.totalCount}条数据 ${thePageLength}页`)
var pageArr = [],
firstNo = 1,
endNo = 5;
if (thePageNo > 3) {
firstNo = thePageNo - 2;
endNo = Math.min((Number(thePageNo) + 2), thePageLength);
} else {
endNo = Math.min(thePageLength, 5);
};
for (let i = firstNo; i <= endNo; i++) {
if (i == thePageNo) {
pageArr.push(
'' + i + ''
);
} else {
pageArr.push(
'' + i + ''
);
}
};
$('.pageNumber').remove();
$('.pagePre').after(pageArr.join(''));
$('footer').show();
colFun();
}
});
}
//f分页
function pages() {
$('.pagination').on('click', 'li', function (e) {
e.preventDefault();
if (this.className === 'pagePre') {
if (thePageNo > 1) {
thePageNo = 1;
loadDate(thePageNo);
}
} else if (this.className === 'pageNext') {
if (thePageNo < thePageLength) {
thePageNo = thePageLength;
loadDate(thePageNo);
}
} else {
var nextPageNo = $(this).children()[0].text;
if (thePageNo != nextPageNo) {
$(this).siblings("li").removeClass("active");
$(this).addClass("active");
thePageNo = nextPageNo;
loadDate(thePageNo);
};
};
});
}
//输入跳转
function inpFun() {
$('.inp button').on('click', function () {
let val = $(this).siblings().val();
if (!isNaN(val) && val <= thePageLength && val > 0&&val%1=='0') {
thePageNo = val;
loadDate(thePageNo);
} else {
msg('请输入正确页码')
}
})
}
//搜索
function search() {
$('.searchBtn').click(function () {
let val = $('.demandSearch').val();
dataList.name = val;
loadDate();
})
}
/* 提示 */
//提示框渐隐函数
function msg(txt) {
if ($('.smg').hasClass('active')) {
return;
}
$('.smg').addClass('active');
var lit = $('#msg').val(txt);
setTimeout(function () {
$('.smg').removeClass('active')
$('#msg').val('');
}, 2000)
}
//收藏
function colFun(){
$('.txt .heart').click(function (e) {
let loginTxt=$('.head_login')[0];
if(loginTxt&&($(loginTxt).text())=='登录'){
window.location.hash='jump'
msg('请先登录!')
return false;
}else{
if(window.adminData&&window.adminData.mobile){
msg('账号不正确,请退出重新登入。')
return;
}
}
e.preventDefault();
e.stopPropagation();
let nub=parseInt($(this).siblings('.nubCollect').text()),
heart = $(this),
id=$(this).parents('.txt').attr('data-id');
if (heart.hasClass('active')) {
$(this).removeClass('active')
$(this).siblings('.nubCollect').text(nub-1);
collectionApi(0,id,nub) //取消关注
} else {
$(this).addClass('active');
$(this).siblings('.nubCollect').text(nub+1);
collectionApi(1,id,nub) //关注
}
})
}
function collectionApi(index,ids,nub) {
let url = index?'/api/user/portal/expertInterest':'/api/user/portal/expertCancelInterest';
$.ajax({
method: "post",
dataType: "json",
url: globalConfig.context + url,
data: {
id:ids
},
success: function (data) {
if (data.error && data.error.length) {
msg(data.error[0].message);
}else{
if(!index){
$('#msg').val('取消关注')
}else{
$('#msg').val('关注成功,请至个人中心-我的关注查看.');
}
msg(index?'关注成功,请至个人中心-我的关注查看.':'取消关注');
}
}
})
}
//排序调用接口
sortFun();
function sortFun(){
$('.sort .relTime').click(function(){
if($(this).hasClass('active')){
$(this).removeClass('active');
dataList.sortType='';
thePageNo=1
loadDate(thePageNo);
}else{
$('.colNumber').removeClass('active')
$(this).addClass('active');
dataList.sortType=0;
thePageNo=1;
loadDate(thePageNo);
}
})
$('.sort .colNumber').click(function(){
if($(this).hasClass('active')){
$(this).removeClass('active');
dataList.sortType='';
thePageNo=1;
loadDate(thePageNo);
}else{
$('.relTime').removeClass('active')
$(this).addClass('active');
dataList.sortType=1;
thePageNo=1;
loadDate(thePageNo);
}
})
}
})