<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../angular-1.5.5/angular.js"></script>
<style>
p{
text-align: center;
margin-left:15px;
}
.bu{
background: green;
text-align: center;
margin-left: 50px;
color: white;
}
#bu{
margin-left: 800px;
}
.button{
background: green;
text-align: center;
color: white;
}
.tab{
border-collapse: collapse;
text-align: center;
margin: 0 auto;
width: 700px;
margin-top: 20px;
}
.tab tr td,th{
border: 1px solid black;
}
.tab tr:nth-child(1){background: #565656}
.tab tr:nth-child(odd){background: #B1B1B1}
.tab tr:nth-child(even){background: white}
.red{
color: #0c60ee;
text-decoration:underline;
}
.div{
width: 500px;
height: 500px;
margin: 0 auto;
border: 1px solid black;
margin-top: 20px;
}
ul{
width: 300px;
height: 200px;
margin: 0 auto;
background: lightcoral;
}
.cc{
border: 1px solid red;
}
</style>
<script>
var myapp=angular.module("myapp",[]);
myapp.controller("myCtrl",function ($scope) {
$scope.data=[
{check:false,id:1,goods:"iphone4",user:"张三",dh:"151111111",price:"4999.00",city:"北京",time:"08-01 10:00",zt:"发货"},
{check:false,id:2,goods:"小米6",user:"李四",dh:"15222222",price:"2999.00",city:"北京",time:"08-02 10:00",zt:"发货"},
{check:false,id:3,goods:"华为P9",user:"王五",dh:"153333333",price:"3999.00",city:"上海",time:"09-01 10:00",zt:"待发货"},
{check:false,id:4,goods:"oppo R11",user:"赵六",dh:"15444444",price:"4999.00",city:"天津",time:"09-03 10:00",zt:"已收货"},
{check:false,id:5,goods:"vivo",user:"周七",dh:"15555555",price:"2999.00",city:"淮安",time:"10-04 10:00",zt:"已发货"},
];
/* //判断发货的颜色
$scope.has=false;
for(var i=0;i<$scope.data.length;i++) {
if ($scope.data[i].zt == "发货") {
$scope.has = true;
console.log($scope.has)
return;
} else {
$scope.has = false;
}
break;
}*/
//按地区查询
$scope.city="选择城市";
$scope.cityfilter=function (item) {
if($scope.city!="选择城市"){
if($scope.city==item.city){
if($scope.city=="淮安"){
return "淮安";
}
else
if($scope.city=="北京"){
return "北京";
}
else
if($scope.city=="上海"){
return "上海";
}
else
if($scope.city=="天津"){
return "天津";
}
else
if($scope.city=="重庆"){
return "重庆";
}
}
}else{
return true;
}
}
//按状态区分
$scope.zt="选择状态";
$scope.ztfilter=function (item) {
if($scope.zt!="选择状态"){
if($scope.zt==item.zt){
if($scope.zt=="发货"){
return "发货";
}
else
if($scope.zt=="已发货"){
return "已发货";
}
else
if($scope.zt=="已收货"){
return "已收货";
}
}
}else{
return true;
}
}
// 通过月份过滤
$scope.filterByMonth = function (order) {
if ($scope.filter_begin_month == undefined || $scope.filter_begin_month == "") {
return true;
}
if ($scope.filter_end_month == undefined || $scope.filter_end_month == "") {
return true;
}
var beginMonth = parseInt($scope.filter_begin_month);
var endMonth = parseInt($scope.filter_end_month);
if (beginMonth > endMonth) {
return true;
}
var month = order.time.substr(0, order.time.indexOf("-"));
month = parseInt(month);
return (month >= beginMonth && month <= endMonth);
};
//id进行排序
$scope.n=0;
$scope.zj=false;
$scope.sjpx=function () {
$scope.n++;
$scope.id=function (item) {
return item.id;
}
if($scope.n%2==0){
$scope.zj=true;
}else{
$scope.zj=false;
}
}
//价格进行排序
$scope.n=0;
$scope.jz=false;
$scope.jgpx=function () {
$scope.n++;
$scope.jg=function (item) {
return item.price;
}
if($scope.n%2==0){
$scope.jz=true;
}else{
$scope.jz=false;
}
}
//按日期排序
$scope.n=0;
$scope.jj=false;
$scope.timepx=function () {
$scope.n++;
$scope.rq=function (item) {
return item.time;
}
if($scope.n%2==0){
$scope.jj=true;
}else{
$scope.jj=false;
}
}
//全选
$scope.qx=false;
$scope.qxx=function () {
if($scope.qx==true){
for(var i=0;i<$scope.data.length;i++){
$scope.data[i].check=true;
}
}else if($scope.qx==false){
for(var i=0;i<$scope.data.length;i++){
$scope.data[i].check=false;
}
}
}
//进行反选
$scope.f=0;
$scope.fx=function (index) {
if($scope.data[index].check==true){
$scope.f++;
}else{
$scope.f--;
}
if( $scope.f==$scope.data.length){
$scope.qx=true;
}else {
$scope.qx=false;
}
}
//2、点击“新增订单”,弹出上框,新增订单状态都是“待发货”
$scope.xs=false;
$scope.pname="商品名不能为空";
$scope.uname="用户名不能为空";
$scope.phone1="137705475147";
$scope.xz="选择城市"
$scope.show=false;
$scope.ff=false; //判断边框红色
$scope.add=function () {
$scope.xs=true;
//提交的动作
$scope.sub=function () {
//商品名不能为空
if($scope.pname!=null&& $scope.pname!=""){
//商品名必须是6-20个字符
if( $scope.pname.length>=6&& $scope.pname.length<=20){
//用户名不能为空
if($scope.uname!=null&& $scope.uname!=""){
//用户名必须是4-16个字符
if( $scope.uname.length>=4&& $scope.uname.length<=16){
// 手机号是不能为空
if($scope.phone1!=null&& $scope.phone1!=""){
if(!(/^1(3|4|5|7|8)\d{9}$/.test( $scope.phone))){
$scope.show=false;
$scope.date=new Date().toLocaleTimeString();
$scope.date1= new Date().toLocaleDateString()
$scope.dd= $scope.date1+" "+ $scope.date;
//添加
if($scope.xz!="选择城市"){
$scope.show=false;
$scope.data.push({check:false,id:$scope.data.length+1,goods:$scope.pname,user: $scope.uname,dh: $scope.phone1,price:"2999.00",city:$scope.xz,time: $scope.dd,zt:"待发货"})
$scope.xs=false;
}
}else{
$scope.show=true;
}
}else{
$scope.show=true;
}
}else{
$scope.ff=true;
$scope.show=true;
}
}else{
$scope.show=true;
}
}else{
$scope.show=true;
}
}else{
$scope.show=true;
}
}
}
//5、点击“发货”按钮,将“待发货”状态改成“已发货” (10分)
$scope.pfh=function () {
for(var i=0; i<$scope.data.length;i++){
if($scope.data[i].check==true) {
if($scope.data[i].zt=="待发货"){
$scope.data[i].zt="已发货";
}
}
}
}
$scope.dj=function (i) {
alert(i)
if($scope.data[i].check==true&&$scope.data[i].zt=="发货") {
$scope.data[i].zt="已发货";
}
}
//批量删除
$scope.del=function () {
for(var i=0; i<$scope.data.length;i++){
if($scope.data[i].check==true) {
$scope.data.splice(i,1);
i--;
}
}
}
});
</script>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
<p>
<input type="text" placeholder="用户名搜索" ng-model="name"/>
<input type="text" placeholder="手机号搜索" ng-model="phone"/>
<select ng-model="city">
<option>选择城市</option>
<option>淮安</option>
<option>北京</option>
<option>上海</option>
<option>重庆</option>
<option>天津</option>
</select>
<select ng-model="zt">
<option>选择状态</option>
<option>发货</option>
<option>已发货</option>
<option>已收货</option>
</select>
<select class="choose_time_begin_month" ng-model="filter_begin_month">
<option value="">开始月份</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select> -
<select class="choose_time_end_month" ng-model="filter_end_month">
<option value="">结束月份</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
</p>
<button class="bu" id="bu" ng-click="add()">新增订单</button> <button class="bu" ng-click="pfh()">批量发货</button> <button class="bu" ng-click="del()">批量删除</button>
<table class="tab">
<tr>
<th><input type="checkbox" ng-model="qx" ng-click="qxx()"/>全选</th>
<th>ID <button class="button" ng-click="sjpx()">排序</button></th>
<th>商品名</th>
<th>用户名</th>
<th>手机号</th>
<th>价格 <button class="button" ng-click="jgpx()">排序</button></th>
<th>城市</th>
<th>下单时间 <button class="button" ng-click="timepx()" >排序</button></th>
<th>状态</th>
</tr>
<tr ng-repeat="item in data|filter:{user:name}|filter:{dh:phone}|filter:cityfilter|filter:ztfilter|orderBy:id:zj|orderBy:jg:jz|orderBy:rq:jj|filter:filterByMonth">
<td><input type="checkbox" ng-model="item.check" ng-click="fx($index)"/></td>
<td>{{item.id}}</td>
<td>{{item.goods}}</td>
<td>{{item.user}}</td>
<td>{{item.dh}}</td>
<td>{{item.price|currency:"¥"}}</td>
<td>{{item.city}}</td>
<td>{{item.time}}</td>
<td ng-class="{red:has}" ng-click="dj($index)">{{item.zt}}</td>
</tr>
</table>
<div class="div" ng-show="xs">
<h3>新增订单</h3>
<p>商品名:<input type="text" placeholder="6-20个字符" ng-model="pname"/></p>
<p>用户名:<input type="text" placeholder="4-16个字符" ng-model="uname" ng-class="{cc:ff}"/></p>
<p>手机号:<input type="text" ng-model="phone1"/></p>
<p>
城市 <select ng-model="xz">
<option>选择城市</option>
<option>淮安</option>
<option>北京</option>
<option>上海</option>
<option>重庆</option>
<option>天津</option>
</select>
</p>
<ul ng-show="show">
<li>商品名不能为空</li>
<li>商品名必须是6-20个字符</li>
<li>用户名不能为空</li>
<li>用户名必须是4-16个字符</li>
<li>手机号是不能为空</li>
<li>手机号格式不正确</li>
<li>请选择城市</li>
</ul>
<button class="bu" ng-click="sub()">提交</button>
</div>
</body>
</html>
AngularJS一系列筛选,添加、显示
最新推荐文章于 2018-08-28 15:22:16 发布