xing.li 4 years ago
parent
commit
e4bc84bdc9
5 changed files with 67 additions and 12 deletions
  1. 45 3
      pages/food/food.js
  2. 5 1
      pages/food/food.wxml
  3. 8 0
      pages/food/food.wxss
  4. 4 5
      pages/foodOrder/foodOrder.js
  5. 5 3
      pages/foodOrder/foodOrder.wxss

+ 45 - 3
pages/food/food.js

@@ -13,6 +13,7 @@ Page({
     showCart:false,
     mask:true,
     series:[],//商品分类
+    cartList:[],//购物车列表
     currentProductList:[],//商品
     totalNum:0,//购物车总数
     totalPrice:0.00//购物车总价格
@@ -94,6 +95,8 @@ Page({
     if(this.data.cartList.length ==0){
       this.setData({showCart:false})
     }
+    await this.initProduct();
+    this.cartWwing();
   },
 
   onLoad: async function (options) {
@@ -101,9 +104,10 @@ Page({
       tableId:options.table_id,
       storeId:options.store_id
     })
+    await this.getCart();
     await this.productTypeList();
     await this.getProductList();
-    await this.getCart();
+  
 
   },
   
@@ -145,18 +149,31 @@ Page({
   initProduct: function(){
     let series = this.data.series;
     let productList = this.data.productList;
+    
+    let cartList = this.data.cartList;
+      cartList.forEach((ite,index) => {
+        productList.forEach((ele,pindex) => {
+          ele.hasChoose = false;
+        if (ele.id == ite.productId){
+          ele.hasChoose = true;
+          ele.hasNum = ite.num;
+        }
+        
+      });
+    });
+ 
     let currentProductList = [];
     series.forEach((item,index) => {
       currentProductList[index] = [];
       let i = 0;
       productList.forEach((element,pindex) => {
-        
         if (element.productTypeId == item.id){
           currentProductList[index][i] = element;
           i++;
         }
       });
     });
+
     this.setData({
       currentProductList:currentProductList
     })
@@ -178,5 +195,30 @@ Page({
     }else{
       this.setData({showCart:false})
     }
-  }
+  },
+  /**
+ * 点击商品+号购物车摆动
+ * @return void 
+ */
+cartWwing: function()
+{
+ 
+ // 创建动画实例(animation)
+ var animation = wx.createAnimation({
+ duration: 100,//动画持续时间
+ timingFunction: 'ease-in',//动画以低速开始
+ //具体配置项请查看文档
+ })
+ 
+ // 通过实例描述对象()
+ animation.translateX(6).rotate(21).step()
+ animation.translateX(-6).rotate(-21).step()
+ animation.translateX(0).rotate(0).step()
+ 
+ // 导出动画
+ this.setData({
+ ani: animation.export()
+ })
+ 
+},
 })

+ 5 - 1
pages/food/food.wxml

@@ -31,6 +31,8 @@
                    </view>
                    <view class="add-cart">
                      <image bindtap="updateCartClick"  data-type ="1" data-no="{{item.id}}" class="add-cart-size" src='../../images/jias.png'></image>
+                     <text class="cart-good-num" wx:if="{{item.hasChoose}}">{{item.hasNum}}</text>
+                     <image class="add-cart-size" wx:if="{{item.hasChoose}}" bindtap="updateCartClick" data-type="2" data-no="{{item.id}}" src='../../images/cart-jian.png' ></image>
                    </view>
                   </block>
                 </view>
@@ -41,7 +43,7 @@
      </swiper>
      <view class="cart">
          <view class="cart-icon cart-mar" bindtap="openCartDialog" data-type="open">
-            <image class="cart-icon-size" src="../../images/cart.png"></image>
+            <image class="cart-icon-size" animation="{{ ani }}" src="../../images/cart.png"></image>
          </view>
          <view class="cart-num cart-mar" bindtap="openCartDialog" data-type="open">
             <text class="cart-num-txt" wx:if="{{cartList.length == 0}}">购物车空空如也~~~</text>
@@ -64,7 +66,9 @@
   <view class="weui-mask init" wx:if="{{mask}}" bindtap="openCartDialog" data-type="close"></view>
   <view class="weui-half-screen-dialog cart-dialog">
     <view class="weui-half-screen-dialog__hd cart-hd" >
+      <view class="delete-cart" bindtap="deleteCart">清空</view>
        <view class="discount-txt">已点{{totalNum}}件商品,合计:¥{{totalPrice}}</view>
+      
       <view bindtap="openCartDialog" data-type="close">
         <view class=" weui-icon-btn_close">关闭</view>
         </view>

+ 8 - 0
pages/food/food.wxss

@@ -1149,6 +1149,14 @@ width: 100%;
 .cart-good-num{
   padding: 0 15rpx 0 15rpx;
 }
+.delete-cart{
+  background-color:#e64340;
+  color:#fff;
+  width: 80rpx;
+  text-align: center;
+  border-radius: 10rpx;
+  
+}
 
 
 

+ 4 - 5
pages/foodOrder/foodOrder.js

@@ -72,9 +72,8 @@ Page({
     })
     let self = this;
     let data = {
-      productIdAndNum : cartList,
-      storeId: self.data.shopId,
-      mobile: self.data.mobile
+      cartId  : self.data.cartId,
+      tableId  : self.data.tableId
     }
     const rs = await orderApi.createFoodOrder(data)
     let orderId = rs.orderId;
@@ -86,13 +85,13 @@ Page({
       paySign: rs.paySign,
       success (res) {
         setTimeout(()=>{
-          wx.navigateTo({
+          wx.reLaunch({
             url: '../order/order?id=' + orderId,
           })
         },2000) 
       },
       fail (res) { 
-        wx.navigateTo({
+        wx.reLaunch({
           url: '../order/order?id=' + orderId,
         })
       }

+ 5 - 3
pages/foodOrder/foodOrder.wxss

@@ -205,12 +205,13 @@ margin-left: 1%;
  .order-info-ft{
   height: 100rpx;
   background-color: #404040;
-  width: 96%;
+  width: 100%;
   bottom: 0rpx;
   position: fixed;
   display: inline-flex;
   align-items: center;
-  margin-left: 2%;
+  padding-left:10rpx;
+  /* margin-left: 2%; */
   }
 .good-money {
   font-weight: bold;
@@ -236,11 +237,12 @@ margin-left: 1%;
 
  .pay {
     width: 200rpx!important;
-    margin-right: 15rpx!important;
+    margin-right: 30rpx!important;
     float:right!important;
     background-color: #d81e06!important;
     justify-content: center!important;
     align-items: center!important;
     color:#fff!important;
     border-radius: 10rpx!important;
+    font-size:30rpx!important;
  }