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


    shop--8.商品类别--批量操作--删除(后端)

    $(function() {
        var shopId = 1;
        var listUrl = '/shopadmin/getproductcategorylist?shopId=' + shopId;
        var addUrl = '/shopadmin/addproductcategories';
        var deleteUrl = '/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() {
            /*tempArr数组遍历上面添加的名为****temp的列表*/
            var tempArr = $('.temp');
            var productCategoryList = [];
            /*然后对tempArr遍历*/
            tempArr.map(function(index, item) {
                var tempObj = {};
                tempObj.productCategoryName = $(item).find('.category').val();
                tempObj.priority = $(item).find('.priority').val();
                /*将商品分类的名和优先级拼接到tempObj的json中*/
                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,
                            shopId : shopId
                        },
                        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();
    
            });
    
    });
    

      

  • 相关阅读:
    python 执行sql得到字典格式数据
    python爬虫 url链接编码成gbk2312格式
    windows环境下elasticsearch安装教程(单节点)
    python SQLServer 存储图片
    爬虫的本质是和分布式爬虫的关系
    requests form data 请求 爬虫
    mysql 删除 binlog 日志文件
    查看mysql数据表的大小
    xshell 连接报错 Disconnected from remote host
    centos 7.3 安装 mysqldb 报错 EnvironmentError: mysql_config not found ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  • 原文地址:https://www.cnblogs.com/SkyeAngel/p/8934270.html
Copyright © 2020-2023  润新知