138 lines
3.4 KiB
JavaScript
138 lines
3.4 KiB
JavaScript
// pages/setAvatarNickname/setAvatarNickname.js
|
|
var miucms = require('../../utils/miucms.js');
|
|
const app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
avatarUrl: '',
|
|
nickname: ""
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
avatarUrl: app.globalData.user && app.globalData.user.avatar || '../../img/defaultAvatar.png',
|
|
nickname: app.globalData.user && app.globalData.user.nickname,
|
|
isIndex: options.isIndex ? true : false, // 判断是否顶部返回键的
|
|
token: options.token,
|
|
})
|
|
},
|
|
|
|
onChooseAvatar(e) {
|
|
let avatarUrl = e.detail.avatarUrl
|
|
avatarUrl = 'data:image/jpeg;base64,' + wx.getFileSystemManager().readFileSync(avatarUrl, "base64")
|
|
this.setData({
|
|
avatarUrl
|
|
})
|
|
|
|
miucms.request("https://passport.gter.net/api/user/uploadAvatar", {
|
|
data: avatarUrl
|
|
}).then(res => {
|
|
let data = res.data
|
|
app.globalData.user = data.user
|
|
app.globalData['setSate'] = true
|
|
})
|
|
},
|
|
submitNickname() {
|
|
miucms.request("https://passport.gter.net/api/user/updateNickname", {
|
|
nickname: this.data.nickname
|
|
}).then(res => {
|
|
if (res.code == 200) {
|
|
let data = res.data
|
|
app.globalData.user = data.user
|
|
app.globalData.setSate = true
|
|
if (this.data.isIndex) {
|
|
wx.navigateBack({
|
|
delta: 1,
|
|
fail: function () {
|
|
wx.navigateTo({
|
|
url: '/pages/more_offer/index/index',
|
|
})
|
|
}
|
|
})
|
|
return
|
|
}
|
|
|
|
if (data.status == 1 || data.status == 2) {
|
|
wx.redirectTo({
|
|
url: '/pagesSquare/pages/PCAuthorization/PCAuthorization?token=' + this.data.token + "&status=" + data.status,
|
|
})
|
|
} else {
|
|
wx.navigateBack({
|
|
delta: 1,
|
|
fail: function () {
|
|
wx.navigateTo({
|
|
url: '/pages/more_offer/index/index',
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
} else {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: res.message,
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
submit() {
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |