ageChange.js 1.67 KB
// pages/ageChange/ageChange.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    age:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

  //选择年龄段
  selectAge(e) {
    let age = e.currentTarget.dataset['index']
    this.setData({
      age: age
    })
  },

  //提交年龄段
  updateAge(e){
      var that = this;
      var config = wx.getStorageSync('config');
      wx.request({
        url: app.url + 'ajax_update_user_age.php',
        data: {
          unionId: config.unionId,
          age: that.data.age
        },
        header: { 'content-type': 'application/json' },
        method: 'GET',
        dataType: 'json',
        success: function (res) {
          wx.showToast({
            title: '选择成功!',
            icon: 'success',
            duration: 2000
          });
          if (res.data.status == 'OK' && res.data.result.recommend) {
            wx.redirectTo({
              url: '/pages/memberChange/memberChange',
            })
          } else {
            //跳转到首页
            wx.switchTab({
              url: '../index/index',
            });
          }

        },
        fail: function (res) {
          wx.showToast({
            title: '系统错误!',
            icon: 'success',
            duration: 2000
          });
        },
        complete: function (res) { },
      })
  },

})