disabled");
            }
            function toggleEdit(isEnabled) {
                var toggle = isEnabled? "removeClass" : "addClass";
                $els.edit[toggle]("disabled");
            }
            function getSpChkBoxsOfAComp($compChkBox) {
                var pars = $compChkBox.parentsUntil('#pro_de_cartContainer');
                return pars.eq(pars.length - 1).find(".chkbox-shangpin");
            }
            function getElmOfASp($base, searchClass) {
                var pars = $base.parentsUntil('.pro_de_cart_group');
                return pars.eq(pars.length - 1).find(searchClass);
            }
            function getElmOfASpGrp($base, searchClass) {
                var pars = $base.parentsUntil('.pro_de_cartContent');
                return pars.eq(pars.length - 1).find(searchClass);
            }
            function refreshSpPrice($el, type) {
                var rslt = shopCart.chgNumFromUI(
                    $el.data("detailId"),
                    $el.data("spGrpId"),
                    $el.data("compId"),
                    type,
                    $el.val && $el.val()
                );
                rslt.err && console.log(rslt.err);
                getElmOfASp($el, ".input-shangpin-num").val(rslt.num);
                var pars = $el.parentsUntil('.pro_de_cartContent');
                var $grp = pars.eq(pars.length - 1);
                $grp.children().each(function () {
                    if ($(this).find(".chkbox-shangpin:checked").length) {
                        $(this).find(".label-unit-price").text(formatNum(rslt.price.toFixed(2)));
                        $(this).find(".pro_de_cartPl").text(function () {
                            var num = +getElmOfASp($(this), ".input-shangpin-num").val();
                            return formatNum((rslt.price * num).toFixed(2));
                        });
                    } else {
                        var $spCB = $(this).find(".chkbox-shangpin");
                        var sp = shopCart.getShangpin(
                            $spCB.data("detailId"),
                            $spCB.data("spGrpId"),
                            $spCB.data("compId")
                        );
                        $(this).find(".label-unit-price").text(formatNum(sp.price.toFixed(2)));
                        $(this).find(".pro_de_cartPl").text(formatNum((sp.price * sp.num).toFixed(2)));
                    }
                });

                $els.totalPrice.text(formatNum(shopCart.calcTotal().toFixed(2)));
            }
            // 数组格式
            function addFavOrDel1(url, type) {//购物车删除功能，移入收藏夹功能，完成功能
                if ($(this).hasClass("disabled")) return;
                var shangpinCBs = $els.list.find(".chkbox-shangpin:checked");
                var params;
                var delarr = [], favarr = [];
                shangpinCBs.each(function (){
                    var sp = shopCart.comps[$(this).data("compId")].shangpins[$(this).data("spGrpId")].sameSPs[$(this).data("detailId")];
                    favarr.push({
                        lineId: sp.detailId,
                        productId:sp.id,
                        shopId: sp.sellerId
                    });
                    delarr.push(sp.detailId);
                });
                switch (type) {
                    case "delete":
                        params={"lineIds":delarr.join(",")};
                        break;
                    default:
                        params={"favoritesList":favarr};
                        break;
                }
                //debugger;
                console.log("favorite / remove these shangpins:");
                console.log(params);
                $.ajax({
                    url: url,
                    type: "post",
                    contentType: "application/json; charset=utf-8",
                    dataType: "jsonp",
                    data:params,
                    success: function (data) {
                        console.log(data)
                        if (data.status==200) {
                            shopCart.isEditing = false;
                            toggleFavDel(false);
                            shangpinCBs.each(function () {
                                shopCart.removeAShangpin(
                                    $(this).data("detailId"),
                                    $(this).data("spGrpId"),
                                    $(this).data("compId")
                                );
                                $(this).parentsUntil('.pro_de_cart_group').remove();
                            });
                            var compCBs = $els.list.find(".chkbox-comp:checked");
                            compCBs.each(function () {
                                $(this).parentsUntil('#pro_de_cartContainer').remove();
                            });
                            updateTotalPrice();
                            if(shopCart.compIds.length==0){
                                var str=""
                                str =
                                    "<div class='pro_de_cartContent' class='sh_te_align_c sh_font_sz0'>" +//当购物车内容为空时
                                    "<img src='http://res.csc86.com/v2/shopping_center/market/demo/pro_de_cart_bl.png' alt='' class='loading sh_img_max sh_margin_a'/>" +
                                    "</div>";//如果没有数据或者长度为0时
                                $("#pro_de_cartContainer").html(str);
                                return;
                            }
                            console.log(shopCart.compIds)
                        }
                    },
                    error: function (xhr, type) {
                        console.log('Ajax error!');
                    }
                });

            }
            function updateTotalPrice() {
                $els.totalPrice.text(formatNum(shopCart.calcTotal().toFixed(2)));
                $els.selectedNum.text(shopCart.SpSelcNum);
                shopCart.SpSelcNum==0 && $els.chkAll.prop("checked", false);
            }
            function _bindEvents() {
                $els.totalPrice = $("#pro_de_totalprice");
                $els.selectedNum = $("#pro_de_cartNum");
                $els.list = $("#pro_de_cartContainer");
                $els.addFavr = $("#pro_de_cartSto");
                $els.delete = $("#pro_de_cartDe");
                $els.btnGrp1 = $(".pro_de_cartShow");
                $els.btnGrp2 = $(".pro_de_cartOp");
                $els.edit = $("#edit-btn");
                $els.chkAll = $(".check-all").click(function () {//全选
                    $els.list.find(".chkbox-shangpin" + (this.checked? ":not(:checked)" : ":checked")).trigger("click");
                });
                $els.list.find(".chkbox-comp").click(function () {
                    var el = $(this), compId = el.data("compId");

                    getSpChkBoxsOfAComp(el).filter(this.checked? ":not(:checked)" : ":checked").trigger("click");

                });
                $els.list.find(".chkbox-shangpin").click(function () {
                    var el = $(this), compId = el.data("compId");
                    var spGrpId = el.data("spGrpId");
                    var spId = el.data("detailId");
                    shopCart.clickAShangpinChk(spId, spGrpId, compId, this.checked);
                    var pars = el.parentsUntil('#pro_de_cartContainer');
                    pars.eq(pars.length - 1).find(".chkbox-comp").prop("checked", shopCart.comps[compId].chkNum == shopCart.comps[compId].shangpinIds.length);
                    $els.chkAll.prop("checked", (shopCart.chkNum == shopCart.compIds.length));
                    refreshSpPrice(getElmOfASp($(this), ".input-shangpin-num"), "click