yann hai 5 meses
pai
achega
9596df67a7

+ 2 - 2
app.json

@@ -1,6 +1,5 @@
 {
   "pages": [
-      "pages/order/confirmOrder/confirmOrder",
       "pages/index/index",
       "pages/all/all",
       "pages/cart/cart",
@@ -10,7 +9,8 @@
       "pages/Mall/sortCommodity/sortCommodity",
       "pages/Mall/presaleCommodity/presaleCommodity",
       "pages/Mall/newCommodity/newCommodity",
-      "pages/Mall/hotCommodity/hotCommodity"
+      "pages/Mall/hotCommodity/hotCommodity",
+      "pages/order/confirmOrder/confirmOrder"
   ],
   "window": {
     "backgroundColor": "#FFFFFF",

+ 13 - 2
components/addCartModel/addCartModel.js

@@ -51,7 +51,7 @@ Component({
       // 选择属性
       selectSpec(e) {
         let index = e.currentTarget.dataset.index;
-        let availQty = this.data.productDetail.prodAttrList[index].availQty;
+        let {availQty} = this.data.productDetail.prodAttrList[index];
         this.setData({ 
             selectIndex:index,
             quantity:availQty > 0?1:0
@@ -75,7 +75,18 @@ Component({
       },
       
       handleAddToCart() { 
-        let {mercId,prodAttrList,prodId} = this.data.productDetail;  
+        let {mercId,prodAttrList,prodId} = this.data.productDetail;
+        if(this.data.product.buy){
+            let prod = this.data.productDetail;
+            let {attrName,prodAttrPrice} = prodAttrList[this.data.selectIndex];
+            prod.attrName = attrName;
+            prod.quantity = this.data.quantity;
+            prod.price = prodAttrPrice.price;
+            wx.navigateTo({
+              url: '/pages/order/confirmOrder/confirmOrder?prods='+encodeURIComponent(JSON.stringify([prod])),
+            })
+            return;
+        }
         const cartItem = {
             prodAttrId: prodAttrList[this.data.selectIndex].prodAttrId,
             mercId,

+ 1 - 1
components/addCartModel/addCartModel.wxml

@@ -41,7 +41,7 @@
     
     <!-- 底部按钮 -->
     <view class="footer">
-      <button class="add-btn" bindtap="handleAddToCart">加入购物车</button>
+      <button class="add-btn" bindtap="handleAddToCart">{{product.buy?"立即购买":"加入购物车"}}</button>
     </view>
   </view>
 </view>

+ 15 - 4
components/existProduct-list/existProduct-list.js

@@ -1,13 +1,24 @@
 // components/existProduct-list/existProduct-list.js
 Component({
-
+    properties:{
+        prods:{
+            type:Array,
+            value:[]
+        }
+    },
   /**
    * 页面的初始数据
    */
   data: {
-    cartList: [
-        { id: 1, prodName: "商品A商品A商品A商品A商品A", price: 100, prodAttrName:'属性',checked: false, quantity: 1 }
-    ],
+    cartList: [],
+  },
+  observers:{
+      "prods":function(list){
+          console.log(list);
+          this.setData({
+            cartList:list
+          })
+      }
   },
 
   methods:{

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

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

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

@@ -15,7 +15,7 @@
                 </view>
                 <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=""/>
+                    <image class="buy-now" src="/images/index/buy-now.png" mode="" data-prod="{{item}}" catchtap="addCart"/>
                 </view>
             </view>
             <view class="goods-action" wx:else>

+ 13 - 2
pages/order/confirmOrder/confirmOrder.js

@@ -1,18 +1,29 @@
 // pages/order/confirmOrder/confirmOrder.js
+import {formatPrice} from "../../../utils/utils";
+
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    prods:[],
+    totalPrice:0, // 订单总金额
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-
+    let list = JSON.parse(decodeURIComponent(options.prods));
+    let total = 0;
+    list.forEach(item=>{
+        total += item.quantity*item.price;
+    })
+    this.setData({
+        prods:list,
+        totalPrice:formatPrice(total)
+    })
   },
 
   /**

+ 4 - 4
pages/order/confirmOrder/confirmOrder.wxml

@@ -13,11 +13,11 @@
 </view>
 
 <!-- 商品 -->
-<existProduct></existProduct>
+<existProduct prods="{{prods}}"></existProduct>
 
 <!-- 订单信息 -->
 <view class="orderInfo">
-   <view class="info">
+   <!-- <view class="info">
       <view>
         <text class="title">配送费</text><text class="value">快递费:¥8.00</text>
       </view>
@@ -28,14 +28,14 @@
         <text class="title">订单备注</text>
         <text class="value">无备注</text>
       </view>
-   </view>
+   </view> -->
    <view class="info">
       <text class="title">商品总件数</text>
       <text class="value">共5件商品</text>
    </view>
    <view class="info">
       <text class="title">商品总价</text>
-      <text class="value">¥8290.00</text>
+      <text class="value">¥{{totalPrice}}</text>
    </view>
 </view>
 

+ 4 - 0
utils/utils.js

@@ -0,0 +1,4 @@
+// 保留两位小数
+export function formatPrice(price){
+    return price.toFixed(2)
+}