综合学习增删改查

<!DOCTYPE html>
<html ng-app="OrderApp">
<head>
    <meta charset="UTF-8">
    <title>订单管理</title>
    <!--添加依赖-->
    <script type="text/javascript" src="js/jquery-2.1.0.js"></script>
    <script type="text/javascript" src="js/angular.js"></script>
    <!--添加css样式-->
    <link type="text/css" href="css/style.css" rel="stylesheet"/>
    <!--添加angularjs实现效果-->
    <!--1.初始化数据-->
    <script type="text/javascript" src="js/Data.js"></script>
    <!--2.实现内部功能-->
    <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属性的值
                });
            });
        });
        // 定义angularJS的使用范围
        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;
            // 获取信息列表中的ID
            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.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.priceClassName = "";
                // 输入信息有误时,hasErr状态值为false
                $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();
                // 对输入的信息进行判断 - 输入无误时,hasErr状态值变为true
                // 判断商品名
                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 = "";
                // 输入信息有误时,hasErr状态值为false
                $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;
                // 对输入的信息进行判断 - 输入无误时,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.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" ng-click="batchDeliver()">批量发货</button>
    <!--批量删除-->
    <button class="remove_btn" ng-click="batchRemove()">批量删除</button>
    <!--敏感字提示-->
    敏感字:米(商品名)-> 替换成 *
</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="14%">商品名</th>
            <th width="8%">用户名</th>
            <th width="14%">手机号</th>
            <th width="10%">价格</th>
            <th width="8%">城市</th>
            <th width="12%">下单时间</th>
            <th width="8%">状态</th>
            <th width="14%">操作</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>
            <!--angularjs信息占位符:内部添加信息-->
            <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>
    <!--msg模块:输入信息有误时,将提示信息添加到msg模块中-->
    <div class="errTips" ng-show="hasErr">
        <ul>
            <li ng-repeat="msg in errTips">{{ msg }}</li>
        </ul>
    </div>
    <!--msg中的提示内容在<span class="label"></span>版块中显示-->
    <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>
    <!--msg模块:输入信息有误时,将提示信息添加到msg模块中-->
    <div class="errTips" ng-show="hasErr">
        <ul>
            <li ng-repeat="msg in errTips">{{ msg }}</li>
        </ul>
    </div>
    <!--msg中的提示内容在<span class="label"></span>版块中显示-->
    <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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值