浏览代码

各画面使用的商品列表中,立即购买和加入购物车的功能修正

baolei 2 月之前
父节点
当前提交
6f031fecd8

+ 1 - 1
components/product-list/product-list.js

@@ -90,7 +90,7 @@ Component({
         addCart(prod){
         addCart(prod){
             console.log(prod);
             console.log(prod);
             let prodInfo = prod.currentTarget.dataset.prod;
             let prodInfo = prod.currentTarget.dataset.prod;
-            prodInfo.buy = true;
+            prodInfo.buy = prod.currentTarget.dataset.buy;
             this.triggerEvent('addCart',prodInfo);
             this.triggerEvent('addCart',prodInfo);
         },
         },
         // 观察滚动触底事件
         // 观察滚动触底事件

+ 2 - 2
components/product-list/product-list.wxml

@@ -14,8 +14,8 @@
                     <image src="/images/index/fav.png" class="favorite-icon"></image>
                     <image src="/images/index/fav.png" class="favorite-icon"></image>
                 </view>
                 </view>
                 <view class="goods-but">
                 <view class="goods-but">
-                    <image class="add-to-cart" src="/images/index/add-cart.png" mode="" data-prod="{{item}}" catchtap="addCart"/>
-                    <image class="buy-now" src="/images/index/buy-now.png" mode="" data-prod="{{item}}" catchtap="addCart"/>
+                    <image class="add-to-cart" src="/images/index/add-cart.png" mode="" data-prod="{{item}}" data-buy="{{false}}" catchtap="addCart"/>
+                    <image class="buy-now" src="/images/index/buy-now.png" mode="" data-prod="{{item}}" data-buy="{{true}}" catchtap="addCart"/>
                 </view>
                 </view>
             </view>
             </view>
             <view class="goods-action" wx:else>
             <view class="goods-action" wx:else>

+ 16 - 0
pages/cart/cart.js

@@ -11,6 +11,8 @@ Page({
         totalPrice:0,
         totalPrice:0,
         checkedCount:0,
         checkedCount:0,
         isManage:false, // 是否进入管理模式
         isManage:false, // 是否进入管理模式
+        showAddCartModal:false,
+        currentProduct:null
     },
     },
     // 获取购物车商品
     // 获取购物车商品
     getCartProds(){
     getCartProds(){
@@ -141,6 +143,20 @@ Page({
             url: '/pages/order/confirmOrder/confirmOrder?prods='+encodeURIComponent(JSON.stringify(prods)),
             url: '/pages/order/confirmOrder/confirmOrder?prods='+encodeURIComponent(JSON.stringify(prods)),
         })
         })
     },
     },
+    // 显示商品属性模态框
+    showAddCartModal(e) {
+      const product = e.detail;
+      this.setData({
+          showAddCartModal: true,
+          currentProduct:product
+      });
+    },
+    // 关闭属性选择模态框
+    handleCloseAddCartModal(){
+        this.setData({
+            showAddCartModal:false
+        })
+    },
     onLoad(){
     onLoad(){
     },
     },
     onShow(){
     onShow(){

+ 2 - 1
pages/cart/cart.json

@@ -1,6 +1,7 @@
 {
 {
   "navigationBarTitleText":"购物车",
   "navigationBarTitleText":"购物车",
   "usingComponents": {
   "usingComponents": {
-    "product-list":"/components/product-list/product-list"
+    "product-list":"/components/product-list/product-list",
+    "addCartModel":"/components/addCartModel/addCartModel"
   }
   }
 }
 }

+ 4 - 1
pages/cart/cart.wxml

@@ -36,7 +36,10 @@
            <text class="text">更多个性化推荐</text>
            <text class="text">更多个性化推荐</text>
            <text class="line"></text>
            <text class="line"></text>
         </view>
         </view>
-        <product-list position="hot"></product-list>
+        <product-list position="hot" bindaddCart="showAddCartModal"></product-list>
+          <!-- 商品属性模态框 -->
+        <addCartModel visible="{{showAddCartModal}}" product="{{currentProduct}}" bindclose="handleCloseAddCartModal"></addCartModel>
+
     </view>
     </view>
     <!-- 底部全选和总价 -->
     <!-- 底部全选和总价 -->
     <view class="footer {{isManage && 'manageFooter'}}" >
     <view class="footer {{isManage && 'manageFooter'}}" >