Jelajahi Sumber

client: 首页修改

x 4 tahun lalu
induk
melakukan
9fbdbef79b
1 mengubah file dengan 21 tambahan dan 1 penghapusan
  1. 21 1
      view/xcx/pages/index/index.js

+ 21 - 1
view/xcx/pages/index/index.js

@@ -1,6 +1,6 @@
 const app = getApp();
 import wxh from '../../utils/wxh.js';
-import { getIndexData, getCoupons, getTemlIds, getLiveList } from '../../api/api.js';
+import { getIndexData, getCoupons, getTemlIds, getLiveList, getNotifications } from '../../api/api.js';
 import { CACHE_SUBSCRIBE_MESSAGE } from '../../config.js';
 import { getCategoryList, getProductHot, getProductslist } from '../../api/store.js';
 import { getCouponReceive} from '../../api/user.js';
@@ -98,6 +98,7 @@ Page({
     wxh.selfLocation(1);
     this.getCategoryData();
     // this.getCoupon();
+    this.getNotification();
     this.get_host_product();
     this.get_product_list();
     this.setData({
@@ -149,6 +150,7 @@ Page({
   onShow: function () {
     // this.getCoupon();
     this.getIndexConfig();
+    this.getNotification();
     // this.getSeckillTime();
 
     var activity = this.data.activities[this.data.tapActive];
@@ -380,6 +382,24 @@ Page({
       // });
     });
   },
+  getNotification: function() {
+    var that = this;
+    getNotifications().then(res=>{
+      var unread = res.data.unread;
+      if(unread > 0) {
+        wx.setTabBarBadge({
+          index: 2,
+          text: res.data.unread.toString()
+        });
+      } else {
+        wx.removeTabBarBadge({
+          index: 2,
+        });
+      }
+    }).catch(err=>{
+
+    });
+  },
   receiveCoupon: function (e) {
     if (!app.globalData.isLog) {
       this.setData({