zhaoxiaohai há 3 anos atrás
pai
commit
69d598a225
3 ficheiros alterados com 97 adições e 53 exclusões
  1. 60 50
      pages/tabbar/mine/index.js
  2. 21 0
      pages/tabbar/mine/index.scss
  3. 16 3
      pages/tabbar/mine/index.wxml

+ 60 - 50
pages/tabbar/mine/index.js

@@ -8,6 +8,7 @@ Page({
         wusercenter: false, //个人中心权限
         userMsg: {},
         pathList: [], //功能权限
+        bdWeChat: false, //绑定微信权限
     },
     /**
      * 生命周期函数--监听页面加载
@@ -15,42 +16,38 @@ Page({
     onLoad(options) {
         this.queryUserMsg();
         let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心'])[0].apps;
-        let wusercenter = false; //个人中心
+        let wusercenter = false, //个人中心
+            bdWeChat = false; //绑定微信
         let pathList = [];
         auth.forEach(v => {
-            if (v.name == 'wusercenter') {
-                wusercenter = true;
-            } else {
-                switch (v.name) {
-                    case "teamManagement":
-                        pathList.push({
-                            name: "团队管理",
-                            icon: "icon-a-wodetuanduiguanli",
-                            color: "var(--assist)",
-                            path: `/${v.path}`
-                        })
-                        break;
-                    case "changePassword":
-                        pathList.push({
-                            name: "修改登录密码",
-                            icon: "icon-a-wodeguanyuyingyong",
-                            color: "var(--warning)",
-                            path: `/${v.path}`
-                        })
-                        break;
-                    case "wechatAgreement":
-                        pathList.push({
-                            name: "绑定微信",
-                            icon: "icon-a-wodebangdingweixin",
-                            color: "var(--success)",
-                            path: `#`
-                        })
-                        break;
-                }
+            switch (v.name) {
+                case "wusercenter":
+                    wusercenter = true;
+                    break;
+                case "teamManagement":
+                    pathList.push({
+                        name: "团队管理",
+                        icon: "icon-a-wodetuanduiguanli",
+                        color: "var(--assist)",
+                        path: `/${v.path}`
+                    })
+                    break;
+                case "changePassword":
+                    pathList.push({
+                        name: "修改登录密码",
+                        icon: "icon-a-wodeguanyuyingyong",
+                        color: "var(--warning)",
+                        path: `/${v.path}`
+                    })
+                    break;
+                case "wechatAgreement":
+                    bdWeChat = true;
+                    break;
             }
         });
         this.setData({
             wusercenter,
+            bdWeChat,
             pathList
         })
     },
@@ -101,13 +98,26 @@ Page({
             url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}`
         })
     },
-    listClick(e) {
-        const {
-            item
-        } = e.currentTarget.dataset;
-        const that = this;
-        if (item.name == '绑定微信') return wx.getUserProfile({
-            desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+    /* 绑定或解绑微信 */
+    bindingWechat(e) {
+        if (this.data.userMsg.iswechatbinding) {
+            let that = this;
+            wx.showModal({
+                title: "提示",
+                content: "是否解除绑定",
+                success: (res) => {
+                    console.log(res)
+                    if (res.confirm) that.handleBDWechat(0);
+                }
+            })
+        } else {
+            this.handleBDWechat(1);
+        }
+    },
+    handleBDWechat(isbinging) {
+        let that = this;
+        wx.getUserProfile({
+            desc: '用于完善用户资料',
             success: ({
                 userInfo
             }) => {
@@ -118,31 +128,31 @@ Page({
                             "method": "WechatBinding",
                             content: {
                                 "wechat_code": res.code,
-                                isbinging: 1, // 0解绑 1绑定
+                                isbinging, // 0解绑 1绑定
                                 wechatuserinfo: userInfo
                             }
-                        }).then(res => {
-                            console.log(res)
-                            if (res.code == 0) return wx.showToast({
-                                title: res.data,
+                        }).then(s => {
+                            if (s.msg != '成功') return wx.showToast({
+                                title: s.data,
                                 icon: "none"
                             });
-                            wx.showToast({
-                                title: '绑定成功',
-                            })
-                            that.setData({
-                                "userMsg.iswechatbinding": true
-                            })
+                            setTimeout(() => {
+                                wx.showToast({
+                                    title: isbinging == 0 ? '解除成功' : '绑定成功',
+                                    icon: "none"
+                                })
+                            }, 100);
+                            that.queryUserMsg();
                         })
                     }
                 })
             },
             fail: () => {
                 wx.showToast({
-                    title: '绑定失败,未获得授权',
+                    title: '操作失败,未获得授权',
                     icon: "none"
                 })
             }
         })
-    }
+    },
 })

+ 21 - 0
pages/tabbar/mine/index.scss

@@ -119,6 +119,20 @@
                     font-size: 50rpx;
                     margin-right: 10rpx;
                 }
+
+                .bd-wechat {
+                    width: 90rpx;
+                    height: 36rpx;
+                    line-height: 36rpx;
+                    text-align: center;
+                    border-radius: 4rpx;
+                    border: 1rpx solid #CCCCCC;
+                    font-size: 20rpx;
+                    font-family: PingFangSC-Regular-, PingFangSC-Regular;
+                    font-weight: normal;
+                    color: #999999;
+                    margin-left: 10rpx;
+                }
             }
 
         }
@@ -132,6 +146,13 @@
         display: flex;
         align-items: center;
         line-height: 20rpx;
+
+        .user-img {
+            width: 58rpx;
+            height: 58rpx;
+            border-radius: 50%;
+            margin-right: 20rpx;
+        }
     }
 
     .tips {

+ 16 - 3
pages/tabbar/mine/index.wxml

@@ -23,15 +23,28 @@
     </My_card>
 </view>
 <My_card custom-class='operating' hover>
-    <navigator class="item" url="{{item.path}}" wx:for="{{pathList}}" data-item="{{item}}" bindtap="listClick">
+    <navigator class="item" url="{{item.path}}" wx:for="{{pathList}}">
         <view class="con">
             <view class="label">
                 <text class="iconfont {{item.icon}}" style="color: {{item.color}};" />
                 {{item.name}}
             </view>
             <view class="item-right">
-                <view wx:if="{{item.name=='绑定微信'}}" class="tips {{userMsg.iswechatbinding?'':'right-false'}}">
-                    {{userMsg.iswechatbinding?'已绑定':'未绑定'}}
+                <van-icon size='30rpx' name="arrow" />
+            </view>
+        </view>
+    </navigator>
+    <navigator wx:if="{{bdWeChat}}" class="item" url="#" bindtap="bindingWechat">
+        <view class="con">
+            <view class="label">
+                <text class="iconfont icon-a-wodebangdingweixin" style="color: var(--success);" />
+                绑定微信
+                <view wx:if="{{userMsg.iswechatbinding}}" class="bd-wechat">已绑定</view>
+            </view>
+            <view class="item-right">
+                <image class="user-img" wx:if="{{userMsg.iswechatbinding}}" src="{{userMsg.wechatuserinfo.avatarUrl}}" />
+                <view class="tips right-false" wx:else>
+                    未绑定
                 </view>
                 <van-icon size='30rpx' name="arrow" />
             </view>