103
103
<h5 class =" font-weight-bold" >
104
104
合计: <span class =" text-primary" >¥{{totalPrice}}</span >
105
105
</h5 >
106
- <a href =" #" tabindex =" -1" class =" btn btn-outline-primary btn-sm btn-rounded mx-2" v-on:click =" ClearShopCart()" >清理购物车</a > <a href =" #" tabindex =" -1" class =" btn btn-primary btn-sm btn-rounded mx-2" >去结算</a >
106
+ <a href =" #" tabindex =" -1" class =" btn btn-outline-primary btn-sm btn-rounded mx-2" v-on:click =" ClearShopCart()" >清理购物车</a >
107
+ <a href =" #" tabindex =" -1" class =" btn btn-primary btn-sm btn-rounded mx-2" v-on:click =" Order()" >去结算</a >
107
108
</div >
108
109
</div >
109
110
</div >
@@ -455,9 +456,13 @@ export default {
455
456
logout : function () {
456
457
this .username = ' ' ;
457
458
this .signusername = ' ' ;
459
+ this .userId = ' ' ;
458
460
this .setCookie (" session" , " " , 365 );
459
461
this .setCookie (" username" , " " , 365 );
462
+ this .setCookie (" userId" , " " , 365 );
460
463
this .isLoging = false ;
464
+ this .shopCartList = [];
465
+ this .GetShopCartInfo ();
461
466
},
462
467
463
468
GetFoodList : function () {
@@ -483,18 +488,21 @@ export default {
483
488
var total= 0 ;
484
489
var totalNum= 0 ;
485
490
_this .returnList .map (item => {
486
- let FoodItem = _this .foodList .find (i => i .Id === item .foodid )
487
- // if(typeof foo !== 'undefined'){
488
- var shopCartListItem = {
489
- shopCartItem: item,
490
- foodName: FoodItem .Name ,
491
- price: FoodItem .Price
492
- };
493
- // alert(JSON.stringify(shopCartListItem));
494
- _this .shopCartList .push (shopCartListItem);
495
- total+= (item .num * FoodItem .Price );
496
- totalNum+= item .num ;
497
- // }
491
+ let FoodItem = _this .foodList .find (i => i .Id === item .foodid )
492
+ // if(typeof foo !== 'undefined'){
493
+ var shopCartListItem = {
494
+ shopCartItem: item,
495
+ foodName: FoodItem .Name ,
496
+ price: FoodItem .Price ,
497
+ foodId: item .foodid ,
498
+ foodNum: item .num ,
499
+ foodPrice: FoodItem .Price
500
+ };
501
+ // alert(JSON.stringify(shopCartListItem));
502
+ _this .shopCartList .push (shopCartListItem);
503
+ total+= (item .num * FoodItem .Price );
504
+ totalNum+= item .num ;
505
+ // }
498
506
})
499
507
console .log (" 总价格:" + total)
500
508
_this .totalPrice = total;
@@ -530,7 +538,36 @@ export default {
530
538
_this .GetShopCartInfo ();
531
539
}
532
540
})
541
+ },
542
+
543
+ Order : function (){
544
+ let _this = this ;
545
+ const userId = this .getCookie (" userId" );
546
+ if (userId === ' ' || userId === undefined ){
547
+ $ (" #login-modal" ).modal (' show' );
548
+ return ;
549
+ }
550
+ this .axios
551
+ .post (' /api/orders/create' ,{
552
+ additionalAmount: _this .totalPrice ,
553
+ itemsList: _this .shopCartList ,
554
+ note: " " ,
555
+ userName: _this .username ,
556
+ userId: userId
557
+ })
558
+ .then (function (result ) {
559
+ // alert(JSON.stringify(result));
560
+ console .log (result);
561
+ if (result .status === 200 ) {
562
+ _this .shopCartList = [];
563
+ _this .DeleteFoodFromShopCart ();
564
+ _this .GetShopCartInfo ();
565
+ _this .$router .push (' /orders' );
566
+ }
567
+ })
533
568
}
569
+
570
+
534
571
}
535
572
536
573
}
0 commit comments