/*
* @author:liting
* @update:2018/06/20
*
*/
import 'css/bootstrap.less';
import 'bootstrap/dist/js/bootstrap.js';
import 'css/newMenu/public.css';
import 'css/newMenu/header.css'
import 'css/newMenu/serviceList.css';
import 'js/public.js';
"use strict";
$(function () {
var thePageNo = 1,
thePageLength = 1,
dataList = {},
pageSize = 15;
init();
function init() {
pages();
inpFun();
summary();
search();
jump();
$('.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('topId') > -1 || hash.indexOf('secondId') > -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('topId') > -1) {
let topIds = item.split('=')
dataList.topId = decodeURIComponent(topIds[1])
}
if (item.indexOf('secondId') > -1) {
let secondIds = item.split('=')
dataList.secondId = decodeURIComponent(secondIds[1])
}
})
} else {
if (newHash.indexOf('name') > -1) {
let names = newHash.split('=')
dataList.name = decodeURIComponent(names[1])
}
if (newHash.indexOf('topId') > -1) {
let topIds = newHash.split('=')
dataList.topId = decodeURIComponent(topIds[1])
}
if (newHash.indexOf('secondId') > -1) {
let secondIds = newHash.split('=')
dataList.secondId = decodeURIComponent(secondIds[1])
}
}
loadDate()
}
} else {
dataList.name = "",
dataList.topId = "", //行业
dataList.secondId = "" //类型
loadDate();
}
}
function summary() {
let hash = window.location.search;
$.ajax({
method: "get",
dataType: "json",
url: globalConfig.context + "/portal/service/jtBusiness/getCategoryList",
data: {
},
success: function (data) {
var theArrs = [];
if (data.data && data.data.length) {
let thisdata = data.data;
thisdata.unshift({
topLevelId: '',
topLevel: '不限',
children: [{
id: '',
name: '不限'
}]
})
thisdata.map((item,index) => {
if(index||hash){
theArrs.push(`
${item.topLevel}
`)
}else{
theArrs.push(`
${item.topLevel}
`)
}
})
$('.industryList ul').html(theArrs);
$('.industryList ul li').eq(0).className = "active";
$('.productionType ol').html(`不限`);
$('.productionType ol li ').eq(0).addClass = "active";
onSelect(thisdata);
};
}
})
}
function loadDate(pageNo) {
$('.loading').show();
$.ajax({
method: "get",
dataType: "json",
url: globalConfig.context + "/portal/service/jtProject/list",
data: {
pageNo: pageNo || 1,
pageSize: 15,
name: dataList.name,
topId: dataList.topId, //行业
secondId: dataList.secondId //类型
},
success: function (data) {
var theArrs = [];
if(data.data&&data.data.error){
msg(data.data.error[0])
};
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];
theArrs.push(`
`);
};
};
$('.loading').hide();
$('.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(''));
}
});
}
//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 () {
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.topLevelId == 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);
let txt = $(this).text();
$('.onSelect .preFirst').css('display', 'block').html(`
${txt}
`)
loadDate();
$('.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}
x
`)
loadDate();
})
});
}
//搜索
function search() {
$('.hot ul li').click(function () {
dataList.name = $(this).text();
dataList.topId = '';
dataList.secondId = '';
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)
}
})