购物车 数量,总价,删除

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="angular-1.3.0.js"></script>
    <script src="jquery-1.11.0.js"></script>
    <script>
        var myapp= angular.module("myapp",[]);

        var data=[
            {
                done:false,
                id:"1234",
                name:"ipad",
                price:3400,
                quantity:1,

            },
            {
                done:false,
                id:1244,
                name:"iphone",
                price:6400,
                quantity:1

            },
            {
                done:false,
                id:1334,
                name:"mypad",
                price:4400,
                quantity:1,

            },
            {
                done:false,
                id:8234,
                name:"zpad",
                price:8400,
                quantity:1,

            }
        ]
        myapp.controller("myctrl",function ($scope) {
            $scope.data=data;

            //删除信息
            $scope.del=(function (hh) {
                var con=confirm("确定删除吗?");
                if(con==true){
                    for(var i=0;i<$scope.data.length;i++){
                        if($scope.data[i].name==hh)
                        {
                            $scope.data.splice(i,1);
                        }
                    }
                }
            });
            /*删除选中的*/
            $scope.delall=function () {
                var con=confirm("确定删除么?");
                if(con==true){
                    for(var i=0;i<$scope.data.length;i++)
                    {
                        if($scope.data[i].done==true)
                        {
                            $scope.data.splice(i,1);
                            i--;
                        }
                    }
                }else{

                }

            }

            /*全选*/
            $scope.checkAll=function () {
                for(var i=0;i<$scope.data.length;i++)
                {
                    if($scope.chec==true)
                    {
                        $scope.data[i].done=true;
                    }
                    else{
                        $scope.data[i].done=false;
                    }
                }
            }
            //减少数量
            $scope.reduce=function (index) {
                if($scope.data[index].quantity>1){
                    $scope.data[index].quantity--;
                }else{
                    $scope.del(data.name);
                }
            }
            //增加数量
            $scope.add = function(index){
                $scope.data[index].quantity++;
            }
            //所有商品总价
            $scope.totalQuantity=function () {

                var allprice = 0
                for(var i = 0 ; i <$scope.data.length;i++ ){
                    allprice += $scope.data[i].quantity * $scope.data[i].price;
                }
                return allprice;

            }
            //清空购物车
            $scope.qk = function(){

                if(confirm("您确定要清空购物车吗?")){

                    $scope.data=[];

                }
            }

        });


    </script>
</head>
<body ng-app="myapp" ng-controller="myctrl">

<div>
    <h3>商品库存信息管理</h3>
    <hr>
    <div style="background-color: #E8FBFF;height:25px">
    <input type="text" value="" placeholder="请输入关键字...." ng-model="search">
    <button type="button" style="margin-left: 1000px;color:#c3c3c3;background-color:red " ng-click="delall()">批量删除</button>
        <button type="button" style="color:#c3c3c3;background-color:red " ng-click="qk()">清空购物车</button>
    </div>
</div>

<div>
    <table  border="1" bordercolor="#c3c3c3" width="500" cellpadding="0" cellspacing="0" style="width:1350px;text-align: center">
        <tr>
            <td><input type="checkbox" ng-click="checkAll()" ng-model="chec"></td>
            <td >商品编号</td>
            <td >商品名称</td>
            <td >商品价格</td>
            <td >商品数量</td>
            <td >商品总价</td>
            <td >商品操作</td>

        </tr >
        <tr ng-repeat="item in data|filter:{'name':search}">
            <td><input type="checkbox" ng-model="item.done"></td>
            <td>{{item.id}}</td>
            <td>{{item.name}}</td>
            <td>{{item.price|currency:"¥"}}</td>
            <td>
                <button ng-click="reduce($index)" class="button">-</button>

                <input type="text" class="num" ng-model="item.quantity" ng-change="change($index)"/>

                <button ng-click="add($index)" class="button">+</button>

            </td>
            <td>{{item.price * item.quantity|currency:"¥"}}</td>
            <td>
                <button style="color: #E8FBFF;background-color: yellow" ng-click="del(item.name)">删除</button>
            </td>

        </tr>
        <tr>
            <td>
                <span>总价:</span>
                <span ng-bind="totalQuantity()"></span>
            </td>
        </tr>

    </table>

</div>



</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值