// pages/activity/describe/index.js const app = getApp(); var WxParse = require('../../../wxParse/wxParse.js'); import util from '../../../utils/util' Page({ /** * 页面的初始数据 */ data: { activityId:'' }, onLoad: function (options) { console.log(options) if(options.id){ this.setData({activityId:options.id}); this.getDetail() } }, getDetail(){ var that = this; app.http('GET','activity/activityInfo/'+this.data.activityId).then((res)=>{ console.log(res) if(res.data.success){ this.setData({activityDetail:res.data.data}); let article = res.data.data.content; WxParse.wxParse('article', 'html', article, that,5); } else{ wx.showToast({ title: res.data.msg, icon:'none' }) } }) }, call(){ wx.makePhoneCall({ phoneNumber: this.data.activityDetail.publisherVo.phone, fail:function(){ console.log('取消') } }) }, collect(){ let data = {}; data.id = this.data.activityDetail.id; data.type = 'collect'; data.status = this.data.activityDetail.collect ? false : true; if(wx.getStorageSync('userInfo') != ''){ this.requestCollect(data) } else{ wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) var iv = res.iv; var encryptedData = res.encryptedData; var userInfo = res.userInfo; wx.login({ success: request => { // 发送 res.code 到后台换取 openId, sessionKey, unionId app.http('POST','wxapp/auth',{code : request.code,iv:iv,encryptedData:encryptedData}).then( response =>{ if(response.data.success){ wx.setStorageSync('token', 'Bearer '+ response.data.data.token); wx.setStorageSync('userInfo', userInfo); this.requestCollect(data) } else{ wx.showToast({ title: response.data.msg, icon : 'none' }) } } ) } }) } }) } }, requestCollect(data){ app.http('POST','activity/collect',data).then((res)=>{ if(res.data.success){ wx.showToast({ title: '操作成功!', }) this.getDetail(); } else{ wx.showToast({ title: res.data.msg, icon:'none' }) } }) }, toSignPage(){ if(wx.getStorageSync('userInfo') != ''){ wx.navigateTo({ url: '../signIn/index?id='+this.data.activityId, }) } else{ wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) var iv = res.iv; var encryptedData = res.encryptedData; var userInfo = res.userInfo; wx.login({ success: request => { // 发送 res.code 到后台换取 openId, sessionKey, unionId app.http('POST','wxapp/auth',{code : request.code,iv:iv,encryptedData:encryptedData}).then( response =>{ if(response.data.success){ wx.setStorageSync('token', 'Bearer '+ response.data.data.token); wx.setStorageSync('userInfo', userInfo); wx.navigateTo({ url: '../signIn/index?id='+this.data.activityId, }) } else{ wx.showToast({ title: response.data.msg, icon : 'none' }) } } ) } }) } }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })