Vue购物车

第五次记录 新人

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            background: #666666;
        }
        .box{
            width: 426px;
            height: 374px;
            margin: 100px auto;
            background-color: #ffffff;
            box-shadow:10px 10px 5px #888888;
            position: relative;
        }
        .box .box_item{
            width:426px ;
            height: 100px;
            box-shadow: 3px 3px 3px #dddddd;
        }
        .box .box_item .box_left{
            width: 50px;
            height: 100px;
            line-height: 100px;
            float: left;
            text-align: center;
        }
        .box  .box_item .box_left>input{
            width: 20px;
            height: 20px;
            /*border-radius: 50%;*/
        }
        .box .box_item  .box_right{
            width: 375px;
            height: 100px;
            float: left;
            position: relative;
        }
        .box .box_item  .box_right>img{
            width: 67px;
            height: 67px;
            float: left;
            background-color: #666666;
            margin-top: 20px;
        }
        .box .box_item  .box_right>h3{
            width: 300px;
            float: left;
            font-size: 17px;
            margin-top: 20px;
            margin-left: 5px;
        }
        .box .box_item .box_right>span:nth-child(3){
            color: gray;
            font-size: 13px;
            display: inline-block;
            margin-left: 5px;
        }
        .box .box_item .box_right>span:nth-child(5){
            color: #e4393e;
            font-size: 16px;
            float: left;
            margin-left: 5px;
        }
        .box_right_Calc{
            position: absolute;
            bottom: 10px;
            right: 20px;
            border: 1px solid #9A9A9A;
            line-height: 30px;
            text-align: center;
            border-radius: 5px;
        }
        .box_right_Calc .calcDown{
            display: inline-block;
            width: 30px;
            height: 30px;
            cursor: pointer;
        }
        .box_right_Calc .calcNum{
            width: 28px;
            height: 28px;
            border: none;
            text-align: center;
            border-left: 1px solid #9A9A9A;
            border-right: 1px solid #9A9A9A;
            outline: none;
        }
        .box_right_Calc .calcUp{
            display: inline-block;
            width: 30px;
            height: 30px;
            cursor: pointer;
        }
        .box_footer{
            position: absolute;
            width:426px;
            height: 69px;
            background-color: #ffffff;
            bottom: 0
        }
        .box_footer_left{
            width: 69px;
            line-height: 69px;
            text-align: center;
            float: left;
            position: relative;
        }
        .box_footer_left>input{
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 20px;
            height: 20px;
            left: 10px;
        }
        .box_footer_left>span:nth-child(2){
            float: right;
            display: block;
        }
        .box_footer_prices{
            margin-left: 20px;
            float: left;
            line-height: 30px;
        }
       .box_footer_Computations{
           width: 135px;
           height: 69px;
           background-color: #f5a625;
           float: right;
           line-height: 69px;
           text-align: center;
       }
        .box_footer_Computations>span{
            color: white;
        }
    </style>

</head>
<body>
    <div id="app">
        <div class="box">
            <div class="box_item" v-for="(item, index) in arr">
                <div class="box_left">
                    <input type="checkbox" v-model="item.isTrue" @change="oneChange" />
                </div>
                <div class="box_right">
                    <img :src='item.thumbnail' height="130" width="129"/>
                    <h3>{{item.name}}</h3>
                    <span>规格:50g</span><br/>
                    <span>¥{{item.reduct_price}}</span>
                    <div class="box_right_Calc">
                        <span  class="calcDown" @click="calcDown(index)">-</span>
                        <input class="calcNum" v-model.number="item.num" @change="onWrite"/>
                        <span  class="calcUp" @click="calcUp(index)" >+</span>
                    </div>
                </div>
            </div>


            <div class="box_footer">
                <div class="box_footer_left">
                    <input type="checkbox" @change="allChecked" v-model="all"/>
                    <span>全选</span>
                </div>
                <div class="box_footer_prices">
                    <span>总计:¥{{totalPrices}}</span><br/>
                    <span>不含运费,已优惠¥0.00</span>
                </div>
                <div class="box_footer_Computations">
                    <span>去结算({{total}}件)</span>
                </div>
            </div>
        </div>
    </div>
</body>
    <script src="../js/vue.js"></script>
    <script type="text/javascript">
        var app=new Vue({
            el:'#app',
            data:{
                arr:[
                    {
                        "id": "00001",
                        "name": "施华蔻伊采染发膏60ml",
                        "brand": "施华蔻",
                        "original_price": "100",
                        "inventory": "1062",
                        "thumbnail": "https:\/\/fjlyl.xyz\/assets\/hairDye\/products (1).jpg",
                        "product_id": "00021",
                        "time_start": "2018-12-17 06:00:00",
                        "time_end": "2018-12-17 07:00:00",
                        "total": "727",
                        "reduct_price": "69",
                        "stock": "113",
                        "num":3,
                        "isTrue":false
                    }, {
                        "id": "00002",
                        "name": "施华蔻伊采染发膏100ml",
                        "brand": "施华蔻",
                        "original_price": "264",
                        "inventory": "2615",
                        "thumbnail": "https:\/\/fjlyl.xyz\/assets\/hairDye\/products (2).jpg",
                        "product_id": "00022",
                        "time_start": "2018-12-17 21:00:00",
                        "time_end": "2018-12-17 23:00:00",
                        "total": "559",
                        "reduct_price": "241",
                        "stock": "320",
                        "num":2,
                        "isTrue":false
                    }, {
                        "id": "00003",
                        "name": "施华蔻伊采染发膏200ml",
                        "brand": "施华蔻",
                        "original_price": "97",
                        "inventory": "3001",
                        "thumbnail": "https:\/\/fjlyl.xyz\/assets\/hairDye\/products (3).jpg",
                        "product_id": "00023",
                        "time_start": "2018-12-17 07:00:00",
                        "time_end": "2018-12-17 08:00:00",
                        "total": "2393",
                        "reduct_price": "35",
                        "stock": "1054",
                        "num":2,
                        "isTrue":false
                    }
                ],
                all:false
            },
            methods:{
                //手动输入
                onWrite:function(event){

                },
                //单选
                oneChange:function(){
                    this.all=true;
                    for (var i=0;i<this.arr.length;i++){
                        if (!this.arr[i].isTrue){
                            this.all = false;
                            break;
                        }
                    }
                },
                //全选
                allChecked:function () {
                    for (var i=0;i<this.arr.length;i++){
                        this.arr[i].isTrue =this.all;
                    }
                },
                //减
                calcDown:function (index) {
                    if (this.arr[index].num>0){
                        this.arr[index].num-=1;
                    }
                },
                //加
                calcUp:function (index) {
                    this.arr[index].num +=1;
                }
            },
            computed:{
                //总计
                totalPrices:function () {
                    var num=0;
                    for (var i=0;i<this.arr.length;i++){
                        if (this.arr[i].isTrue){
                            num += parseInt(this.arr[i].reduct_price)*parseInt(this.arr[i].num)
                        }
                    }
                    return num;
                },
                //件数
                total:function () {
                    var number=0;
                    for (var i=0;i<this.arr.length;i++){
                        if (this.arr[i].isTrue){
                            number += this.arr[i].num
                        }
                    }
                    return number;
                }
            }
        })
    </script>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值