总价 删除

<body ng-app="myapp" ng-controller="mycon">
<div class="d1">
<h1>我的购物车详情</h1>
<input type="text" placeholder="根据名称查询" id="sname" ng-model="sname"/>
<table border="1px" cellpadding="0px" cellspacing="0px">
<thead>
<tr>
<td>商品编号<button class="btn1" ng-click="orderid()"></button></td>
<td>商品名称</td>
<td>商品数量</td>
<td>商品单价</td>
<td>价格小计<button class="btn1" ng-click="orderxiaoji()"></button></td>
<td>操作</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in shops|filter:sname|orderBy:ob">
<td>{{x.gid}}</td>
<td>{{x.gname}}</td>
<td><input type="number" ng-model="x.gnum" id="shu"/></td>
<td>{{x.gprice}}</td>
<td>{{x.gnum*x.gprice}}</td>
<td><button class="del" ng-click="del(x.gname)">删除</button></td>

</tr>
</tbody>
</table>
<div class="d2">
<span>商品总数:{{getznum()}}</span>
<span>商品总价:{{getzj()}}</span>
<button class="del" ng-click="alldel()">清空购物车</button>
</div>
</div>
<script type="text/javascript">
var app = angular.module("myapp",[]);
app.controller("mycon",function($scope,$http){
/*$http({
method:"GET",
url:"http://result.eolinker.com/TRFqLf402814d04c74641c1f3895afde6c8c9af19a2297b?uri=result"
}).then(function success(obj){
$scope.shops = obj.data;
});*/
$scope.shops=[{ gid:1001, gname:"手机", gnum: 3,gprice: 1000, gcount: 3000 }, 
{ gid: 1002, gname: "电脑", gnum: 3, gprice: 2000, gcount: 6000 },
{ gid: 1003, gname: "电视", gnum: 6, gprice: 500, gcount: 3000 }];
//alert($scope.shops.length);
$scope.getznum=function(){
var zongshu=0;
for (var i = 0; i < $scope.shops.length; i++) {
//alert($scope.shops[i].gnum);
if($scope.shops[i].gnum==0){
var shanchu= confirm("确定要删除数据吗");
if(shanchu){
$scope.shops.splice(i,1);
break;
}else{
alert("点击了取消");
break;
}

}else{
zongshu = zongshu + $scope.shops[i].gnum;
}


}

return zongshu;
}

$scope.getzj=function(){
var total=0;
for (var i = 0; i < $scope.shops.length; i++) {
total=total+($scope.shops[i].gnum*$scope.shops[i].gprice);
}
return total;
}
$scope.ob="";
$scope.isclick=true;
$scope.orderid=function(){
if($scope.isclick){
$scope.ob="gid";
$scope.isclick=false;
}else{
$scope.ob="-gid";
$scope.isclick=true;
}
}

$scope.orderxiaoji=function(){
if($scope.isclick){
$scope.ob="-gcount";
$scope.isclick=false;
}else{
$scope.ob="gcount";
$scope.isclick=true;
}
}

//删除
$scope.del=function(name){
for (var i = 0; i < $scope.shops.length; i++) {
if($scope.shops[i].gname==name){
$scope.shops.splice(i,1);
break;
}

}
}

$scope.alldel=function(){
$scope.shops=[];
}
});
</script>
</body>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值