You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
222 lines
5.8 KiB
222 lines
5.8 KiB
3 years ago
|
// pages/activity/detail/index.js
|
||
|
const app = getApp();
|
||
|
import util from '../../../utils/util'
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
activityId:'',
|
||
|
activityDetail:{},
|
||
|
current:1,
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
let erCodeId = wx.getStorageSync('activityId');
|
||
|
if(options.id){
|
||
|
this.setData({activityId:options.id});
|
||
|
this.getDetail()
|
||
|
}
|
||
|
if(erCodeId && !options.id){ //扫码进来
|
||
|
console.log('扫码进来')
|
||
|
this.setData({activityId:erCodeId});
|
||
|
this.getDetail()
|
||
|
}
|
||
|
},
|
||
|
getDetail(){
|
||
|
app.http('GET','activity/activityInfo/'+this.data.activityId).then((res)=>{
|
||
|
if(res.data.success){
|
||
|
let detail = res.data.data;
|
||
|
detail.time1 = util.setTime(detail.createTime).split(' ')[0];
|
||
|
detail.time2 = util.setTime(detail.applyStartTime).split(' ')[0];
|
||
|
detail.time3 = util.setTime(detail.applyEndTime).split(' ')[0];
|
||
|
detail.time4 = util.setTime(detail.activityEndTime).split(' ')[0];
|
||
|
detail.flag = detail.flag.split(',');
|
||
|
detail.activityStartTime = util.setTime(detail.activityStartTime);
|
||
|
detail.activityEndTime = util.setTime(detail.activityEndTime);
|
||
|
detail.applyStartTime = util.setTime(detail.applyStartTime);
|
||
|
detail.applyEndTime = util.setTime(detail.applyEndTime);
|
||
|
this.setData({activityDetail:detail,current:detail.status})
|
||
|
} else{
|
||
|
wx.showToast({
|
||
|
title: res.data.msg,
|
||
|
icon:'none'
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
openMap(){
|
||
|
const latitude = this.data.activityDetail.latitude
|
||
|
const longitude = this.data.activityDetail.longitude
|
||
|
wx.openLocation({
|
||
|
latitude,
|
||
|
longitude,
|
||
|
scale: 18
|
||
|
})
|
||
|
},
|
||
|
shareClick(){
|
||
|
wx.showShareMenu({
|
||
|
withShareTicket: true,
|
||
|
menus: ['shareAppMessage', 'shareTimeline']
|
||
|
})
|
||
|
},
|
||
|
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{
|
||
|
this.getUserProfile()
|
||
|
}
|
||
|
},
|
||
|
toDescribe(){
|
||
|
wx.navigateTo({
|
||
|
url: '../describe/index?id='+this.data.activityDetail.id,
|
||
|
})
|
||
|
},
|
||
|
getUserProfile(){
|
||
|
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 () {
|
||
|
|
||
|
}
|
||
|
})
|