Browse Source

商城浮动按钮

zhaoxiaohai 2 years ago
parent
commit
849cfeb92f

+ 4 - 2
packageA/market/detail.js

@@ -13,9 +13,8 @@ Page({
       sa_itemgroupid: options.id,
       itemno: 'BM8270 0150000'
     })
-    this.getDetail()
+    this.getDetail();
   },
-
   /* 获取详情 */
   getDetail() {
     _Http.basic({
@@ -111,6 +110,9 @@ Page({
       })
     })
   },
+  onShow() {
+    this.selectComponent("#Float").setNum(getApp().globalData.num)
+  },
   onReady() {
 
   }

+ 3 - 1
packageA/market/detail.json

@@ -1,3 +1,5 @@
 {
-  "usingComponents": {}
+  "usingComponents": {
+    "Float": "../shopping/modules/float"
+  }
 }

+ 0 - 14
packageA/market/detail.scss

@@ -167,17 +167,3 @@ swiper {
 		margin-top: 10rpx;
 	}
 }
-
-.corner-mark {
-	position: absolute;
-	display: inline-block;
-	height: 28rpx;
-	font-size: 20rpx;
-	color: #FFFFFF;
-	background-color: red;
-	padding: 0 10rpx;
-	border-radius: 14rpx;
-	top: -45rpx;
-	left: 0rpx;
-	z-index: 9999;
-}

+ 4 - 11
packageA/market/detail.wxml

@@ -30,7 +30,6 @@
 		<text>库存:1200 紧缺</text>
 	</view>
 </view>
-
 <!-- 选择型号 -->
 <view class="model">
 	<view class="label">
@@ -40,7 +39,6 @@
 		<navigator url="#" class="product {{itemno===item.itemno?'active':''}}" wx:for="{{rows}}" wx:key="item.itemno" bindtap="changeItemno" data-item="{{item}}">{{item.spec}}</navigator>
 	</view>
 </view>
-
 <van-tabs custom-class='tabs' title-active-color='var(--assist)' color='var(--assist)'>
 	<van-tab title="商品简介">
 		<view class="tab-box">
@@ -81,16 +79,11 @@
 		</view>
 	</van-tab>
 </van-tabs>
-
-<Yl_FloatingButton useSlot>
-	<view>
-		<text class="corner-mark">99+</text>
-		<image style="width: 160rpx; height: 160rpx; transform: translate(-50%,-50%);" src='../../static/image/shopping.png' data-title="新建线索" />
-	</view>
-</Yl_FloatingButton>
-
 <!-- 底部 -->
 <view style="height: 150rpx;" />
 <view class="footer">
 	<van-button custom-class='but' bindtap="storage">加入购物车</van-button>
-</view>
+</view>
+
+<!-- 购物车按钮 -->
+<Float id="Float" />

+ 19 - 8
packageA/market/index.js

@@ -18,6 +18,7 @@ Page({
 	},
 	onLoad(options) {
 		this.getBrand()
+		this.getNum();
 	},
 	/* 切换分类 */
 	typeChange({
@@ -97,12 +98,6 @@ Page({
 			})
 		})
 	},
-	/* 去购物车 */
-	toShopping() {
-		wx.navigateTo({
-			url: '/packageA/shopping/index',
-		})
-	},
 
 	startFiltration() {
 		/* _Http.basic().then(res => {
@@ -110,9 +105,11 @@ Page({
 		}) */
 	},
 	/* 搜索 */
-	onSearch({detail}){
+	onSearch({
+		detail
+	}) {
 		this.setData({
-			"content.where.condition":detail
+			"content.where.condition": detail
 		});
 		this.getList(true)
 	},
@@ -123,4 +120,18 @@ Page({
 	setListHeight() {
 		this.selectComponent("#ListBox").setHeight(".division", this);
 	},
+	/* 获取购物车数量 */
+	getNum() {
+		_Http.basic({
+			"id": 20220927093202,
+			"content": {}
+		}).then(res => {
+			console.log("购物车数量", res)
+			getApp().globalData.num = res.data.num;
+			this.selectComponent("#Float").setNum(res.data.num)
+		});
+	},
+	onShow() {
+		if (getApp().globalData.num) this.selectComponent("#Float").setNum(getApp().globalData.num)
+	}
 })

+ 2 - 1
packageA/market/index.json

@@ -1,6 +1,7 @@
 {
   "usingComponents": {
     "List": "./modules/list/index",
-    "Tabs": "./modules/tabs/index"
+    "Tabs": "./modules/tabs/index",
+    "Float": "../shopping/modules/float"
   }
 }

+ 1 - 13
packageA/market/index.scss

@@ -16,19 +16,7 @@
 		background-color: #FAFAFA;
 	}
 }
-.corner-mark {
-	position: absolute;
-	display: inline-block;
-	height: 28rpx;
-	font-size: 20rpx;
-	color: #FFFFFF;
-	background-color: red;
-	padding: 0 10rpx;
-	border-radius: 14rpx;
-	top: -45rpx;
-	left: 0rpx;
-	z-index: 9999;
-}
+
 .division{
 	height: 10rpx;
 	background-color: #F4F5F7;

+ 2 - 12
packageA/market/index.wxml

@@ -3,25 +3,15 @@
 <template is="skeleton" wx:if="{{loading}}" />
 
 <Yl_HeadNav styleType="1" sort='{{content.sort}}' bindonSearch="onSearch" />
-
 <!-- 品牌列表 -->
 <Tabs list="{{brandList}}" box-class='brand-box' tab-class='brand-tab-class' active-class='brand-active-class' />
 <!-- 产品列表 -->
 <Tabs wx:for="{{typeList}}" active="{{item.active}}" wx:key="{{index}}" rowIndex="{{index}}" list="{{item.list}}" bind:onChange="typeChange" name='itemclassname' box-class='brand-box' tab-class='brand-tab-class' active-class='brand-active-class' />
-
-
-
 <view class="division" />
 <Yl_ListBox id='ListBox' bind:getlist='getList'>
 	<List list="{{list}}" />
 </Yl_ListBox>
-
-<Yl_FloatingButton useSlot bindtap="toShopping">
-	<view>
-		<text class="corner-mark">99+</text>
-		<image style="width: 160rpx; height: 160rpx; transform: translate(-50%,-50%);" src='/static/image/shopping.png' data-title="新建线索" />
-	</view>
-</Yl_FloatingButton>
-
 <!-- 筛选条件 -->
 <Yl_Filtrate id='Filtrate' bind:handle="handleFilter" />
+<!-- 购物车按钮 -->
+<Float id="Float" />

+ 20 - 0
packageA/shopping/modules/float/index.js

@@ -0,0 +1,20 @@
+const _Http = getApp().globalData.http;
+Component({
+  data: {
+    num: 0,
+  },
+  methods: {
+    /* 去购物车 */
+    toShopping() {
+      wx.navigateTo({
+        url: '/packageA/shopping/index',
+      })
+    },
+    /* 设置数量 */
+    setNum(num) {
+      this.setData({
+        num
+      })
+    }
+  }
+})

+ 4 - 0
packageA/shopping/modules/float/index.json

@@ -0,0 +1,4 @@
+{
+  "component": true,
+  "usingComponents": {}
+}

+ 13 - 0
packageA/shopping/modules/float/index.scss

@@ -0,0 +1,13 @@
+.corner-mark {
+	position: absolute;
+	display: inline-block;
+	height: 28rpx;
+	font-size: 20rpx;
+	color: #FFFFFF;
+	background-color: red;
+	padding: 0 10rpx;
+	border-radius: 14rpx;
+	top: -45rpx;
+	left: 0rpx;
+	z-index: 9999;
+}

+ 6 - 0
packageA/shopping/modules/float/index.wxml

@@ -0,0 +1,6 @@
+<Yl_FloatingButton useSlot bindtap="toShopping">
+	<view>
+		<text class="corner-mark" wx:if="{{num>0}}">{{num}}</text>
+		<image style="width: 160rpx; height: 160rpx; transform: translate(-50%,-50%);" src='/static/image/shopping.png' data-title="新建线索" />
+	</view>
+</Yl_FloatingButton>

+ 4 - 6
utils/Http.js

@@ -43,15 +43,13 @@ class HTTP {
                     })
                 } else if (res.data.msg == '登陆状态已过期,请重新登陆!') {
                     clearTimeout(count);
+                    wx.redirectTo({
+                        url: '/pages/home/index',
+                    });
                     wx.showToast({
-                        title: '登陆状态已过期,请重新登陆!',
+                        title: res.data.msg,
                         icon: "none"
                     })
-                    count = setTimeout(() => {
-                        wx.redirectTo({
-                            url: '/pages/home/index',
-                        });
-                    }, 500)
                 }
             }
         })