找回密码
 立即注册

扫一扫,访问微社区

查看: 3779|回复: 2

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

[复制链接]
发表于 2017-1-9 19:51:15 | 显示全部楼层 |阅读模式
本帖最后由 柿霖不是林 于 2017-1-9 19:52 编辑






[mw_shl_code=html,true]// 获取全局应用程序实例对象
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 });
  },
})[/mw_shl_code]

游客,如果您要查看本帖隐藏内容请回复


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

0

主题

1

回帖

17

金钱

新人求带

积分
0
发表于 2018-1-16 17:40:09 | 显示全部楼层
学习一下~~
回复

使用道具 举报

0

主题

222

回帖

509

金钱

新人求带

积分
0
发表于 2020-4-12 15:55:28 | 显示全部楼层
专注于与个人游戏开发者合作,有产品的朋友联系微信号jim20180688,详聊
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|微信小程序开发|教程|文档|资源汇总_即速论坛 ( 粤ICP备14097199号-1  

GMT+8, 2024-4-26 13:48 , Processed in 0.115853 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表