// pages/detail/index.js const app = getApp(); let touchDotX = 0; //X按下时坐标 let touchDotY = 0; //y按下时坐标 let interval; //计时器 let time = 0; //从按下到松开共多少时间*100 Page({ /** * 页面的初始数据 */ data: { navHeight: '', //swiper background: ['bg1', 'bg2', 'bg3'], vertical: false, autoplay: false, interval: 2000, duration: 500, current: 0, //下啦 isScroll: false, //地图 markers: [{ latitude: 0, longitude: 0, }], BASEIMGURL: app.globalData.BASEIMGURL, //图片域名 BASEIMGURL1: app.globalData.BASEIMGURL1, //图片域名 currentActivity: {}, //详情 userInfo: {}, scrollTop: 0, hideGetInfo: true, loading: true }, add(e) { //参加活动 if (!app.globalData.userInfo.avatar) { return this.setData({ hideGetInfo: false }) } if (this.data.currentActivity.isoverdue) { return wx.showToast({ title: '活动时间已截止,您可以参加其它活动哦~', icon: 'none' }) } let actid = this.data.currentActivity.id; app.globalData.api.activity_attend({ phone: app.globalData.userInfo.phone, actid }).then(res => { //获取最新数据 this.getAcDetail(actid); wx.showToast({ title: '您已成功参加活动!', icon: 'none' }) }) }, getAcDetail(actid) { app.globalData.api.activity_id(actid).then(res => { let v = res.data; //判断当前时间是否大于活动结束时间 let myDate = new Date(); let now = myDate.valueOf(); let time = new Date(v.endtime).valueOf(); if (app.globalData.systemInfo.platform == 'ios') { let _date = v.endtime.replace(/\.|\-/g, '/'); time = new Date(_date).valueOf(); } if (now > time) { v.isoverdue = true; } else { v.isoverdue = false; } v.starttime = v.starttime.substr(0, 16); v.deadline = v.deadline.substr(0, 16); v.endtime = v.endtime.substr(0, 16); v.shareMember = 0; v.content && (v.content = v.content.split('&hc').join('\n')); v.attention && (v.attention = v.attention.split('&hc').join('\n')); if (v.images) { try { v.imgList = JSON.parse(v.images); } catch (error) { } } let someOne = v.members.some(v => { return v.phone == app.globalData.userInfo.phone; }); if (someOne) { v.shareMember = 1; } // if (v.members) { // v.membersList = v.members.split(';').filter(v => { // return v != ''; // }) // if (v.membersList.indexOf(app.globalData.userInfo.phone || '0') > -1) { // v.shareMember = 1; // } // } this.setData({ currentActivity: v, markers: [{ latitude: v.latitude || 0, longitude: v.longitude || 0 }], loading: false }) }) }, async getPhoneNumber(e) { const that = this; if (e.detail.errMsg == "getPhoneNumber:ok") { let res = await app.globalData.api.bindphone({ "openid": app.globalData.userInfo.openid, "encryptedData": e.detail.encryptedData, "iv": e.detail.iv, "invitor": app.globalData.shareOpenId }) app.globalData.userInfo.phone = res.data.phone; that.setData({ userInfo: { ...this.data.userInfo, 'phone': res.data.phone } }); //参加活动 that.add(e); // wx.showToast({ // title: '参加成功!', // icon: 'none' // }) } else { wx.showToast({ title: '请授权您的手机号!', icon: 'none' }) } }, change(e) { this.setData({ current: e.detail.current }) }, scroll(e) { if (e.detail.scrollTop > 1) { if (this.data.isScroll) return; this.setData({ isScroll: true }) } else { if (!this.data.isScroll) return; this.setData({ isScroll: false }) } // else if (e.detail.scrollTop < 1 && this.data.isScroll == true) { // this.setData({ // isScroll: false // }) // } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (options.openid) { app.globalData.shareOpenId = options.openid; } if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo }, () => { if (options.actid) { this.getAcDetail(options.actid); } else { this.setData({ currentActivity: app.globalData.currentActivity, markers: [{ latitude: app.globalData.currentActivity.latitude || 0, longitude: app.globalData.currentActivity.longitude || 0 }] }) } }) } else { // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userInfoReadyCallback = res => { this.setData({ userInfo: res }, () => { if (options.actid) { this.getAcDetail(options.actid); } else { this.setData({ currentActivity: app.globalData.currentActivity, markers: [{ latitude: app.globalData.currentActivity.latitude || 0, longitude: app.globalData.currentActivity.longitude || 0 }] }) } }) } }; }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ isScroll: false }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { this.setData({ loading: true }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage() { const openid = wx.getStorageSync('openid') let param = openid && typeof openid === 'string' ? `pages/detail/index?openid=${ openid }&actid=${this.data.currentActivity.id}` : `pages/index/index` return { title: this.data.currentActivity.title, desc: '快来参加活动吧~', // imageUrl: 'https://cirraybucket.oss-cn-shanghai.aliyuncs.com/nowwa-h5/aboutUs/share.jpg', path: param } }, onPageScroll(e) {}, userInfoHandler(e) { const that = this; if (e.detail.errMsg == "getUserInfo:ok") { let userInfo = e.detail.userInfo; let params = Object.assign({}, { openid: app.globalData.userInfo.openid, nickName: userInfo.nickName, gender: userInfo.gender, avatarUrl: userInfo.avatarUrl }); app.globalData.api.binduserinfo(params).then(res => { let newUserInfo = app.globalData.userInfo; newUserInfo.avatar = userInfo.avatarUrl; newUserInfo.gender = userInfo.gender; newUserInfo.nickname = userInfo.nickName; app.globalData.userInfo = newUserInfo; that.setData({ userInfo: newUserInfo, hideGetInfo: true }) that.add(); }) } else { wx.showToast({ title: '请授权您的头像!', icon: 'none' }) } }, })