简单的购物车实现 +多选框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="angular1.4.6.min.js"></script>
    <script src="angular-route.js"></script>
    <style>
        *{
            margin: 0 auto;
            padding: 0;
        }
        .head{
            width: 100%;
            height: 200px;
            background-color: cadetblue;
            font-size: 50px;
            text-align: center;
            line-height: 200px;
        }
        li{
            list-style-type: none;
            font-size: 20px;
            margin-top: 50px;
            text-align: center;
        }
        a{
            text-decoration: none;
        }
        table{
            border-collapse: collapse;
            margin-top: 20px;
        }
        input{
            margin-top: 10px;
        }
        th{
            border: 1px solid black;
            padding: 30px;
        }
        td{
            border: 1px solid black;
            padding: 30px;
        }
        .pi{
            border: 1px solid red;
            background: red;
            color: white;
        }
        .shan{
            background: orange;
            border: 1px solid orange;
            color: white;
        }
        .top{
            color: red;
        }
    </style>
    <script>
        var myApp=angular.module("myApp",["ngRoute"]);

        myApp.controller("newsCtrl",function ($scope) {
            $scope.items=[
                {bianhao:1234,name:"ipad",price:3400,kucun:10,check:false},
                {bianhao:1244,name:"aphone",price:6400,kucun:100,check:false},
                {bianhao:1334,name:"mypad",price:4400,kucun:20,check:false},
                {bianhao:8234,name:"zpad",price:8400,kucun:130,check:false},
            ]
            /*排序*/
            $scope.orderName="bianhao";
            $scope.order=false;
            $scope.paixu=function (column) {
                if($scope.orderName==column)
                {
                    $scope.order=!$scope.order;
                }else{
                    $scope.order=false;
                }
                $scope.orderName=column;
            };
            $scope.getClass=function (column) {
                if($scope.orderName==column)
                {
                    return "top"
                }
            }
            $scope.chk=false;
            $scope.xuanz=false;
            $scope.check=function (val) {
                if (val){
                    $scope.xuanz=true;
                }else{
                    $scope.xuanz=false;
                }
            }
            $scope.checkD=false;
            $scope.xuan1=[];
            $scope.xuan=function (xuan1,bianhao) {
                console.log(bianhao);
                $scope.checkD=xuan1;
                if (xuan1){
                    $scope.xuan1.push(bianhao);
                }
            }
            $scope.del=function () {
                //判断是否确认删除
                if($scope.xuanz||$scope.checkD){
                    var b=confirm("确认删除");
                    if (b){
                        //删除所有商品信息
                        if($scope.chk){
                            $scope.items.splice(0,$scope.items.length);
                            //让商品信息管理页面为空白页面
                        }else{
                            for(var i=$scope.xuan1.length-1;i>=0;i--){
                                console.log($scope.xuan1[i]);
                                for(var j=0;j<$scope.items.length;j++){
                                    console.log($scope.items[j].bianhao==$scope.xuan1[i]);
                                    if($scope.items[j].bianhao==$scope.xuan1[i]){
                                        $scope.items.splice(j,1);
                                    }
                                }

                            }
                        }
                    }
                }else{
                    alert("先进行选中要删除的商品信息");
                }
            }

            $scope.shanchu=function (index) {/*删除单个*/
                if(confirm("确定删除吗?"))
                {
                    $scope.items.splice(index,1);
                }
            }
        });

    </script>

</head>
<body ng-app="myApp" ng-controller="newsCtrl">
<div style="margin-left: 30px">
    <input type="text" placeholder="输入关键字.." ng-model="search">
    <button class="pi" ng-click="del()">批量删除</button>
    <table>
        <thead>
        <tr>
            <th><input type="checkbox" ng-model="chk" ng-click="check(chk)"></th>
            <th ng-click="paixu('bianhao')" ng-class="getClass('bianhao')">商品编号</th>
            <th ng-click="paixu('name')" ng-class="getClass('name')">商品名称</th>
            <th ng-click="paixu('price')" ng-class="getClass('price')">商品价格</th>
            <th ng-click="paixu('kucun')" ng-class="getClass('kucun')">商品库存</th>
            <th>数据操作</th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="item in items|filter:search|orderBy:orderName:order">
            <td><input type="checkbox" ng-model="xuanz" ng-click="xuan(xuanz,item.bianhao)"></td>
            <td>{{item.bianhao}}</td>
            <td>{{item.name}}</td>
            <td>{{item.price|currency:"¥:"}}</td>
            <td>{{item.kucun}}</td>
            <td><button class="shan" ng-click="shanchu($index)">删除</button></td>
        </tr>
        </tbody>
    </table>
</div>


</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现uniapp多选框购物车卡片式,可以按照以下步骤进行操作: 1.在购物车页面中,使用u-checkbox组件实现多选框功能。可以使用v-model绑定选中状态,使用@change监听选中状态的变化。 2.使用u-card组件实现商品卡片的展示。可以在卡片中展示商品图片、名称、价格等信息。 3.在卡片中使用u-number-box组件实现商品数量的选择。可以使用v-model绑定商品数量,使用@change监听数量的变化。 4.在底部使用u-tab-bar组件实现结算功能。可以在tab-bar中展示已选商品数量和总价,并使用u-button组件实现结算按钮。 以下是示例代码: ```html <template> <div> <div v-for="(item, index) in goodsList" :key="index"> <u-checkbox v-model="item.checked" @change="onCheckedChange(index)"></u-checkbox> <u-card> <img :src="item.imgUrl" /> <div>{{ item.name }}</div> <div>{{ item.price }}</div> <u-number-box v-model="item.num" @change="onNumChange(index)"></u-number-box> </u-card> </div> <u-tab-bar> <div slot="center">已选{{ selectedNum }}件商品,共{{ totalPrice }}元</div> <u-button slot="right" @click="onPayClick">结算</u-button> </u-tab-bar> </div> </template> <script> export default { data() { return { goodsList: [ { imgUrl: 'xxx', name: '商品1', price: 10, num: 1, checked: false }, { imgUrl: 'xxx', name: '商品2', price: 20, num: 2, checked: false } ] } }, computed: { selectedNum() { return this.goodsList.filter(item => item.checked).length }, totalPrice() { return this.goodsList.reduce((total, item) => { if (item.checked) { return total + item.price * item.num } else { return total } }, 0) } }, methods: { onCheckedChange(index) { this.goodsList[index].checked = !this.goodsList[index].checked }, onNumChange(index) { // do something }, onPayClick() { // do something } } } </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值