您的位置:首页 > 其它

添加验证,根据状态删除

2017-12-21 09:03 176 查看
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/angular.js"></script>
<script src="js/jquery-2.1.0.js"></script>
<style>
.kuan{
width: 100px;
height: 20px;
border-top-left-radius: 5em;
border-top-right-radius: 5em;
border-bottom-right-radius: 5em;
border-bottom-left-radius: 5em;
margin-left: 10px;
}
.sjh{
width: 100px;
height: 20px;
border-top-left-radius: 5em;
border-top-right-radius: 5em;
border-bottom-right-radius: 5em;
border-bottom-left-radius: 5em;
margin-left: 10px;
}
.ya{
border: 1px solid red;
}
.ya2{
background-color: yellow;
border: 1px solid red;
}
</style>
<script>

var app = angular.module("myApp",[]);
var time1 = new Date("2017-12-19 9:41:53");
var time2 = new Date("2017-12-18 10:41:53");
var time3 = new Date("2017-12-17 11:41:53");
var time4 = new Date("2017-12-16 12:41:53");
app.controller("myCtrl",function($scope){

$scope.orders = [{
id:2001,
sname:"iPhoneX",
yname:"张三",
telnum:13525565588,
price:8699.00,
city:"北京",
time:time1,
orderState:true,
state:false
},{
id:3006,
sname:"iPhone6",
yname:"王红",
telnum:18524565588,
price:5635.00,
city:"郑州",
time:time2,
orderState:true,
state:false
},{
id:5312,
sname:"iPhone7",
yname:"赵小龙",
telnum:17545585598,
price:6180.00,
city:"北京",
time:time3,
orderState:false,
state:false
},{
id:2132,
sname:"iPhone8",
yname:"赵强",
telnum:17625565618,
price:7190.00,
city:"上海",
time:time4,
orderState:false,
state:false
}];
//更改状态
$scope.changeorderState = function(or){
or.orderState = true;
}
//全选,全不选
$scope.selsectAll = false;
$scope.selectFun = function(){
if($scope.selsectAll){
for(index in $scope.orders){
$scope.orders[index].state = true;
}
}else{
for(index in $scope.orders){
$scope.orders[index].state = false;
}
}
}
//批量删除已发货商品
$scope.deleteSel = function(){
var selArr = [];
for(index in $scope.orders){
if($scope.orders[index].state){//多选框被选中的商品
if($scope.orders[index].orderState){//多选框被选中的已发货商品
selArr.push($scope.orders[index]);
}
}
}

if(selArr.length > 0){
for(index in selArr){
for(index2 in $scope.orders){
if(selArr[index] == $scope.orders[index2]){
$scope.orders.splice(index2,1);
}
}
}
}else{
alert("先选择被选中的已发货商品");
}
}
//id排序
$scope.flag = "";
$scope.bname = "id";
$scope.pid = function(bname){
$scope.bname = bname;
if($scope.flag == ""){
$scope.flag = "-";
}else{
$scope.flag = "";
}
}
//价格排序
$scope.flag = "";
$scope.bname = "id";
$scope.pprice = function(bname){
$scope.bname = bname;
if($scope.flag == ""){
$scope.flag = "-";
}else{
$scope.flag = "";}
}
//时间排序
$scope.flag = "";
$scope.bname = "id";
$scope.ptime = function(bname){
$scope.bname = bname;
if($scope.flag == ""){
$scope.flag = "-";
}else{
$scope.flag = "";
}
}
//添加数据保存
$scope.show = false;
$scope.add = function(){
$scope.show = true;
}
$scope.s1 = false; var flag1 = false;
$scope.s2 = false; var flag2 = false;
$scope.s3 = false; var flag3 = false;
$scope.s4 = false; var flag4 = false;
$scope.s5 = false; var flag5 = false;
$scope.s6 = false; var flag6 = false;
$scope.keep = function(){

//判断id
if($scope.jid == "" || $scope.jid == null){
$("#j1").addClass("ya");
$("#i1").addClass("ya2");

$scope.s1 = true;
flag1 = false;
}else{
$scope.s1 = false;
$("#j1").removeClass("ya");
flag1 = true;
}
//判断商品名
if($scope.jsname == "" || $scope.jsname == null){
$("#j2").addClass("ya");
$("#i2").addClass("ya2");

$scope.s2 = true;
flag2 = false;
}else{
$scope.s2 = false;
$("#j2").removeClass("ya");
flag2 = true;
}
//判断用户名
if($scope.jyname == "" || $scope.jyname == null){
$("#j3").addClass("ya");
$("#i3").addClass("ya2");

$scope.s3 = true;
flag3 = false;
}else{
$scope.s3 = false;
$("#j3").removeClass("ya");
flag3 = true;
}
//判断手机号
if($scope.jtelnum == "" || $scope.jtelnum == null){
$("#j4").addClass("ya");
$("#i4").addClass("ya2");

$scope.s4 = true;
flag4 = false;
}else{
$scope.s4 = false;
$("#j4").removeClass("ya");
flag4 = true;
}
//判断价格
if($scope.jprice == "" || $scope.jprice == null){
$("#j5").addClass("ya");
$("#i5").addClass("ya2");

$scope.s5 = true;
flag5 = false;
}else{
$scope.s5 = false;
$("#j5").removeClass("ya");
flag5 = true;
}
//判断城市
if($scope.jcity == "" || $scope.jcity == null){
$("#j6").addClass("ya");
$("#i6").addClass("ya2");

$scope.s6 = true;
flag6 = false;
}else{
$scope.s6 = false;
$("#j6").removeClass("ya");
flag6 = true;
}

if(flag1 && flag2 && flag3 && flag4 && flag5 && flag6 ){
$scope.orders.push({
id:$scope.jid,
sname:$scope.jsname,
yname:$scope.jyname,
telnum:$scope.jtelnum,
price:$scope.jprice,
city:$scope.jcity
});
}
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<h3>商品订单管理系统</h3>
<table border="1" cellpadding="10" cellspacing="0">
<input type="button" value="新增订单" ng-click="add()" />
<input type="button" value="批量删除" ng-click="deleteSel()" />
<input type="text" placeholder="按照商品名称查询..." class="kuan" ng-model="search" />
<input type="text" placeholder="按照手机号查询..." class="sjh" ng-model="telNum" />

<select style="margin-left: 30px;" ng-model="orderStateSel">
<option value="">--按照状态查询--</option>
<option value="true">--已发货--</option>
<option value="false">--未发货--</option>
</select><br /><br />

<tr>
<th><input type="checkbox" ng-click="selectFun()" ng-model="selsectAll"/></th>
<th width="60px" align="center">id<input type="button" value="排序" ng-click="pid('id')"/></th>
<th>商品名</th>
<th width="50px">用户名</th>
<th>手机号</th>
<th width="80px">价格<input type="button" value="排序" ng-click="pprice('price')"/></th>
<th width="40px">城市</th>
<th>下单时间<input type="button" value="排序" ng-click="ptime('time')"/></th>
<th>状态</th>
</tr>

<tr ng-repeat="or in orders | filter:{sname:search,telnum:telNum,orderState:orderStateSel} | orderBy:flag+bname">
<td><input type="checkbox" ng-model="or.state"/></td>
<td>{{or.id}}</td>
<td>{{or.sname}}</td>
<td>{{or.yname}}</td>
<td>{{or.telnum}}</td>
<td>{{or.price | currency:"¥:"}}</td>
<td>{{or.city}}</td>
<td width="200px" align="center">{{or.time | date:"yyyy--MM-dd hh:mm:ss"}}</td>
<td width="120px" align="center">
<button style="background: green; border: none;" ng-show="or.orderState">已发货</button>
<button style="background: yellow; border: none;" ng-show="!or.orderState" ng-click="changeorderState(or)">未发货</button>
</td>
</tr>
</table><br /><br />

<fieldset style="width: 500px;" ng-show="show">
<legend>添加商品列表</legend><br /><br />

<div>
id<input type="text" style="margin-left: 12px;" ng-model="jid" id="j1"/> <input type="text" ng-show="s1"  id="i1" placeholder="id不能为空"/><br /><br />

商品名<input type="text" ng-model="jsname" id="j2"/> <input type="text" ng-show="s2" id="i2" placeholder="商品名不能为空"/><br /><br />

用户名<input type="text" ng-model="jyname" id="j3"/> <input type="text" ng-show="s3" id="i3" placeholder="用户号不能为空"/><br /><br />

手机号<input type="text" ng-model="jtelnum" id="j4"/> <input type="text" ng-show="s4" id="i4" placeholder="手机号不能为空"/><br /><br />

价格 <input type="text" ng-model="jprice" id="j5"/> <input type="text" ng-show="s5" id="i5" placeholder="价格不能为空"/><br /><br />

城市 <select ng-model="jcity" id="j6">
<option value="">---选择城市</option>
<option value="北京">北京</option>
<option value="上海">上海</option>
<option value="深圳">深圳</option>
</select> <input type="text" ng-show="s6" id="i6" placeholder="城市必须选择"/>
<br /><br />

<button ng-click="keep()">保存</button>

</div>
</fieldset>
</center>
</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐