/*
* @author:liting
* @update:2018/05/19
*
*/
import 'css/bootstrap.less';
import 'bootstrap/dist/js/bootstrap.js';
import 'css/newMenu/public.css';
import 'css/newMenu/header.css'
import 'css/newMenu/achievementList.css';
import 'js/public.js';
$(function () {
var thePageNo = 1,
thePageLength = 1,
dataList = {},
pageSize = 15;
init();
function init() {
pages();
inpFun();
jump();
hotSearch();
$('.onSelect .preFirst').css('display', 'none')
$('.onSelect .next').css('display', 'none')
};
//一级界面跳转此页面
function jump() {
let hash = window.location.search;
if (hash) {
if (hash.indexOf('name') > -1 || hash.indexOf('fieldA') > -1 ) {
let newHash = hash.substr(1, hash.length)
if (newHash.indexOf('&') > -1) {
let hashArr = newHash.split('&');
hashArr.map(item => {
if (item.indexOf('name') > -1) {
let names = item.split('=')
dataList.name = decodeURIComponent(names[1]);
}
if (item.indexOf('fieldA') > -1) {
let topIds = item.split('=')
dataList.topId = decodeURIComponent(topIds[1])
}
})
} else {
if (newHash.indexOf('name') > -1) {
let names = newHash.split('=')
dataList.name = decodeURIComponent(names[1])
}
if (newHash.indexOf('fieldA') > -1) {
let topIds = newHash.split('=')
dataList.topId = decodeURIComponent(topIds[1])
}
}
summary(dataList)
loadDate()
}
} else {
dataList.name = "",
dataList.topId = "", //行业
dataList.secondId = "" //类型
loadDate();
summary(dataList)
}
}
//热搜
function hotSearch() {
$('.searchMain ol li').click(function () {
$(this).addClass('active').siblings().removeClass('active');
$('.searchMain ol li').eq(0).addClass('active');
dataList.name = $(this).text().trim();
let index = $(this).index();
$('.productionType ol').html(`
不限`);
$('.industryList ul li').removeClass('active');
$('.productionType ol li').removeClass('active')
heightFun();
if (index) {
dataList.topId = '';
dataList.secondId = '';
loadDate();
}
})
}
function summary(dataList) {
let hash = window.location.search;
$.ajax({
method: "get",
dataType: "json",
url: globalConfig.context + "/open/industryList",
data: {
},
success: function (data) {
var theArrs = [],proArr=[];
if (data.data && data.data.length) {
let thisdata = data.data;
thisdata.unshift({
id: '',
name: '不限',
children: [{
id: '',
name: '不限'
}]
})
thisdata.map((item, index) => {
if (index || hash) {
if(dataList&&dataList.topId&&dataList.topId>=0&&dataList.topId==item.id){
$('.onSelect .preFirst').css('display', 'block').html(`
${item.name}
`)
theArrs.push(`
${item.name}
`);
let List = item.children
List.map(atem=>{
proArr.push(`
${atem.name}
`)
})
$('.productionType ol').html(proArr.join(''));
}else{
theArrs.push(`
${item.name}
`)
}
} else {
theArrs.push(`
${item.name}
`)
}
})
$('.industryList ul').html(theArrs);
$('.industryList ul li').eq(0).className = "active";
if(proArr.length){
$('.productionType ol').html(proArr.join(''));
}else{
$('.productionType ol').html(`不限`);
}
$('.productionType ol li ').eq(0).addClass = "active";
heightFun();
onSelect(thisdata);
proFun();
};
}
})
}
function heightFun(){
let proH = $('.productionType ol').height();
$('.productionType p').css({height:proH+'px',lineHeight:proH+'px'})
$('.productionType').css({height:proH+'px',lineHeight:proH+'px'})
}
function loadDate(pageNo) {
$('.loading').show();
$.ajax({
method: "get",
dataType: "json",
url: globalConfig.context + "/open/achievementList",
data: {
pageNo: pageNo || 1,
pageSize: 15,
name: dataList.name,
fieldA: dataList.topId, //行业
fieldB: dataList.secondId //类型
},
success: function (data) {
var theArrs = [];
if(data.data&&data.data.error){
msg(data.data.error[0])
};
let times = new Date().getTime();
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],
news = formatDuring(times)-formatDuring(thisdata.createTime);
theArrs.push(`
${thisdata.name}
${thisdata.dataCategoryS?thisdata.dataCategoryS:'实用技术'}
${thisdata.fieldAS}
`);
};
};
$('.loading').hide().stop(true,true);
$('.achievementHot .hotList').empty();
$('.achievementHot .hotList').append(theArrs.join(''));
$('.pagination_box').css('display', 'block');
$('.inp').css('display', 'block');
if (data.data.list.length === 0) {
$('.achievementHot .hotList').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(''));
}
});
}
//时间转换
function formatDuring(mss) {
var days = parseInt(mss / (1000 * 60 * 60 * 24));
var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
var seconds = (mss % (1000 * 60)) / 1000;
return days ;
}
//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 .btn').on('click', function () {
let val = $(this).siblings().val();
if (!isNaN(val) && val <= thePageLength && val > 0) {
thePageNo = val;
loadDate(thePageNo);
}else{
msg('请输入正确页码')
}
})
}
//已选类型
function onSelect(data) {
$('.industryList ul li').on('click', function () {
$('.searchMain ol li').removeClass('active');
$('.searchMain ol li').eq(0).addClass('active');
let secondTxt = [],
scondHtml = [];
$(this).addClass('active').siblings().removeClass('active')
dataList.topId = $(this).attr('data-id');
dataList.name = '';
dataList.secondId = '';
$('.next').css('display', 'none')
data.map(item => {
if (item.id == dataList.topId) {
secondTxt = item.children
}
})
secondTxt.map(item => {
scondHtml.push(`
${item.name}
`)
})
if (!dataList.topId) {
dataList.topId = '';
dataList.secondId = '';
$('.preFirst').html('不限');
$('.next').css('display', 'none')
scondHtml = ['不限'];
}
$('.productionType ol').html(scondHtml);
heightFun();
let txt = $(this).text();
$('.onSelect .preFirst').css('display', 'block').html(`
${txt}
`)
loadDate();
proFun();
});
}
function proFun(){
$('.productionType ol li').on('click', function () {
dataList.name = '';
dataList.topId = $('.industryList ul li.active').attr('data-id');
$(this).addClass('active').siblings().removeClass('active');
dataList.secondId = $(this).attr('data-id');
if (!dataList.secondId) return;
let txt = $(this).text();
$('.onSelect .next').css('display', 'block').html(`
${txt}
`)
loadDate();
})
}
$('.searchBtn').click(function () {
let val = $('.demandSearch').val();
if (val) {
dataList.name = val;
dataList.topId = '';
dataList.secondId = '';
loadDate();
}
})
/* 提示 */
//提示框渐隐函数
function msg(txt) {
$('.smg').addClass('active');
var lit = $('#msg').val(txt);
setTimeout(function () {
$('.smg').removeClass('active');
$('#msg').val('');
}, 2000)
}
})