You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

735 lines
24 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const app = getApp();
const commonUtil = require("../../utils/commonUtil.js");
Page({
data: {
tabs: [],
activeTab: 0,
systemInfo: {},
getMenuButtonBoundingClientRect: {},
// 手机基础信息
tabs2: [],
loadMore: "",
loadContent: [
"马不停蹄加载更多数据中...",
"-- 已经到底了,加不了咯 --"
],
activeTab2: 0,
contentIndex: 0,
latestClass: 0,
zoneClass: 0,
jobList: [],
jobSpecialLabelNames: [],
storeJobListSearchForm: {
pageNum: 1,
pageSize: 25,
classify: 1,
sex: -1,
workTypeStr: "",
lat: "",
lng: "",
jobClassify: '',
sortTag: 0,
jobSpecialLabelIds: '',
cityName: '',
brandIds: '',
jobCategory: undefined,
},
loading: true,
topJobList: [],
hasLocation: false,
chooseActive: false,
//筛选是否高亮
labelItems: [],
checkedlabelItems: [],
hasMoreData: true, //下拉是否还有更多数据
inputShowed: false,
inputVal: "",
wxCode: '',
isCollect: false,
collectTxt: '收藏',
isLogin: false,
searchCityParamStorage: {name: '', shortName: ''},
isShow:false
},
searchKey: function(e) {
console.log(e);
this.data.jobList = [];
this.data.storeJobListSearchForm.pageNum = 1;
this.data.storeJobListSearchForm.keys = e.detail.value;
this.getJobList();
},
showInput: function() {
this.setData({
inputShowed: true
});
},
hideInput: function() {
this.setData({
inputVal: "",
inputShowed: false
});
},
clearInput: function() {
this.setData({
inputVal: "",
inputShowed: false,
hasMoreData: true,
});
this.data.jobList = [];
this.data.storeJobListSearchForm.pageNum = 1;
this.data.storeJobListSearchForm.keys = '';
this.getJobList();
},
inputTyping: function(e) {
this.setData({
inputVal: e.detail.value
});
},
clear() {
wx.clearStorage();
console.log("清除成功");
},
onLoad(options) {
var that = this;
wx.showLoading({
title: '加载中...',
})
let id = options.id;
if(id == "608"){
wx.setNavigationBarTitle({
title: '今日热推'
})
}else if(id == "602"){
wx.setNavigationBarTitle({
title: '短期工'
})
}else if(id == "610"){
wx.setNavigationBarTitle({
title: '寒假工'
})
}else if(id == "603"){
wx.setNavigationBarTitle({
title: '大龄工'
})
}
console.log(id);
that.data.storeJobListSearchForm.jobCategory = id;
that.setData({
storeJobListSearchForm: that.data.storeJobListSearchForm,
})
//登录=================================start
if (app.globalData.isLogin) {
this.setData({
isLogin: app.globalData.isLogin
});
} else {
// 由于 userLogin 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userLoginCallback = res => {
this.setData({
isLogin: app.globalData.isLogin
});
}
}
this.initData();
//登录=================================end
//this.getHopeJobLabels();
var reset = true;
},
onTabClick(e) {
const index = e.detail.index
this.setData({
activeTab: index
})
},
onChange(e) {
const index = e.detail.index
this.setData({
activeTab: index
})
},
findLocation() {
var that = this;
// 注释
// wx.getLocation({
// type: 'gcj02',
// success(res1) {
// console.log("获取位置2");
// console.log(res1);
// app.globalData.lng = res1.longitude;
// app.globalData.lat = res1.latitude;
// },
// fail() {
// }
// });
},
onShow() {
this.setData({
isLogin: app.globalData.isLogin
});
if(app.globalData.isLogin) {
this.collectedStoreJobList();
} else {
this.wxLogin();
}
console.log(app.globalData.header)
/*this.wxLogin();
let res = wx.getStorageSync({
key: "storeJobId"
}); //详情页返回
if (app.isEmptyCheck(res.data)) {
this.setData({
jobList: []
});
} else {
wx.removeStorageSync({
key: "storeJobId"
});
}
console.log("on show");
this.getHopeJobLabels();
var reset = true;*/
},
collectedStoreJobList() {
var that = this;
wx.request({
url: app.globalData.ip + "/store/job/collected/list?ucj=1",
method: "GET",
data: {},
header: app.globalData.header,
success: function(res) {
console.log(res);
let collectList = res.data.data.jobList;
let jobs = that.data.jobList;
if(collectList != null && collectList != '' && collectList != undefined && collectList.length != 0 && jobs != null && jobs != '' && jobs != undefined && jobs.length != 0) {
for(var j = 0; j != jobs.length; ++j) {
jobs[j].collected = 2;
}
for(var i = 0; i != collectList.length; ++i) {
for(var j = 0; j != jobs.length; ++j) {
if(collectList[i].storeJobId - jobs[j].id == 0) {
jobs[j].collected = 1;
break;
}
}
}
that.setData({
jobList: jobs,
});
}
},
fail: function(res) {
}
});
},
getHopeJobLabels() {
var that = this;
wx.request({
url: app.globalData.ip + "/labels/findAllHopeJobLabels",
// ?category=4
method: "GET",
data: {},
success: function(res0) {
console.log("感兴趣职位 ↓↓↓");
console.log(res0);
if (res0.data.data != null) {
res0.data.data.forEach((item, index) => {
item["title"] = item.name;
item["checked"] = false;
if (index == 0 || index == 1) {
item["checked"] = true;
}
});
}
that.setData({
labelItems: res0.data.data == null ? [] : res0.data.data
});
that.initData();
console.log("感兴趣职位 赋值title↓↓↓");
console.log(res0);
},
fail: function(res) {
wx.showToast({
title: '获取失败',
icon: 'none',
duration: 2000
})
}
});
},
makePhoneCall() {
var that = this;
wx.makePhoneCall({
phoneNumber: '17639080029'
});
},
goScreen(){
wx.navigateTo({
url: '../screen/index',
})
},
goCity(){
wx.navigateTo({
url: '../city/index',
})
},
initData() {
var that = this;
this.getJobList();
},
getJobList() {
var that = this;
if (that.data.storeJobListSearchForm.sortTag == 2) {//如果按照距离排序,拼接上坐标
that.data.storeJobListSearchForm.lng = app.globalData.lng;
that.data.storeJobListSearchForm.lat = app.globalData.lat;
}
wx.request({
url: app.globalData.ip + "/store/job/list",
method: "POST",
header: app.globalData.header,
data: that.data.storeJobListSearchForm,
success: function(res) {
console.log("职位列表↓↓↓↓");
console.log(res);
that.setData({
loading: true
});
if (app.isEmptyCheck(res.data.data)) {
that.setData({
hasMoreData: false
});
} else if (
res.data.data.jobList == null ||
res.data.data.jobList.length == 0 ||
res.data.data.jobList.length < 25
) {
var jobListTemp = that.disposeJobListData(res.data.data.jobList);
that.data.jobList = that.data.jobList.concat(jobListTemp);
that.setData({
hasMoreData: false
});
that.setData({
jobList: that.data.jobList,
});
} else {
var jobListTemp = that.disposeJobListData(res.data.data.jobList);
that.data.jobList = that.data.jobList.concat(jobListTemp);
that.setData({
jobList: that.data.jobList,
});
}
that.setData({
loading: false,
storeJobListSearchForm: that.data.storeJobListSearchForm
});
}
});
setTimeout(function(){
wx.hideLoading();
that.setData({
isShow:true
})
},200)
},
/**
* 处理后台返回的职位列表
*/
disposeJobListData(jobList) {
var that = this;
jobList.forEach(item => {
item["workType"] = commonUtil.getWorkTypeById(
item.workTypeMulti
);
if (app.isNotEmptyCheck(item.distance)) {
item["distanceKm"] = commonUtil.getDistanceName(
item.distance
);
}
//年龄
var ageStr = '';
if (app.isNotEmptyCheck(item.minAge) && app.isNotEmptyCheck(item.maxAge)) {
ageStr = item.minAge + '-' + item.maxAge + '岁';
} else if (app.isNotEmptyCheck(item.minAge)) {
ageStr = item.minAge + '岁以上';
} else if (app.isNotEmptyCheck(item.maxAge)) {
ageStr = item.maxAge + '岁以下';
}
item["age"] = ageStr;
//时薪
var hourlyPayStr = '';
var hasHourlyPay = false;
if (app.isNotEmptyCheck(item.hourlyPay)) {
hourlyPayStr = item.hourlyPay + '元/小时';
hasHourlyPay = true;
} else if (app.isNotEmptyCheck(item.dayPay)) {
hourlyPayStr = item.dayPay + '元/日';
hasHourlyPay = true;
} else {
if (app.isNotEmptyCheck(item.minMonthlyPay) && app.isNotEmptyCheck(item.maxMonthlyPay)) {
if (item.minMonthlyPay == item.maxMonthlyPay) {
hourlyPayStr = item.minMonthlyPay;
} else {
hourlyPayStr = item.minMonthlyPay + '-' + item.maxMonthlyPay;
}
} else if (app.isNotEmptyCheck(item.minMonthlyPay)) {
hourlyPayStr = item.minMonthlyPay;
} else if (app.isNotEmptyCheck(item.maxMonthlyPay)) {
hourlyPayStr = item.maxMonthlyPay;
}
}
item["hourlyPay"] = hourlyPayStr;
//月薪
var monthlyPayStr = '';
if (hasHourlyPay) {
if (app.isNotEmptyCheck(item.minMonthlyPay) && app.isNotEmptyCheck(item.maxMonthlyPay)) {
if (item.minMonthlyPay == item.maxMonthlyPay) {
monthlyPayStr = item.minMonthlyPay;
} else {
monthlyPayStr = item.minMonthlyPay + '-' + item.maxMonthlyPay;
}
} else if (app.isNotEmptyCheck(item.minMonthlyPay)) {
monthlyPayStr = item.minMonthlyPay;
} else if (app.isNotEmptyCheck(item.maxMonthlyPay)) {
monthlyPayStr = item.maxMonthlyPay;
}
}
item["monthlyPay"] = monthlyPayStr;
//地址深圳丨龙岗区丨
var districtStr = '';
if (app.isNotEmptyCheck(item.district)) {
var districtArr = item.district.split(',');
if(districtArr.length < 3) {
districtStr = districtArr[districtArr.length - 1];
} else {
districtStr = districtArr[1] + '丨' + districtArr[2];
}
//districtStr = districtArr[1] + '丨' + districtArr[2];
}
item["district"] = districtStr;
//职位特色
item['jobSpecialLabelNames'] = that.getJobSpecialLabelNamesArray(item.jobSpecialLabelNames);
});
return jobList;
},
// 下拉加载更多
onScrollToLower() {
console.log(1);
var that = this;
that.data.storeJobListSearchForm.pageNum =
that.data.storeJobListSearchForm.pageNum + 1;
that.getJobList(); // alert(1);
// 根据实际数据加载情况设定 loadMore 的值即可,分别为 load 和 over
this.setData({
loadMore: "load",
// loading:true
});
},
getJobSpecialLabelNamesArray(jobSpecialLabelNames) {
if (app.isNotEmptyCheck(jobSpecialLabelNames)) {
return jobSpecialLabelNames.split(', ');
}
return [];
},
handleTabClick(e) {
var that = this;
var index = e.detail.index;
console.log(
e.detail.index
);
let categoryCurr = that.data.tabs2[index].category; // that.data.tabs2.forEach((item,index2) => {
// if (index == index2) {
// categoryCurr = item.category
// }
// if( index == 0){
// categoryCurr = -1
// }
// })
this.setData({
// [tabsName]: index,
contentIndex: index
});
console.log(categoryCurr);
that.data.storeJobListSearchForm.jobClassify = categoryCurr;
that.data.storeJobListSearchForm.pageNum = 1;
that.setData({
jobList: []
});
that.getJobList();
},
goDetail(e) {
console.log(e);
var that = this;
wx.navigateTo({
url: "../detail/index?storeJobId=" + e.currentTarget.dataset.id + "&wxCode=" + that.data.wxCode
});
},
goEnroll(e) {
// wx.navigateTo({
// url: "../enroll/index?applyType=0"
// });
var that = this;
wx.setStorageSync('jobDetailStorage', that.data.jobList[e.currentTarget.dataset.idx]);
wx.navigateTo({
url: "../enroll/index?applyType=1&tel=" + app.globalData.loginUserInfo.tel
});
},
emptyMethod() {
},
wxLogin() {
var that = this;
wx.login({
success(res) {
if (res.code) {
that.setData({
wxCode: res.code
});
} else {
console.log('获取code失败' + res.errMsg)
}
}
})
},
getPhoneNumber(e) {
var that = this;
console.log(e)
console.log(e.detail.errMsg)
/*wx.setStorageSync({
key: "jobDetailStorage",
data: that.data.jobList[e.currentTarget.dataset.idx]
});*/
wx.setStorageSync('jobDetailStorage', that.data.jobList[e.currentTarget.dataset.idx]);
// console.log(e);
// console.log(e.detail.errMsg)
// console.log(e.detail.iv)
// console.log(e.detail.encryptedData)
if ("getPhoneNumber:ok" == e.detail.errMsg) { //同意
var iv = e.detail.iv;
var encryptedData = e.detail.encryptedData;
wx.checkSession({
success() {
//session_key 未过期,并且在本生命周期一直有效
wx.request({
url: app.globalData.ip + '/getWechatTel',
data: {
code: that.data.wxCode,
iv: iv,
encryptedData: encryptedData,
},
success: function(res) {
console.log(res);
let promise = app.setLoginUserTokenInfo(res.data.data.phoneNumber, null);
var collected = e.currentTarget.dataset.collected;
if (collected) {
promise.then(res => {
that.setData({
isLogin: app.globalData.isLogin
});
that.doCollected(collected, e.currentTarget.dataset.jobid);
that.collectedStoreJobList();
})
} else {
wx.navigateTo({
url: "../enroll/index?applyType=1&tel=" + res.data.data.phoneNumber
});
}
},
fail: function(res) {
console.log("获取用户手机号错误");
}
})
},
fail() {
// session_key 已经失效,需要重新执行登录流程
wx.login({
success(res) {
if (res.code) {
console.log(res.code);
//发起网络请求
wx.request({
url: app.globalData.ip + '/getWechatTel',
data: {
code: res.code,
iv: iv,
encryptedData: encryptedData,
},
success: function(res) {
console.log(res);
let promise = app.setLoginUserTokenInfo(res.data.data.phoneNumber, null);
var collected = e.currentTarget.dataset.collected;
if (collected) {
promise.then(res => {
that.setData({
isLogin: app.globalData.isLogin
});
that.doCollected(collected, e.currentTarget.dataset.jobid);
})
} else {
wx.navigateTo({
url: "../enroll/index?applyType=1&tel=" + res.data.data.phoneNumber
});
}
},
fail: function(res) {
console.log("获取用户手机号错误");
}
})
} else {
console.log('获取手机号失败!' + res.errMsg)
}
}
})
}
})
} else { //拒绝
var collected = e.currentTarget.dataset.collected;
if (collected) {
try {
wx.setStorageSync('comeFromPage', 'index');
} catch (e) {
console.log("index-页面跳转,设置参数错误:", e);
}
wx.navigateTo({
url: '/pages/login/index',
})
} else {
wx.navigateTo({
url: "../enroll/index?applyType=1"
});
}
}
return false;
},
collectPaste(e) {
var txt;
var that = this;
var collected = e.currentTarget.dataset.collected;
var storeJobId = e.currentTarget.dataset.jobid;
that.doCollected(collected, storeJobId);
// console.log(collected);
// if(!this.data.isCollect){
// that.setData({
// isCollect: true,
// collectTxt:'已收藏'
// })
// txt = '收藏成功'
// }else{
// that.setData({
// isCollect: false,
// collectTxt:'收藏'
// })
// }
},
doCollected(collected, storeJobId) {
var that = this;
var url = '/user/collect/job/add';
if (collected - 1 == 0) {
url = '/user/collect/job/remove';
}
console.log(app.globalData.header)
//发起网络请求
wx.request({
url: app.globalData.ip + url,
data: {
storeJobId: storeJobId,
},
header: app.globalData.header,
method: "GET",
success: function(res) {
var txt;
if (collected - 1 == 0) { //取消收藏
for (var i = 0; i != that.data.jobList.length; ++i) {
if (that.data.jobList[i].id - storeJobId == 0) {
that.data.jobList[i].collected = 2;
that.data.jobList.splice(i,1);
break;
}
}
txt = '取消收藏';
} else { //收藏
for (var i = 0; i != that.data.jobList.length; ++i) {
if (that.data.jobList[i].id - storeJobId == 0) {
that.data.jobList[i].collected = 1;
break;
}
}
txt = '收藏成功';
}
that.setData({
jobList: that.data.jobList,
isLogin: app.globalData.isLogin
});
wx.showToast({
icon: "none",
title: txt,
})
},
fail: function(res) {
console.log("操作失败");
}
})
},
});