shuziren/job-seeker/miniprogram-2/homeSub/pages/jobDetail/jobDetail.js

311 lines
9.3 KiB
JavaScript
Raw Normal View History

2024-02-29 08:06:26 +00:00
// homeSub/pages/jobDetail/jobDetail.js
import {
myhttp
} from "../../../utils/service";
const url = require("../../../utils/url")
Page({
/**
* 页面的初始数据
*/
data: {
jobId: Number,
jobInfo: {},
JobRelative: [],
starIcon: 'star-o',
poplogin: false
},
startload() {
this.setData({
poplogin: true
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let jobId = options.jobId
this.setData({
jobId: jobId
})
wx.showShareMenu({
menus: ['shareAppMessage', 'shareTimeline'],
});
//网络请求传入jobid获得jobInfo
this.getJobDetail()
//根据工作标签,网络请求获取相关工作
this.getLoveJobList()
},
getLoveJobList() {
myhttp({
url: url.backUrl + "/vxJob/getYourLikeJob?jobId=" + this.data.jobId,
data: {},
method: "GET"
}).then((res) => {
if (res.code == 0) {
console.log("aaaa")
console.log(res.data)
const d = res.data.map(item => ({
jobId: item.id,
jobName: item.jobName,
salary: item.salary,
company: item.company.companyName,
staffNum: item.company.staffNumber + "人",
}))
this.setData({
JobRelative: d
})
} else {
wx.showToast({
title: "获取推荐失败",
icon: "error"
})
}
})
},
getJobDetail() {
myhttp({
url: url.backUrl + "/recruitment/get_jobById?id=" + this.data.jobId,
data: {},
method: "GET"
}).then((res) => {
console.log("看看有没有这个岗位是否被关注")
console.log(res)
if (res.code == 0) {
const d = res.data
const companyId = d.companyEncoding
const star = d.isLike
this.getStar(star)
var companyInfo = {}
myhttp({
url: url.backUrl + "/recruitment/get_companyDetail?encoding=" + companyId,
data: {},
method: "GET"
}).then((respon) => {
if (respon.code == 0) {
console.log(respon)
companyInfo = {
companyImgUrl: JSON.parse(respon.data.companyLogo)[0].url,
companyId: companyId,
companyName: respon.data.companyName,
staffNum: respon.data.staffNumber + "人",
companyType: respon.data.type,
}
var Demand = ""
switch (d.requirement) {
case 1:
Demand = "无学历要求"
break;
case 2:
Demand = "小学/初中"
break;
case 3:
Demand = "高中/中专"
break;
case 4:
Demand = "大专及以上"
break;
case 5:
Demand = "本科及以上"
break;
case 6:
Demand = "研究生及以上"
break;
}
const respond = {
jobName: d.jobName,
salary: d.minSalary + "~" + d.maxSalary,
jobCareerDemand: Demand,
jobDemand: d.details,
jobWelfare: d.jobTips.slice(1, -1).split(', ').map(item => ({
name: item
})),
company: companyInfo,
label: d.jobTips.slice(1, -1).split(', ').map(item => ({
name: item
})),
position: d.address.slice(1, -1).split(', ')[1] + "-" + d.address.slice(1, -1).split(', ')[2]
}
console.log(respond)
this.setData({
jobInfo: respond
})
} else {
wx.showToast({
title: res.message,
icon: "error"
})
}
})
} else {
wx.showToast({
title: '获取信息失败',
icon: "error"
})
}
})
},
getStar(star) {
this.setData({
starIcon: star == 1 ? "star" : "star-o"
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
jumpCompanyDetail(e) {
wx.navigateTo({
url: '/homeSub/pages/companyDetail/companyDetail?companyId=' + e.currentTarget.dataset.companyid
})
},
jumpJobDetail(e) {
wx.navigateTo({
url: '/homeSub/pages/jobDetail/jobDetail?jobId=' + e.currentTarget.dataset.jobid
})
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
starHandler() {
const token = wx.getStorageSync('token') || '';
if (token) {
console.log("收藏/取消收藏岗位")
if(this.data.starIcon === 'star-o'){
this.addJoblike()
}else{
this.cancelJoblike()
}
} else {
this.startload()
//登录完成后,进行收藏岗位操作
}
},
cancelJoblike(){
myhttp({
url: url.backUrl + "/vxJob/cancelJobLike?jobId="+this.data.jobId+"&userId="+wx.getStorageSync("userInfo").id,
data: {
// jobId: this.data.jobId,
// userId: wx.getStorageSync("userInfo").id,
},
method: "DELETE"
}).then((res) => {
console.log(res)
if(res.code == 0){
this.setData({
starIcon: this.data.starIcon === 'star-o' ? 'star' : 'star-o'
});
}else{
wx.showToast({
title: '取消收藏失败',
icon: "error"
})
}
})
},
addJoblike(){
myhttp({
url: url.backUrl + "/vxJob/addJobLike",
data: {
jobId: this.data.jobId,
userId: wx.getStorageSync("userInfo").id,
},
method: "POST"
}).then((res) => {
console.log(res)
if(res.code == 0){
this.setData({
starIcon: this.data.starIcon === 'star-o' ? 'star' : 'star-o'
});
}else{
wx.showToast({
title: '收藏岗位失败',
icon: "error"
})
}
})
},
// shareHandler() {
// const token = wx.getStorageSync('token') || '';
// if (token) {
// console.log("分享岗位")
// } else {
// this.startload()
// //登录完成后,进行分享岗位操作
// }
// },
submitHandler() {
const token = wx.getStorageSync('token') || '';
if (token) {
myhttp({
url: url.backUrl + "/vx_interview/addInterviewApplication",
data: {
jobId: this.data.jobId,
userId: wx.getStorageSync("userInfo").id,
postingId: 4,
companyEncoding: this.data.jobInfo.company.companyId
},
method: "POST"
}).then((res) => {
console.log(res)
if (res.code == 0) {
wx.showToast({
title: '成功投递简历',
icon: "success"
})
} else {
wx.showToast({
title: '提交简历失败',
icon: "error"
})
}
})
} else {
this.startload()
//登录完成后,进行投递简历操作
}
},
})