123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- const util = require('../../../../utils/util.js');
- const api = require('../../../../config/api.js');
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- phone: '',
- bCode: '',
- showPicker: false,
- cityId: '',
- cityValue: '请选择城市',
- cityList: [],
- columns: [],
- username: '',
- userInfo: {},
- },
- onCancel: function () {
- this.setData({
- showPicker: false,
- });
- },
- onConfirm: function (event) {
- this.setData({
- cityId: this.data.cityList[event.detail.index].id,
- cityValue: event.detail.value,
- showPicker: false,
- });
- },
- showPicker() {
- this.setData({
- showPicker: true,
- });
- },
- nameInput(e) {
- this.setData({
- username: e.detail.value
- })
- },
- getAllCity() {
- util.request(api.GetAllCity, {}, 'get').then(res => {
- if (res.errno === 0) {
- let list = res.data;
- let columns = list.map(item => {
- return item.cityName
- });
- this.setData({
- cityList: list,
- columns: columns
- })
- } else {
- util.showErrorToast(res.errmsg);
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getAllCity();
- this.setData({
- phone: app.globalData.recommend.phone,
- bCode: app.globalData.recommend.bCode
- })
- },
- confirmRegister() {
- if (this.data.cityValue == '请选择城市') {
- util.showErrorToast('请选择城市');
- } else if (this.data.username == '') {
- util.showErrorToast('请输入姓名');
- } else {
- wx.getUserProfile({
- desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (res) => {
- console.log(res);
- if (res.userInfo == null) {
- wx.showToast({
- title: '未授权,无法完善信息',
- icon: 'success',
- duration: 3000
- });
- return;
- } else {
- this.setData({
- userInfo: res.userInfo,
- });
- this.registerReferrer();
- }
- }
- })
- }
- },
- registerReferrer() {
- util.request(api.RegisterReferrer, {
- "applyCode": this.data.bCode,
- "avatar": this.data.userInfo.avatarUrl,
- "cityId": this.data.cityId,
- "customerName": this.data.username,
- "gender": this.data.userInfo.gender,
- "nickname": this.data.userInfo.nickName,
- "openId": app.globalData.recommend.openId,
- "phone": this.data.phone,
- "ruserid": app.globalData.rId,
- "sessionKey": app.globalData.recommend.sessionKey,
- "unionId": app.globalData.recommend.unionId
- }, "POST")
- .then((res) => {
- if (res.errno == 0) {
- //存储用户信息
- app.globalData.hasLogin = true;
- wx.setStorageSync('userInfo', res.data.userInfo);
- wx.setStorageSync('token', res.data.token);
- app.globalData.shareImage = res.data.sharImage;
- // wx.navigateTo({
- // url: '../steward/steward',
- // })
- wx.showToast({
- title: '注册成功',
- duration: 2000,
- success: function () {
- setTimeout(function(){
- wx.switchTab({
- url: '/pages/index/index',
- })
- },2000);
- }
- })
- } else {
- util.showErrorToast(res.errmsg);
- }
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|