您现在的位置: 微信小程序 > 微信小程序DEMO >

微信小程序学习用demo推荐:T沙龙;分享,简单布局

来源:微信小程序 编辑:易用通 发布时间:03-14热度:








代码示例:
[AppleScript] 纯文本查看 复制代码
?
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// 获取全局应用程序实例对象
const app = getApp();
// 获得 AV 的引用
const AV = require('../../libs/av-weapp-min.js');
 
// 创建页面实例对象
Page({
  // 页面名称
  name: "detail",
  // 页面的初始数据
  data: {
    objectId: '',
    salon: { },
    orators: [],
  },
 
  // 生命周期函数--监听页面加载
  onLoad: function(option) {
    this.setData({
      objectId: option.objectId
    });
    wx.setNavigationBarTitle({
      title: '<T> 沙龙详情',
    });
  },
  // 生命周期函数--监听页面初次渲染完成
  onReady () {
    var params = {
      'objectId': this.data.objectId,
    }
    var that = this;
    AV.Cloud.run('getSalonWithObjectId', params).then(salon => {
      var speeches = salon.salon_speeches;
      this.setData({ orators: [] });
      speeches.forEach(function (speech, i, a) {
        var id = speech.speech_orator_id;
        var query = new AV.Query('TGuest');
        query.get(id).then(function (orator) {
          console.log(orator);
          var newOrators = that.data.orators;
          newOrators.push(orator);
          that.setData({ orators: newOrators });
        }).catch(console.error);
      })
      this.setData({ salon: salon });
    }).catch(error => {
      app.showError(error);
    });
  },
 
  // 自定义事件
  toggleEnroll: function(e) {
    // 首先检查是否需要完善信息
    var that = this;
    var userid = app.globalData.user.objectId;
    var params = {
      'userid': userid,
    }
    AV.Cloud.run('checkShouldFullInfo', params).then(result => {
      if (result == null) {
        // 需要,则跳转至报名界面
        wx.showModal({
          title: '报名',
          content: '我们需要您完善个人信息才能完成报名,是否前往完善信息?',
          success: function(res) {
            if (res.confirm) {
              var objectId = that.data.objectId;
              console.log(objectId);
              // 跳转到报名页面
              wx.redirectTo({ url: '../enroll/enroll?objectId=' + objectId });
            }
          }
        });
      } else {
        // 不需要,则直接调用报名接口
        wx.showModal({
          title: '报名',
          content: '是否确认报名?确认后暂不支持主动取消,如果需要取消报名请联系沙龙主办方',
          success: function(res) {
            if (res.confirm) {
              var enrollParams = {
                'salon_id': that.data.objectId,
                'guest_id': result.objectId,
              };
              AV.Cloud.run('enrollSalon', enrollParams).then(result => {
                console.log(result);
                if (result) {
                  // 报名成功,跳转报名成功页面
                  wx.navigateTo({ url: '../success/success' });
                } else {
                  var error = '报名失败!';
                  app.showError(error);
                }
              }).catch(error => {
                app.showError(error);
              });
            }
          }
        });
      }
    }).catch(error => {
      app.showError(error);
    });
  },
  onShareAppMessage: function() {
    var title = this.data.salon.salon_title;
    return {
      title: title,
      desc: title + '<T> 沙龙即将召开,感兴趣的朋友快来报名参加吧~',
      path: '/page/detail/detail',
    };
  },
 
  toggleGuests: function(e) {
    var objectId = this.data.objectId;
    // 跳转到用户详情页面
    wx.navigateTo({ url: '../users/users?objectId=' + objectId });
  },
})