<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
* {
margin: 0 auto;
padding: 0;
}
#box {
width: 800px;
height: 700px;
background: gold;
}
#add {
width: 100px;
height: 35px;
border-radius: 5px;
margin-left: 20px;
}
#deles {
width: 100px;
height: 35px;
border-radius: 5px;
}
#gnamecha {
margin-left: 20px;
width: 160px;
height: 33px;
border-radius: 5px;
}
#shoujihaocha {
width: 160px;
height: 33px;
border-radius: 5px;
}
#zhuangtaicha {
margin-left: 20px;
width: 160px;
height: 33px;
}
table {
width: 750px;
margin-top: 30px;
}
.false{
background: yellow;
}
.true{
background: green;
}
</style>
</head>
<body>
<div id="box" ng-app="myApp" ng-controller="myCtrl">
<header>
<input type="button" id="add" value="新增订单" ng-click="add()" />
<input type="button" id="deles" value="批量删除" ng-click="deles()" />
<input type="text" placeholder="按商品名称查询" id="gnamecha" ng-model="gcha" ng-keydown="gnamecha($event)">
<input type="text" placeholder="按手机号称查询" id="shoujihaocha" ng-model="scha" ng-keydown="shoujihaocha($event)">
<select ng-model="zcha" ng-init="zcha = '--根据状态查询--'" ng-change="zhuangtaicha()">
<option>--根据状态查询--</option>
<option>已发货</option>
<option>未发货</option>
</select>
</header>
<table border="1px" cellspacing="0" cellpadding="0">
<tr>
<th><input type="checkbox" class="cl1"></th>
<th>id<input type="button" ng-click="idpai()" value="排序"></th>
<th>商品名</th>
<th>用户名</th>
<th>手机号</th>
<th>价格<input type="button" ng-click="pricepai()" value="排序"></th>
<th>城市</th>
<th>下单时间<input type="button" ng-click="timepai()" value="排序"></th>
<th>状态</th>
</tr>
<tr ng-repeat="good in goods">
<td><input type="checkbox" class="cl2" ng-click="dianji($index)"></td>
<td>{{good.id}}</td>
<td>{{good.gname}}</td>
<td>{{good.uname}}</td>
<td>{{good.shoujihao}}</td>
<td>{{good.price|currency:"¥"}}</td>
<td>{{good.city}}</td>
<td>{{good.time|date:"MM-dd hh-mm-ss"}}</td>
<td><input type="button" class="{{good.zhuangtai}}" value="{{good.zhuangtai|myfilter}}" ng-click="fahuo($index)"/></td>
</tr>
</table>
<fieldset ng-show="xs">
<legend>添加订单信息</legend>
商品名:<input type="text" ng-model="gname" class="gname"/><span class="gnameT"></span><br />
用户名:<input type="text" ng-model="uname" class="uname"/><span class="unameT"></span><br />
手机号:<input type="text" ng-model="shoujihao" class="shoujihao"/><span class="shoujihaoT"></span><br />
价格为:<input type="text" ng-model="price" class="price"/><span class="priceT"></span><br />
城市:<select ng-model="city" ng-init="city='--选择城市--'" class="city">
<option>--选择城市--</option>
<option>山东</option>
<option>青岛</option>
<option>北京</option>
</select><span class="cityT"></span><br />
<input type="button" value="保存" ng-click="baocun()" />
</fieldset>
</div>
<script type="text/javascript">
var m = angular.module("myApp", []);
m.controller("myCtrl", function($scope) {
var arr = [{
"id": 1,
"isChecked":false,
"gname": "柠檬",
"uname": "小猪",
"shoujihao": "15810203278",
"price": 5,
"city": "北京",
"time": 121345100000,
"zhuangtai": false
}, {
"id": 2,
"isChecked":false,
"gname": "西瓜",
"uname": "小狗",
"shoujihao": "15810204378",
"price": 6,
"city": "青岛",
"time": 1215110000,
"zhuangtai": false
}, {
"id": 3,
"isChecked":false,
"gname": "菠萝",
"uname": "小熊",
"shoujihao": "15810205566",
"price": 7,
"city": "上海",
"time": 1215120000,
"zhuangtai": false
}, {
"id": 4,
"isChecked":false,
"gname": "火龙果",
"uname": "小猫",
"shoujihao": "15810207788",
"price": 8,
"city": "单县",
"time": 1215130000,
"zhuangtai": false
}];
$scope.goods = arr;
//添加开始
$scope.add = function(){
$scope.xs = true;
}
$scope.baocun = function(){
var gname = $scope.gname;
var uname = $scope.uname;
var shoujihao = $scope.shoujihao;
var price = $scope.price;
var city = $scope.city;
if(gname == ""||gname == null){
$(".gnameT").html("商品名不能为空");
$(".gname").css({"border":"1px solid red"})
return;
}else{
$(".gnameT").html("");
$(".gname").css({"border":"1px solid black"})
}
if(uname == ""||uname == null){
$(".unameT").html("用户名不能为空");
$(".uname").css({"border":"1px solid red"})
return;
}else{
$(".unameT").html("");
$(".uname").css({"border":"1px solid black"})
}
if(shoujihao == ""||shoujihao == null){
$(".shoujihaoT").html("手机号不能为空");
$(".shoujihao").css({"border":"1px solid red"})
return;
}else{
$(".shoujihaoT").html("");
$(".shoujihao").css({"border":"1px solid black"})
}
if(price == ""||price == null){
$(".priceT").html("价格不能为空");
$(".price").css({"border":"1px solid red"})
return;
}else{
$(".priceT").html("");
$(".price").css({"border":"1px solid black"})
}
if(city == "--选择城市--"){
$(".cityT").html("城市不能为空");
$(".city").css({"border":"1px solid red"})
return;
}else{
$(".cityT").html("");
$(".city").css({"border":"1px solid black"})
}
//获得id
var t_id = $scope.goods[$scope.goods.length-1].id;
t_id ++;
//获得时间
var t = new Date();
var time = t.getTime();
var newgood = {
"id":t_id,
"isChecked":false,
"gname":gname,
"uname":uname,
"shoujihao":shoujihao,
"price":price,
"city":city,
"time":time,
"zhuangtai":false
}
arr.push(newgood);
$scope.goods = arr;
$scope.xs = false;
}
//添加结束
$scope.fahuo = function($index){
arr[$index].zhuangtai = true;
$scope.goods = arr;
}
//根据商品名查询
$scope.gnamecha = function($event){
var k = $event.keyCode;
var newood = [];
if(k == 13){
var gn = $scope.gcha;
for(var i = 0; i<arr.length;i++){
var a = arr[i];
if(a.gname.indexOf(gn)>=0){
newood.push(a);
}
}
$scope.goods = newood;
}
}
//根具手机号查询
$scope.shoujihaocha = function($event){
var k = $event.keyCode;
var newood = [];
if(k == 13){
var gn = $scope.scha;
for(var i = 0; i<arr.length;i++){
var a = arr[i];
if(a.shoujihao.indexOf(gn)>=0){
newood.push(a);
}
}
$scope.goods = newood;
}
}
//根具状态查询
$scope.zhuangtaicha = function(){
var z = $scope.zcha;
var ngood = [];
if(z=="已发货"){
for(var i = 0 ;i<arr.length;i++){
var b = arr[i].zhuangtai;
if(b){
ngood.push(arr[i]);
}
}
}else{
for(var i = 0 ;i<arr.length;i++){
var b = arr[i].zhuangtai;
if(b==false){
ngood.push(arr[i]);
}
}
}
$scope.goods = ngood;
}
$scope.dianji = function($index){
arr[$index].isChecked =! arr[$index].isChecked;
}
//批量删除
$scope.deles = function(){
for(var i = 0 ;i<arr.length;i++){
var g = arr[i];
var f = g.isChecked;
var h = g.zhuangtai;
if(f == true && h == true){
arr.splice(i,1);
}
}
$scope.goods = arr;
}
//id排序
var idflag = true;
$scope.idpai = function(){
if(idflag){
arr.sort(function(a,b){
return a.id - b.id;
})
}else{
arr.sort(function(a,b){
return b.id - a.id;
})
}
idflag =! idflag;
$scope.goods = arr;
}
//价格排序
var priceflag = true;
$scope.pricepai = function(){
alert("safs")
if(priceflag){
arr.sort(function(a,b){
return a.price - b.price;
})
}else{
arr.sort(function(a,b){
return b.price - a.price;
})
}
priceflag =! priceflag;
$scope.goods = arr;
}
//时间排序
var timeflag = true;
$scope.timepai = function(){
if(timeflag){
arr.sort(function(a,b){
return a.time - b.time;
})
}else{
arr.sort(function(a,b){
return b.time - a.time;
})
}
timeflag =! timeflag;
$scope.goods = arr;
}
})
//过滤器状态
m.filter("myfilter",function(){
return function(input){
if(input){
return "已发货";
}else{
return "未发货";
}
return input;
}
})
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
* {
margin: 0 auto;
padding: 0;
}
#box {
width: 800px;
height: 700px;
background: gold;
}
#add {
width: 100px;
height: 35px;
border-radius: 5px;
margin-left: 20px;
}
#deles {
width: 100px;
height: 35px;
border-radius: 5px;
}
#gnamecha {
margin-left: 20px;
width: 160px;
height: 33px;
border-radius: 5px;
}
#shoujihaocha {
width: 160px;
height: 33px;
border-radius: 5px;
}
#zhuangtaicha {
margin-left: 20px;
width: 160px;
height: 33px;
}
table {
width: 750px;
margin-top: 30px;
}
.false{
background: yellow;
}
.true{
background: green;
}
</style>
</head>
<body>
<div id="box" ng-app="myApp" ng-controller="myCtrl">
<header>
<input type="button" id="add" value="新增订单" ng-click="add()" />
<input type="button" id="deles" value="批量删除" ng-click="deles()" />
<input type="text" placeholder="按商品名称查询" id="gnamecha" ng-model="gcha" ng-keydown="gnamecha($event)">
<input type="text" placeholder="按手机号称查询" id="shoujihaocha" ng-model="scha" ng-keydown="shoujihaocha($event)">
<select ng-model="zcha" ng-init="zcha = '--根据状态查询--'" ng-change="zhuangtaicha()">
<option>--根据状态查询--</option>
<option>已发货</option>
<option>未发货</option>
</select>
</header>
<table border="1px" cellspacing="0" cellpadding="0">
<tr>
<th><input type="checkbox" class="cl1"></th>
<th>id<input type="button" ng-click="idpai()" value="排序"></th>
<th>商品名</th>
<th>用户名</th>
<th>手机号</th>
<th>价格<input type="button" ng-click="pricepai()" value="排序"></th>
<th>城市</th>
<th>下单时间<input type="button" ng-click="timepai()" value="排序"></th>
<th>状态</th>
</tr>
<tr ng-repeat="good in goods">
<td><input type="checkbox" class="cl2" ng-click="dianji($index)"></td>
<td>{{good.id}}</td>
<td>{{good.gname}}</td>
<td>{{good.uname}}</td>
<td>{{good.shoujihao}}</td>
<td>{{good.price|currency:"¥"}}</td>
<td>{{good.city}}</td>
<td>{{good.time|date:"MM-dd hh-mm-ss"}}</td>
<td><input type="button" class="{{good.zhuangtai}}" value="{{good.zhuangtai|myfilter}}" ng-click="fahuo($index)"/></td>
</tr>
</table>
<fieldset ng-show="xs">
<legend>添加订单信息</legend>
商品名:<input type="text" ng-model="gname" class="gname"/><span class="gnameT"></span><br />
用户名:<input type="text" ng-model="uname" class="uname"/><span class="unameT"></span><br />
手机号:<input type="text" ng-model="shoujihao" class="shoujihao"/><span class="shoujihaoT"></span><br />
价格为:<input type="text" ng-model="price" class="price"/><span class="priceT"></span><br />
城市:<select ng-model="city" ng-init="city='--选择城市--'" class="city">
<option>--选择城市--</option>
<option>山东</option>
<option>青岛</option>
<option>北京</option>
</select><span class="cityT"></span><br />
<input type="button" value="保存" ng-click="baocun()" />
</fieldset>
</div>
<script type="text/javascript">
var m = angular.module("myApp", []);
m.controller("myCtrl", function($scope) {
var arr = [{
"id": 1,
"isChecked":false,
"gname": "柠檬",
"uname": "小猪",
"shoujihao": "15810203278",
"price": 5,
"city": "北京",
"time": 121345100000,
"zhuangtai": false
}, {
"id": 2,
"isChecked":false,
"gname": "西瓜",
"uname": "小狗",
"shoujihao": "15810204378",
"price": 6,
"city": "青岛",
"time": 1215110000,
"zhuangtai": false
}, {
"id": 3,
"isChecked":false,
"gname": "菠萝",
"uname": "小熊",
"shoujihao": "15810205566",
"price": 7,
"city": "上海",
"time": 1215120000,
"zhuangtai": false
}, {
"id": 4,
"isChecked":false,
"gname": "火龙果",
"uname": "小猫",
"shoujihao": "15810207788",
"price": 8,
"city": "单县",
"time": 1215130000,
"zhuangtai": false
}];
$scope.goods = arr;
//添加开始
$scope.add = function(){
$scope.xs = true;
}
$scope.baocun = function(){
var gname = $scope.gname;
var uname = $scope.uname;
var shoujihao = $scope.shoujihao;
var price = $scope.price;
var city = $scope.city;
if(gname == ""||gname == null){
$(".gnameT").html("商品名不能为空");
$(".gname").css({"border":"1px solid red"})
return;
}else{
$(".gnameT").html("");
$(".gname").css({"border":"1px solid black"})
}
if(uname == ""||uname == null){
$(".unameT").html("用户名不能为空");
$(".uname").css({"border":"1px solid red"})
return;
}else{
$(".unameT").html("");
$(".uname").css({"border":"1px solid black"})
}
if(shoujihao == ""||shoujihao == null){
$(".shoujihaoT").html("手机号不能为空");
$(".shoujihao").css({"border":"1px solid red"})
return;
}else{
$(".shoujihaoT").html("");
$(".shoujihao").css({"border":"1px solid black"})
}
if(price == ""||price == null){
$(".priceT").html("价格不能为空");
$(".price").css({"border":"1px solid red"})
return;
}else{
$(".priceT").html("");
$(".price").css({"border":"1px solid black"})
}
if(city == "--选择城市--"){
$(".cityT").html("城市不能为空");
$(".city").css({"border":"1px solid red"})
return;
}else{
$(".cityT").html("");
$(".city").css({"border":"1px solid black"})
}
//获得id
var t_id = $scope.goods[$scope.goods.length-1].id;
t_id ++;
//获得时间
var t = new Date();
var time = t.getTime();
var newgood = {
"id":t_id,
"isChecked":false,
"gname":gname,
"uname":uname,
"shoujihao":shoujihao,
"price":price,
"city":city,
"time":time,
"zhuangtai":false
}
arr.push(newgood);
$scope.goods = arr;
$scope.xs = false;
}
//添加结束
$scope.fahuo = function($index){
arr[$index].zhuangtai = true;
$scope.goods = arr;
}
//根据商品名查询
$scope.gnamecha = function($event){
var k = $event.keyCode;
var newood = [];
if(k == 13){
var gn = $scope.gcha;
for(var i = 0; i<arr.length;i++){
var a = arr[i];
if(a.gname.indexOf(gn)>=0){
newood.push(a);
}
}
$scope.goods = newood;
}
}
//根具手机号查询
$scope.shoujihaocha = function($event){
var k = $event.keyCode;
var newood = [];
if(k == 13){
var gn = $scope.scha;
for(var i = 0; i<arr.length;i++){
var a = arr[i];
if(a.shoujihao.indexOf(gn)>=0){
newood.push(a);
}
}
$scope.goods = newood;
}
}
//根具状态查询
$scope.zhuangtaicha = function(){
var z = $scope.zcha;
var ngood = [];
if(z=="已发货"){
for(var i = 0 ;i<arr.length;i++){
var b = arr[i].zhuangtai;
if(b){
ngood.push(arr[i]);
}
}
}else{
for(var i = 0 ;i<arr.length;i++){
var b = arr[i].zhuangtai;
if(b==false){
ngood.push(arr[i]);
}
}
}
$scope.goods = ngood;
}
$scope.dianji = function($index){
arr[$index].isChecked =! arr[$index].isChecked;
}
//批量删除
$scope.deles = function(){
for(var i = 0 ;i<arr.length;i++){
var g = arr[i];
var f = g.isChecked;
var h = g.zhuangtai;
if(f == true && h == true){
arr.splice(i,1);
}
}
$scope.goods = arr;
}
//id排序
var idflag = true;
$scope.idpai = function(){
if(idflag){
arr.sort(function(a,b){
return a.id - b.id;
})
}else{
arr.sort(function(a,b){
return b.id - a.id;
})
}
idflag =! idflag;
$scope.goods = arr;
}
//价格排序
var priceflag = true;
$scope.pricepai = function(){
alert("safs")
if(priceflag){
arr.sort(function(a,b){
return a.price - b.price;
})
}else{
arr.sort(function(a,b){
return b.price - a.price;
})
}
priceflag =! priceflag;
$scope.goods = arr;
}
//时间排序
var timeflag = true;
$scope.timepai = function(){
if(timeflag){
arr.sort(function(a,b){
return a.time - b.time;
})
}else{
arr.sort(function(a,b){
return b.time - a.time;
})
}
timeflag =! timeflag;
$scope.goods = arr;
}
})
//过滤器状态
m.filter("myfilter",function(){
return function(input){
if(input){
return "已发货";
}else{
return "未发货";
}
return input;
}
})
</script>
</body>
</html>