商品订单:数据的判断、添加,批量删除,排序,模糊查询

来源:互联网 发布:mac opengl 编辑:程序博客网 时间:2024/05/29 10:26
<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title></title>
  <script type="text/javascript" src="../js/agular/angular.js" ></script>
  <style type="text/css">
   .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;
   }
  </style>
  <script type="text/javascript">
   var app=angular.module("myApp",[]);
   var time1 = new Date("2017-12-19 10:00:00");
   var time2 = new Date("2017-12-19 12:00:00");
   var time3 = new Date("2017-12-19 14:00:00");
   var time4 = new Date("2017-12-19 16:00:00");
   app.controller("myCtrl",function($scope){
    //模拟数据
    $scope.shops=[{
      "id": 123,
      "sname": "iphonex",
      "yname": "张三",
      "tel": 13716167236,
      "price": 8699,
      "city": "北京",
      "time": time1,
      "orderState": true,
      "state": false

     },
     {
      "id": 456,
      "sname": "iphone6",
      "yname": "王红",
      "tel": 10086121212,
      "price": 5635,
      "city": "郑州",
      "time": time4,
      "orderState": true,
      "state": false
     },
     {
      "id": 789,
      "sname": "iphone7",
      "yname": "赵小龙",
      "tel": 13693324137,
      "price": 6180,
      "city": "北京",
      "time": time3,
      "orderState": false,
      "state": false
     },
     {
      "id": 110,
      "sname": "iphone8",
      "yname": "赵强",
      "tel": 13722335577,
      "price": 7190,
      "city": "上海",
      "time": time2,
      "orderState": false,
      "state": false
     }];
     
     //更改状态
     $scope.changeOrderState=function(shop){
      shop.orderState=true;
     }
     
     //批量删除已发货商品
     $scope.deleteSel=function(){
      var selArr=[];
      for(index in $scope.shops){
       if($scope.shops[index].state){
        if($scope.shops[index].orderState){
         selArr.push($scope.shops[index]);
        }
       }
      }
      
      if(selArr.length>0){
       for(index1 in selArr){
        for(index2 in $scope.shops){
         if(selArr[index1]==$scope.shops[index2]){
          $scope.shops.splice(index2,1);
         }
        }
       }
      }else{
       alert("先选择被选中的已发货商品");
      }
      
     }
     
     //点击列名 进行排序
     $scope.flag="";
     $scope.column="id";
     $scope.orderColumn=function(column){
      $scope.column=column;
      if($scope.flag==""){
       $scope.flag="-";
      }else{
       $scope.flag="";
      }
     }
     
     //添加商品
     $scope.addshop=function(){
      var flag1=false;
      var flag2=false;
      var flag3=false;
      var flag4=false;
      var flag5=false;
      var flag6=false;
      var flag7=false;
      
      if($scope.newID==""||$scope.newID==null){
       alert("ID不能为空");
       flag1=false;
      }else if(isNaN($scope.newID)){
       alert("ID必须为数字");
       flag1=false;
      }else{
       flag1=true;
      }
      
      if($scope.newShop==""||$scope.newShop==null){
       alert("商品名不能为空");
       flag2=false;
      }else{
       flag2=true;
      }
      
      if($scope.newName==""||$scope.newName==null){
       alert("用户名不能为空");
       flag3=false;
      }else{
       flag3=true;
      }
      if(isNaN($scope.newTel)){
       alert("手机号要是数字");
       flag4=false;
      }else if($scope.newTel.length != 11){
       alert("请输入正确手机号");
       flag4=false;
      }else{
       flag4=true;
      }
      
      if($scope.newPrice==""||$scope.newPrice==null){
       alert("价格不能为空");
       flag5=false;
      }else{
       flag5=true;
      }
      
      if($scope.newCity==""||$scope.newCity==null){
       alert("城市不能为空");
       flag6=false;
      }else{
       flag6=true;
      }
      
      if($scope.newTime==""||$scope.newTime==null){
       alert("时间不能为空");
       flag7=false;
      }else{
       flag7=true;
      }
      //添加
      if(flag1 && flag2 && flag3 && flag4 && flag5 && flag6 && flag7){
       $scope.shops.push({
        id:$scope.newID,
        sname:$scope.newShop,
        yname:$scope.newName,
        tel:$scope.newTel,
        price:$scope.newPrice,
        city:$scope.newCity,
        time:$scope.newTime,
       });
      }
      
     }
     
   });
  </script>
 </head>
 <body ng-app="myApp" ng-controller="myCtrl">
  <center>
   <h3>商品订单管理</h3>
   <table border="1px" cellpadding="10" cellspacing="0">
    <input type="button" value="新增订单" />
    <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="selectAll" /></th>
     <th>id<input type="submit" value="排序" ng-click="pid(shop,id)"/></th>
     <th>商品名</th>
     <th>用户名</th>
     <th>手机号</th>
     <th>价格<input type="submit" value="排序"/></th>
      <th>城市</th>
      <th>下单时间<input type="button" ng-click="orderColumn('time')" value="排序"/></th>
      <th>状态</th>
    </tr>
    //filter:{sname:search,tel:telNum,orderState:orderStateSel} 查询商品 手机号
    <tr ng-repeat="shop in shops | filter:{sname:search,tel:telNum,orderState:orderStateSel} | orderBy:flag+column">
     <td><input type="checkbox" ng-model="shop.state" /></td>
     <td>{{shop.id}}</td>
     <td>{{shop.sname}}</td>
     <td>{{shop.yname}}</td>
     <td>{{shop.tel}}</td>
     <td>{{shop.price | currency:"¥:"}}</td>
     <td>{{shop.city}}</td>
     <td>{{shop.time | date:"yyyy-MM-dd hh:mm:ss"}}</td>
     <td>
      <button disabled="disabled" style="background: green; border: none;" ng-show="shop.orderState">已发货</button>
      <button style="background: yellow; border: none;" ng-show="!shop.orderState" ng-click="changeOrderState(shop)">未发货</button>
     </td>
    </tr>
    
   </table>
   <fieldset id="" style="width: 500px;">
    <legend>添加商品列表</legend>
    <table border="1" cellpadding="10" cellspacing="0">
     <tr>
      <td>id</td>
      <td><input type="text" ng-model="newID"/></td>
     </tr>
     <tr>
      <td>商品名</td>
      <td><input type="text" ng-model="newShop"/></td>
     </tr>
     <tr>
      <td>用户名</td>
      <td><input type="text" ng-model="newName"/></td>
     </tr>
     <tr>
      <td>手机号</td>
      <td><input type="text" ng-model="newTel"/></td>
     </tr>
     <tr>
      <td>价格</td>
      <td><input type="text" ng-model="newPrice"/></td>
     </tr>
     <tr>
      <td>城市</td>
      <td><input type="text" ng-model="newCity"/></td>
     </tr>
     <tr>
      <td>下单时间</td>
      <td><input type="text" ng-model="newTime"/></td>
     </tr>
     <tr>
      <td colspan="2"><input type="submit" value="提交" ng-click="addshop()"/></td>
     </tr>
    </table>
   </fieldset>
   
  </center>
 </body>
</html>
阅读全文
0 0