按条件增,按钮 删 模糊 查 正序逆序

<!DOCTYPE html>
<html>


<head>
<meta charset="UTF-8">
<title></title>
<script src="js/angular.min.js"></script>
<script src="js/jquery-1.11.1.js"></script>
<script>
angular.module("rxy", []).controller("week3", function($scope) {
$scope.ss = false;
$scope.hh = false;
$scope.s = false;
$scope.goods = [{
names: "qq",
price: 12.9,
num: 2,
}, {
names: "wx",
price: 23.9,
num: 1,
}, {
names: "wx",
price: 99.9,
num: 1,
}];
$scope.add = function() {
$scope.s = true;
}
$scope.sure = function() {
var flag=/米/g;
var na= $("#name").val().replace(flag,'*');
var n = {
names:na,
price: $("#price").val(),
num: $("#num").val(),
};
$scope.goods.push(n);
}
$scope.suan = function(e, name) {
for(var j = 0; j < $scope.goods.length; j++) {
if($scope.goods[j].names == name) {
if($scope.goods[j].num == 1 && e == -1) {
if(confirm("您是否将该商品移除购物车")) {
$scope.goods.splice(j, 1);
}
} else {
$scope.goods[j].num = $scope.goods[j].num + e;
}
}
}
}
$scope.del = function(i) {
$scope.goods.splice(i, 1);
}
$scope.ckAll = function() {
for(var i = 0; i < $scope.goods.length; i++) {
$scope.goods[i].ck = $scope.flag;
}
}
$scope.delAll = function() {
for(var i = 0; i < $scope.goods.length; i++) {
if($scope.goods[i].ck) {
$scope.goods.splice(i, 1);
i--;
}
}
if($scope.goods.length == 0) {
$scope.hh = true;
$scope.ss = true;
}
}
$scope.sum = function() {
var count = 0;
for(var i = 0; i < $scope.goods.length; i++) {
count = count + $scope.goods[i].price * $scope.goods[i].num;
}
return count;
}
})
</script>
</head>


<body ng-app="rxy" ng-controller="week3">
<h1>我的购物车</h1>
<h3 ng-show="ss">购物车为空请继续购物</h3>
<div ng-hide="hh">
<input placeholder="请输入关键字搜索..." ng-model="nn" />
<select style="margin-left: 500px;" ng-model="pai">
<option value="">按数量排序</option>
<option value="+num">按数量正序排序</option>
<option value="-num">按数量倒序排序</option>
</select>
<button style="background: greenyellow;border: none;" ng-click="add()">入库</button><br /><br />
<button style="margin-left: 750px;background: red;border: none;" ng-click="delAll()">清空购物车</button>
<table border="1" style="width: 800px;border-collapse: collapse;text-align: center;">
<tr>
<th><input type="checkbox" ng-click="ckAll()" ng-model="flag" /></th>
<th>name</th>
<th>price</th>
<th>number</th>
<th>totalPrice</th>
<th>option</th>
</tr>
<tr ng-repeat="i in goods|filter:{name:nn}|orderBy:pai">
<td><input type="checkbox" ng-model="i.ck" /></td>
<td>{{i.names}}</td>
<td>{{i.price|currency:"¥"}}</td>
<td><button ng-click="suan(-1,i.names)">-</button>{{i.num}}<button ng-click="suan(+1,i.names)">+</button></td>
<td>{{i.price*i.num|currency:"¥"}}</td>
<td><button ng-click="del($index)">删除</button></td>
</tr>
<tr>
<td colspan="6">总价为:{{sum()|currency:"¥"}}</td>
</tr>
</table>
<div ng-show="s">
name:<input id="name" /> price:
<input id="price" /> num:
<input id="num" />
<button ng-click="sure()">确定</button>
</div>
</div>
</body>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值