购物车修改排序删除

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript" src="anglular/angular.js" ></script>
        <script>
            var app=angular.module("myApp",[]);
            app.controller("myCtrl",function($scope){
                $scope.phone=[
                {id:80,name:"iphone",price:5400},
                {id:290,name:"ipad",price:1420},
                {id:500,name:"ipad air",price:2340},
                {id:910,name:"imac",price:15400},
                {id:1200,name:"ipad mini",price:2200}
                ];
            $scope.flag="";
            $scope.line="id";
            $scope.product=function(line){
                $scope.line=line;
                if($scope.flag==""){
                    $scope.flag="-";
                }else{
                    $scope.flag="";
                }
            }

            $scope.xz="请选择";
            $scope.ifShow=function(price){
                if($scope.xz=="请选择"){
                    return true;
                }else{
                     var arr=$scope.xz.split("-");
                     var xiao=arr[0];
                     var da=arr[1];
                     if(price<xiao||price>da){

                        return false;
                     }else{
                        return true;
                     }
                }
            }

            $scope.erxz;
            $scope.xzer=function(){
                if($scope.erxz=="id"){
                    $scope.flag="";
                    $scope.line="id";
                }else
                if($scope.erxz=="-id"){
                    $scope.flag="-";
                    $scope.line="id";
                }else 
                if($scope.erxz=="price"){
                    $scope.flag="";
                    $scope.line="price";
                }else 
                if($scope.erxz=="-price"){
                    $scope.flag="-";
                    $scope.line="price";
                }
            }

            $scope.dxsc=function(delname){
            for(index in $scope.phone){
                if(delname==$scope.phone[index].name){
                    $scope.phone.splice(index,1);
                }else{

                }
            }
            }

            $scope.xg=function(price){
                for(index in $scope.phone){
                    if(price==$scope.phone[index].price){
                        var result=parseInt(window.prompt("请输入要修改的金额",price));

                        if(result<0){
                            alert("输入有误,请重新修改");

                    }else{
                        if(window.confirm("确定要将"+$scope.phone[index].name+"的价格更改为"+result+"么?")){
                            $scope.phone[index].price=result;
                        };
                    }
                }else{

            }
                }
            }   

            $scope.quanxuan=false;
            $scope.allfun=function(){
                if($scope.quanxuan){
                    for(index in $scope.phone){
                        $scope.phone[index].state=true;
                    }
                }else{
                    for(index in $scope.phone){
                        $scope.phone[index].state=false;
                    }
                }
            }

            $scope.xuanze=function(){
                var flag=false;
                for(index in $scope.phone){
                    if(!$scope.phone[index].state){
                        flag=true;
                    }
                }
                if(flag){
                    $scope.quanxuan=false;
                }else{
                    $scope.quanxuan=true;
                }
            }
                $scope.del=function(){
                    var is=[];
                    for(index in $scope.phone){
                        if($scope.phone[index].state){
                            is.push($scope.phone[index]);
                        }
                    }

                    for(index in is){
                        var name=is[index].name;
                for(index2 in $scope.phone){

                    if(name==$scope.phone[index2].name){
                        $scope.phone.splice(index2,1);
                    }
                }
                }
                }

            });
        </script>
    </head>
    <body ng-app="myApp" ng-controller="myCtrl">
        <center>
            <input type="text" placeholder="产品名称" ng-model="search"/>产品价格
            <select ng-model="xz">
                <option>请选择</option>
                <option>1000-2000</option>
                <option>2000-3000</option>
                <option>3000-4000</option>
                <option>4000-5000</option>
                <option>5000-6000</option>
                <option>6000-无穷大</option>

            </select>
            <select ng-model="erxz" ng-change="xzer()">
                <option value="">排序方式</option>
                <option value="id">id正序</option>
                <option value="-id">id逆序</option>
                <option value="price">价格正序</option>
                <option value="-price">价格逆序</option>

            </select>
            <button ng-click="del()">批量删除</button><br /><br />
            <table border="1px solid #000" cellpadding="10" cellspacing="0">
                <tr>
                    <td> <input type="checkbox" ng-model="quanxuan" ng-click="allfun()" ></td>
                    <td ng-click="product('id')">产品编号</td>
                    <td ng-click="product('name')">产品名称</td>
                    <td ng-click="product('price')">产品价格</td>
                    <td>操作</td>
                </tr>
                <tr ng-repeat="sz in phone | filter:{'name':search} | orderBy:(flag+line)" ng-if="ifShow(sz.price)">
                    <td><input type="checkbox"ng-model="sz.state" ng-click="xuanze()"></td>
                    <td>{{sz.id}}</td>
                    <td>{{sz.name}}</td>
                    <td>{{sz.price}}</td>
                    <td><button ng-click="dxsc(sz.name)"> 删除</button><button ng-click="xg(sz.price)">修改</button></td>
                </tr>
            </table>
        </center>
    </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值