• shop--9.商品类别--批量操作--删除类别(前端)


    productcategorymanagement.js

    $(function() {
        var listUrl = '/o2o/shopadmin/getproductcategorylist';
        var addUrl = '/o2o/shopadmin/addproductcategorys';
        var deleteUrl = '/o2o/shopadmin/removeproductcategory';
        getList();
        function getList() {
            $.getJSON(listUrl, function(data) {
                if (data.success) {
                    $('.category-wrap').html('');
                    var tempHtml = '';
                    //遍历procategorylist的列表
                    data.productcategorylist.map(function(item, index) {
                        tempHtml += ''
                            + '<div class="row row-product-category now">'
                            + '<div class="col-33 product-category-name">'
                            + item.productCategoryName
                            + '</div>'
                            + '<div class="col-33">'
                            + item.priority
                            + '</div>'
                            + '<div class="col-33"><a href="#" class="button delete" data-id="'
                            + item.productCategoryId
                            + '">删除</a></div>'
                            + '</div>';
                    });
                    //填进category-wrap控件里
                    $('.category-wrap').append(tempHtml);
                }
            });
        }
        $('#new').click(function(){
            var tempHtml = '<div class="row row-product-category temp">'
                + '<div class = "col-33"><input class="category-input category" type="text" placeholder="分类名"></div>'
                + '<div class = "col-33"><input class="category-input priority" type="number" placeholder="优先级"></div>'
                + '<div class="col-33"><a href="#" class="button delete">删除</a></div>'
                + '</div>';
            $('.category-wrap').append(tempHtml);
        });
        $('#submit').click(function() {
            var tempArr = $('.temp');
            var productCategoryList = [];
            tempArr.map(function(index, item) {
                var tempObj = {};
                tempObj.productCategoryName = $(item).find('.category').val();
                tempObj.priority = $(item).find('.priority').val();
                if (tempObj.productCategoryName && tempObj.priority) {
                    productCategoryList.push(tempObj);
                }
            });
            $.ajax({
                url : addUrl,
                type : 'POST',
                data : JSON.stringify(productCategoryList),
                contentType : 'application/json',
                success : function(data) {
                    if (data.success) {
                        $.toast('提交成功!');
                        getList();
                    } else {
                        $.toast('提交失败!');
                    }
                }
            });
        });
        
        /*删除数据库中商品类别*/
        $('.category-wrap').on('click', '.row-product-category.now .delete',
            function(e) {
                var target = e.currentTarget;
                $.confirm('确定么?', function() {
                    $.ajax({
                        url : deleteUrl,
                        type : 'POST',
                        data : {
                            productCategoryId : target.dataset.id,
                        },
                        dataType : 'json',
                        success : function(data) {
                            if (data.success) {
                                $.toast('删除成功!');
                                getList();
                            } else {
                                $.toast('删除失败!');
                            }
                        }
                    });
                });
            });
     
        /*删除新增的商品类别*/
        $('.category-wrap').on('click','.row-product-category.temp .delete',
            function(e) {
                console.log($(this).parent().parent());
                $(this).parent().parent().remove();
     
            });
    });
  • 相关阅读:
    简爱 灵魂所在
    charles抓取http/https
    Class.forName()用法
    ArrayList源码剖析
    java中的多线程
    分布式负载均衡缓冲系统,如何快速定位到是那个服务器
    maven依赖jar包时版本冲突的解决
    简单工厂模式设计(java反射机制改进)
    Fiddler 抓包工具使用详解
    Fiddler 使用
  • 原文地址:https://www.cnblogs.com/windbag7/p/9392408.html
Copyright © 2020-2023  润新知