(angularjs+jQuery)商品表(增删改查)+表单判断+各种排序方式
2017-10-25 19:29
555 查看
<!DOCTYPE html> <html ng-app="OrderApp"> <head> <meta charset="UTF-8"> <title>订单管理</title> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <script type="text/javascript" src="jquery.1.12.4.js"></script> <script type="text/javascript" src="angular-1.3.0.js"></script> <script type="text/javascript" src="data.js"></script> <style type="text/css"> * { font-size: 14 4000 px; margin: 0; padding: 0; } body { padding: 16px 32px; } .filter { position: relative; width: 800px; height: 40px; margin: 0 auto; } .filter input { width: 146px; height: 24px; border: 1px solid #999; border-radius: 4px; padding-left: 8px; } .filter select { width: 82px; height: 24px; border: 1px solid #999; border-radius: 4px; } .buttons { width: 800px; height: 40px; margin: 0 auto; } .buttons button { width: 80px; height: 24px; background-color: green; border: 0; border-radius: 4px; color: white; } .list { width: 800px; margin: 0 auto; } .list table tr { height: 32px; } .list thead tr { background-color: #777; } .list tbody tr:nth-child(odd) { background-color: #ccc; } .list tbody tr:nth-child(even) { background-color: #fff; } .list button { width: 40px; height: 18px; line-height: 18px; background-color: green; border: 0; border-radius: 4px; color: white; font-size: 8px; } .form { width: 460px; border: 1px solid #999; margin: 0 auto; } .form div { clear: both; } .form .formErr { border: 1px solid red; } .form .label { display: block; float: left; width: 80px; height: 40px; line-height: 40px; text-align: end; } .form .txt { display: block; float: left; width: 340px; height: 40px; line-height: 40px; padding-left: 16px; } .form input { width: 312px; height: 24px; border: 1px solid #999; border-radius: 4px; padding-left: 8px; } .form select { width: 86px; height: 24px; border: 1px solid #999; border-radius: 4px; } .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; } </style> <script type="text/javascript"> // 全选/全不选 $(function () { $("input[name='check_all']").click(function () { var checked = this.checked; // 获取 <input type="checkbox" name="check_all"/> 中checked属性的值 $("input[name='order_id[]']").each(function () { this.checked = checked; // 依次设置每一个 <input type="checkbox" name="order_id[]"/> 中checked属性的值 }); }); }); var app = angular.module("OrderApp", []); // 敏感词 app.filter("sensitiveWord", function () { return function (msg, flag) { return msg.replace(flag, "*"); } }); app.controller("OrderCtrl", function ($scope) { $scope.data = data; var id = 12; //用过月份过滤 $scope.filterByMonth = function (order) { if ($scope.filter_begin_month == undefined || $scope.filter_begin_month == "") { return true; } if ($scope.filter_end_month == undefined || $scope.filter_end_month == "") { return true; } var beginMonth = parseInt($scope.filter_begin_month); var endMonth = parseInt($scope.filter_end_month); if (beginMonth > endMonth) { return true; } var month = order.dtCreated.substr(0, order.dtCreated.indexOf("-")); month = parseInt(month); return (month >= beginMonth && month <= endMonth); }; $scope.changePriceOrderType = function () { if ($scope.price_order_type == "price") { $scope.price_order_type = "-price"; } else { $scope.price_order_type = "price"; } }; // 将待发货,改成已发货 $scope.deliver = function (id) { for (var i in $scope.data) { if ($scope.data[i].id == id) { $scope.data[i].status = "已发货"; } } }; // 批量发货 $scope.batchDeliver = function () { $("input[name='order_id[]']:checked").each(function () { $scope.deliver(this.id); }); }; // 删除 $scope.remove = function (id) { for (var i in $scope.data) { if ($scope.data[i].id == id) { $scope.data.splice(i, 1); } } }; // 批量删除 $scope.batchRemove = function () { $("input[name='order_id[]']:checked").each(function () { $scope.remove(this.id); }); }; $scope.isShowAddOrderForm = false; $scope.showAddOrderForm = function () { $scope.isShowAddOrderForm = true; }; $scope.errTips = []; // 提交新增订单表单 $scope.submitAddOrderForm = function () { $scope.errTips = []; $scope.goodsNameClassName = ""; $scope.userNameClassName = ""; $scope.phoneClassName = ""; $scope.hasErr = false; var goodsName = $scope.goodsName == undefined ? "" : $scope.goodsName.trim(); var userName = $scope.userName == undefined ? "" : $scope.userName.trim(); var phone = $scope.phone == undefined ? "" : $scope.phone.trim(); var price = $scope.price == undefined ? "" : $scope.price.trim(); if (goodsName == "") { $scope.errTips.push("商品名不能为空!"); $scope.goodsNameClassName = "formErr"; $scope.hasErr = true; } if (userName == "") { $scope.errTips.push("用户名不能为空!"); $scope.userNameClassName = "formErr"; $scope.hasErr = true; } if (phone == "") { $scope.errTips.push("手机号不能为空!"); $scope.phoneClassName = "formErr"; $scope.hasErr = true; } if (price == "") { $scope.errTips.push("价格不能为空!"); $scope.priceClassName = "formErr"; $scope.hasErr = true; } if ($scope.city == undefined || $scope.city == "") { $scope.errTips.push("请选择城市!"); $scope.hasErr = true; } if (goodsName.length < 6 || goodsName.length > 20) { $scope.errTips.push("商品名必须是6-20个字符!"); $scope.goodsNameClassName = "formErr"; $scope.hasErr = true; } if (userName.length < 4 || userName.length > 16) { $scope.errTips.push("用户名必须是4-16个字符!"); $scope.userNameClassName = "formErr"; $scope.hasErr = true; } if (!/^\d{11}$/.test(phone)) { $scope.errTips.push("手机号格式不正确!"); $scope.phoneClassName = "formErr"; $scope.hasErr = true; } price = parseFloat(price); if (isNaN(price) || price <= 0) { $scope.errTips.push("价格必须大于0!"); $scope.priceClassName = "formErr"; $scope.hasErr = true; } if ($scope.hasErr) { return; } $scope.data.push({ id: ++id, goodsName: goodsName, userName: userName, phone: phone, price: price, city: $scope.city, dtCreated: "10-25 10:00", status: "待发货" }); $scope.goodsName = ""; $scope.userName = ""; $scope.phone = ""; $scope.price = ""; $scope.city = ""; $scope.isShowAddOrderForm = false; }; // 显示修改订单表单 $scope.edit = function (id) { for (var i in $scope.data) { if ($scope.data[i].id == id) { $scope.edit_goodsName = $scope.data[i].goodsName; $scope.edit_userName = $scope.data[i].userName; $scope.edit_phone = $scope.data[i].phone; $scope.edit_price = $scope.data[i].price; $scope.edit_city = $scope.data[i].city; $scope.edit_id = $scope.data[i].id; } } $scope.isShowEditOrderForm = true; }; // 提交修改订单表单 $scope.submitEditOrderForm = function () { $scope.errTips = []; $scope.edit_userNameClassName = ""; $scope.edit_phoneClassName = ""; $scope.edit_priceClassName = ""; $scope.hasErr = false; var id = $scope.edit_id == undefined ? "" : parseInt($scope.edit_id); var userName = $scope.edit_userName == undefined ? "" : $scope.edit_userName.trim(); var phone = $scope.edit_phone == undefined ? "" : $scope.edit_phone.trim(); var price = $scope.edit_price == undefined ? "" : $scope.edit_price; if (userName == "") { $scope.errTips.push("用户名不能为空!"); $scope.userNameClassName = "formErr"; $scope.hasErr = true; } if (phone == "") { $scope.errTips.push("手机号不能为空!"); $scope.phoneClassName = "formErr"; $scope.hasErr = true; } if (price == "") { $scope.errTips.push("价格不能为空!"); $scope.priceClassName = "formErr"; $scope.hasErr = true; } if ($scope.edit_city == undefined || $scope.edit_city == "") { $scope.errTips.push("请选择城市!"); $scope.hasErr = true; } if (userName.length < 4 || userName.length > 16) { $scope.errTips.push("用户名必须是4-16个字符!"); $scope.userNameClassName = "formErr"; $scope.hasErr = true; } if (!/^\d{11}$/.test(phone)) { $scope.errTips.push("手机号格式不正确!"); $scope.phoneClassName = "formErr"; $scope.hasErr = true; } price = parseFloat(price); if (isNaN(price) || price <= 0) { $scope.errTips.push("价格必须大于0!"); $scope.priceClassName = "formErr"; $scope.hasErr = true; } if ($scope.hasErr) { return; } for (var i in $scope.data) { if ($scope.data[i].id == id) { $scope.data[i].userName = userName; $scope.data[i].phone = phone; $scope.data[i].price = price; $scope.data[i].city = $scope.edit_city; } } $scope.edit_goodsName = ""; $scope.edit_userName = ""; $scope.edit_phone = ""; $scope.edit_price = ""; $scope.edit_city = ""; $scope.isShowEditOrderForm = false; }; }); </script> </head> <body ng-controller="OrderCtrl"> <div class="filter"> <input type="text" placeholder="用户名搜索" ng-model="filter_user_name"/> <input type="text" placeholder="手机号搜索" ng-model="filter_phone"/> <select class="choose_city" ng-model="filter_city"> <option value="">选择城市</option> <option value="北京">北京</option> <option value="上海">上海</option> <option value="天津">天津</option> <option value="重庆">重庆</option> </select> <select class="choose_status" ng-model="filter_status"> <option value="">选择状态</option> <option value="待发货">待发货</option> <option value="已发货">已发货</option> <option value="已收货">已收货</option> </select> <select class="choose_time_begin_month" 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> - <select class="choose_time_end_month" 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 class="id_order" ng-model="id_order_type"> <option value="">ID排序</option> <option value="id">ID正序</option> <option value="-id">ID倒序</option> </select> </div> <div class="buttons"> <button class="add_btn" ng-click="showAddOrderForm();">新增订单</button> <button class="deliver_btn">批量发货</button> <button class="remove_btn" ng-click="batchRemove()">批量删除</button> 敏感字:米(商品名)-> 替换成 * <input type="hidden" ng-model="price_order_type" ng-init="price_order_type='price'"/> </div> <div class="list"> <table width="800px" cellspacing="0" rules="cols" border="1px"> <thead> <tr> <th width="4%"> <input type="checkbox" name="check_all"/> </th> <th width="6%">ID</th> <th width="10%">商品名</th> <th width="10%">用户名</th> <th width="12%">手机号</th> <th width="10%">价格 <button ng-click="changePriceOrderType()">排序</button> </th> <th width="10%">城市</th> <th width="14%">下单时间 <button>排序</button> </th> <th width="8%">状态</th> <th width="10%">操作</th> </tr> </thead> <tbody> <tr align="center" ng-repeat="order in data | filter: {userName: filter_user_name} | filter: {phone: filter_phone} | filter: {city: filter_city} | filter: {status: filter_status} | filter: filterByMonth | orderBy: id_order_type"> <td> <input type="checkbox" name="order_id[]" id="{{ order.id }}"/> </td> <td>{{ order.id }}</td> <td>{{ order.goodsName| sensitiveWord: "米" }}</td> <td>{{ order.userName }}</td> <td>{{ order.phone }}</td> <td>{{ order.price | currency: "¥"}}</td> <td>{{ order.city }}</td> <td>{{ order.dtCreated }}</td> <td> <span ng-show="order.status=='待发货'" ng-click="deliver(order.id)"> <a href="javascript: void(0);">发货</a> </span> <span ng-show="order.status=='已发货'" >已发货</span> <span ng-show="order.status=='已收货'">已收货</span> </td> <td> <a href="javascript: void(0);" ng-click="edit(order.id)">修改</a> <a href="javascript: void(0);" ng-click="remove(order.id)">删除</a> </td> </tr> </tbody> </table> </div> <div class="form" ng-show="isShowAddOrderForm"> <div> <span class="label">新增订单</span> <span class="txt"></span> </div> <div> <span class="label" >商品名</span> <span class="txt"><input type="text" placeholder="6-20个字符" ng-model="goodsName" ng-class="goodsNameClassName"/></span> </div> <div> <span class="label">用户名</span> <span class="txt"><input type="text" placeholder="4-16个字符" ng-model="userName" ng-class="userNameClassName"/></span> </div> <div> <span class="label">手机号</span> <span class="txt"><input type="text" ng-model="phone" ng-class="phoneClassName"/></span> </div> <div> <span class="label">价格</span> <span class="txt"><input type="text" ng-model="price" ng-class="priceClassName"/></span> </div> <div> <span class="label">城市</span> <span class="txt"> <select ng-model="city"> <option value="">选择城市</option> <option value="北京">北京</option> <option value="上海">上海</option> <option value="天津">天津</option> <option value="重庆">重庆</option> </select> </span> </div> <div class="errTips" ng-show="hasErr"> <ul> <li ng-repeat="msg in errTips">{{ msg }}</li> </ul> </div> <div> <span class="label"></span> <span class="txt"><button ng-click="submitAddOrderForm()">提交</button></span> </div> <div style="clear: both"></div> </div> <div class="form" ng-show="isShowEditOrderForm"> <div> <span class="label">修改订单</span> <span class="txt"></span> </div> <div> <span class="label">商品名</span> <span class="txt"> <input type="text" placeholder="6-20个字符" ng-model="edit_goodsName" readonly/> </span> </div> <div> <span class="label">用户名</span> <span class="txt"> <input type="text" placeholder="4-16个字符" ng-model="edit_userName" ng-class="edit_userNameClassName"/> </span> </div> <div> <span class="label">手机号</span> <span class="txt"><input type="text" ng-model="edit_phone" ng-class="edit_phoneClassName"/></span> </div> <div> <span class="label">价格</span> <span class="txt"><input type="text" ng-model="edit_price" ng-class="edit_priceClassName"/></span> </div> <div> <span class="label">城市</span> <span class="txt"> <select ng-model="edit_city"> <option value="">选择城市</option> <option value="北京">北京</option> <option value="上海">上海</option> <option value="天津">天津</option> <option value="重庆">重庆</option> </select> </span> </div> <div class="errTips" ng-show="hasErr"> <ul> <li ng-repeat="msg in errTips">{{ msg }}</li> </ul> </div> <div> <span class="label"></span> <input type="hidden" ng-model="edit_id"/> <span class="txt"><button ng-click="submitEditOrderForm()">提交</button></span> </div> <div style="clear: both"></div> </div> </body> </html> 效果图
相关文章推荐
- 2. AngularJs+JQuery:模糊查询过滤内容,下拉菜单排序,过滤敏感字符,验证判断后添加表格信息
- js replace 全局替换 以表单的方式提交参数 判断是否为ie浏览器 将jquery.qqFace.js表情转换成微信的字符码 手机端省市区联动 新字体引用本地运行可以获得,放到服务器上报404 C#提取html中的汉字 MVC几种找不到资源的解决方式 使用Windows服务定时去执行一个方法的三种方式
- AngularJs+JQuery:模糊查询过滤内容,下拉菜单排序,过滤敏感字符,验证判断后添加表格信息
- JS及jQuery获取各种宽度、高度的简单介绍以及判断滚动条滚动到底部事件
- js判断是否安装了客户端(针对IE,IE6除外)以及表单提交方式打开新页面
- 商品订单(增删改查):新增订单;批量删除,发货;模糊查询,下拉菜单内容过滤(含时间);全选反选,列名排序
- JS/jQuery判断数据类型的几种方式
- ng-messages AngularJs 表单校验方式
- Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)
- jquery表单验证插件(jquery.validate.js)的3种使用方式
- JS组件系列——又一款MVVM组件:Vue(一:30分钟搞定前端增删改查)
- jQuery Validate 表单验证插件----利用jquery.metadata.js将校验规则直接写在class属性里面并定义错误信息的提示
- jquery.validate.js表单验证
- [转]AngularJS+UI Router(1) 多步表单
- 轻量级的jQuery表单验证插件 - HAPPY.js
- jquery.validate.js表单验证
- Html中Select的增删改查排序,和jQuery中的常用功能
- Angular.JS判断复选框checkbox是否选中并实时显示
- js:Jquery 异步提交表单(post)
- Jquery,JS的表单提交