123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- // 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'
- })
- }
- },
- })
|