shuziren/job-seeker/miniprogram-2/pages/home/home.js

521 lines
16 KiB
JavaScript
Raw Permalink Normal View History

2024-02-29 08:06:26 +00:00
// pages/home/home.js
import {
areaList
} from '../../cityFile/area-data/dist/data';
var QQMapWX = require('../../qqmap-wx-jssdk.js');
var qqmapsdk = new QQMapWX({
key: 'Q7ZBZ-EKQWQ-CFU5J-GOWED-2WHXO-3FBGA' // 必填填自己在腾讯位置服务申请的key
});
const url = require("../../utils/url")
import {
createStoreBindings
} from 'mobx-miniprogram-bindings'
import {
store
} from '../../store/store'
import {
myhttp
} from "../../utils/service";
import { setWatcher } from '../../utils/watch';
Page({
/**
* 页面的初始数据
*/
data: {
areaList,
selectCity: "扬州市",
swiperList: [],
suggestJobTypeList: [],
defaultList: [{
suggestJobName: "C语言软件开发工程师",
suggestJobList: [{
jobId: "1212",
jobName: "C语言开发工程师",
salary: "8-10k",
company: "扬州农商银行",
staffNum: "1000-9999人",
label: [{
name: 'c++'
}, {
name: 'windows'
}],
position: "扬州市-文汇西路"
}, {
jobId: "1212",
jobName: "C语言开发工程师",
salary: "8-10k",
company: "扬州农商银行",
staffNum: "1000-9999人",
label: [{
name: 'c++'
}, {
name: 'windows'
}],
position: "扬州市-文汇西路"
}, {
jobId: "1212",
jobName: "C语言开发工程师",
salary: "8-10k",
company: "扬州农商银行",
staffNum: "1000-9999人",
label: [{
name: 'c++'
}, {
name: 'windows'
}],
position: "扬州市-文汇西路"
}, {
jobId: "1212",
jobName: "C语言开发工程师",
salary: "8-10k",
company: "扬州农商银行",
staffNum: "1000-9999人",
label: [{
name: 'c++'
}, {
name: 'windows'
}],
position: "扬州市-文汇西路"
}, {
jobId: "1212",
jobName: "C语言开发工程师",
salary: "8-10k",
company: "扬州农商银行",
staffNum: "1000-9999人",
label: [{
name: 'c++'
}, {
name: 'windows'
}],
position: "扬州市-文汇西路"
}, {
jobId: "1212",
jobName: "C语言开发工程师",
salary: "8-10k",
company: "扬州农商银行",
staffNum: "1000-9999人",
label: [{
name: 'c++'
}, {
name: 'windows'
}],
position: "扬州市-文汇西路"
}, {
jobId: "1212",
jobName: "C语言开发工程师",
salary: "8-10k",
company: "扬州农商银行",
staffNum: "1000-9999人",
label: [{
name: 'c++'
}, {
name: 'windows'
}],
position: "扬州市-文汇西路"
}, {
jobId: "1212",
jobName: "C语言开发工程师Last",
salary: "8-10k",
company: "扬州农商银行",
staffNum: "1000-9999人",
label: [{
name: 'c++'
}, {
name: 'windows'
}],
position: "扬州市-文汇西路"
}]
}, {
suggestJobName: "java后端开发工程师"
}, {
suggestJobName: "大数据开发工程师"
}, {
suggestJobName: "嵌入式开发工程师"
}, {
suggestJobName: "前端开发工程师"
}],
showPos: false,
isLoad: false,
poplogin: false
},
poploginHandler(e){
this.setData({
poplogin:e.detail.poplogin,
})
},
/**
* 生命周期函数--监听页面加载
*/
getLocation() {
var that = this;
wx.getLocation({
type: 'wgs84',
success(res) {
qqmapsdk.reverseGeocoder({
//位置坐标,默认获取当前位置,非必须参数
//Object格式
location: {
latitude: res.latitude,
longitude: res.longitude
},
success: function (res) { //成功后的回调
console.log(res.result.ad_info.city);
that.setData({
selectCity: res.result.ad_info.city
})
wx.setStorageSync('city', res.result.ad_info.city)
},
fail: function (error) {
console.error(error);
},
complete: function (res) {
console.log(res);
}
})
}
})
},
popupPos() {
this.setData({
showPos: true
})
},
searchBoxHandler() {
if (this.data.isLoad == false) {
this.startlogin()
} else {
if (this.data.userInfo) {
wx.showToast({
title: '请先填写/上传简历',
icon: "none",
duration: 1500,
mase: true
})
} else {
wx.navigateTo({
url: '/homeSub/pages/search/search'
})
}
}
},
writeResume() {
wx.navigateTo({
url: '/homeSub/pages/writeResume/writeResume',
})
},
uploadResume() {
console.log("用户token" + wx.getStorageSync("token"))
this.chooseFile()
},
chooseFile() {
const that = this
wx.chooseMessageFile({
count: 1, //能选择文件的数量
type: 'all', //能选择文件的类型,我这里只允许上传文件.还有视频,图片,或者都可以
success(res) {
console.log(res)
var size = res.tempFiles[0].size;
var filename = res.tempFiles[0].name;
if (size > 4194304 || !/(\.doc|\.docx|\.pdf|\.png|\.jpg|\.bmp)$/.test(filename)) { //我还限制了文件的大小和具体文件类型
wx.showToast({
title: '简历文件大小不能超过4MB只能上传pdf、doc、docx、jpg、png、bmp格式',
icon: "none",
duration: 4000,
mask: true
})
} else {
console.log(filename)
console.log(res.tempFiles[0].path)
wx.uploadFile({
url: url.backUrl + "/upload_resume", //上传的路径
filePath: res.tempFiles[0].path, //刚刚在data保存的文件路径
name: 'file', //后台获取的凭据
header: {
'Content-Type': 'multipart/form-data',
"authorization": wx.getStorageSync('token') || ""
},
success(res) {
console.log(res)
that.yesResume()
console.log(that.data.userInfo)
wx.showToast({ //做个提示或者别的操作
title: '成功上传',
icon: "none",
duration: 2000,
mask: true,
success: function (res) {}
})
}
})
}
}
})
},
// 显示组件
showSelector() {
this.setData({
selectorVisible: true,
});
},
watch: {
poplogin: function (newValue) {
console.log(newValue,"登录状态")
if(newValue == false){
this.yesLoad()
this.getRecommendList()
}
},
},
// 当用户选择了组件中的城市之后的回调函数
onSelectCity(e) {
const {
province,
city
} = e.detail;
this.setData({
selectedProvince: province,
selectedCity: city,
});
},
getSwiperImage() {
myhttp({
url: url.backUrl + "/vx_interview/getCarouselChart",
data: {},
method: "GET"
}).then((res) => {
if (res.code == 0) {
const d = res.data
var swiperImgList = JSON.parse(d)
console.log(swiperImgList)
var swiperImage = swiperImgList.map(item => ({
image_src: item.url
}))
this.setData({
swiperList: swiperImage
})
} else {
wx.showToast({
title: '轮播图信息获取失败',
icon: "error"
})
}
})
},
onLoad(options) {
// this.computeScrollViewHeight()
setWatcher(this);
this.getLocation()
this.getSwiperImage()
// wx.setTabBarBadge({
// index: 2,
// text: 10+""
// })
this.storeBindings = createStoreBindings(this, {
store,
fields: ['isLoad', 'userInfo', 'myResume'],
actions: ['yesLoad', 'noLoad', 'yesResume', 'noResume', 'setResumeInfo']
})
const token = wx.getStorageSync('token') || '';
if (token) {
this.yesLoad()
this.getRecommendList()
} else {
this.noLoad()
console.log("onload 默认推荐")
// this.getDefaultList()
}
if (wx.getStorageSync("myResume") === '') {
this.noResume()
} else {
this.yesResume()
this.setResumeInfo(wx.getStorageSync("myResume"))
}
},
getDefaultList() {
myhttp({
url: url.backUrl + "/vxJob/getSuggestList?userId=" + 32,
data: {
},
method: "GET"
}).then((res) => {
console.log(res)
if (res.code == 0) {
var d = res.data
d = d.map(item => ({
suggestJobList: item.suggestJobList.map(i => ({
company: i.company,
createTime: i.createTime,
createUser: i.createUser,
jobId: i.id,
jobName: i.jobName,
position: i.position,
salary: i.salary,
staffNum: " " + i.staffNumber + "人",
updateTime: i.updateTime,
updateUser: i.updateUser,
label: i.label.slice(1, -1).split(', ').map(x => ({
name: x
}))
})),
suggestJobName: item.suggestJobName
}))
console.log(d)
this.setData({
suggestJobTypeList: d
})
// suggestJobTypeList
} else {
wx.showToast({
title: '获取岗位失败',
icon: "error"
})
}
})
},
getRecommendList() {
myhttp({
url: url.backUrl + "/vxJob/getSuggestList?userId=" + wx.getStorageSync('userInfo').id,
data: {
},
method: "GET"
}).then((res) => {
console.log(res)
if (res.code == 0) {
var d = res.data
d = d.map(item => ({
suggestJobList: item.suggestJobList.map(i => ({
company: i.company,
createTime: i.createTime,
createUser: i.createUser,
jobId: i.id,
jobName: i.jobName,
position: i.position,
salary: i.salary,
staffNum: " " + i.staffNumber + "人",
updateTime: i.updateTime,
updateUser: i.updateUser,
label: i.label.slice(1, -1).split(', ').map(x => ({
name: x
}))
})),
suggestJobName: item.suggestJobName
}))
console.log(d)
this.setData({
suggestJobTypeList: d
})
// suggestJobTypeList
} else {
// wx.showToast({
// title: '关注推荐岗位失败',
// icon: "error"
// })
}
})
},
confirmPos(e) {
console.log(e.detail.values)
this.setData({
selectCity: e.detail.values[1].name,
showPos: false
})
wx.setStorageSync('city', e.detail.values[1].name)
},
cancelPos() {
this.setData({
showPos: false
})
},
jumpJobDetail(e) {
wx.navigateTo({
url: '/homeSub/pages/jobDetail/jobDetail?jobId=' + e.currentTarget.dataset.jobid
})
},
startlogin() {
this.setData({
poplogin: true
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
onPageScroll(res) {
},
// //计算 scroll-view 的高度
// computeScrollViewHeight() {
// let that = this
// let query = wx.createSelectorQuery().in(this)
// query.select('.position-search-box').boundingClientRect(function (res) {
// //得到搜索框的高度
// let searchHeight = res.height
// //scroll-view的高度 = 屏幕高度- tab高(50) - 10 - 10 - searchHeight
// //获取屏幕可用高度
// let screenHeight = wx.getSystemInfoSync().windowHeight
// //计算 scroll-view 的高度
// let scrollHeight = screenHeight - searchHeight*6.7 - 70
// that.setData({
// scrollHeight: scrollHeight
// })
// }).exec()
// },
/**
* 生命周期函数--监听页面显示
*/
onShow() {
const token = wx.getStorageSync('token') || '';
if (token) {
this.yesLoad()
this.getRecommendList()
} else {
this.noLoad()
// this.getDefaultList()
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
this.storeBindings.destroyStoreBindings();
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})