vue2.0中实现单选,全选,购物车加减计算等效果

<!doctype html>
<html class="no-js">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello Amaze UI</title>

<!-- Set render engine for 360 browser -->
<meta name="renderer" content="webkit">

<!-- No Baidu Siteapp-->
<meta http-equiv="Cache-Control" content="no-siteapp" />

<link rel="stylesheet" href="assets/css/amazeui.min.css">
<link rel="stylesheet" href="assets/css/app.css">
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>

<body class="bgcolor_five">
<div class="box" id="app">
<div class="am-g am-text-center bgcolor_white am-padding-vertical-xs border_bttom am-margin-bottom-sm">
<div class="am-u-sm-12 am-padding-left">
<span class="color_three marin_tfour">我的购物车</span>
<a href="" class="am-fr color_three am-text-sm">
</a>
</div>
</div>

<div class="comd">
<div class="am-g bgcolor_white">
<div class="am-u-sm-12 am-padding-left am-padding-vertical-sm border_bttom am-cf fincom">
<!--<input type="checkbox" name="" id="" value="" class="am-text-middle pcheck checkPall" />-->
<span class="am-text-sm color_six am-text-middle am-text-center">拉夏贝尔官方旗舰店</span>
<span class="am-fr am-text-sm color_six" v-on:click="compile" v-bind:class="{disnone:isactive}">编辑</span>
<span class="am-fr am-text-sm color_six disnone finish" v-on:click="close" v-bind:class="{disblack:isactive}">完成</span>
</div>
</div>

<div v-for="(item,index) in list">
<div class="am-g bgcolor_white border_bttom am-padding-bottom-sm goods am-padding-top-sm">
<div class="am-u-sm-6 am-padding-left">
<input type="checkbox" v-model="item.checked" @click="checkIsall" name="" id="" value="" class="am-text-middle check checkPall" />
<img src="img/clearbg.jpg" width="100px" />
</div>
<div class="am-u-sm-6 am-padding-0">
<div class="delblack disnone" v-bind:class="{disblack:isactive}">
<span class="am-cf inline_block am-text-center">
<span class="am-margin-top-lg inline_block span_wih am-fl border_left border_top border_bttom subtract" @click="subtract(index)">-</span>
<input type="" name="" id="" v-model="item.quantity" class="am-fl span_wih cart_ipt am-margin-top-lg am-text-center in_put" />
<span class="inline_block span_wih am-fl border_right border_top am-margin-top-lg border_bttom plus" @click="add(index)">+</span>
<span class="del am-text-sm am-padding-left-xs color_white cart_ipt inline_block lin_he bgcolor_bc">
<a href="javascript:" class="am-text-sm color_white" @click="remove(index)">删除</a>
</span>
</span>
</div>
<div class="delnone" v-bind:class="{disnone:isactive}">
<p class="am-text-sm am-margin-0 am-padding-top">{{item.name}}</p>
<span class="am-text-sm color_aaa">款式:{{item.color}}</span>
<span class="am-text-sm color_aaa am-padding-left-sm">尺码:{{item.size}}</span>
<p class="am-margin-0 am-cf">
<span class="am-text-lg color_six">¥<span class="price">{{item.price}}</span></span>
<del class="am-text-sm color_aaa">¥{{item.marprice}}</del>
<span class="am-text-sm am-padding-left-sm">X</span>
<span class="am-text-sm am-padding-left-xs numb">{{item.quantity}}</span>
</p>
</div>

</div>
</div>
</div>
<!--<div class="am-g bgcolor_white am-margin-bottom-sm">
<div class="am-u-sm-12 am-padding-left am-padding-vertical-sm">
<p class="am-margin-0">
<span class="am-text-sm">共 <span>1</span>件商品</span>
<span class="am-text-lg am-fr color_bc">¥<span class="aprice">195.50</span></span>
<span class="am-text-sm marin_tfour am-fr">总价:</span>
</p>
</div>
</div>-->
</div>
<!--<div class="comd">
<div class="am-g bgcolor_white">
<div class="am-u-sm-12 am-padding-left am-padding-vertical-sm border_bttom am-margin-bottom-sm am-cf fincom">
<input type="checkbox" name="" id="" value="" class="am-text-middle pcheck checkPall" />
<span class="am-text-sm color_six am-text-middle am-text-center">衣品天成官方旗舰店</span>
<span class="am-fr am-text-sm color_six" v-on:click="open" v-bind:class="{disnone:down}">编辑</span>
<span class="am-fr am-text-sm color_six disnone finish" v-on:click="updo" v-bind:class="{disblack:down}">完成</span>
</div>
</div>
<div class="am-g bgcolor_white border_bttom am-padding-bottom-sm goods">
<div class="am-u-sm-6 am-padding-left">
<input type="checkbox" name="" id="" value="" class="am-text-middle check checkPall" />
<img src="img/cart02.png" width="100px" />
</div>
<div class="am-u-sm-6 am-padding-0">
<div class="delblack disnone" v-bind:class="{disblack:down}">
<span class="am-cf inline_block am-text-center">
<span class="am-margin-top-lg inline_block span_wih am-fl border_left border_top border_bttom subtract">-</span>
<input type="" name="" id="" value="1" class="am-fl span_wih cart_ipt am-margin-top-lg am-text-center in_put" />
<span class="inline_block span_wih am-fl border_right border_top am-margin-top-lg border_bttom plus">+</span>
<span class="del am-text-sm am-padding-left-xs color_white cart_ipt inline_block lin_he bgcolor_bc">
<a href="javascript:" class="am-text-sm color_white">删除</a>
</span>
</span>
</div>
<div class="delnone" v-bind:class="{disnone:down}">
<p class="am-text-sm am-margin-0 am-padding-top am-text-truncate">长袖宽条纹针织毛衣女休闲打底衫</p>
<span class="am-text-sm color_aaa">款式:黄色</span>
<span class="am-text-sm color_aaa am-padding-left-sm">尺码:170</span>
<p class="am-margin-0 am-cf">
<span class="am-text-lg color_six">¥<span class="price">149.00</span></span>
<del class="am-text-sm color_aaa">¥399.00</del>
<span class="am-text-sm am-padding-left-sm">X </span>
<span class="am-text-sm am-padding-left-xs numb">1</span>
</p>
</div>
</div>
</div>
<div class="am-g bgcolor_white border_bttom am-padding-bottom-sm am-padding-top-sm goods">
<div class="am-u-sm-6 am-padding-left">
<input type="checkbox" name="" id="" value="" class="am-text-middle check checkPall" />
<img src="img/cart.png" width="100px" />
</div>
<div class="am-u-sm-6 am-padding-0">
<div class="delblack disnone" v-bind:class="{disblack:down}">
<span class="am-cf inline_block am-text-center">
<span class="am-margin-top-lg inline_block span_wih am-fl border_left border_top border_bttom subtract">-</span>
<input type="" name="" id="" value="1" class="am-fl span_wih cart_ipt am-margin-top-lg am-text-center in_put" />
<span class="inline_block span_wih am-fl border_right border_top am-margin-top-lg border_bttom plus">+</span>
<span class="del am-text-sm am-padding-left-xs color_white cart_ipt inline_block lin_he bgcolor_bc">
<a href="javascript:" class="am-text-sm color_white">删除</a>
</span>
</span>
</div>
<div class="delnone" v-bind:class="{disnone:down}">
<p class="am-text-sm am-margin-0 am-padding-top am-text-truncate">秋冬新款马海毛格子长款毛呢大衣</p>
<span class="am-text-sm color_aaa">款式:浅绿</span>
<span class="am-text-sm color_aaa am-padding-left-sm">尺码:170</span>
<p class="am-margin-0 am-cf">
<span class="am-text-lg color_six">¥<span class="price">699.00</span></span>
<del class="am-text-sm color_aaa">¥999.00</del>
<span class="am-text-sm am-padding-left-sm">X </span>
<span class="am-text-sm am-padding-left-xs numb">1</span>
</p>
</div>
</div>
</div>
<div class="am-g bgcolor_white am-margin-bottom-sm">
<div class="am-u-sm-12 am-padding-left am-padding-vertical-sm">
<p class="am-margin-0">
<span class="am-text-sm">共 <span>1</span>件商品</span>
<span class="am-text-lg am-fr color_bc">¥<span class="aprice">149.00</span></span>
<span class="am-text-sm marin_tfour am-fr">总价:</span>
</p>
</div>
</div>
</div>-->

<div class="am-g color_six am-text-center am-text-default bgcolor_white ma_bto">
<div class="am-u-sm-3 am-padding-top am-padding-right-0">
<input type="checkbox" v-on:click="checkAll" v-model="allChecked" name="" id="" value="" class="am-text-middle checkPall allcheck" id="" />
<!--<span class="am-fl inline_block circle_span circle_mspan active"></span>-->
<span class="am-text-sm am-fl">全选</span>
</div>
<div class="am-u-sm-6 am-text-right">
<p class="am-margin-0 am-padding-right-xs">总价:<span class="color_bc">¥<span class="allprice">{{total | formatePrice}}</span></span>
</p>
<p class="am-margin-0 am-padding-right-xs color_aaa am-text-xs">不含减满优惠,不含运费</p>
</div>
<div class="am-u-sm-3 bgcolor_bc am-padding-vertical-sm">
<a href="clearing.html" class="am-text-default color_white">提交订单</a>
</div>
</div>
</div>
<div class="bttom fixed pos_bttom">
<ul class="am-text-center am-cf bgcolor_white am-padding-vertical-xs">
<li>
<a href="index.html">
<img src="img/icon_index.png" width="21px" />
<p class="am-text-xs color_six am-margin-0">首页</p>
</a>
</li>
<li>
<a href="purchase.html">
<img src="img/icon_bag.png" width="21px" />
<p class="am-text-xs am-margin-0 color_six">伊人购</p>
</a>
</li>
<li>
<a href="attention.html">
<img src="img/icon_heart.png" width="24px" />
<p class="am-text-xs am-margin-0 color_six">关注</p>
</a>
</li>
<li>
<a href="cart.html">
<img src="img/icon_cartred.png" width="24px" />
<p class="am-text-xs am-margin-0 color_bc">购物车</p>
</a>
</li>
<li>
<a href="mg_center.html">
<img src="img/icon_my.png" width="21px" />
<p class="am-text-xs am-margin-0 color_six">我的</p>
</a>
</li>
</ul>
</div>
<!--[if (gte IE 9)|!(IE)]><!-->
<script src="assets/js/jquery.min.js"></script>
<!--<![endif]-->
<!--[if lte IE 8 ]>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->
<script src="assets/js/amazeui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(‘#accordion‘).on(‘open.collapse.amui‘, function(e) {
$(e.target).find(‘.am-panel-bd‘).fadeIn(3000)
}).on(‘close.collapse.amui‘, function(e) {
$(e.target).find(‘.am-panel-bd‘).fadeOut();
});
})
</script>
<script src="js/cart.js" type="text/javascript" charset="utf-8"></script>
<script type=" text/javascript ">
var app = new Vue({
el: ‘#app‘,
data: {
isactive: false,
allChecked: true,
total: 0.00,
down: false,
list: [
{ name: "2016冬装新款连衣裙", color: "黑色", quantity: 1, size: "M", price: "195.00", marprice: 399.00, marsize: 1, checked: true, lowest: false },
{ name: "2017冬装新款连衣裙", color: "黑色", quantity: 1, size: "M", price: "400.00", marprice: 499.00, marsize: 2, checked: true, lowest: false },
{
name: "2018冬装新款连衣裙",
color: "黑色",
quantity: 1,
size: "M",
price: "305.00",
marprice: 999.00,
marsize: 1,
checked: true,
lowest: false
}
]
},
filters: {
formatePrice: function(value) {
value = parseFloat(value);
return value.toFixed(3)
}
},
methods: {
compile: function() {
this.isactive = true;
},
close: function() {
this.isactive = false;
},
open: function() {
this.down = true;
},
updo: function() {
this.down = false;
}, //加减
add: function(i) {
this.list[i].quantity++;
this.sum();
},
subtract: function(k) {
var vm=this
if(this.list[k].quantity >1) {
this.list[k].quantity--;
} else {
if(confirm("你确定移除该商品?")) {
this.list.splice(k, 1)
this.list[k].quantity == 1;
}
}
this.sum();
},
//删除
remove: function(index) {
if(confirm("你确定移除该商品?")) {
this.list.splice(index, 1)
}
},
//单选
check: function(i) {
this.sum();
this.checkIsall();
},
checkIsall: function() {
this.sum();
var t = 0;
for(var i = 0; i < this.list.length; i++) {
if(this.list[i].checked == true) {
t++;
}
}
if(t == this.list.length) {
this.allChecked = true
} else {
this.allChecked = false
}
},
//全选
checkAll: function() {
//this.allChecked=!this.allChecked 如果是仿的复选框需要写 不是局部用写
for(var i = 0; i < this.list.length; i++) {
this.list[i].checked = this.allChecked;
}
this.sum();
},
sum: function() {
this.total = 0;
for(var i = 0; i < this.list.length; i++) {
if(this.list[i].checked) {
this.total += this.list[i].price * this.list[i].quantity
}
}
}
},
created: function() {
this.sum();
}
//计算
})
</script>
</body>

</html>

时间: 2024-11-06 09:19:42

vue2.0中实现单选,全选,购物车加减计算等效果的相关文章

checkbox的单选全选,反选,计算价格,删除

activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" a

Vue2.0+Node.js+MongoDB 全栈打造商城系统

第1章 课程介绍简单回顾前端近几年的框架模式,了解不同时期下的框架特点.其次介绍Vue框架的背景和核心思想,以及同其它MV*框架的对比.1-1 课程-导学1-2 前端框架回顾1-3 vue概况以及核心思想1-4 vue框架优缺点对比 第2章 Vue基础从0到1,如何搭建一个简单的Vue项目:本章节主要讲解Node和Npm环境的搭建,其次介绍vue-cli脚手架的使用,以及通过详细拆解介绍脚手架生成的配置文件信息,最后给大家介绍了Vue涵盖的基础语法.2-1 nodejs和npm的安装和环境搭建2

JS中表格的全选和删除要注意的问题

在项目开发中,由于刚刚开始做项目,我对js还不是很精通,所以在用js对表格的全选和删除中遇到了不少问题,后来通过查找资料解决了,之后总结了一下关于js表格的全选和删除出现的一些问题,希望能帮助到大家. 以下是我自己做的一个小例子,用来更简单明了的说明js全选和删除. 一.全选的说明:当选中全选的checkbox时,下面1-5都会选中,没有选中时1-5都不会选中,这个实现不难,步骤如下: 1.获取全选框的选中状态, 2.for循环设置所有的单选框的选中状态 主要代码: //1.获取全选按钮 var

vue2.0中router-link详解

vue2.0中router-link详解:https://blog.csdn.net/lhjuejiang/article/details/81082090 在vue2.0中,原来的v-link指令已经被<router-link>组件替代了 <router-link>组件支持用户在具有路由功能的应用中点击导航.通过to属性指定目标地址,默认渲染为带有正确连接的<a>标签,可以通过配置tag属性生成别的标签.另外,当目标路由成功激活时,链接元素自动设置一个表示激活的css

页面中公用的全选按钮,单选按钮组件的编写

相应的js代码为: var checkAll = $("[data-checkbox-checkall]"); //遍历处理每一组的情况 checkAll.each(function(){ var groupName = $(this).attr("data-checkbox-group"); startCheck(groupName); }); function startCheck(groupName){ //所有的该组元素 var allCheckbox =

关于Winform下DataGridView中实现checkbox全选反选、同步列表项的处理

近期接手一个winform 项目,虽然之前有.net 的经验,但是对一些控件的用法还不是很熟悉. 这段时间将会记录一些在工作中遇到的坎坷以及对应的解决办法,写出来与大家分享并希望大神提出更好解决方法来促进进步. 我也会尽可能把我查找到资料的出处引出来,以此来感恩对我提供帮助的人们. 正题如下 一.关于Winform下DataGridView中实现checkbox全选反选.同步列表项的处理 1.checkbox的添加:在设计页面选择编辑列在新添加的列中注意如下几个属性: SortMode = No

Vue2.0+Node.js+MongoDB全栈打造商城系统

第1章 课程介绍   1-1 课程-导学   1-2 前端框架回顾   1-3 vue概况以及核心思想   1-4 vue框架优缺点对比第2章 Vue基础   2-1 nodejs和npm的安装和环境搭建   2-2 vue环境搭建以及vue-cli使用   2-3 vue配置(上)   2-4 vue配置(下)   2-5 vue基础语法第3章 Vue-router   3-1 路由基础介绍   3-2 动态路由匹配   3-3 嵌套路由   3-4 编程式路由   3-5 命名路由和命名视图

vue2.0 中#$emit,$on的使用详解

vue1.0中 vm.$dispatch 和 vm.$broadcast 被弃用,改用$emit,$on 1. vm.$on( event, callback ) 监听当前实例上的自定义事件.事件可以由vm.$emit触发.回调函数会接收所有传入事件触发函数的额外参数. 1 vm.$emit( event, [-args] ) 触发当前实例上的事件.附加参数都会传给监听器回调. 例子: 1 //父组件 2 <template> 3 <ratingselect @select-type=&

vue2.0中使用sass

第一部分:Sass语言 Sass是一种强大的css扩展语言(css本身并不是一门语言),它允许你使用变量.嵌套规则.mixins.导入等css没有但开发语言(如Java.C#.Ruby等)有的一些特性,并且完全兼容CSS语法.Sass有助于保持大型样式表结构良好. Sass有两种语法. 一种称为SCSS,是一个CSS3语法的扩充版本,也就是说,所有符合CSS3语法的样式表也都是具有相同语法意义的SCSS文件,SCSS样式表文件要以.scss扩展名结尾.在vue中,我们可以使用<style lan