img_txt.js 7.7 KB
const app = getApp();
var wxParse = require('../../wxParse/wxParse.js');

Page({
  /**
   * 页面的初始数据
   */
  data: {
    type: 0,
    id: '',
    status: '',
    cover_type: false
  },
  //查看更多报名用户信息(审核端)
  look_more(e) {
    wx.navigateTo({
      url: '/pages/enroll/enroll?status=' + e.currentTarget.dataset.status + '&id=' + this.data.id + '&user_id=' + e.currentTarget.dataset.user_id + '&join_id=' + e.currentTarget.dataset.join_id
    })
  },
  // 工作内容(管理员)
  join_info() {
    let that = this;
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let url = 'index/member_center/getJoinPerson';
    let params = {
      id: that.data.id
    }
    app.post(url, params, head).then((res) => {
      that.setData({
        join_info: res
      })
    }).catch((err) => {

    })
  },
  //保存海报到本地
  save_poster() {
    wx.downloadFile({
      url: this.data.poster,
      success: (res) => {
        if (res.statusCode === 200) {
          wx.saveImageToPhotosAlbum({
            filePath: res.tempFilePath,
            success: (r) => {
              wx.showToast({
                title: '保存成功',
                mask: true,
                duration: 1000
              })
            }
          })
        }
      }
    })

  },
  // 改变弹窗状态
  change_cover(e) {
    this.setData({
      cover_type: !this.data.cover_type,
      cover_id: e.currentTarget.dataset.id
    })

  },
  // 退出活动
  out() {
    let url = 'index/index/quitActivity'
    let params = {
      id: this.data.id
    }
    let header = {
      'XX-Token': wx.getStorageSync('token')
    }
    app.post(url, params, header).then((res) => {
      wx.showToast({
        title: '退出成功',
        mask: true,
        duration: 1000,
        success: () => {
          setTimeout(() => {
            wx.navigateBack({
              delta: 1
            })
          }, 1000)
        }
      })

    })
  },
  // 编辑报名信息
  edit_info() {
    wx.navigateTo({
      url: '/pages/enroll/enroll?id=' + this.data.id + '&type=5'
    })
  },
  get_poster() {
    let url = 'index/index/makePic'
    let params = {
      id: this.data.id
    }
    let header = {
      'XX-Token': wx.getStorageSync('token')
    }
    app.post(url, params, header).then((res) => {
      this.setData({
        poster: res.url
      })
    })
  },
  /**
   * 获取设备信息
   */
  getSystemInfo() {
    let that = this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          height: res.windowHeight + 'px'
        })
      }
    })
  },
  getdatalist() {
    let that = this;
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let url = '';
    let params = ''
    if (that.data.status == '1') {
      url = 'index/index/activity_info';
      params = {
        id: that.data.id
      }
    } else if (that.data.status == '2') {
      url = 'index/member_center/about';
      params = {};
    } else if (that.data.status == '3') {
      url = 'index/member_center/contact';
      params = {};
    }
    app.post(url, params, head).then((res) => {
      that.setData({
        datalist: res,
        "datalist.button_status": Number(res.button_status)
      })
      if (that.data.status == '1') {
        that.get_poster()
        that.join_info()
      }
      wxParse.wxParse('content', 'html', res.content, that, 5);
    }).catch((err) => {

    })
  },
  get_news() {
    let that = this;
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let url = 'index/index/news_info';
    let params = {
      id: that.data.id
    }
    app.post(url, params, head).then((res) => {
      that.setData({
        datalist: res
      })
      wxParse.wxParse('content', 'html', res.content, that, 5);
    }).catch((err) => {

    })
  },


  //判断是否登陆
  get_token() {
    let that = this
    wx.login({
      success: function(s) {
        let url = 'wxapp/public/getSessionKey';
        if (s.code) {
          var code = s.code;
          var param = {
            code: code
          }
          app.post(url, param).then((res) => {
            let url = 'wxapp/public/get_token'
            let params = {
              openid: res.openid
            }
            app.post(url, params).then((res) => {
              if (res.data) {
                wx.setStorageSync('token', res.data)
                that.getdatalist()
              } else {
                wx.navigateTo({
                  url: '/pages/start/start',
                })
              }
            }).catch((err) => {

            })
          }).catch((errMsg) => {

          })
        }
      }
    });
  },



  start(e) {
    let that = this
    wx.login({
      success: function (s) {
        let url = 'wxapp/public/getSessionKey';
        if (s.code) {
          var code = s.code;
          var param = {
            code: code
          }
          app.post(url, param).then((res) => {
            that.login(res.openid, res.session_key)
          }).catch((errMsg) => {

          })
        }
      }
    });
  },
  login(openid, session_key) {
    wx.showLoading({
      title: '加载中',
    })
    let that = this
    let param = {
      openid: openid,
      session_key: session_key
    }
    let url = 'wxapp/public/get_token'
    app.post(url, param).then((res) => {
      wx.setStorageSync('token', res.token)
      wx.hideLoading()
      that.getdatalist()
    }).catch((errMsg) => {

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    if (options.scene) {
      wx.setNavigationBarTitle({
        title: '活动详情'
      })
      that.setData({
        status: 1,
        id: options.scene
      })
      that.start()
    } else {
      if (options.type == 1) {
        wx.setNavigationBarTitle({
          title: '活动详情'
        })
        that.setData({
          type: options.type,
          id: options.id,
          status: options.status
        })
        that.get_news()
      } else {
        if (options.status == '1') {
          that.setData({
            id: options.id,
            status: options.status
          })
          wx.setNavigationBarTitle({
            title: '活动详情'
          })
          that.getdatalist();
        } else if (options.status == '2') {
          that.setData({
            status: options.status
          })
          wx.setNavigationBarTitle({
            title: '关于我们'
          })
          that.getdatalist();
        } else if (options.status == '3') {
          that.setData({
            status: options.status
          })
          wx.setNavigationBarTitle({
            title: '联系我们'
          })
          that.getdatalist();
        }
        that.getSystemInfo()
      }
    }



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    wx.hideShareMenu()
    if (wx.getStorageSync('page_type')) {
      wx.removeStorageSync('page_type')
      this.getdatalist()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      title: this.data.datalist.activity_name,
      path: "/pages/img_txt/img_txt?scene=" + this.data.id,
      imageUrl: this.data.datalist.thumbnail
    }
  }
})