Skip to content

Commit fae16dc

Browse files
authored
Merge pull request idcf-boat-house#236 from IDCF-BoatHouse-Team2/Jajuar-IssueId-技术债添加到购物车后界面无法直接进行下单处理
Jajuar issue 207 技术债添加到购物车后界面无法直接进行下单处理
2 parents 9466db5 + df365f5 commit fae16dc

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

client/web/src/App.vue

+50-13
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
<h5 class="font-weight-bold">
104104
合计: <span class="text-primary">¥{{totalPrice}}</span>
105105
</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>
107108
</div>
108109
</div>
109110
</div>
@@ -455,9 +456,13 @@ export default {
455456
logout: function () {
456457
this.username = '';
457458
this.signusername = '';
459+
this.userId = '';
458460
this.setCookie("session", "", 365);
459461
this.setCookie("username", "", 365);
462+
this.setCookie("userId", "", 365);
460463
this.isLoging = false;
464+
this.shopCartList=[];
465+
this.GetShopCartInfo();
461466
},
462467
463468
GetFoodList: function () {
@@ -483,18 +488,21 @@ export default {
483488
var total=0;
484489
var totalNum=0;
485490
_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+
// }
498506
})
499507
console.log("总价格:"+total)
500508
_this.totalPrice=total;
@@ -530,7 +538,36 @@ export default {
530538
_this.GetShopCartInfo();
531539
}
532540
})
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+
})
533568
}
569+
570+
534571
}
535572
536573
}

client/web/src/components/Food.vue

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export default {
7676
AddFoodToCart: function (e) {
7777
let _this = this
7878
const userId = _this.$parent.getCookie("userId");
79+
if(userId === '' || userId === undefined){
80+
$("#login-modal").modal('show');
81+
return;
82+
}
7983
let postData = {
8084
userid: userId,
8185
foodid: parseInt(e.Id),

product-service/api/src/main/java/com/idcf/boathouse/services/ShopCartService.java

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public List<Map<String, Object>> listFoodsInCart(Integer userId){
7878
if(userId != null){
7979
sql.append(" where userId = ");
8080
sql.append(userId.toString());
81+
}else{
82+
sql.append(" where userId = -1");
8183
}
8284
return BaseDao.exec(sql.toString());
8385
}

0 commit comments

Comments
 (0)