订单页点击跳转到对应位置

工作日志 随手笔记 仅供参考

当你从上一页点击相应的内容时,将id携带到下一页,通过判断id 去判断点击的

比如我点击第一页的待发货,将待发货的id携带到下一页 在下一页去判断 上一页携带过来的id 是否相等

 //    全部订单
        $(document).on('click','.all_Order',function () {
            var order_state = $(this).data('id');
          window.location.href = 'order.html?buyer_id=1'+'&order_state='+ order_state
        })
//待发货 、待收货 、待付款 、已收货
        $(document).on('click','.Order',function () {
            console.log($(this).data('id'));
            var order_state = $(this).data('id');
            window.location.href = 'order.html?buyer_id=1'+'&order_state='+ order_state
        })
function GetRequest() { //将上一页数据携带过来
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }

        var buyer_id = GetRequest().buyer_id; //用户id
        var order_state = GetRequest().order_state; //订单状态
   

        $('.header_whole').map(function () { 
            if ($(this).data('id') == order_state) { //判断订单状态
                $(this).addClass("active"); //添加下划线
                $(this).siblings().removeClass("active");
                $.ajax({
                    url: **********,
                    type: "GET",
                    data: {
                        buyer_id: buyer_id,//用户id
                        order_state: order_state//订单状态
                    },
                    success: function (res) {
                        console.log(res);
                        if (res.result == "暂无订单") { //如果暂无订单 就显示暂无订单页面
                            var no_order = "no-order"; 
                            var tem_no_order = template(no_order, res);
                            $(".order_modal").html(tem_no_order)
                        } else { //如果有数据直接渲染模板
                            var order = "order";
                            var tem_order = template(order, res.result);
                            $(".order_modal").html(tem_order)
                        }

                    }
                });
            }
        })
//点击订单状态 订单状态:10:未付款;20:已付款;30:已发货;40:已收货;
        $(".header_whole").on("click", function () { //点击订单状态 加载不同数据
            console.log($(this).context.innerHTML);
            $(this).addClass("active");
            $(this).siblings().removeClass("active")
            var order_state = $(this).data('id');
            console.log(order_state);
            $.ajax({
                url: "*************",
                dataType: 'json',
                type: "GET",
                data: {
                    buyer_id: 1,
                    order_state: order_state //订单状态
                },
                success: function (res) {
                    console.log(res)

                    if (res.result == "暂无订单") {
                        var no_order = "no-order";
                        var tem_no_order = template(no_order, res);
                        $(".order_modal").html(tem_no_order)
                    } else {
                        var order = "order";
                        var tem_order = template(order, res.result);
                        $(".order_modal").html(tem_order)
                    }
                }
            })
        })

猜你喜欢

转载自blog.csdn.net/Acitylion/article/details/81981593