import tool from "../../../utils/tool.js"; import volunteer from "../../../pages/data/volunteer.js"; import growth from "../../../pages/data/growth.js"; var app = getApp(); var util = require("../../../utils/util.js"); var QQMapWX = require("../../../utils/qqmap-wx-jssdk.js"); var map; map = new QQMapWX({ key: "RA3BZ-PSGW4-GZUUX-DDAU7-6B54E-KJFQ7", // 必填 }); Page({ /** * 页面的初始数据 */ data: { appAssetsUrl: app.appAssetsUrl, appAssetsUrl2: app.appAssetsUrl2, nodata: util.nodata(), indicatorData: true, autoplay: true, interval: 3000, circular: true, autostop: false, params: { pageNum: 1, pageSize: 10, city: "", area: "", type: 1, //1推荐 2最新 3最热 }, total: { currPage: 0, totalPage: 0, }, noMore: false, statusBarHeightTop: 0, statusBarHeight: 0, nameIndex: 0, nameList: [{ name: "推荐兼职", }, { name: "最新兼职", }, { name: "最热兼职", }, ], classList: [{ // image: app.appAssetsUrl2 + "wjxy/homejianzhi.png", image: app.appAssetsUrl2 + "new/job-icon.png", name: "勤工俭学", }, { // image: app.appAssetsUrl2 + "wjxy/homeactive.png", image: app.appAssetsUrl2 + "new/activity-icon.png", name: "热门活动", }, { image: app.appAssetsUrl2 + "wjxy/homeshen.png", name: "青雲问鼎", }, // { // // image: app.appAssetsUrl2 + "wjxy/homevip.png", // image: app.appAssetsUrl2 + "new/goods-icon.png", // name: "市集优选", // }, { // image: app.appAssetsUrl2 + "wjxy/homevip.png", image: app.appAssetsUrl2 + "new/member-icon.png", name: "联名福利", }, // { // image: app.appAssetsUrl2 + "wjxy/homecode.png", // name: "邀请码", // }, ], cityList: [], cityListPickerData: [], cityListIndex: [], listData: [], imglist: [], currentCity: {}, current: 0, maskShow: false, activeList: [], jobList: [], perList: [], expertList: [], shopObj: {}, popupImg: "", latitude: "", longitude: "", goodsClassfiyList: [], goodsList0: [], goodsList1: [], shopList: [], }, moreHandler() { this.experience(); }, experience(e) { console.log(e, 11111111); if ( e.currentTarget.dataset.index == 4 || e.currentTarget.dataset.index == 3 ) { if (wx.getStorageSync("USER")) { wx.navigateTo({ url: e.currentTarget.dataset.index == 4 ? "/invitationCode/index" : "/pages/myMember/myMember", }); } else { wx.navigateTo({ url: "/pages/login", }); } } else { app.params.pePageToIndex = e === undefined ? 0 : e.currentTarget.dataset.index + 1; switch (e.currentTarget.dataset.index) { case 0: wx.switchTab({ url: "/pages/practicalExperience/practicalExperience", }); break; case 1: wx.switchTab({ url: "/pages/experience/index/index", }); break; case 2: wx.switchTab({ url: "/pages/dashen/index", // url: "/pages/quality/index/index", }); break; case 3: wx.navigateTo({ url: "/pages/myMember/myMember", }); break; default: wx.navigateTo({ url: "/invitationCode/index", }); } } }, // 热门活动 hotActive() { let nowCity = wx.getStorageSync("CHOOSECITY"); let that = this; app._post_form( "act/list", "", { city: nowCity.cityId, limit: 10, page: 1, isFrontPage: 1, }, function (res) { if (res.code == 0) { res.page.list.map((v) => { v.startTime = v.startTime.replace(/-/g, ".").split(" ")[0]; v.endTime = v.endTime.replace(/-/g, ".").split(" ")[0]; }); that.setData({ activeList: res.page.list, }); } }, function (res) { } ); }, // 最新兼职 newJob() { let nowCity = wx.getStorageSync("CHOOSECITY"); let that = this; app._post_form( "home/label", "", { city: nowCity.cityId, pageNum: 1, isHome: 1, pageSize: 4, }, function (res) { if (res.code == 0) { that.setData({ jobList: res.page.list, }); } }, function (res) { } ); }, // 校园代理人 schoolPer() { let that = this; app._get( `campusagent/page`, { page: 1, limit: 10, }, (res) => { if (res.code === 0) { that.setData({ perList: res.page.list, }); } } ); }, // 推荐行家 getExpert() { let that = this; let nowCity = wx.getStorageSync("CHOOSECITY"); app._get( "expert/greatGodGangPage", { page: 1, limit: 10, city: nowCity.cityId, }, function (res) { if (res.code == 0) { that.setData({ expertList: res.page.list, }); } } ); }, // 门店推荐 getShop() { let that = this; let nowCity = wx.getStorageSync("CHOOSECITY"); app._get( "store/storeRecommendation", { lon: that.data.longitude, lat: that.data.latitude, }, function (res) { if (res.code == 0 && res.data) { let val = res.data.calculateNew / 1000; let formatVal = parseInt(val * 10); that.setData({ shopObj: res.data, "shopObj.calculateNew": formatVal / 10, "shopObj.storePhoto": res.data.storePhoto.split(",")[0], }); } } ); }, // 查看门店详情 goStore(e) { console.log(e, 111); let that = this; wx.navigateTo({ url: "/expert/storedetail/storedetail?id=" + that.data.shopObj.id + "&lon=" + that.data.longitude + "&lat=" + that.data.latitude, }); }, // 查看地图 goLocal() { let that = this; let [latitude, longitude] = [ this.data.shopObj.coordinate.split(",")[0], this.data.shopObj.coordinate.split(",")[1], ]; console.log(Number(latitude), Number(longitude)); wx.openLocation({ latitude: Number(longitude), longitude: Number(latitude), name: that.data.shopObj.name, address: that.data.shopObj.address, success: function () { console.log("success"); }, }); }, callPhone() { let that = this; wx.makePhoneCall({ phoneNumber: that.data.shopObj.phone, }); }, // 开屏弹窗 openPopup() { app._get("openscreenpopup/openScreenPopup", {}, (res) => { if (res.code == 0 && res.data) { let maskShow = false; if (wx.getStorageSync("popId") != res.data.id) { wx.setStorageSync("popId", res.data.id); maskShow = true; } this.setData({ popupImg: res.data.popUpPicture, maskShow: maskShow, }); } }); }, // 兼职详情 toPartDetail(e) { wx.navigateTo({ url: `/pages/home/index/partDetail/partDetail?id=${e.currentTarget.dataset.id}`, }); }, // 校园代理人详情 perDetail(e) { // console.log(e) wx.navigateTo({ url: "/expert/agentdetail/agentdetail?id=" + e.currentTarget.dataset.id + "&type=校园代理人", }); }, // 行家详情 toExpertDetail(e) { wx.navigateTo({ url: `/expert/detail/detail?id=${e.currentTarget.dataset.id}`, }); }, onBindFocus: function (e) { let _this = this; wx.navigateTo({ url: "/pages/search/index", }); }, closePopup() { this.setData({ maskShow: false, }); }, nameHandler(e) { this.setData({ nameIndex: e.target.dataset.index, }); this.loadList(true); }, growthMore: function (event) { wx.navigateTo({ url: "/pages/home/index/growth/growthMore/growthMore", }); }, activitymore: function (event) { wx.reLaunch({ url: "/pages/experience/index/index?type=1", }); }, onReady: function () { this.popup2 = this.selectComponent("#popup2"); // this.setData({ // maskShow: true // }) }, onLoad: function (options) { this.loadCity(); this.height(); if (wx.getStorageSync("USER")) { this.PushVipInfo(); } let _this = this; _this.data.option = options; setTimeout(function () { _this.loadDictionary(); }, 100); _this.addScore(); _this.getLocal(); _this.getAgree() }, toPrivacy() { wx.openPrivacyContract({ success: () => { }, // 打开成功 fail: () => { }, // 打开失败 complete: () => { } }) // wx.navigateTo({ // url: "/pages/privacy/privacy", // }); }, closeAgree() { this.popup2.hidePopup(); }, handleAgreePrivacyAuthorization() { this.getLocal(); this.popup2.hidePopup(); }, getAgree() { wx.getPrivacySetting({ success: res => { console.log(res, 3333) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' } if (res.needAuthorization) { this.popup2.showPopup(); // 需要弹出隐私协议 } else { // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口 // wx.getUserProfile() // wx.chooseMedia() // wx.getClipboardData() // wx.startRecord() } }, fail: () => { }, complete: () => { } }) }, onShow() { this.openPopup(); }, //获取城市信息 getLocal() { const _this = this; wx.getLocation({ type: "gcj02", isHighAccuracy: true, success(res) { console.log("经纬度", res); const latitude = res.latitude; const longitude = res.longitude; _this.setData({ latitude: res.latitude, longitude: res.longitude, }); //通过【小程序定位】获取经纬度,在通过第三方sdk获取的地址信息 _this.pointToAddress(latitude, longitude, function (address) { if (address) { wx.setStorageSync("CHOOSECITY", { cityName: address.city, areaName: address.district, }); _this.loadCity(); } }); console.log("111"); }, fail(e) { _this.loadCity(); console.log("222"); }, }); }, // 定义 pointToAddress 方法 pointToAddress: function (latitude, longitude, callback) { var _this = this; // 调用接口 map.reverseGeocoder({ location: { latitude: latitude, longitude: longitude, }, success: function (res) { // 解析成功返回地址 callback(res.result.ad_info); }, fail: function (res) { console.log(res); }, complete: function (res) { }, }); }, //统计积分(每日登录) addScore: function () { if (!util.getUserId()) { return; } wx.showLoading({ title: "努力加载中...", }); app._post_form( "scoreStu/dailyLogin", "", { stuId: util.getUserId(), }, function (res) { if (res.code === 0) { } } ); }, // 首页banner loadImg: function () { let _this = this; let nowCity = wx.getStorageSync("CHOOSECITY"); let params = { type: "01", area: "", }; app._post_form("img/mylist", "application/json", params, function (res) { if (res.code == 0) { _this.setData({ imglist: res.data, }); } }); }, //banner跳转 imgJump(v) { console.log(v); console.log(v.currentTarget.dataset.item.jumpAddressType); if (v.currentTarget.dataset.item.jumpAddressType == 0) { //内部跳转 wx.navigateTo({ url: v.currentTarget.dataset.item.linkUrl, }); } else if (v.currentTarget.dataset.item.jumpAddressType == 1) { //公众号跳转 'https://www.kujiale.cn/design/3FO4EQWQJF0M/show' wx.setStorageSync("gzurl", v.currentTarget.dataset.item.linkUrl); wx.navigateTo({ url: "./gz/gz", }); } }, more(e) { console.log(e); if (e.currentTarget.dataset.type == "tab") { wx.switchTab({ url: e.currentTarget.dataset.url, }); } else { wx.navigateTo({ url: e.currentTarget.dataset.url, }); } }, popupDetail() { this.setData({ maskShow: false, }); wx.navigateTo({ url: "/expert/popupdetail/popupdetail", }); }, changeSwiper(e) { let { current, source } = e.detail; if (source === "autoplay" || source === "touch") { this.setData({ current: current, }); } // this.setData({ // current: e.detail.current // }) }, loadCity: function () { let _this = this; app._post_form("region/list", "", null, function (res) { if (res.data.length) { //设置城市选择的数据 let cityData = { cityName: "", cityId: "", // areaName: '', // areaId: '' }; console.log(res.data); //设置城市下拉框数据 let cityListPickerData = res.data; let cityListIndex = []; //nowCity是之前首页的城市选择下拉框的数据 let nowCity = wx.getStorageSync("CHOOSECITY"); if (nowCity) { a: for (let i = 0; i < res.data.length; i++) { let cityName = res.data[i].name; if (nowCity.cityName === cityName) { cityData.cityName = res.data[i].name; cityData.cityId = res.data[i].id; cityListIndex.push(i); // for (let m = 0; m < res.data[i].childRegionList.length; m++) { // let areaName = res.data[i].childRegionList[m].name; // if (nowCity.areaName === areaName) { // cityData.areaName = res.data[i].childRegionList[m].name; // cityData.areaId = res.data[i].childRegionList[m].id; // cityListPickerData.push(res.data[i].childRegionList); // cityListIndex.push(m); // break a; // } // } } } } else { cityData.cityName = res.data[0].name; cityData.cityId = res.data[0].id; cityData.areaName = res.data[0].childRegionList[0].name; cityData.areaId = res.data[0].childRegionList[0].id; cityListPickerData = [res.data, res.data[0].childRegionList]; cityListIndex = [0, 0]; } //设置城市选择数据 wx.setStorageSync("CHOOSECITY", cityData); //设置城市下拉框数据 _this.setData({ cityList: res.data, cityListPickerData, cityListIndex, currentCity: cityData, }); console.log(_this.data.cityListPickerData); setTimeout(function () { _this.loadImg(); _this.hotActive(); _this.newJob(); _this.schoolPer(); _this.getExpert(); _this.getShop(); _this.getGoodsClassfiy(); _this.getShopList(); // _this.loadList(true); }, 300); } }); }, // 查看活动详情 activeDetail: function (e) { if (e.currentTarget.dataset.id) { wx.navigateTo({ url: "/pages/home/index/activityDetail/activityDetail?id=" + e.currentTarget.dataset.id, }); } }, // 自定义高度处理 height() { const { platform, statusBarHeight } = wx.getSystemInfoSync(); let statusBarHeightTop = statusBarHeight; let height = statusBarHeight + 4; //ios 24px let mH = statusBarHeight + 4; if (platform.toLowerCase() == "android") { height += 4; //android 28px mH += 4; } height = height + 100; // height = height + 38 + 118; // 胶囊高度 32px 下边框6px height 状态栏高度 this.setData({ statusBarHeightTop: statusBarHeightTop + "px", statusBarHeight: height + "px", statusBarMH: mH + "px", }); }, loadDictionary() { let _this = this; app._post_form( "bizcatelog/apiSelectBizcatelog/workUnit", "", null, function (res) { _this.setData(res); } ); }, PushVipInfo() { let _this = this; let id = util.getUserId(); let parm = { id, }; app._post_form( "member/apiSelectMeberInfo", "application/json", JSON.stringify(parm), function (res) { if (res.code === 0) { wx.setStorageSync("USER", res.member); } else { wx.removeStorageSync("USER"); // wx.reLaunch({ // url: '/pages/login', // }) wx.switchTab({ url: "/pages/my/index/index", }); } } ); }, // 获取商品分类 getGoodsClassfiy() { app._get("goodscategory/select", {}, (res) => { if (res.code == 0) { const arr = res.list.splice(0, 2); this.setData({ goodsClassfiyList: arr, }); if (this.data.goodsClassfiyList[0]) { // this.getGoodsList0(this.data.goodsClassfiyList[0].id); } if (this.data.goodsClassfiyList[1]) { this.getGoodsList1(this.data.goodsClassfiyList[1].id); } } }); }, getGoodsList0(categoryId, i) { app._get( "goods/page", { pageSize: 1, pageNum: 1, categoryId: categoryId, }, (res) => { if (res.code == 0) { this.setData({ goodsList0: res.page.list || [], }); } } ); }, getGoodsList1(categoryId) { app._get( "goods/page", { pageSize: 3, pageNum: 1, categoryId: categoryId, }, (res) => { if (res.code == 0) { this.setData({ goodsList1: res.page.list || [], }); } } ); }, toGoodsList(e) { wx.setStorageSync('classfiyId', e.currentTarget.dataset.id) wx.navigateTo({ url: `/pages/quality/index/index`, }); }, goodsDetail(e) { wx.navigateTo({ url: `/pages/quality/detail/index?id=${e.currentTarget.dataset.id}`, }); }, getShopList() { let nowCity = wx.getStorageSync("CHOOSECITY"); app._get( "store/list", { lon: this.data.longitude, lat: this.data.latitude, limit: 2, }, (res) => { if (res.code == 0) { this.setData({ shopList: res.list || [], }); } } ); }, // tanslateM(value) { // let val = value > 1000 ? (value / 1000).toFixed(2) + "KM" : value + "M"; // return val; // }, // 查看地图 goLocalNew(e) { let that = this; let [latitude, longitude] = [ this.data.shopObj.coordinate.split(",")[0], this.data.shopObj.coordinate.split(",")[1], ]; console.log(Number(latitude), Number(longitude)); wx.openLocation({ latitude: Number(longitude), longitude: Number(latitude), name: e.currentTarget.dataset.name, address: e.currentTarget.dataset.address, success: function () { console.log("success"); }, }); }, callPhoneNew(e) { let that = this; wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.phone, }); }, // 查看门店详情 goShopStore(e) { let that = this; wx.navigateTo({ url: "/expert/storedetail/storedetail?id=" + e.currentTarget.dataset.id + "&lon=" + that.data.longitude + "&lat=" + that.data.latitude, }); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { var _this = this; //强制更新 setTimeout(() => { _this.getLocal(); }, 200); // 处理完成后,终止下拉刷新 wx.stopPullDownRefresh(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { // this.loadList(); }, //重新选择城市 cityPickerChange(e) { let cityListIndex = e.detail.value; let cityData = { cityName: this.data.cityListPickerData[cityListIndex].name, cityId: this.data.cityListPickerData[cityListIndex].id, // areaName: this.data.cityList[cityListIndex[0]].childRegionList[cityListIndex[1]].name, // areaId: this.data.cityList[cityListIndex[0]].childRegionList[cityListIndex[1]].id, }; this.setData({ cityListIndex, currentCity: cityData, }); //设置城市选择数据 wx.setStorageSync("CHOOSECITY", cityData); // this.loadList(true) this.hotActive(); this.newJob(); this.schoolPer(); this.getExpert(); this.getShop(); this.getGoodsClassfiy(); this.getShopList(); console.log(e); }, cityPickerColumnChange(e) { if (e.detail.column == 0) { this.setData({ cityListPickerData: [ this.data.cityList, this.data.cityList[e.detail.value].childRegionList, ], }); } }, /** * @param {Object} isRefresh 是否刷新,否则就是下一页 */ loadList(isRefresh) { let that = this; if (!isRefresh && this.data.noMore) { wx.showToast({ title: "没有更多了~", icon: "none", }); return false; } let nowCity = wx.getStorageSync("CHOOSECITY"); if (!nowCity || !nowCity.cityId) { return false; } this.setData({ listData: isRefresh ? [] : this.data.listData, params: { ...this.data.params, pageNum: isRefresh ? 1 : this.data.params.pageNum + 1, city: nowCity.cityId, area: nowCity.areaId, type: this.data.nameIndex + 1, }, noMore: isRefresh ? false : this.data.noMore, }); wx.showLoading({ title: "努力加载中...", }); app._post_form( "home/mylist", "", this.data.params, function (res) { if (res.code == 0) { if ( res.page.list.length > 0 && that.data.listData.length > 0 && res.page.list[0].id == that.data.listData[0].id ) { return; } let listData = that.data.listData; listData.push(...res.page.list); that.setData({ listData, currPage: res.page.currPage, totalPage: res.page.totalPage, noMore: res.page.totalPage == res.page.currPage, }); } }, function (res) { wx.hideLoading(); } ); }, onShareAppMessage: function () { }, });