一.实现要求
1、 完成页面(30分)
2、 点击“新增订单”,弹出上框,新增订单状态都是“待发货”
3、 每个排序5分
4、 提交订单时,检查表单,提示错误内容,并且将文本框颜色变红色(错误提示:10分,提交成功:5分)
5、 选择状态查询:待发货、已发货、已收货(5分)
6、 点击“发货”按钮,将“待发货”状态改成“已发货”(10分)
7、 通过Checkbox全选和全不选(5分)
8、 点击“批量删除”按钮,删除选中的订单(10分)
9、 选择“开始月份”:01~12
10、 选择“结束月份”:01~12,查询开始月份和结束月份之间的订单(10分)
二.实现代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="angular-1.3.0.js"></script>
<script type="text/javascript" src="jquery.1.12.4.js"></script>
<title>练习</title>
<style>
*{
margin: 10px auto;
}
.even_cls {
background-color: #fff;
}
.odd_cls {
background-color: #cccccc;
}
table{
width: 1095px;
height: 50px;
}
td, th {
border: 1px solid gainsboro;
text-align: center;
}
button {
width: 100px;
height: 40px;
background: #087E08;
color: white;
border: 0px;
border-radius: 5px;
}
.search {
width: 1083px;
height: 50px;
line-height: 50px;
margin-bottom: 10px;
}
.search input {
width: 230px;
height: 25px;
color: #999;
padding: 5px;
border-radius: 5px;
border: 1px solid gainsboro;
}
.search select{
width: 100px;
height: 26px;
border: 1px solid #999;
border-radius: 4px;
margin-left: 10px;
}
.search1{
width: 1083px;
height: 50px;
line-height: 50px;
margin-bottom: 10px;
}
.search1 button {
background: #087E08;
}
.form {
width: 600px;
border: 1px solid #999;
margin: 0 auto;
}
h3{
margin-left: 20px;
}
.form .label {
display: block;
float: left;
width: 80px;
height: 40px;
line-height: 40px;
text-align: end;
}
.form input {
width: 312px;
height: 24px;
border: 1px solid #999;
border-radius: 4px;
padding-left: 8px;
}
.form .txt {
display: block;
float: left;
width: 340px;
height: 40px;
line-height: 40px;
padding-left: 16px;
}
.form button {
width: 56px;
height: 24px;
background-color: green;
border: 0;
border-radius: 4px;
color: white;
}
.form .errTips {
width: 226px;
background-color: lightpink;
color: darkred;
border-radius: 4px;
margin-left: 96px;
margin-top: 6px;
margin-bottom: 4px;
padding: 16px 48px;
}
.form select {
width: 84px;
height: 24px;
border: 1px solid #999;
border-radius: 4px;
}
.btn{
width: 45px;
height: 25px;
text-align: center;
}
.btn1{
width: 40px;
height: 25px;
text-align: center;
}
.btn2{
width: 86px;
height: 30px;
text-align: center;
}
.active {
color: red;
}
</style>
<script>
var flag=false;
var data =
[
{"id": 1, "phone_name": 'iPhone4',"name":'张三',"phone_num":'15111111111', "price": 4999, "city": '北京',"time":'08-01 10:00', status: "待发货"},
{"id": 2, "phone_name": '小米6',"name":'李四', "phone_num":'15222222222', "price": 2999, "city": '北京',"time":'08-02 10:00', status: "待发货"},
{"id": 3, "phone_name": '华为R9',"name":'王五', "phone_num":'15333333333', "price": 3999, "city": '上海',"time":'08-03 10:00', status: "已发货"},
{"id": 4, "phone_name": 'OPPO R11',"name":'赵六',"phone_num":'15444444444', "price": 4999, "city": '天津',"time":'09-04 10:00', status: "已收货"},
{"id": 5, "phone_name": 'VIVO',"name":'周七',"phone_num":'15555555555', "price": 2999, "city": '重庆',"time":'10-04 10:00', status: "已发货"},
];
var myapp = angular.module("myapp", []);
myapp.controller("myCtrl", function ($scope) {
$scope.myFromshow=false;
$scope.s1 = false;
$scope.s2 = false;
$scope.s3 = false;
$scope.s4 = false;
$scope.s5 = false;
$scope.s6 = false;
$scope.s7 = false;
//添加
$scope.add = function() {
//判断是否为空
if ($scope.phone_name == undefined || $scope.phone_name == "") {
$scope.myFromshow = true;
$scope.s1 = true;
$scope.myObj = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj = {
"border": "1px solid #999"
}
}
//判断商品名是否是6-20个字符
if ($scope.phone_name.length < 6 || $scope.phone_name.length > 20) {
$scope.myFromshow = true;
$scope.s2 = true;
$scope.myObj = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj = {
"border": "1px solid #999"
}
}
//判断用户名是否为空
if ($scope.name == undefined || $scope.name == "") {
$scope.myFromshow = true;
$scope.s3 = true;
$scope.myObj1 = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj1 = {
"border": "1px solid #999"
}
}
//判断用户名是否是6-20个字符
if ($scope.name.length < 4 || $scope.name.length > 16) {
$scope.myFromshow = true;
$scope.s4 = true;
$scope.myObj1 = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj1 = {
"border": "1px solid #999"
}
}
//判断手机号是否为空
if ($scope.phone_num == undefined || $scope.phone_num == "") {
$scope.myFromshow = true;
$scope.s5 = true;
$scope.myObj2 = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj2 = {
"border": "1px solid #999"
}
}
//判断手机号是否合格
if($scope.phone_num.length!=11){
$scope.myFromshow=true;
$scope.s6 = true;
$scope.myObj3 = {
"border" : "1px solid red"
}
return;
}else{
$scope.myObj3 = {
"border" : "1px solid #999"
}
}
//判断是否选择城市
if ($scope.city == undefined || $scope.city == "") {
$scope.myFromshow = true;
$scope.s7 = true;
$scope.myObj3 = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj3 = {
"border": "1px solid #999"
}
}
for(var i=2;i<$scope.data.length;i++) {
$scope.id = $scope.data[0].id+$scope.data[0+i].id;
$scope.price = $scope.data[i].price;
$scope.time = $scope.data[i].time;
}
$scope.data.push({
id:$scope.id,
phone_name:$scope.phone_name,
name:$scope.name,
phone_num:$scope.phone_num,
city:$scope.city,
price: $scope.price,
time: $scope.time,
});
$scope.phone_name="";
$scope.name="";
$scope.phone_num="";
$scope.city="";
$scope.addUserIsShow = false;
};
$scope.addUser = function(){
$scope.addUserIsShow = true;
};
//排序
$scope.order2 = function (num) {
if($scope.count1==2){
flag=true;
}else{
flag=false;
}
data.sort(function(a,b){
if(flag){
return a.id> b.id?1:-1;
}else{
return a.id< b.id?1:-1;
}
})
}
//默认为倒序
$scope.data = data;
data.sort(function(a,b){
if(flag){
return a.id> b.id?1:-1;
}else{
return a.id< b.id?1:-1;
}
});
//设置页面默认显示
$scope.show = true;
//设置checkbox默认不选中
$scope.chk = false;
$scope.xuanz = false;
$scope.check = function (val) {
//判断是否选中,然后控制下方的是否选中
if (val) {
$scope.xuanz = true;
} else {
$scope.xuanz = false;
}
}
//批量删除
$scope.search;
// 删除
$scope.remove = function (index) {
var b = confirm("确认删除");
if (b) {
$scope.data.splice(index, 1);
}
}
$scope.del = function () {
if ($scope.xuanz || $scope.checkD) {
var b = confirm("确认删除");
if (b) {
//删除所有商品信息
if ($scope.chk) {
$scope.data.splice(0, $scope.data.length);
$scope.show = false;
$scope.hide = true;
} else {
for (var i = $scope.xuan1.length - 1; i >= 0; i--) {
console.log($scope.xuan1[i]);
for (var j = 0; j < $scope.data.length; j++) {
console.log($scope.data[j].id == $scope.xuan1[i]);
if ($scope.data[j].id == $scope.xuan1[i]) {
$scope.data.splice(j, 1);
}
}
}
}
}
} else {
alert("先进行选中要删除的商品信息");
}
}
//批量发货
$scope.goods = function(){
if ($scope.xuanz || $scope.checkD) {
var b = confirm("确认发货");
if (b) {
if ($scope.chk) {
for (var i in $scope.data) {
if ($scope.data[i].status == "待发货") {
$scope.data[i].status = "已发货";
}
}
} else {
for (var i = $scope.xuan1.length - 1; i >= 0; i--) {
for (var j = 0; j < $scope.data.length; j++) {
if ($scope.data[j].id == $scope.xuan1[i]) {
$scope.data[j].status = "已发货";
}
}
}
}
}
} else {
alert("先进行选中要发货的商品信息");
}
};
//全选
$scope.checkD = false;
$scope.xuan1 = [];
$scope.xuan = function (xuanl, id) {
console.log(id);
$scope.checkD = xuanl;
if (xuanl) {
$scope.xuan1.push(id);
}
}
// 将待发货,改成已发货
$scope.deliver = function (id) {
for (var i in $scope.data) {
if ($scope.data[i].id == id) {
$scope.data[i].status = "已发货";
}
}
};
//选择月份
$scope.filterByMonth = function (item) {
if ($scope.filter_begin_month == undefined || $scope.filter_begin_month == "") {
return true;
}
if ($scope.filter_end_month == undefined || $scope.filter_end_month == "") {
return true;
}
if ($scope.filter_begin_month > $scope.filter_end_month) {
return true;
}
var month = item.time.substr(0, item.time.indexOf("-"));
month = parseInt(month);
return (month >= $scope.filter_begin_month && month <= $scope.filter_end_month);
};
//按照价钱排序
$scope.changePriceOrderType = function () {
if ($scope.price_order_type == "price") {
$scope.price_order_type = "-price";
} else {
$scope.price_order_type = "price";
}
};
//按照时间排序
$scope.changeTimeOrderType = function () {
if ($scope.time_order_type == "time") {
$scope.time_order_type = "-time";
} else {
$scope.time_order_type = "time";
}
};
//全部删除
$scope.removeAll = function () {
var b = confirm("确认全部删除");
if(b){
$scope.data = [];
$scope.show=false;
$scope.hide=true;
}
};
//修改内容
$scope.editUser = function (index) {
var item = $scope.data[index];
$scope.id = item.id;
$scope.name = $scope.data[index].name;
$scope.phone_name=$scope.data[index].phone_name;
$scope.phone_num = $scope.data[index].phone_num;
$scope.city=$scope.data[index].city;
$scope.editUserIsShow = true;
$scope.index = index;
};
$scope.edit = function () {
//判断是否为空
if ($scope.phone_name == undefined || $scope.phone_name == "") {
$scope.myFromshow = true;
$scope.s1 = true;
$scope.myObj = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj = {
"border": "1px solid #999"
}
}
//判断商品名是否是6-20个字符
if ($scope.phone_name.length < 6 || $scope.phone_name.length > 20) {
$scope.myFromshow = true;
$scope.s2 = true;
$scope.myObj = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj = {
"border": "1px solid #999"
}
}
//判断用户名是否为空
if ($scope.name == undefined || $scope.name == "") {
$scope.myFromshow = true;
$scope.s3 = true;
$scope.myObj1 = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj1 = {
"border": "1px solid #999"
}
}
//判断用户名是否是6-20个字符
if ($scope.name.length < 4 || $scope.name.length > 16) {
$scope.myFromshow = true;
$scope.s4 = true;
$scope.myObj1 = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj1 = {
"border": "1px solid #999"
}
}
//判断手机号是否为空
if ($scope.phone_num == undefined || $scope.phone_num == "") {
$scope.myFromshow = true;
$scope.s5 = true;
$scope.myObj2 = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj2 = {
"border": "1px solid #999"
}
}
//判断手机号是否合格
if($scope.phone_num.length!=11){
$scope.myFromshow=true;
$scope.s6 = true;
$scope.myObj3 = {
"border" : "1px solid red"
}
return;
}else{
$scope.myObj3 = {
"border" : "1px solid #999"
}
}
//判断是否选择城市
if ($scope.city == undefined || $scope.city == "") {
$scope.myFromshow = true;
$scope.s7 = true;
$scope.myObj3 = {
"border": "1px solid red"
}
return;
} else {
$scope.myObj3 = {
"border": "1px solid #999"
}
}
$scope.data[$scope.index].phone_name = $scope.phone_name;
$scope.data[$scope.index].name = $scope.name;
$scope.data[$scope.index].phone_num = $scope.phone_num;
$scope.data[$scope.index].city = $scope.city;
$scope.addUserIsShow = false;
$scope.editUserIsShow = false;
};
})
</script>
</head>
<div ng-app="myapp" ng-controller="myCtrl">
<div class="search">
<input type="text" placeholder="用户名搜索" ng-model="search">
<input type="text" placeholder="手机号搜索" ng-model="search_phone">
<select class="level" ng-model="search_city" >
<option value="">选择城市</option>
<option value="北京">北京</option>
<option value="上海">上海</option>
<option value="天津">天津</option>
<option value="重庆">重庆</option>
</select>
<select class="level" ng-model="filter_status">
<option value="">选择状态</option>
<option value="待发货">待发货</option>
<option value="已发货">已发货</option>
<option value="已收货">已收货</option>
</select>
<select class="level" 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>
<span style="margin-left: 5px;">-</span>
<select class="level" 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>
<select ng-model="count1" ng-change="order2()">
<option value="">ID倒序</option>
<option value="2">ID正序</option>
</select>
</div>
<div class="search1">
<button class="tian" ng-click="addUser()">新增订单</button>
<button class="tian" ng-click="goods(item.id)">批量发货</button>
<button ng-click="del()">批量删除</button>
<button ng-click="removeAll()">全部删除</button>
<h3 ng-show="hide">您的商品为空,去逛超市</h3>
</div>
<!--用来遍历对象并渲染到页面中-->
<table cellpadding="10" cellspacing="0" ng-show="show">
<thead style="background-color: #777777">
<th><input type="checkbox" ng-model="chk" ng-click="check(chk)"></th>
<th>ID</th>
<th>商品名</th>
<th>用户名</th>
<th>手机号</th>
<th>价格 <button ng-click="changePriceOrderType()" class="btn">排序</button> </th>
<th>城市</th>
<th>下单时间<button ng-click="changeTimeOrderType()" class="btn1">排序</button></th>
<th>状态</th>
<th colspan="2">数据操作</th>
</thead>
<tbody>
<!--实现模糊查询-->
<tr ng-repeat="item in data| filter:{name:search} | filter: {phone_num: search_phone} | filter: {status: filter_status} | filter: filterByMonth | filter: {city: search_city}| orderBy: price_order_type | orderBy: time_order_type " ng-class="{even_cls: !$even, odd_cls: !$odd}">
<td><input type="checkbox" ng-model="xuanz" ng-click="xuan(xuanz,item.id)"></td>
<td>{{item.id}}</td>
<td> {{item.phone_name}}</td>
<td> {{item.name}}</td>
<td> {{item.phone_num}}</td>
<td>{{item.price | currency:"¥"}}</td>
<td>{{item.city}}</td>
<td>{{item.time}}</td>
<td>
<span ng-show="item.status=='待发货'" ng-click="deliver(item.id)">
<a href="javascript: void(0);">发货</a>
</span>
<span ng-show="item.status=='已发货'">已发货</span>
<span ng-show="item.status=='已收货'">已收货</span>
</td>
<td><button ng-click="editUser($index)" class="btn2">修改内容</button></td>
<td>
<button ng-click="remove()" class="btn2">删除</button>
</td>
</tr>
</tbody>
</table>
<div class="form" ng-show="addUserIsShow">
<h3>新增订单</h3>
<div>
<span class="label">商品名</span>
<span class="txt"><input type="text" placeholder="6-20个字符" ng-model="phone_name" ng-style="myObj" /></span>
</div>
<div style="clear: both"></div>
<div>
<span class="label">用户名</span>
<span class="txt"><input type="text" placeholder="4-16个字符" ng-model="name" ng-style="myObj1" /></span>
</div>
<div style="clear: both"></div>
<div>
<span class="label">手机号</span>
<span class="txt"><input type="text" ng-model="phone_num" ng-style="myObj2" /></span>
</div>
<div style="clear: both"></div>
<div>
<span class="label">城市</span>
<span class="txt">
<select ng-model="city" ng-style="myObj3">
<option value="">选择城市</option>
<option value="1">北京</option>
<option value="2">上海</option>
<option value="3">天津</option>
<option value="4">重庆</option>
</select>
</span>
</div>
<div style="clear: both"></div>
<div class="errTips" ng-show="myFromshow">
<ul>
<li ng-show="s1">商品名不能为空!</li>
<li ng-show="s2">商品名必须是6-20个字符!</li>
<li ng-show="s3">用户名不能为空!</li>
<li ng-show="s4">用户名必须是4-16个字符!</li>
<li ng-show="s5">手机号不能为空!</li>
<li ng-show="s6">手机号格式不正确!</li>
<li ng-show="s7">请选择城市!</li>
</ul>
</div>
<div style="clear: both"></div>
<div>
<span class="label"></span>
<span class="txt"><button ng-click="add()">提交</button></span>
</div>
<div style="clear: both"></div>
</div>
<div class="form" ng-show="editUserIsShow">
<h3>修改订单</h3>
<div>
<span class="label">商品名</span>
<span class="txt"><input type="text" placeholder="6-20个字符" ng-model="phone_name" ng-style="myObj" /></span>
</div>
<div style="clear: both"></div>
<div>
<span class="label">用户名</span>
<span class="txt"><input type="text" placeholder="4-16个字符" ng-model="name" ng-style="myObj1" /></span>
</div>
<div style="clear: both"></div>
<div>
<span class="label">手机号</span>
<span class="txt"><input type="text" ng-model="phone_num" ng-style="myObj2" /></span>
</div>
<div style="clear: both"></div>
<div>
<span class="label">城市</span>
<span class="txt">
<select ng-model="city" ng-style="myObj3">
<option value="">选择城市</option>
<option value="1">北京</option>
<option value="2">上海</option>
<option value="3">天津</option>
<option value="4">重庆</option>
</select>
</span>
</div>
<div style="clear: both"></div>
<div class="errTips" ng-show="myFromshow">
<ul>
<li ng-show="s1">商品名不能为空!</li>
<li ng-show="s2">商品名必须是6-20个字符!</li>
<li ng-show="s3">用户名不能为空!</li>
<li ng-show="s4">用户名必须是4-16个字符!</li>
<li ng-show="s5">手机号不能为空!</li>
<li ng-show="s6">手机号格式不正确!</li>
<li ng-show="s7">请选择城市!</li>
</ul>
</div>
<div style="clear: both"></div>
<div>
<span class="label"></span>
<span class="txt"><button ng-click="edit()">提交</button></span>
</div>
<div style="clear: both"></div>
</div>
</div>
</body>
</html>