Commit 471716d8557c97048c37b041958933ed6765bcf5

Authored by 泉州测试
1 parent c2769c74

feat:添加昵称手动更新按钮

pages/user/index/index.js
... ... @@ -41,7 +41,9 @@ Page({
41 41 actImg: "",
42 42 is_assistance: 0, //助力活动
43 43 ad_img:"",
44   - add_card_data:'', //等级卡的内容
  44 + add_card_data:'', //等级卡的内容
  45 +
  46 +
45 47 },
46 48 goto_nav: function(e) {
47 49 var th = this;
... ... @@ -72,6 +74,9 @@ Page({
72 74 })
73 75 app.getUserFir();
74 76  
  77 +
  78 +
  79 +
75 80 //-- 读取会员中心按钮列表 --
76 81 /*--
77 82 getApp().request.get("/api/weshop/userTool/page?pageSize=100&store_id="+os.stoid, {
... ... @@ -460,6 +465,8 @@ Page({
460 465  
461 466 },
462 467  
  468 +
  469 +
463 470 //判断会员是后有改服务项目
464 471 check_is_has_qy: function(item, g_qy_list) {
465 472 if (!g_qy_list) return false;
... ...
pages/user/userinfo/userinfo.js
... ... @@ -69,6 +69,10 @@ Page({
69 69 check_label: [], //我选择的兴趣标签
70 70 fir_guide_id:null, //存储会员详情接口出来的美导ID
71 71  
  72 + userInfo: {},
  73 + hasUserInfo: false,
  74 + canIUseGetUserProfile: false,
  75 +
72 76 },
73 77 //通过路径跳转到其他页面
74 78 goto: function(e) {
... ... @@ -615,7 +619,55 @@ Page({
615 619 }
616 620 }
617 621 this.initial_user();
  622 +
  623 + // 获取用户昵称
  624 + if (wx.getUserProfile) {
  625 + this.setData({
  626 + canIUseGetUserProfile: true
  627 + })
  628 + }
  629 +
  630 + },
  631 +
  632 + // 获取用户头像昵称
  633 + getUserProfile(e) {
  634 + var th = this;
  635 + new Promise((resolve, reject) => {
  636 + wx.getUserProfile({
  637 + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  638 + success: (res) => {
  639 + th.data.user.nickname = res.userInfo.nickName;
  640 + th.data.user.head_pic = res.userInfo.avatarUrl;
  641 + this.setData({
  642 + userInfo: res.userInfo,
  643 + hasUserInfo: true,
  644 + user: th.data.user,
  645 + });
  646 + resolve(res.userInfo);
  647 + },
  648 +
  649 + });
  650 + }).then((userInfo) => {
  651 + getApp().request.get("/api/weshop/users/update", {
  652 + data: {
  653 + storeId: r.stoid,
  654 + userId: getApp().globalData.user_id,
  655 + nickname: userInfo.nickName,
  656 + head_pic: userInfo.avatarUrl
  657 +
  658 + },
  659 + success: function(su) {
  660 + if (su.data.code == 0) {
  661 + console.log("update user info OK");
  662 + }
  663 + }
  664 + });
  665 + });
  666 +
  667 +
618 668 },
  669 +
  670 +
619 671 //-----------会员是否初始化---------------------
620 672 initial_user: function() {
621 673  
... ...
pages/user/userinfo/userinfo.wxml
... ... @@ -8,11 +8,16 @@
8 8 <view class="flex-center">
9 9 <image class="Headportrait" src="{{user.head_pic}}"></image>
10 10 </view>
  11 +
11 12 <view class="flex-center vipmax">
12 13 <view>
  14 +
13 15 <view>
14   - <view class="ellipsis-2 Nickname" style="font-size: 31rpx">{{user.nickname}}
  16 + <view class="ellipsis-2 Nickname" style="font-size: 31rpx">
  17 + <view style="float:left;">{{user.nickname}}</view>
  18 + <button bindtap="getUserProfile" style="margin-left:10rpx;float:left;width: 200rpx;height:50rpx;font-size:20rpx;" class="flex-center fs30 confirmtext"> 点击更新头像昵称 </button>
15 19 </view>
  20 +
16 21 </view>
17 22  
18 23 <view class="flex fs22 vip">
... ... @@ -33,6 +38,8 @@
33 38 </navigator>
34 39 </block>
35 40 </view>
  41 +
  42 +
36 43 </view>
37 44 </view>
38 45 </view>
... ...