公寓小程序端前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

276 lines
8.0 KiB

// subpages/index/recruitment/recruitment.js
import { recruitmentList,dictDataList,getDetailByGraduateId,getPostListByType } from "../../../api/index"
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
searchValue: '',
areaValue: '',
industryValue: '',
positionValue: '', // 默认选中"岗位"
salaryValue: '',
showTip: true,
loading: false,
navigationHeight: 44,
statusHeight: 20,
jobList: [],
// 筛选选项
areaOptions: [],
industryOptions: [],
positionOptions: [
{ text: '岗位', value: '' },
],
salaryOptions: [],
userInfo: {},
recommendShow: true
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 获取系统信息,设置导航栏高度
const systemInfo = wx.getSystemInfoSync();
const navigationHeight = systemInfo.platform === 'ios' ? 44 : 48;
this.setData({
navigationHeight: navigationHeight,
statusHeight: systemInfo.statusBarHeight
});
this.getDictData();
if(options.recommendShow){
this.setData({
recommendShow:false
})
}
},
async getDetailByGraduateId() {
try {
const res = await getDetailByGraduateId({ graduateId: app.globalData.userInfo.graduateId });
if (res.code === 200) {
this.setData({
userInfo: res.data || {},
showTip: res.data.hopeWorkAddress && res.data.hopeCareer && res.data.hopeSalary&&res.data.hopePosition,
areaValue:this.data.areaOptions.find(item => item.dictValue == res.data.hopeWorkAddress)?.text || '',
industryValue:this.data.industryOptions.find(item => item.dictValue == res.data.hopeCareer)?.text || '',
salaryValue:this.data.salaryOptions.find(item => item.dictValue == res.data.hopeSalary)?.text || '',
});
}
} catch (error) {
if(error.data){
this.setData({
userInfo: error.data || {},
showTip: error.data.hopeWorkAddress && error.data.hopeCareer && error.data.hopeSalary&&error.data.hopePosition,
areaValue:this.data.areaOptions.find(item => item.dictValue == error.data.hopeWorkAddress)?.text || '',
industryValue:this.data.industryOptions.find(item => item.dictValue == error.data.hopeCareer)?.text || '',
salaryValue:this.data.salaryOptions.find(item => item.dictValue == error.data.hopeSalary)?.text || '',
});
}
} finally {
this.getPostListByType()
this.loadJobList();
}
},
async getDictData() {
try {
const res1 = await dictDataList({ dictType: 'sys_career' });
if (res1.code === 200) {
this.setData({
industryOptions: [
{ text: '行业', value: '' },
...res1.rows.map(item => ({
text: item.dictLabel,
value:item.dictLabel,
...item
}))
]
});
}
const res2 = await dictDataList({ dictType: 'sys_salary' });
if (res2.code === 200) {
this.setData({
salaryOptions: [
{ text: '薪资', value: '' },
...res2.rows.map(item => ({
text: item.dictLabel,
value:item.dictLabel,
...item
}))
]
});
}
const res3 = await dictDataList({ dictType: 'working_place' });
if (res3.code === 200) {
this.setData({
areaOptions: [
{ text: '区域', value: '' },
...res3.rows.map(item => ({
text: item.dictLabel,
value:item.dictLabel,
...item
}))
]
});
}
this.getDetailByGraduateId();
} catch (error) {
console.error('获取字典数据失败:', error);
}
},
/**
* 搜索
*/
onSearch() {
console.log('搜索关键词:', this.data.searchValue);
this.loadJobList();
},
/**
* 城区筛选
*/
onAreaChange(event) {
this.setData({
areaValue: event.detail
});
this.loadJobList();
},
/**
* 行业筛选
*/
onIndustryChange(event) {
this.setData({
industryValue: event.detail,
});
this.getPostListByType(true);
this.loadJobList();
},
async getPostListByType(change) {
const res = await getPostListByType({ type: this.data.industryValue });
if (res.code === 200) {
// 重置岗位选项,确保"岗位"选项在最前面
const basePositionOptions = [{ text: '岗位', value: '' }];
const newPositionOptions = res.data.map(item => ({
text: item,
value: item,
}));
this.setData({
positionOptions: [
...basePositionOptions,
...newPositionOptions
],
positionValue:change?'':this.data.userInfo.hopePosition?this.data.userInfo.hopePosition:'' // 设置为空字符串,对应"岗位"选项的value
});
console.log(this.data.positionOptions,this.data.positionValue);
}
},
/**
* 岗位筛选
*/
onPositionChange(event) {
this.setData({
positionValue: event.detail
});
this.loadJobList();
},
/**
* 薪资筛选
*/
onSalaryChange(event) {
this.setData({
salaryValue: event.detail
});
this.loadJobList();
},
/**
* 去完善信息
*/
goComplete() {
wx.navigateTo({
url: '/subpages/mine/editUser/editUser'
});
},
/**
* 点击职位
*/
onJobTap(event) {
const item = event.currentTarget.dataset.item;
wx.navigateTo({
url: `/subpages/index/recruitment/detail/detail?id=${item.id}`
});
},
/**
* 加载职位列表
*/
async loadJobList() {
this.setData({
loading: true
});
try {
const res = await recruitmentList({
position:this.data.positionValue,
positionCategory: this.data.industryValue,
workAddr: this.data.areaValue,
hopeWage: this.data.salaryValue,
searchKeyword: this.data.searchValue,
});
if (res.code === 200) {
this.setData({
jobList: res.rows || [],
loading: false
});
} else {
this.setData({
loading: false
});
wx.showToast({
title: '加载失败',
icon: 'none'
});
}
} catch (error) {
console.error('加载招聘列表失败:', error);
this.setData({
loading: false
});
wx.showToast({
title: '网络错误',
icon: 'none'
});
}
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
// this.loadJobList();
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.loadJobList();
wx.stopPullDownRefresh();
},
handleGoToBack() {
wx.navigateBack({
delta: 1
});
}
})