123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- // pages/userchange/userchange.js
- import Toast from '@vant/weapp/toast/toast';
- const {upLoad,chooseImage} = require('../../utils/util');
- const {modify} = require('../../API/appraise');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- changeAvatarUrl:'',
- changeNickName:'',
- changePhoneNumber:'',
- changePersonalSignatrue:''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
-
- chooseImage() {
- chooseImage().then((res)=>{
- this.uploadImage(res.tempFilePaths[0]);
- })
- },
- uploadImage(imagePath){
- upLoad( imagePath ).then((res) => {
- console.log(res);
- this.setData({
- changeAvatarUrl: res.Url
- });
- wx.setStorageSync('changeAvatarUrl', res.Url);
- })
- },
- onChangeUsername:function(e){
- wx.setStorageSync('changeNickName', e.detail);
- },
- onChangePhonenumber:function(e){
- wx.setStorageSync('changePhoneNumber', e.detail);
- },
- // onChangePassword: function(e) {
- // wx.setStorageSync('password', e.detail);
- // },
- onChangePersonalSignatrue: function(e) {
- wx.setStorageSync('changePersonalSignatrue', e.detail);
- },
-
- changeInfo:function(){
- console.log(wx.getStorageSync('uid'));
- console.log(wx.getStorageSync('changePersonalSignatrue'));
- // modifyOption.data = {
- // avatar: wx.getStorageSync('changeAvatarUrl'),
- // name: wx.getStorageSync('changeNickName'),
- // phone: wx.getStorageSync('changePhoneNumber'),
- // sign: wx.getStorageSync('changePersonalSignatrue'),
- // uid: wx.getStorageSync('uid'),
- // }
- var modifyOption = {
- data: {
- avatar: wx.getStorageSync('changeAvatarUrl'),
- name: wx.getStorageSync('changeNickName'),
- phone: wx.getStorageSync('changePhoneNumber'),
- sign: wx.getStorageSync('changePersonalSignatrue'),
- uid: wx.getStorageSync('uid'),
- },
- }
- console.log(wx.getStorageSync('changeAvatarUrl'));
- console.log(wx.getStorageSync('changePersonalSignatrue'));
- console.log(modifyOption.data);
- modify(modifyOption).then((res)=>{
- console.log(res);
- console.log(res.data);
- console.log(res.data.data);
- wx.setStorageSync('avatarUrl', res.data.data.avatar);
- wx.setStorageSync('nickName', res.data.data.name);
- wx.setStorageSync('personalSignatrue', res.data.data.sign);
- wx.switchTab({
- url: '/pages/user/user',
- })
- }).catch((err) => {
- if(err.data.message == "fail to update"){
- Toast.fail('无效修改');
- }else if(err.data.message == "phone number already be used"){
- Toast.fail('手机号已被占用');
- }
- })
- wx.setStorageSync('changeAvatarUrl', '');
- wx.setStorageSync('changeNickName', '');
- wx.setStorageSync('changePhoneNumber', '');
- wx.setStorageSync('changePersonalSignatrue', '');
- // wx.request({
- // url: 'http://192.168.31.28:8084',
- // method: 'POST',
- // data: {
- // "avatar": avatar,
- // "name": nickName,
- // "phone": phoneNumber,
- // "sign": personalSignatrue,
- // "uid": uid,
- // },
- // success (res) {
- // console.log(res);
- // wx.switchTab({
- // url: '/pages/user/user',
- // })
- // }
- // }),
- }
- })
|