const app = getApp(); const commonUtil = require("../../utils/commonUtil.js"); import { customRequest } from '../../utils/request.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: "", ucj: 1, }, 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, serviceInfo: app.globalData.serviceInfo, hasUserInfo: 0, }, 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: "加载中...", }); //登录=================================start if (app.globalData.isLogin) { this.setData({ isLogin: app.globalData.isLogin, hasUserInfo: app.globalData.hasUserInfo, }); } else { // 由于 userLogin 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userLoginCallback = (res) => { this.setData({ isLogin: app.globalData.isLogin, hasUserInfo: app.globalData.hasUserInfo, }); }; } 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 () { if (!app.globalData.isLogin) { console.log('unlogin'); wx.setStorageSync('comeFromPage', "collect") wx.redirectTo({ url: "/pages/login/index", }); } else { // wx.switchTab({ // url: "/pages/mine/index", // }); this.collectedStoreJobList(); } this.setData({ isLogin: app.globalData.isLogin, }); // if (app.globalData.isLogin) { // this.collectedStoreJobList(); // } else { // this.wxLogin(); // } console.log(app.globalData.headers); /*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; customRequest("/store/job/collected/list?ucj=1", { header: 'headers', method: 'GET', data: {} }).then((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, }); } }) // wx.request({ // url: app.globalData.ip + "/store/job/collected/list?ucj=1", // method: "GET", // data: {}, // header: app.globalData.headers, // 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; customRequest("/labels/findAllHopeJobLabels", { header: 'headers', method: 'GET', data: {} }).then((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(); }).catch(() => { wx.showToast({ title: "获取失败", icon: "none", duration: 2000, }); }) // 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: that.data.serviceInfo.workPhone || '0371-6611 3723', }); }, 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; } customRequest("/store/job/list", { header: 'headers', method: 'POST', data: that.data.storeJobListSearchForm }).then((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 = commonUtil.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 = commonUtil.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, }); }) // wx.request({ // url: app.globalData.ip + "/store/job/list", // method: "POST", // header: app.globalData.headers, // 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 = commonUtil.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 = commonUtil.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 (recordList) { var that = this; recordList.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; // console.log(item.salaryClassify,'=============', item.salaryClassifyValue); item["salaryClassifyValue"] = commonUtil.getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue); // //时薪 // 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; //地址深圳丨龙岗区丨 let citys = commonUtil.setJobListInfoPosition(item.district); // console.log(citys); // 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"] = citys; //职位特色 item.jobSpecialLabelNameArray = []; that.getJobSpecialLabelNamesArray(item.jobSpecialLabelNames).forEach((i, index) => { if (index <= 2) { item["jobSpecialLabelNameArray"].push(i); } }); // item["jobSpecialLabelNames"] = ; }); return recordList; }, // 下拉加载更多 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, // }); }, goNewEnroll (e) { let that = this; wx.setStorageSync("jobDetailStorage", that.data.jobList[e.currentTarget.dataset.idx]); let argument; argument = JSON.stringify(e.currentTarget.dataset.info).replace(/\=|\&/g, "3D"); wx.navigateTo({ url: `../newEnroll/index?applyType=1&info=${argument}`, }); }, 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 未过期,并且在本生命周期一直有效 customRequest("/getWechatTel", { header: 'headers', method: 'GET', data: { code: that.data.wxCode, iv: iv, encryptedData: encryptedData, } }).then((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 { promise.then(() => { let argument; argument = JSON.stringify(e.currentTarget.dataset.info).replace(/\=|\&/g, "3D"); wx.navigateTo({ url: `../newEnroll/index?applyType=1&info=${argument}`, }); }); } }) // 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 { // promise.then(() => { // let argument; // argument = JSON.stringify(e.currentTarget.dataset.info).replace(/\=|\&/g, "3D"); // wx.navigateTo({ // url: `../newEnroll/index?applyType=1&info=${argument}`, // }); // }); // } // }, // fail: function (res) { // console.log("获取用户手机号错误"); // }, // }); }, fail () { // session_key 已经失效,需要重新执行登录流程 wx.login({ success (res) { if (res.code) { console.log(res.code); //发起网络请求 customRequest("/getWechatTel", { header: 'headers', method: 'GET', data: { code: res.code, iv: iv, encryptedData: encryptedData, } }).then((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, }); } }) // 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) { console.log(false, '废弃页面'); 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.headers); //发起网络请求 customRequest(url, { header: 'headers', method: 'GET', data: { storeJobId: storeJobId, } }).then((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, }); }) // wx.request({ // url: app.globalData.ip + url, // data: { // storeJobId: storeJobId, // }, // header: app.globalData.headers, // 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("操作失败"); // }, // }); }, getUserInfoBtn: function (e) { console.log(e); let that = this; let type = e.currentTarget.dataset.type; var collected = e.currentTarget.dataset.collected; var storeJobId = e.currentTarget.dataset.jobid; let idx = e.currentTarget.dataset.idx; console.log(type); wx.getUserProfile({ desc: "用于完善会员资料", // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res); //发起网络请求 customRequest("/updateUserWechatInfo", { header: 'headers', method: 'POST', data: { nickName: res.userInfo.nickName, avatarUrl: res.userInfo.avatarUrl, gender: res.userInfo.gender, country: res.userInfo.country, province: res.userInfo.province, city: res.userInfo.city, } }).then((res) => { app.globalData.hasUserInfo = 1; that.setData({ hasUserInfo: 1, }); that.doMenuClick(type, collected, storeJobId, idx); }).catch(() => { that.doMenuClick(type, collected, storeJobId, idx); }) // wx.request({ // url: app.globalData.ip + "/updateUserWechatInfo", // data: { // nickName: res.userInfo.nickName, // avatarUrl: res.userInfo.avatarUrl, // gender: res.userInfo.gender, // country: res.userInfo.country, // province: res.userInfo.province, // city: res.userInfo.city, // }, // method: "POST", // header: app.globalData.headers, // success: function (res) { // console.log(res); // app.globalData.hasUserInfo = 1; // that.setData({ // hasUserInfo: 1, // }); // that.doMenuClick(type, collected, storeJobId, idx); // }, // fail: function (res) { // that.doMenuClick(type, collected, storeJobId, idx); // }, // }); }, fail: (res) => { console.log(res); that.doMenuClick(type, collected, storeJobId, idx); }, }); }, });