$(function() {
var isLast = false,
currentPage = 0,
categoryId = '',
locationId = '',
searchText = '',
arrLocation = [],
arrCategories = [],
arrList = [];
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1
c_end = document.cookie.indexOf(";", c_start)
if (c_end == -1) c_end = document.cookie.length
return unescape(document.cookie.substring(c_start, c_end))
}
}
return ''
}
var _templang = getCookie('language') ? getCookie('language') : 'zh';
// console.log(lang)
function _ajax(url, type, data, callback) {
$.ajax({
url: url,
dataType: "json",
type: type || 'GET',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: data,
success: function(data) {
callback(data)
},
error: function(msg) {
}
});
}
function getLocationData() {
_ajax('/recruitment/location/api/get', 'GET', { rnd: Math.random() }, function(data) {
if (data && data.length > 0) {
//
arrLocation = data;
appendLocationHtml(data)
}
})
}
function appendLocationHtml(arr) {
$("._location").empty();
var html = '',
result = arr,
len = arr.length,
i = 0;
if (_templang == 'zh') {
//循环数据
for (; i < len; i++) {
var rs = result[i],
_id = rs.id,
_position = rs.name,
_englishName = rs.englishName;
html += '' + _position + '';
}
} else {
//循环数据
for (; i < len; i++) {
var rs = result[i],
_id = rs.id,
_position = rs.name,
_englishName = rs.englishName;
html += '' + _englishName + '';
}
}
//渲染数据
$("._location").append(html);
}
function getCategoryData() {
_ajax('/recruitment/category/api/get', 'GET', { rnd: Math.random() }, function(data) {
console.log(data)
if (data && data.length > 0) {
//
arrCategories = data;
// var html = '',
// result = data,
// len = result.length,
// i = 0;
// //循环数据
// for (; i < len; i++) {
// var rs = result[i],
// _id = rs.id,
// _category = rs.name,
// _englishName = rs.englishName;
// html += '' + _category + '';
// }
// //渲染数据
// $(".work_list_search_title_con").append(html);
appendCategoryHtml(data)
}
})
}
function appendCategoryHtml(arr) {
$(".work_list_search_title_con").empty();
var html = '',
result = arr,
len = arr.length,
i = 0;
if (_templang == 'zh') {
//循环数据
for (; i < len; i++) {
var rs = result[i],
_id = rs.id,
_category = rs.name,
_englishName = rs.englishName;
html += '' + _category + '';
}
} else {
//循环数据
for (; i < len; i++) {
for (; i < len; i++) {
var rs = result[i],
_id = rs.id,
_category = rs.name,
_englishName = rs.englishName;
html += '' + _englishName + '';
}
}
}
//渲染数据
$(".work_list_search_title_con").append(html);
}
function getPositionData(page, categoryId, locationId, searchText) {
var obj = {
page: page,
categoryId: categoryId,
locationId: locationId,
searchText: searchText,
rnd: Math.random()
}
_ajax('/recruitment/position/api/get', 'GET', obj, function(data) {
if (data && data.content.length > 0) {
//
arrList = data;
isLast = data.last;
currentPage = data.number
appendPositionHtml(data);
}
if (isLast) {
var tempLast = getCookie('language') == 'zh'?'没有更多~':'No more~';
$('.load_more').text(tempLast)
}
})
}
function appendPositionHtml(arr) {
$(".work_list_con").empty();
if (_templang == 'zh') {
var html = '',
result = arr.content,
len = result.length,
i = 0;
//循环数据
for (; i < len; i++) {
var rs = result[i],
_id = rs.id,
_category = rs.categories[0].name,
_categoriesEnglishName = rs.categories[0].englishName,
_englishName = rs.englishName,
_name = rs.name,
_releaseTime = rs.releaseTime,
_demand = rs.demand,
_description = rs.description,
_city = rs.locations[0].name
_city_en = rs.locations[0].englishName
_count = rs.count,
html += '
' +
'
' +
'
' + _name + '
' +
'
' + _city + ', 招' + _count + '人,发布于' + _releaseTime + '
' +
'
' +
'
' +
'加入我们' +
'
' +
'
';
}
//渲染数据
$(".work_list_con").append(html);
showDetail()
} else {
var html = '',
result = arr.content,
len = result.length,
i = 0;
//循环数据
for (; i < len; i++) {
var rs = result[i],
_id = rs.id,
_category = rs.categories[0].name,
_categoriesEnglishName = rs.categories[0].englishName,
_englishName = rs.englishName,
_name = rs.name,
_releaseTime = rs.releaseTime,
_demand = rs.demand,
_description = rs.description,
_city = rs.locations[0].name
_city_en = rs.locations[0].englishName
_count = rs.count,
html += '' +
'
' +
'
' + _englishName + '
' +
'
' + _city_en + ', number:' + _count + ',time:' + _releaseTime + '
' +
'
' +
'
' +
'Apply Now' +
'
' +
'
';
}
//渲染数据
$(".work_list_con").append(html);
showDetail()
}
}
getLocationData();
getCategoryData();
getPositionData(0, categoryId, locationId, searchText);
$('._location').on('click', 'span', function(e) {
var target = $(e.target)
// console.log()
locationId = $(target)[0].dataset.id;
console.log(categoryId)
$('.all_location').removeClass('click_active');
target.siblings().removeClass('click_active');
target.addClass('click_active');
$(".work_list_con").empty();
getPositionData(currentPage, categoryId, locationId, searchText);
})
$('.all_location').click(function(e) {
locationId = "";
$(".work_list_con").empty();
$('.all_location').addClass('click_active');
$('._location').find('span').removeClass('click_active');
getPositionData(currentPage, categoryId, locationId, searchText);
})
$('.work_list_search_title_con').on('click', 'span', function(e) {
var target = $(e.target)
categoryId = $(target)[0].dataset.id;
target.siblings().removeClass('click_active');
target.addClass('click_active');
$(".work_list_con").empty();
getPositionData(currentPage, categoryId, locationId, searchText);
})
$('.form_input').on('input', function() {
searchText = $('.form_input').val()
})
$('.search-btn').click(function() {
$(".work_list_con").empty();
getPositionData(currentPage, categoryId, locationId, searchText);
})
$('.load_more').click(function() {
if (!isLast) {
getPositionData(Number(currentPage) + 1, categoryId, locationId, searchText);
} else {
return
}
})
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1
c_end = document.cookie.indexOf(";", c_start)
if (c_end == -1) c_end = document.cookie.length
return unescape(document.cookie.substring(c_start, c_end))
}
}
return ''
}
function showDetail() {
// $(.)
$('.apply-btn').click(function(e) {
var _lang = getCookie('language')
$('.content_mask_con_bottom_con').empty();
$('.content_mask_con_bottom_con_yaoqiu').empty();
var currentIdx = e.currentTarget.dataset.id,
html1 = _lang == 'zh' ? arrList.content[currentIdx].description : arrList.content[currentIdx].englishDescription,
html2 = _lang == 'zh' ? arrList.content[currentIdx].demand : arrList.content[currentIdx].englishDemand,
name = _lang == 'zh' ? arrList.content[currentIdx].name : arrList.content[currentIdx].englishName,
_count = arrList.content[currentIdx].count,
_releaseTime = arrList.content[currentIdx].releaseTime,
_category = _lang == 'zh' ? arrList.content[currentIdx].categories[0].name : arrList.content[currentIdx].categories[0].englishName,
_location = _lang == 'zh' ? arrList.content[currentIdx].locations[0].name : arrList.content[currentIdx].locations[0].englishName,
fix_sub = _lang == 'zh' ? _category + ',' + _location + ',招' + _count + '人,发布于' + _releaseTime : _category + ',' + _location + ', number' + _count + ', time' + _releaseTime;
// console.log(html)
$('.content_mask_con_top_title').text(name);
$('.content_mask_con_top_sub').text(fix_sub);
$('.content_mask_con_bottom_con').append(html1);
$('.content_mask_con_bottom_con_yaoqiu').append(html2);
$('.join_mask').show();
})
}
$('.content_mask_con').click(function() {
return false;
});
$('.join_mask').click(function() {
$('.join_mask').hide();
});
$('.btn').click(function() {
_templang = getCookie('language');
console.log('asd', _templang)
appendLocationHtml(arrLocation)
appendCategoryHtml(arrCategories);
appendPositionHtml(arrList);
})
baguetteBox.run('.company_detail');
baguetteBox.run('.our_detail');
baguetteBox.run('.middle_img');
})