//添加商品到购物车
this.addGoodsToCartList=function(itemId,num){
}
//添加商品到购物车
$scope.addGoodsToCartList=function(itemId,num){ cartService.addGoodsToCartList(itemId,num).success(
function(response){ if(response.success){
$scope.findCartList();//刷新列表
}else{
alert(response.message);//弹出错误提示
}
}
);
}
< li class="yui3-u-1-8">
<a href="javascript:void(0)" ng-click="addGoodsToCartList(orderItem.itemId,-1)" class="increment mins">-</a>
<input autocomplete="off" type="text" ng-model="orderItem.num" minnum="1" class="itxt" />
<a href="javascript:void(0)" ng-click="addGoodsToCartList(orderItem.itemId,1)" class="increment plus">+</a> </li>
<a href="#none" ng-click="addGoodsToCartList(orderItem.itemId,-orderItem.num)" >删除
</a><br />
//求合计
this.sum=function(cartList){
var totalValue={totalNum:0, totalMoney:0.00 };//合计实体
for(var i=0;i<cartList.length;i++){
var cart=cartList;
for(var j=0;j<cart.orderItemList.length;j++){
var orderItem=cart.orderItemList[j];//购物车明细 totalValue.totalNum+=orderItem.num;
totalValue.totalMoney+= orderItem.totalFee;
}
}
return totalValue;
}
//查询购物车列表
$scope.findCartList=function(){ cartService.findCartList().success(
function(response){
$scope.cartList=response;
$scope.totalValue=cartService.sum($scope.cartList);//求合计数
}
);
}
<div class="chosed">已选择<span>{{totalValue.totalNum}}</span>件商品</div>
<div class="sumprice">
<span><em>总价(不含运费) :
</em><i class="summoney">¥{{totalValue.totalMoney}}</i></span>
</div>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |