Browse Source

始宁农业小程序:农户管理-入驻申请

panyong 2 years ago
parent
commit
4038172759
1 changed files with 39 additions and 27 deletions
  1. 39 27
      htmldev/shiningWxMini/pages/mine/mine.js

+ 39 - 27
htmldev/shiningWxMini/pages/mine/mine.js

@@ -227,6 +227,7 @@ Page({
   // 参考 https://www.cnblogs.com/onesea/p/15005037.html
   async handleSubscribeMessage(e) {
     const { page } = e.currentTarget.dataset
+    const that = this
 
     try {
       const { errMsg, subscriptionsSetting } = await wx.getSetting({ withSubscriptions: true })
@@ -238,44 +239,55 @@ Page({
             const moIdState = subscriptionsSetting.itemSettings[tmplIds]
             if (moIdState === 'accept') {
               // 接受了消息推送
+              wx.navigateTo({
+                url: `/pages/${page}/${page}`
+              })
             } else if (moIdState === 'reject') {
               // 拒绝消息推送
+              wx.navigateTo({
+                url: `/pages/${page}/${page}`
+              })
             } else if (moIdState === 'ban') {
               // 已被后台封禁
+              wx.navigateTo({
+                url: `/pages/${page}/${page}`
+              })
+            } else {
+              that.handleSubscribeMessageBridge(tmplIds, page)
             }
-
-            wx.navigateTo({
-              url: `/pages/${page}/${page}`
-            })
           } else {
-            // 当用户没有点击 ’总是保持以上选择,不再询问‘  按钮。那每次执到这都会拉起授权弹窗
-            wx.showModal({
-              title: '提示',
-              content: '请授权开通服务通知',
-              showCancel: true,
-              success: function (res) {
-                if (res.confirm) {
-                  wx.requestSubscribeMessage({
-                    tmplIds: [tmplIds],
-                    success(res) {
-                      wx.navigateTo({
-                        url: `/pages/${page}/${page}`
-                      })
-                    },
-                    fail(err) {
-                      wx.navigateTo({
-                        url: `/pages/${page}/${page}`
-                      })
-                    }
-                  })
-                }
-              }
-            })
+            that.handleSubscribeMessageBridge(tmplIds, page)
           }
         } else {
           // 订阅消息未开启
+          that.handleSubscribeMessageBridge(tmplIds, page)
         }
       }
     } catch (err) {}
+  },
+  handleSubscribeMessageBridge(tmplIds, page) {
+    // 当用户没有点击 ’总是保持以上选择,不再询问‘  按钮。那每次执到这都会拉起授权弹窗
+    wx.showModal({
+      title: '提示',
+      content: '请授权开通服务通知',
+      showCancel: true,
+      success: function (res) {
+        if (res.confirm) {
+          wx.requestSubscribeMessage({
+            tmplIds: [tmplIds],
+            success(res) {
+              wx.navigateTo({
+                url: `/pages/${page}/${page}`
+              })
+            },
+            fail(err) {
+              wx.navigateTo({
+                url: `/pages/${page}/${page}`
+              })
+            }
+          })
+        }
+      }
+    })
   }
 })