img_txt.js 6.1 KB

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

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cover_type: false,
    enroll_arr: ['线上', '线下', '线上加线下'],
    enroll: '请选择报名方式',
    starTime: '请选择开始时间',
    endTime: '请选择结束时间',
    type: 0,
    id: '',
    status: ''
  },
  // 选择报名方式
  selectenroll(e) {
    let that = this
    that.setData({
      enroll: that.data.enroll_arr[e.detail.value],
      enroll_id: Number(e.detail.value) + 1
    })
    if (e.detail.value == 0) {
      that.setData({
        type: 0
      })
    } else {
      that.setData({
        type: 1
      })
    }
  },
  selecte_startTime(e) {
    this.setData({
      starTime: e.detail.value
    })
  },
  selecte_endTime(e) {
    this.setData({
      endTime: e.detail.value
    })
  },

  change_cover: function() {
    this.setData({
      cover_type: false
    })
  },
  //报名
  submit: function() {
    let that = this
    if (that.data.enroll == '请选择报名方式') {
      wx.showToast({
        title: '请选择报名方式',
        icon: 'none',
        duration: 1000
      })
      return false
    }
    if (that.data.enroll_id != 1) {
      if (that.data.starTime == '请选择开始时间') {
        wx.showToast({
          title: '请选择开始时间',
          icon: 'none',
          duration: 1000
        })
        return false
      }
      if (that.data.endTime == '请选择结束时间') {
        wx.showToast({
          title: '请选择结束时间',
          icon: 'none',
          duration: 1000
        })
        return false
      }
    } else {
    }
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let url = '/index/index/applyJoin';
    let params = {}
    if (that.data.enroll_id != 1){
      params = {
        id: that.data.id,
        type: that.data.enroll_id,
        start_time: that.data.starTime,
        end_time: that.data.end_time
      }
    }else{
      params = {
        id: that.data.id,
        type: that.data.enroll_id,
        start_time: '',
        end_time: ''
      }
    }
    
    app.post(url, params, head).then((res) => {
      wx.showToast({
        title: '提交成功',
        duration: 1000,
        success: (res) => {
          let t = setInterval((res) => {
            clearInterval(t)
            wx.switchTab({
              url: '/pages/index/index',
            })
          }, 1000)
        }
      })

    }).catch((err) => {

    })



  },
  //  展示报名弹窗
  enroll() {
    this.setData({
      cover_type: true
    })
  },
  /**
   * 获取设备信息
   */
  getSystemInfo() {
    let that = this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          height: res.windowHeight + 'px'
        })
      }
    })
  },
  //签到
  sign() {
    let that = this;
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let url = '/index/index/sginIn';
    let params = {
      id: that.data.id
    }
    app.post(url, params, head).then((res) => {
      wx.showToast({
        title: '签到成功',
        duration: 1000,
        success: (res) => {
          let t = setInterval((res) => {
            clearInterval(t)
            wx.switchTab({
              url: '/pages/index/index',
            })
          }, 1000)
        }
      })

    }).catch((err) => {

    })
  },
  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
      })
      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) => {

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    let that = this;
    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() {

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})