nick_avatar.js
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// pages/user/userfw/userfw.js
var e = getApp(), os = e.globalData.setting;
var utils = require('../../../../utils/util.js');
var regeneratorRuntime = require('../../../../utils/runtime.js');
Page({
/**
* 页面的初始数据
*/
data: {
defaultAvatar: os.imghost + "/miniapp/images/no-head.jpg",
ob: {},
load: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(getApp().globalData.up_nick_avatar){
this.setData({
ob: JSON.parse(JSON.stringify(getApp().globalData.up_nick_avatar))
})
getApp().globalData.up_nick_avatar=null;
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: async function () {
},
onChooseAvatar: function (e) {
console.log(e, 1111);
var th = this;
getApp().request.uploadFile(os.url + "/api/weshop/comment/uploadCommentImg", {
filePath: e.detail.avatarUrl,
name: "file",
success: function (t) {
var u = t.data.data;
th.setData({'ob.head_pic': u})
}
});
},
get_val: function (e) {
console.log(e, 2222);
this.setData({'ob.nickname': e.detail.value})
},
save_data() {
var that=this;
setTimeout(()=>{
if (!this.data.ob.head_pic) {
wx.showToast({
title: '请选择头像',
icon: 'none',
duration: 2000
});
return false;
}
if (!this.data.ob.nickname) {
wx.showToast({
title: '请输入昵称',
icon: 'none',
duration: 2000
});
return false;
}
if (this.data.load) return false;
this.setData({load: 1})
wx.showLoading();
getApp().request.put("/api/weshop/users/update", {
data: {
store_id: os.stoid,
user_id: getApp().globalData.user_id,
nickname: this.data.ob.nickname,
head_pic: this.data.ob.head_pic
},
success: function (su) {
setTimeout(()=>{
wx.hideLoading();
if (su.data.code == 0) {
wx.navigateBack({delta: 1})
}else{
that.setData({load: 0})
wx.showToast({
title: su.data.msg,
icon: 'none',
duration: 2000
});
}
},1000)
}
});
},500)
}
})