personalData.js 5.4 KB

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    date:'请选择出生日期',
    array: ['小学及以下', '初中', '高中', '中专/技校','大专','本科','硕士','博士'],
   
    index: 0,
    genderMale:1,
    resume_name:'',
    resume_sex: 1,
    xueliname:'请选择学历',
    resume_education_id:''

  },

  //获取学历
  geteducation(){
    let that = this;
    var url = '/index/category/education';
    var params = {
      

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        array:res.data
      })


    }).catch((err) => {

    })
  },

  // 获取Open ID
  getOpenId() {
    let that = this
    wx.login({
      success: (res) => {
        console.log(res)
        let url = 'wxapp/public/getSessionKey'
        let param = {
          code: res.code,
        }

        app.post(url, param).then((res) => {
          console.log(res)
          that.setData({
            openid: res.data.openid,
            session_key: res.data.session_key
          })
          wx.getSetting({
            success: res => {
              if (res.authSetting['scope.userInfo'] === true) {
                wx.getUserInfo({
                  success: reg => {
                    that.setData({
                      encrypted_data: reg.encryptedData,
                      iv: reg.iv
                    })
                    // 获取完后自动执行login 然后跳转至设置的url
                    // that.login()
                  }
                })
              }

            }
          })

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


      }
    });
  },

  // 获取用户权限信息
  getUserInfo(e) {
    
    let that = this;
    if (e.detail.errMsg == "getUserInfo:ok") {
      that.setData({
        encrypted_data: e.detail.encryptedData,
        iv: e.detail.iv
      })
      
      that.login()
    }


  },

  // 登录
  login() {
    let that = this;
    let url = "wxapp/public/login";
    let data = {
      openid: that.data.openid,
      session_key: that.data.session_key,
      encrypted_data: that.data.encrypted_data,
      iv: that.data.iv,
    }
    app.post(url, data).then((res) => {
      wx.setStorageSync("token", res.data.token);
      wx.showLoading({
        title: '正在进入',
      })

      let t = setInterval(function () {
        clearInterval(t)
        wx.switchTab({
          url: '../index/index',
        })
        wx.hideLoading()
      }, 1500)

    }).catch((err) => {

    })



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

  },




  /**
   * 生命周期函数--监听页面加载
   */
  
  //日期选择器
  bindDateChange: function (e) {
    console.log('picker发送选择改变,携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  gender(){
    this.setData({
      genderMale:1,
      resume_sex:1
    })
  },
  womangender() {
    this.setData({
      genderMale: 2,
      resume_sex: 2
    })
  },

  // 学历选择器
  bindPickerChange: function (e) {
    console.log('picker发送选择改变,携带值为', e.detail.value)
    this.setData({
      index: e.detail.value,
      xueliname: this.data.array[e.detail.value].education_name,
      resume_education_id: this.data.array[e.detail.value].id
    })
  },

  // 性别图片选择
  genderMale(){
    
  },
  //真实姓名
  realname(e){
    this.setData({
      resume_name:e.detail.value
    })
    console.log(this.data.resume_name)
  },
  
  
  onLoad: function (options) {
    this.getOpenId();
    this.geteducation()
  },

  //下一步
  next(){
    let that = this;
    console.log(that.data.resume_name)
    if (that.data.resume_name ==''){
      wx.showToast({
        title: '请输入真实姓名',
        icon:'none'
      })

      return false
    }

    if (that.data.date == '请选择出生日期') {
      wx.showToast({
        title: '请选择出生日期',
        icon: 'none'
      })

      return false
    }

    if (that.data.xueliname == '请选择学历') {
      wx.showToast({
        title: '请选择学历',
        icon: 'none'
      })

      return false
    }
    var url = 'wxapp/public/login';
    var params = {
      openid: that.data.openid,
      session_key: that.data.session_key,
      encrypted_data: that.data.encrypted_data,
      iv: that.data.iv,
      resume_name: that.data.resume_name,
      resume_sex: that.data.resume_sex,
      resume_birthday: that.data.date,
      resume_education_id: that.data.resume_education_id

    }
    app.post(url, params).then((res) => {
      console.log(res);
      if (res.msg =='登录成功!'){
        console.log(9090)
          wx.setStorageSync('token', res.data);
        wx.switchTab({
          url: '../index/index',
        })
      }

    }).catch((err) => {

    })
  },
  

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})