<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<style>
* {
margin: 0px auto;
padding: 0px;
}
.tre1 {
border-radius: 20px;
}
.div1 {
margin-top: 10px;
width: 650px;
}
.bu1 {
background: cyan;
width: 70px;
height: 30px;
border-radius: 6px;
}
.bu2 {
background: cyan;
border-radius: 5px;
}
.tab {
width: 760px;
}
.tab td {
text-align: center;
}
.im1 {
width: 20px;
height: 20px;
}
.im2 {
width: 20px;
height: 20px;
}
.true {
background: greenyellow;
border: 0px;
border-radius: 3px;
}
.false {
background: yellow;
border: 0px;
border-radius: 3px;
}
.fie {
width: 760px;
}
.div3 {
margin-left: 200px;
}
#bao {
width: 150px;
height: 30px;
margin-left: 230px;
}
</style>
</head>
<body ng-app="myapp" ng-controller="cre">
<div class="div1">
<input type="button" value="新增表单" class="bu1" ng-click="add()" />
<input type="button" value="批量删除" class="bu1" ng-click="pi()" />
<input type="text" placeholder="按商品名称查询" class="tre1" ng-model="shang" /><img src="img/a1.png" class="im1" ng-click="im1()" />
<input type="text" placeholder="按手机号查询" class="tre1" ng-model="shou" /><img src="img/a1.png" class="im2" ng-click="im2()" />
<select ng-change="isFaHuo()" ng-model="zhuang" ng-init="zhuang='--按状态查询--'">
<option>--按状态查询--</option>
<option>未发货</option>
<option>已发货</option>
</select>
</div><br />
<div class="div2">
<table border="1px" cellspacing="0px" class="tab">
<th><input type="checkbox" ng-model="che" ng-click="box1()" /></th>
<th>id<input type="button" value="排序" class="bu2" ng-click="xuid()" /></th>
<th>商品名</th>
<th>用户名</th>
<th>手机号</th>
<th>价格<input type="button" value="排序" class="bu2" ng-click="jia()" /></th>
<th>城市</th>
<th>下单时间<input type="button" value="排序" class="bu2" ng-click="shijian()" /></th>
<th>状态</th>
<tr ng-repeat="good in goods|filter:bb">
<td><input type="checkbox" ng-model="good.ckx" /></td>
<td>{{good.uid}}</td>
<td>{{good.uname}}</td>
<td>{{good.name}}</td>
<td>{{good.tel}}</td>
<td>¥{{good.price}}</td>
<td>{{good.cheng}}</td>
<td>{{good.shi|date:"MM-dd hh:mm:ss"}}</td>
<td><input type="button" value="{{good.fal|myfil}}" class="{{good.fal}}" ng-click="fahuo($index)" /></td>
</tr>
</table>
</div>
<fieldset class="fie" ng-show="show">
<legend>添加订单信息</legend>
<div class="div3">
商品名<input type="text" ng-model="uname1" id="uname1" /><span style="color: red;" id="sp1"></span><br /> 用户名:
<input type="text" ng-model="yong" id="yong" /><span style="color: red;" id="sp2"></span><br /> 手机号:
<input type="text" ng-model="utel1" id="utel1" /><span style="color: red;" id="sp3"></span><br /> 价格为:
<input type="text" ng-model="uprice1" id="uprice1" /><span style="color: red;" id="sp4"></span><br /> 城市:
<select ng-model="chengshi" ng-init="chengshi='--请选择城市--'" id="chengshi">
<option>--请选择城市--</option>
<option>北京</option>
<option>上海</option>
<option>天津</option>
<option>南京</option>
</select><span style="color: red;" id="sp5"></span><br /> <br />
</div>
<input type="button" value="保存" id="bao" ng-click="bao()" />
</fieldset>
</body>
<script>
//注入
var mo = angular.module("myapp", []);
//创建控制器
mo.controller("cre", function($scope) {
//定义数组
var arr = [{
"uid": "2001",
"uname": "iPhoneX",
"name": "张三",
"tel": 110,
"price": 8669.00,
"cheng": "北京",
"shi": new Date(543534534534).getTime(),
"fal": false
},
{
"uid": "6006",
"uname": "iPhone6",
"name": "王红",
"tel": 120,
"price": 7669.00,
"cheng": "上海",
"shi": new Date(243534534534).getTime(),
"fal": false
},
{
"uid": "5316",
"uname": "iPhone7",
"name": "赵小红",
"tel": 130,
"price": 7999.00,
"cheng": "河北",
"shi": new Date(343534534534).getTime(),
"fal": false
},
{
"uid": "5312",
"uname": "华为10",
"name": "李四",
"tel": 220,
"price": 19999.00,
"cheng": "天津",
"shi": new Date(54353453423).getTime(),
"fal": false
}
];
//初始化界面
$scope.goods = arr;
//点击显示表单
$scope.add = function() {
$scope.show = true;
}
//已发货和未发货
$scope.fahuo = function($index) {
arr[$index].fal = !arr[$index].fal;
}
//全选和全不选
$scope.box1 = function() {
var aa = $scope.che;
if(aa == true) {
for(var i = 0; i < $scope.goods.length; i++) {
$scope.goods[i].ckx = true;
}
} else {
for(var i = 0; i < $scope.goods.length; i++) {
$scope.goods[i].ckx = false;
}
}
}
//批量删除
$scope.pi = function() {
for(var i = 0; i < $scope.goods.length; i++) {
//获取是否发货的值
var ff = $scope.goods[i].fal;
if($scope.goods[i].ckx == true && ff == true) {
$scope.goods.splice(i, 1);
i--;
}
}
}
//商品名称查询方法
$scope.im1 = function() {
if($scope.shang == "" || $scope.shang == null) {
alert("请输入商品名称");
$scope.bb = $scope.shang;
return;
}
$scope.bb = $scope.shang;
}
/*//根据商品名称查询第二种方法
输入框加上这个键盘监听事件ng-keydown="gname_cha($event)"
$scope.im1 = function($event) {
var arr_temp = []; //定义临时数组
var keyCode = $event.keyCode;
if (keyCode == 13) {
//遍历数组查询
for (var i = 0; i < arr.length; i++) {
if (arr[i].uname.indexOf($scope.shang) != -1) {
arr_temp.push(arr[i]);
}
}
//赋值
$scope.goods = arr_temp;
}
}*/
//手机号查询方法
$scope.im2 = function() {
if($scope.shou == "" || $scope.shou == null) {
alert("请输入手机号");
$scope.bb = $scope.shang;
return;
}
$scope.bb = $scope.shou;
}
//id排序
var xuid1 = true;
$scope.xuid = function() {
if(xuid1) {
arr.sort(function(a, b) {
return a.uid - b.uid;
});
} else {
arr.sort(function(a, b) {
return b.uid - a.uid;
});
}
xuid1 = !xuid1;
$scope.goods = arr;
}
//价格排序
var jia1 = true;
$scope.jia = function() {
if(jia1) {
arr.sort(function(a, b) {
return a.price - b.price;
});
} else {
arr.sort(function(a, b) {
return b.price - a.price;
});
}
jia1 = !jia1;
$scope.goods = arr;
}
//时间排序
var jian = true;
$scope.shijian = function() {
if(jian) {
arr.sort(function(a, b) {
return a.shi - b.shi;
})
} else {
arr.sort(function(a, b) {
return b.shi - a.shi;
});
}
jian = !jian
$scope.goods = arr;
}
//按状态查询
$scope.isFaHuo = function() {
//定义一个临时数组,储存对象
var arr_temp = [];
//获取select里面的值
var f = $scope.zhuang;
if(f == "已发货") {
for(var i = 0; i < arr.length; i++) {
var f1 = arr[i].fal; //获取发货状态
if(f1) {
arr_temp.push(arr[i]);
}
}
} else {
for(var i = 0; i < arr.length; i++) {
var f1 = arr[i].fal; //获取发货状态
if(f1 == false) {
arr_temp.push(arr[i]);
}
}
}
$scope.goods = arr_temp;
}
//id方法
function a1() {
//随机整数
var uid = Math.floor(Math.random() * 10000)
return uid;
}
//判断商品名称的方法
var fl1 = false;
function a2() {
var uname1 = $scope.uname1;
if(uname1 == "" || uname1 == null) {
$("#sp1").text("商品名称不能为空")
$("#uname1").css("border-color", "red")
fl1 = false;
} else {
$("#sp1").text("");
$("#uname1").css("border-color", "")
fl1 = true;
}
}
//判断用户名
var fl2 = false;
function a3() {
var yong = $scope.yong;
if(yong == "" || yong == null) {
$("#sp2").text("用户名称不能为空")
$("#yong").css("border-color", "red")
fl2 = false;
} else {
$("#sp2").text("");
$("#yong").css("border-color", "")
fl2 = true;
}
}
//判断手机号
var fl3 = false;
function a4() {
var utel1 = $scope.utel1;
if(utel1 == "" || utel1 == null) {
$("#sp3").text("手机号不能为空")
$("#utel1").css("border-color", "red")
fl3 = false;
} else {
var aa = /^[0-9]*$/
if(!aa.test(utel1)) {
$("#sp3").text("手机号为纯数字")
$("#utel1").css("border-color", "red")
fl3 = false;
} else {
$("#sp3").text("");
$("#utel1").css("border-color", "")
fl3 = true;
}
}
}
//判断价格
var fl4 = false;
function a5() {
//不能为空
var uprice1 = $scope.uprice1;
if(uprice1 == "" || uprice1 == null) {
$("#sp4").text("价格不能为空")
$("#uprice1").css("border-color", "red")
fl4 = false;
} else {
$("#sp4").text("")
$("#uprice1").css("border-color", "")
var jia = /^[0-9]+([.]{1}[0-9]+){0,1}$/;
if(!jia.test(uprice1)) {
$("#sp4").text("价格为整数或小数")
$("#uprice1").css("border-color", "red")
fl4 = false;
} else {
fl4 = true
}
}
}
//判断城市
var fl5=false;
function a6() {
var chengshi = $scope.chengshi;
if(chengshi=="--请选择城市--"){
$("#sp5").text("城市必须选择")
$("#chengshi").css("border-color", "red")
fl5=false
}else{
$("#sp5").text("")
$("#chengshi").css("border-color", "")
fl5=true
}
}
//添加方法
$scope.bao = function() {
a2();
if(fl1 == true) {
a3();
if(fl2 == true) {
a4();
if(fl3 == true) {
a5();
if(fl4 == true) {
a6();
if(fl5==true){
//创建对象
var g = {
"uid": a1(),
"uname": $scope.uname1,
"name": $scope.yong,
"tel": $scope.utel1,
"price": $scope.uprice1,
"cheng": $scope.chengshi,
"shi": new Date().getTime(),
"fal": false
};
//添加
arr.push(g);
$scope.goods = arr;
//隐藏表单
$scope.show = false;
/*//清空
if($scope.show == false) {
$(".div3 input").val("");
$(".div3 select").val("--请选择城市--");
}*/
}
}
}
}
}
}
});
//自定义过滤器
mo.filter("myfil", function() {
return function(fal) {
if(fal) {
return "已发货"
} else {
return "未发货";
}
}
return fal;
})
</script>
</html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<style>
* {
margin: 0px auto;
padding: 0px;
}
.tre1 {
border-radius: 20px;
}
.div1 {
margin-top: 10px;
width: 650px;
}
.bu1 {
background: cyan;
width: 70px;
height: 30px;
border-radius: 6px;
}
.bu2 {
background: cyan;
border-radius: 5px;
}
.tab {
width: 760px;
}
.tab td {
text-align: center;
}
.im1 {
width: 20px;
height: 20px;
}
.im2 {
width: 20px;
height: 20px;
}
.true {
background: greenyellow;
border: 0px;
border-radius: 3px;
}
.false {
background: yellow;
border: 0px;
border-radius: 3px;
}
.fie {
width: 760px;
}
.div3 {
margin-left: 200px;
}
#bao {
width: 150px;
height: 30px;
margin-left: 230px;
}
</style>
</head>
<body ng-app="myapp" ng-controller="cre">
<div class="div1">
<input type="button" value="新增表单" class="bu1" ng-click="add()" />
<input type="button" value="批量删除" class="bu1" ng-click="pi()" />
<input type="text" placeholder="按商品名称查询" class="tre1" ng-model="shang" /><img src="img/a1.png" class="im1" ng-click="im1()" />
<input type="text" placeholder="按手机号查询" class="tre1" ng-model="shou" /><img src="img/a1.png" class="im2" ng-click="im2()" />
<select ng-change="isFaHuo()" ng-model="zhuang" ng-init="zhuang='--按状态查询--'">
<option>--按状态查询--</option>
<option>未发货</option>
<option>已发货</option>
</select>
</div><br />
<div class="div2">
<table border="1px" cellspacing="0px" class="tab">
<th><input type="checkbox" ng-model="che" ng-click="box1()" /></th>
<th>id<input type="button" value="排序" class="bu2" ng-click="xuid()" /></th>
<th>商品名</th>
<th>用户名</th>
<th>手机号</th>
<th>价格<input type="button" value="排序" class="bu2" ng-click="jia()" /></th>
<th>城市</th>
<th>下单时间<input type="button" value="排序" class="bu2" ng-click="shijian()" /></th>
<th>状态</th>
<tr ng-repeat="good in goods|filter:bb">
<td><input type="checkbox" ng-model="good.ckx" /></td>
<td>{{good.uid}}</td>
<td>{{good.uname}}</td>
<td>{{good.name}}</td>
<td>{{good.tel}}</td>
<td>¥{{good.price}}</td>
<td>{{good.cheng}}</td>
<td>{{good.shi|date:"MM-dd hh:mm:ss"}}</td>
<td><input type="button" value="{{good.fal|myfil}}" class="{{good.fal}}" ng-click="fahuo($index)" /></td>
</tr>
</table>
</div>
<fieldset class="fie" ng-show="show">
<legend>添加订单信息</legend>
<div class="div3">
商品名<input type="text" ng-model="uname1" id="uname1" /><span style="color: red;" id="sp1"></span><br /> 用户名:
<input type="text" ng-model="yong" id="yong" /><span style="color: red;" id="sp2"></span><br /> 手机号:
<input type="text" ng-model="utel1" id="utel1" /><span style="color: red;" id="sp3"></span><br /> 价格为:
<input type="text" ng-model="uprice1" id="uprice1" /><span style="color: red;" id="sp4"></span><br /> 城市:
<select ng-model="chengshi" ng-init="chengshi='--请选择城市--'" id="chengshi">
<option>--请选择城市--</option>
<option>北京</option>
<option>上海</option>
<option>天津</option>
<option>南京</option>
</select><span style="color: red;" id="sp5"></span><br /> <br />
</div>
<input type="button" value="保存" id="bao" ng-click="bao()" />
</fieldset>
</body>
<script>
//注入
var mo = angular.module("myapp", []);
//创建控制器
mo.controller("cre", function($scope) {
//定义数组
var arr = [{
"uid": "2001",
"uname": "iPhoneX",
"name": "张三",
"tel": 110,
"price": 8669.00,
"cheng": "北京",
"shi": new Date(543534534534).getTime(),
"fal": false
},
{
"uid": "6006",
"uname": "iPhone6",
"name": "王红",
"tel": 120,
"price": 7669.00,
"cheng": "上海",
"shi": new Date(243534534534).getTime(),
"fal": false
},
{
"uid": "5316",
"uname": "iPhone7",
"name": "赵小红",
"tel": 130,
"price": 7999.00,
"cheng": "河北",
"shi": new Date(343534534534).getTime(),
"fal": false
},
{
"uid": "5312",
"uname": "华为10",
"name": "李四",
"tel": 220,
"price": 19999.00,
"cheng": "天津",
"shi": new Date(54353453423).getTime(),
"fal": false
}
];
//初始化界面
$scope.goods = arr;
//点击显示表单
$scope.add = function() {
$scope.show = true;
}
//已发货和未发货
$scope.fahuo = function($index) {
arr[$index].fal = !arr[$index].fal;
}
//全选和全不选
$scope.box1 = function() {
var aa = $scope.che;
if(aa == true) {
for(var i = 0; i < $scope.goods.length; i++) {
$scope.goods[i].ckx = true;
}
} else {
for(var i = 0; i < $scope.goods.length; i++) {
$scope.goods[i].ckx = false;
}
}
}
//批量删除
$scope.pi = function() {
for(var i = 0; i < $scope.goods.length; i++) {
//获取是否发货的值
var ff = $scope.goods[i].fal;
if($scope.goods[i].ckx == true && ff == true) {
$scope.goods.splice(i, 1);
i--;
}
}
}
//商品名称查询方法
$scope.im1 = function() {
if($scope.shang == "" || $scope.shang == null) {
alert("请输入商品名称");
$scope.bb = $scope.shang;
return;
}
$scope.bb = $scope.shang;
}
/*//根据商品名称查询第二种方法
输入框加上这个键盘监听事件ng-keydown="gname_cha($event)"
$scope.im1 = function($event) {
var arr_temp = []; //定义临时数组
var keyCode = $event.keyCode;
if (keyCode == 13) {
//遍历数组查询
for (var i = 0; i < arr.length; i++) {
if (arr[i].uname.indexOf($scope.shang) != -1) {
arr_temp.push(arr[i]);
}
}
//赋值
$scope.goods = arr_temp;
}
}*/
//手机号查询方法
$scope.im2 = function() {
if($scope.shou == "" || $scope.shou == null) {
alert("请输入手机号");
$scope.bb = $scope.shang;
return;
}
$scope.bb = $scope.shou;
}
//id排序
var xuid1 = true;
$scope.xuid = function() {
if(xuid1) {
arr.sort(function(a, b) {
return a.uid - b.uid;
});
} else {
arr.sort(function(a, b) {
return b.uid - a.uid;
});
}
xuid1 = !xuid1;
$scope.goods = arr;
}
//价格排序
var jia1 = true;
$scope.jia = function() {
if(jia1) {
arr.sort(function(a, b) {
return a.price - b.price;
});
} else {
arr.sort(function(a, b) {
return b.price - a.price;
});
}
jia1 = !jia1;
$scope.goods = arr;
}
//时间排序
var jian = true;
$scope.shijian = function() {
if(jian) {
arr.sort(function(a, b) {
return a.shi - b.shi;
})
} else {
arr.sort(function(a, b) {
return b.shi - a.shi;
});
}
jian = !jian
$scope.goods = arr;
}
//按状态查询
$scope.isFaHuo = function() {
//定义一个临时数组,储存对象
var arr_temp = [];
//获取select里面的值
var f = $scope.zhuang;
if(f == "已发货") {
for(var i = 0; i < arr.length; i++) {
var f1 = arr[i].fal; //获取发货状态
if(f1) {
arr_temp.push(arr[i]);
}
}
} else {
for(var i = 0; i < arr.length; i++) {
var f1 = arr[i].fal; //获取发货状态
if(f1 == false) {
arr_temp.push(arr[i]);
}
}
}
$scope.goods = arr_temp;
}
//id方法
function a1() {
//随机整数
var uid = Math.floor(Math.random() * 10000)
return uid;
}
//判断商品名称的方法
var fl1 = false;
function a2() {
var uname1 = $scope.uname1;
if(uname1 == "" || uname1 == null) {
$("#sp1").text("商品名称不能为空")
$("#uname1").css("border-color", "red")
fl1 = false;
} else {
$("#sp1").text("");
$("#uname1").css("border-color", "")
fl1 = true;
}
}
//判断用户名
var fl2 = false;
function a3() {
var yong = $scope.yong;
if(yong == "" || yong == null) {
$("#sp2").text("用户名称不能为空")
$("#yong").css("border-color", "red")
fl2 = false;
} else {
$("#sp2").text("");
$("#yong").css("border-color", "")
fl2 = true;
}
}
//判断手机号
var fl3 = false;
function a4() {
var utel1 = $scope.utel1;
if(utel1 == "" || utel1 == null) {
$("#sp3").text("手机号不能为空")
$("#utel1").css("border-color", "red")
fl3 = false;
} else {
var aa = /^[0-9]*$/
if(!aa.test(utel1)) {
$("#sp3").text("手机号为纯数字")
$("#utel1").css("border-color", "red")
fl3 = false;
} else {
$("#sp3").text("");
$("#utel1").css("border-color", "")
fl3 = true;
}
}
}
//判断价格
var fl4 = false;
function a5() {
//不能为空
var uprice1 = $scope.uprice1;
if(uprice1 == "" || uprice1 == null) {
$("#sp4").text("价格不能为空")
$("#uprice1").css("border-color", "red")
fl4 = false;
} else {
$("#sp4").text("")
$("#uprice1").css("border-color", "")
var jia = /^[0-9]+([.]{1}[0-9]+){0,1}$/;
if(!jia.test(uprice1)) {
$("#sp4").text("价格为整数或小数")
$("#uprice1").css("border-color", "red")
fl4 = false;
} else {
fl4 = true
}
}
}
//判断城市
var fl5=false;
function a6() {
var chengshi = $scope.chengshi;
if(chengshi=="--请选择城市--"){
$("#sp5").text("城市必须选择")
$("#chengshi").css("border-color", "red")
fl5=false
}else{
$("#sp5").text("")
$("#chengshi").css("border-color", "")
fl5=true
}
}
//添加方法
$scope.bao = function() {
a2();
if(fl1 == true) {
a3();
if(fl2 == true) {
a4();
if(fl3 == true) {
a5();
if(fl4 == true) {
a6();
if(fl5==true){
//创建对象
var g = {
"uid": a1(),
"uname": $scope.uname1,
"name": $scope.yong,
"tel": $scope.utel1,
"price": $scope.uprice1,
"cheng": $scope.chengshi,
"shi": new Date().getTime(),
"fal": false
};
//添加
arr.push(g);
$scope.goods = arr;
//隐藏表单
$scope.show = false;
/*//清空
if($scope.show == false) {
$(".div3 input").val("");
$(".div3 select").val("--请选择城市--");
}*/
}
}
}
}
}
}
});
//自定义过滤器
mo.filter("myfil", function() {
return function(fal) {
if(fal) {
return "已发货"
} else {
return "未发货";
}
}
return fal;
})
</script>
</html>