Browse Source

列表添加收藏按钮

xiaohaizhao 1 year ago
parent
commit
3e0cbe0786

+ 57 - 28
pages/index/market/modules/list/index.js

@@ -53,35 +53,64 @@ Component({
       })
     },
     buyMore(e) {
-      const item = e.currentTarget.dataset.item.item[0];
-      const item1 = e.currentTarget.dataset.item;
-      wx.showModal({
-        title: '提示',
-        content: `是否确定将“${item.itemname}”加入到购物车`,
-        complete: (res) => {
-          if (res.confirm) _Http.basic({
-            "id": 20220924095102,
-            "content": {
-              sa_brandid: item1.sa_brandid,
-              "itemid": item.itemid, //货品id
-              "qty": item.orderminqty, //数量
-              itemno: item.itemno, //货品编号
-              tradefield: item1.tradefield,
-              width: item.width,
-              length: item.length
-            },
-          }).then(res => {
-            console.log("加入购物车", res)
-            wx.showToast({
-              title: res.msg == '成功' ? '加入成功' : res.msg,
-              icon: "none"
-            });
-            if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
-              badge
-            }))
+      const {
+        name
+      } = e.target.dataset;
+      if (!name) return;
+      const item1 = e.currentTarget.dataset.item,
+        index = e.currentTarget.dataset.index,
+        item = item1.item[0];
+
+      if (name == '购物车') {
+        wx.showModal({
+          title: '提示',
+          content: `是否确定将“${item.itemname}”加入到购物车`,
+          complete: (res) => {
+            if (res.confirm) _Http.basic({
+              "id": 20220924095102,
+              "content": {
+                sa_brandid: item1.sa_brandid,
+                "itemid": item.itemid, //货品id
+                "qty": item.orderminqty, //数量
+                itemno: item.itemno, //货品编号
+                tradefield: item1.tradefield,
+                width: item.width,
+                length: item.length
+              },
+            }).then(res => {
+              console.log("加入购物车", res)
+              wx.showToast({
+                title: res.msg == '成功' ? '加入成功' : res.msg,
+                icon: "none"
+              });
+              if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
+                badge
+              }))
+            })
+          }
+        })
+      } else {
+        let iscollection = item.iscollection == 1 ? false : true
+        _Http.basic({
+          "id": 20231121143403,
+          "content": {
+            "itemid": item.itemid, //货品id
+            "qty": item.orderminqty, //数量
+            iscollection,
+            width: item.width,
+            length: item.length
+          }
+        }).then(res => {
+          console.log(iscollection + "收藏夹", res)
+          wx.showToast({
+            title: res.msg == '成功' ? iscollection ? '收藏成功' : "已取消收藏" : res.msg,
+            icon: "none"
+          });
+          if (res.msg == '成功') getCurrentPages()[getCurrentPages().length - 1].setData({
+            [`list[${index}].item[0].iscollection`]: iscollection ? 1 : 0
           })
-        }
-      })
+        })
+      }
     },
   }
 })

+ 7 - 0
pages/index/market/modules/list/index.scss

@@ -88,11 +88,18 @@
 			}
 
 			.shopping {
+				display: flex;
 				font-size: 24rpx;
+				align-items: center;
 
 				.iconfont {
 					color: #F29C37;
 				}
+
+				.cuIcon {
+					font-size: 36rpx;
+					margin-right: 20rpx;
+				}
 			}
 
 		}

+ 4 - 3
pages/index/market/modules/list/index.wxml

@@ -35,9 +35,10 @@
 				</view>
 				<view class="punit">× {{item.unitname}}</view>
 			</view>
-			<navigator wx:if="{{!item.isscheme}}" url="#" class="shopping" data-item="{{item}}" catchtap="buyMore">
-				<text class="iconfont icon-gouwuche" />
-			</navigator>
+			<view wx:if="{{!item.isscheme}}" class="shopping" data-item="{{item}}" data-index="{{index}}" catchtap="buyMore">
+				<view hover-class="navigator-hover" url="#" data-name="收藏" class="{{item.item[0].iscollection?'cuIcon-favorfill':'cuIcon-favor'}} cuIcon" style="color:{{item.item[0].iscollection?'#FADB14':''}}" />
+				<view hover-class="navigator-hover" url="#" data-name="购物车" class="iconfont icon-gouwuche" />
+			</view>
 		</view>
 	</view>
 </navigator>