소스 검색

商品组加入收藏夹

xiaohaizhao 1 년 전
부모
커밋
6afe5194a6
3개의 변경된 파일70개의 추가작업 그리고 12개의 파일을 삭제
  1. 38 9
      packageA/market/detail.js
  2. 9 2
      packageA/market/detail.wxml
  3. 23 1
      pages/index/index.js

+ 38 - 9
packageA/market/detail.js

@@ -10,6 +10,7 @@ Page({
 	data: {
 		hidePrice: wx.getStorageSync('hidePrice'),
 		badge: getApp().globalData.collectCount,
+		favoriteCount: getApp().globalData.favoriteCount,
 		loading: true,
 		content: {
 			sa_itemgroupid: null,
@@ -209,13 +210,6 @@ Page({
 			content
 		})
 	},
-	clickBut() {
-		this.data.detail.tradefield.length >= 2 ? wx.showToast({
-			title: '请选择加入产品领域',
-			icon: "none",
-			duration: 3000
-		}) : this.handleStorage(0);
-	},
 	/* 打开文档 */
 	openDocument(e) {
 		const {
@@ -258,11 +252,19 @@ Page({
 			}
 		})
 	},
+	clickBut(e) {
+		this.data.detail.tradefield.length >= 2 ? wx.showToast({
+			title: '请选择加入产品领域',
+			icon: "none",
+			duration: 3000
+		}) : this[e.target.id](0);
+	},
 	/* 选择领域 */
 	storage(e) {
-		this.handleStorage(e.detail.value)
+		this.addToShoppingCart(e.detail.value)
 	},
-	handleStorage(index) {
+	/* 加入购物车 */
+	addToShoppingCart(index) {
 		let detail = this.data.detail,
 			content = this.data.content;
 		if (detail.iscustomsize == 1) {
@@ -297,6 +299,33 @@ Page({
 			}))
 		})
 	},
+	/* 加入收藏夹 */
+	addToFavorites() {
+		let iscollection = this.data.detail.iscollection == 1 ? false : true
+		_Http.basic({
+			"id": 20231121143403,
+			"content": {
+				"itemid": this.data.detail.itemid, //货品id
+				iscollection
+			},
+		}).then(res => {
+			console.log(iscollection + "收藏夹", res)
+			wx.showToast({
+				title: res.msg == '成功' ? iscollection ? '收藏成功' : "已取消收藏" : res.msg,
+				icon: "none"
+			});
+			if (res.msg == '成功') {
+				getApp().globalData.getFavoriteCount().then(num => {
+					this.setData({
+						favoriteCount: num
+					})
+				})
+				this.setData({
+					"detail.iscollection": iscollection ? 1 : 0
+				})
+			}
+		})
+	},
 	/* 前往购物车 */
 	toCollect(e) {
 		getApp().globalData.changeBar({

+ 9 - 2
packageA/market/detail.wxml

@@ -153,9 +153,16 @@
         </view>
         购物车
     </navigator>
+    <navigator url="#" class="action" style="height: 100%;display: flex; flex-direction: column; align-items: center;" bindtap="toCollect">
+        <view class="{{detail.iscollection?'cuIcon-favorfill':'cuIcon-favor'}}" style="color:{{detail.iscollection?'#FADB14':''}}">
+            <view class="cu-tag badge">{{favoriteCount}}</view>
+        </view>
+        收藏夹
+    </navigator>
+    <view class="bg-blue submit" id='addToFavorites' bindtap="clickBut">{{detail.iscollection?'取消收藏商品':'加入收藏夹'}}</view>
     <picker wx:if="{{detail.tradefield.length>=2}}" range='{{detail.tradefield}}' range-key='tradefield' bindchange='storage'>
-        <view class="bg-orange submit" bindtap="clickBut">加入购物车</view>
+        <view class="bg-orange submit" id='addToShoppingCart' bindtap="clickBut">加入购物车</view>
     </picker>
-    <view wx:else class="bg-orange submit" bindtap="clickBut">加入购物车</view>
+    <view wx:else class="bg-orange submit" id='addToShoppingCart' bindtap="clickBut">加入购物车</view>
 </view>
 <wxs src="/utils/hidePrice.wxs" module="handleHide" />

+ 23 - 1
pages/index/index.js

@@ -9,7 +9,8 @@ Page({
 	data: {
 		PageCur: 'Home',
 		collectCount: "", //购物车商品数量
-		msgList: []
+		msgList: [],
+		favoriteCount: 0, //收藏夹数量
 	},
 	onLoad(options) {
 		pageInit = {
@@ -24,6 +25,7 @@ Page({
 		})
 		this.refreshData();
 		this.getCollectCount();
+		this.getFavoriteCount();
 		this.updateMsgCount();
 		this.getAnnunciate();
 		if (getApp().globalData.remindchangepassword_str) wx.showModal({
@@ -78,6 +80,8 @@ Page({
 	 */
 	refreshData() {
 		getApp().globalData.getCollectCount = this.getCollectCount.bind(this); //更新购物车件数
+		getApp().globalData.getFavoriteCount = this.getFavoriteCount.bind(this); //更新收藏夹件数
+
 		getApp().globalData.socketCallback = this.updateMsgCount.bind(this); //更新信息数量
 		getApp().globalData.changeBar = this.cutBar.bind(this); //切换首页页面
 		let page = this.selectComponent("#Home");
@@ -297,6 +301,24 @@ Page({
 			return res.data.num;
 		});
 	},
+	/* 更新收藏夹数量 */
+
+	getFavoriteCount() {
+		return _Http.basic({
+			"id": 20231121145103,
+			"content": {
+				pageSize: 1,
+				nocache: true
+			}
+		}).then(res => {
+			console.log("收藏夹数量", res)
+			getApp().globalData.favoriteCount = res.total;
+			this.setData({
+				favoriteCount: res.data.num
+			})
+			return res.total;
+		});
+	},
 	/* 更新消息数量 */
 	updateMsgCount() {
 		pageInit.Message = false;