cart.js 23.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
/**
 * @description:  购物车
 * @author: chenglong.wang@yoho.cn
 * @tips: 购物车的商品计价在服务端处理,客户端只要在每次操作后刷新页面重新渲染就可以了
 */

var $ = require('yoho.jquery');
var Handlerbars = require('yoho.handlebars');
var dialog = require('../common/dialog');

var Confirm = dialog.Confirm;
var Alert = dialog.Alert;

var $cartnewSum = $('.cartnew-sum'),
    $cartnewTips = $('.cartnew-tips'),
    $payWapper = $('.pay-wapper'),
    $goodsDetail = $('.goods-detail'),
    $histroy = $('.histroy'),
    $together = $('.together'),
    $shopCart = $('.shop-cart'),
    $detailBigpic = $('.detail-bigpic'),
    togetherProductSource,
    togetherProductTemplate,
    togetherProductStr,
    subjoinPage,
    subjoinPageNum,
    subjoinPageAll,
    pageDom,
    selected,
    pageNum = 1,
    productNum,
    goodstype,
    delUrl,
    count,
    countJSON,
    id,
    dataJSON,
    pacList = 0,
    shopNum = 1,
    shopNumAll,
    productSku,
    promotionId,
    promotionPrice,
    yetCollect,
    collect,
    isClass,
    content,
    productId,
    shopName,
    delNum,
    understock,
    selectArray = [];


// 关闭温馨提示
$cartnewTips.find('.btn_close').click(function() {
    $cartnewTips.fadeOut();
});

// checkbox提交ajax
function choiceOut(data) {
    dataJSON = {
        skuList: JSON.stringify(data)
    };
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: '/cart/index/select',
        data: dataJSON,
        beforeSend: function() {
            $('.loading').css({
                top: $(document).scrollTop() + 200
            });
            $('.loading').show();
        }
    }).then(function(d) {
        if (d.code === 200) {
            window.history.go(0);
        }
    });
}

//单选提交
$payWapper.on('click', '.common-sell-box input[type="checkbox"], .pre-sell-box input[type="checkbox"]', function() {
    selectArray = [];
    selected = $(this).attr('checked') ? 'Y' : 'N';
    id = $(this).parents('tr').data('id');
    productNum = $(this).parents('tr').data('productnum');
    goodstype = $(this).data('goodstype');
    selectArray.push({
        product_sku: id,
        selected: selected,
        buy_number: productNum,
        goods_type: goodstype
    });
    choiceOut(selectArray);
});

//多选提交
$cartnewSum.on('click', 'input[type="checkbox"]', function() {
    selectArray = [];
    selected = $(this).attr('checked') ? 'Y' : 'N';
    $('.pay-wapper:first tr').each(function() {
        if ($(this).data('id')) {
            selectArray.push({
                product_sku: $(this).data('id'),
                selected: selected,
                buy_number: $(this).data('productnum'),
                goods_type: $(this).find('input[type="checkbox"]').data('goodstype')
            });
        }
    });
    choiceOut(selectArray);
});

// 凑单商品,最近浏览异步加载
togetherProductSource = $('#togetherProduct').html();
togetherProductTemplate = Handlerbars.compile(togetherProductSource);

function getTogetherProduct($obj, url, page) {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: url,
        data: page
    }).then(function(d) {
        if (d.code === 200) {
            if (d.data.item) {
                if (d.data.item.length > 0) {
                    $obj.html(' ');
                    togetherProductStr = togetherProductTemplate(d.data);
                    $obj.append($(togetherProductStr));
                    $('#orderProduct li:last').addClass('end');
                    $('.gift').removeClass('none');
                }
            }
        }
    });
}

// 最近浏览
getTogetherProduct($histroy, '/cart/index/getHistroyProduct');

// 凑单商品
getTogetherProduct($together, '/cart/index/getTogetherProduct');

//凑单商品翻页
$together.on('click', '.pagenext, .pageprev', function() {
    getTogetherProduct($together, '/cart/index/getTogetherProduct', {
        page: Math.ceil(Math.random() * 100) + 1
    });

});

//凑单商品,历史商品商品折叠
$shopCart.on('click', '.icon-minus, .icon-add', function() {
    if ($(this).hasClass('icon-minus')) {
        $(this).parents('.title').next('.main').hide();
        $(this).parents('h2').next('.right').hide();
    } else {
        $(this).parents('.title').next('.main').show();
        $(this).parents('h2').next('.right').show();
    }
    $(this).siblings('i').toggleClass('none');
    $(this).toggleClass('none');

});

// 最近浏览翻页
$histroy.on('click', '.pagenext, .pageprev', function() {
    if ($(this).hasClass('pagenext')) {
        pageNum++;
    } else {
        --pageNum > 0 || (pageNum = 1);
    }
    getTogetherProduct($histroy, '/cart/index/getHistroyProduct', {
        page: pageNum
    });

});


//根据id获取商品信息
function productInfo(data) {
    $.ajax({
        type: 'GET',
        dataType: 'html',
        url: '/cart/index/getProductInfo',
        data: data
    }).then(function(d) {
        $goodsDetail.html(' ');
        $goodsDetail.append(d);
        $('.bigpic :not(:first)').hide();
        $('.detail-bigpic:first .con li:first').addClass('active');
        if ($('.showSizeBox:not(.none) span:first').data('num') > 0) {
            $('.showSizeBox:not(.none) span:first').addClass('atcive');
        } else {
            $('.addcart').addClass('none');
            $('.btn_sellout').removeClass('none');
        }
        $.each($('.showSizeBox span'), function() {
            if ($(this).data('num') <= 0) {
                $(this).addClass('nullAtcivec');
            }
        });

        if (typeof promotionPrice !== 'undefined') {
            $('.oldprice').html('现价:<del>' + $('.oldprice del').html() + '</div>');
            $('.newprice').html('活动价<b class="promotion-price">' + promotionPrice + '</b>');
        }
        $goodsDetail.show();
    });
}

function removeInfo() {
    $goodsDetail.html(' ');
    $goodsDetail.css({
        top: $(document).scrollTop() + 30,
        left: $(document).width() / 2 - $goodsDetail.width() / 2
    });

}

//显示加价购商品信息
$payWapper.on('click', '.cart-add-btn', function() {
    productId = $(this).data('id');
    promotionId = $(this).parents('table').data('promotion');
    promotionPrice = $(this).parents('table').find('.subjoin-price').html();
    removeInfo();
    productInfo({
        productId: productId
    });
});

//凑单商品,历史商品商品记录
$('.clearfix').on('click', '.btn_view_s', function() {
    productId = $(this).data('id');
    promotionId = $(this).parents('table').data('promotion');
    promotionPrice = $(this).parents('table').find('.subjoin-price').html();
    removeInfo();
    productInfo({
        productId: productId
    });
});

//关闭商品信息窗口
$goodsDetail.on('click', '.colse', function() {
    $goodsDetail.hide();
    $goodsDetail.html(' ');
    shopNum = 1;
});

//展开加价购商品列表
function fold(icon) {
    icon.addClass('none').siblings('i').removeClass('none');
    icon.parents('.cart-product-num').siblings('div').toggleClass('fold');
    icon.siblings('.unfold-color').toggleClass('none');
    icon.siblings('.cart-page').toggleClass('none');
}

$payWapper.on('click', '.icon-minusCart, .icon-addCart', function() {
    fold($(this));
});


$payWapper.on('click', '.unfold-color', function() {
    fold($(this));
    $(this).siblings('.icon-minusCart').removeClass('none');
    $(this).siblings('.icon-addCart').addClass('none');
});

//加价购商品分页
$payWapper.on('click', '.cart-btn-next', function() {
    subjoinPage = $(this).siblings('p').find('.f-red');
    subjoinPageAll = Number($(this).siblings('p').find('.subjoinPageNum').html());
    subjoinPageNum = Number(subjoinPage.html());
    subjoinPage.html(subjoinPageNum + 1);
    if (subjoinPageNum >= subjoinPageAll - 1) {
        $(this).hide();
    } else {
        $(this).siblings('i').show();
    }
    pageDom = $(this).parents('.cart-product-num').siblings('div').find('table');
    pageDom.addClass('none').eq(subjoinPageNum).removeClass('none');
});

$payWapper.on('click', '.cart-btn-pre', function() {
    subjoinPage = $(this).siblings('p').find('.f-red');
    subjoinPageAll = Number($(this).siblings('p').find('.subjoinPageNum').html());
    subjoinPageNum = Number(subjoinPage.html());
    subjoinPage.html(subjoinPageNum - 1);
    if (subjoinPageNum <= 2) {
        $(this).hide();
    } else {
        $(this).siblings('i').show();
    }
    pageDom = $(this).parents('.cart-product-num').siblings('div').find('table');
    pageDom.addClass('none').eq(subjoinPageNum - 2).removeClass('none');
});

//删除购物车商品,把删除的商品移入cookie中
function cartDel(data, delUrl, cookieList) {
    dataJSON = {
            skuList: JSON.stringify(data)
        };
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: delUrl,
        data: dataJSON,
        beforeSend: function() {
            $('.loading').css({
                top: $(document).scrollTop() + 200
            });
            $('.loading').show();
        }
    }).then(function(d) {
        if (d.code === 200) {
            if (cookieList) {
                window.setCookie('cart-del-list', JSON.stringify(cookieList), {
                    domain: '.yohobuy.com',
                    path: '/'
                });
            }
            window.history.go(0);
        } else if (d.code === 300) {
            $('.loading').hide();
            new Alert(d.message).show();
        } else if (d.code === 403) {
            if (d.data.url) {
                window.location = d.data.url;
            }
        }
    });
}

//商品信息弹出框,加入收藏夹
$goodsDetail.on('click', '.fav_count', function() {
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: '/product/item/togglecollect',
        data: {
            productId: productId,
            type: 'add'
        }
    }).then(function(d) {
        if (d.code === 200) {
            new Alert(d.message).show();
        } else if (d.code === 403) {
            if (d.data.url) {
                window.location = d.data.url;
            }
        } else {
            new Alert(d.message).show();
        }
    });
});

//删除商品
$payWapper.on('click', '.cart-del-btn', function() {
    id = {};
    countJSON = {};
    isClass = $(this).attr('class');
    productNum = $(this).parents('tr').data('productnum');
    id['' + $(this).parents('tr').data('id')] = productNum;

    content = '<div><span></span>删除商品</div>' +
              '<p>确定从购物车中删除此商品?</p>';
    if (!$(this).data('gift')) {
        countJSON = {
            productPrice: $(this).parents('tr').find('.productPrice').text(),
            productTitle: $(this).parents('tr').find('.pay-pro-info a').text(),
            link: $(this).parents('tr').find('.pay-pro-info a').attr('href'),
            productNum: $(this).parents('tr').data('productnum'),
            productSku: $(this).parents('tr').data('id')
        };
    }
    delUrl = '/cart/index/remove';
    new Confirm({
        content: content,
        cb: function() {
                cartDel(id, delUrl, countJSON);
            }
    }).show();
});

//移入收藏夹
$payWapper.on('click', '.cart-remove-btn', function() {
    id = {};
    isClass = $(this).attr('class');
    productNum = $(this).parents('tr').data('productnum');
    id['' + $(this).parents('tr').data('id')] = productNum;
    cartDel(id, '/cart/index/fav');
});

//批量删除商品
$cartnewSum.on('click', '.delAll', function() {
    id = {};
    selectArray = [];
    $('.pay-wapper:first tr').each(function() {
        if ($(this).data('id')) {
            if ($(this).find('input[type="checkbox"]').attr('checked')) {
                id['' + $(this).data('id')] = $(this).data('productnum');
                countJSON = {
                    productPrice: $(this).find('.productPrice').text(),
                    productTitle: $(this).find('.pay-pro-info a').text(),
                    link: $(this).find('.pay-pro-info a').attr('href'),
                    productNum: $(this).data('productnum'),
                    productSku: $(this).data('id')
                };
                selectArray.push(countJSON);
            }
        }
    });
    delUrl = '/cart/index/remove';
    content = '<div><span></span>删除商品</div>' +
              '<p>确定从购物车中删除所有选中商品?</p>';
    if (!$.isEmptyObject(id)) {
        new Confirm({
            content: content,
            cb: function() {
                    cartDel(id, delUrl, selectArray);
                }
        }).show();
    } else {
        new Alert('请至少选择一件商品').show();
    }
});

//批量移入收藏夹商品
$cartnewSum.on('click', '.removeAll', function() {
    id = {};
    $('.pay-wapper:first tr').each(function() {
        if ($(this).data('id')) {
            if ($(this).find('input[type="checkbox"]').attr('checked')) {
                id['' + $(this).data('id')] = $(this).data('productnum');
            }
        }
    });
    if (!$.isEmptyObject(id)) {
        cartDel(id, '/cart/index/fav');
    } else {
        new Alert('请至少选择一件商品').show();
    }
});

//购物车商品增减
function countAJAX(data) {
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: '/cart/index/modify',
        data: data
    }).then(function(d) {
        if (d.code === 200) {
            window.history.go(0);
        }
    });
}

$payWapper.on('click', '.minus, .plus', function() {
    countJSON = {};
    count = $(this).hasClass('minus') ? 'decreaseNum' : 'increaseNum';
    countJSON['' + count] = 1;
    if ($(this).siblings('input').val() === '1' && $(this).hasClass('minus')) {
        id = {};
        isClass = $(this).attr('class');
        productNum = $(this).parents('tr').data('productnum');
        id['' + $(this).parents('tr').data('id')] = productNum;

        content = '<div><span></span>删除商品</div>' +
                  '<p>确定从购物车中删除此商品?</p>';
        countJSON = {
            productPrice: $(this).parents('tr').find('.productPrice').text(),
            productTitle: $(this).parents('tr').find('.pay-pro-info a').text(),
            link: $(this).parents('tr').find('.pay-pro-info a').attr('href'),
            productNum: $(this).parents('tr').data('productnum'),
            productSku: $(this).parents('tr').data('id')
        };
        delUrl = '/cart/index/remove';

        // new Confirm({
        //     content: content,
        //     cb: function() {
        //             cartDel(id, delUrl);
        //         }
        // }).show();
        return false;
    }

    countAJAX($.extend(countJSON,
        {
            sku: $(this).parents('tr').data('id')
        }
    ));
});



$('.gift').on('click', '.up, .down', function() {
    $(this).siblings('i').toggleClass('none');
    $(this).toggleClass('none');
});

//加入购物车

function addcart(data, cookieList) {
    $.ajax({
        type: 'POST',
        url: '/cart/index/add',
        data: data
    }).then(function(d) {
        if (d.code === 200) {
            window.history.go(0);
            if (cookieList) {
                window.setCookie('cart-del-list', JSON.stringify(cookieList), {
                    domain: '.yohobuy.com',
                    path: '/'
                });
            }
        } else if (d.code === 500) {
            new Alert(d.message).show();
        }
    });
}

$goodsDetail.on('click', '.addcart', function() {
    shopNumAll = $('.showSizeBox:not(.none) .atcive').data('num');
    productSku = $('.showSizeBox:not(.none) .atcive').data('sku');
    dataJSON = {
        productSku: productSku,
        buyNumber: $('#mnum').val(),
        promotionId: promotionId
    };

    if ($('#mnum').val() > shopNumAll) {
        new Alert('库存不足,目前还有' + shopNumAll + '个库存').show();
    } else {
        addcart(dataJSON);
    }
});

$goodsDetail.on('click', '.cut, .add', function() {
    count = $(this).hasClass('minus') ? 'decreaseNum' : 'increaseNum';
    if (promotionId) {
        if ($(this).hasClass('cut')) {
            new Alert('-_-,已经是最后一件,不能在减了!').show();
        } else {
            new Alert('最多只能购买1,您好像购买的太多了!').show();
        }
    } else {
        if ($(this).hasClass('add')) {
            shopNum++;
        } else {
            shopNum--;
        }
        if (shopNum < 1) {
            new Alert('-_-,已经是最后一件,不能在减了!').show();
            return false;
        }

        $('#mnum').val(shopNum);
    }

});

$goodsDetail.on('click', '.color', function() {
    $('.color').find('p').removeClass('atcive');
    $(this).find('p').addClass('atcive');
    $('.showSizeBox').addClass('none').eq($(this).index()).removeClass('none');
    if ($('.showSizeBox:not(.none) span:first').data('num') > 0) {
        $('.showSizeBox:not(.none) span:first').addClass('atcive');
        $('.addcart').removeClass('none');
        $('.btn_sellout').addClass('none');
    } else {
        $('.showSizeBox:not(.none) span:first').addClass('atcivec');
        $('.addcart').addClass('none');
        $('.btn_sellout').removeClass('none');
    }
    $detailBigpic.addClass('none').eq($(this).index()).removeClass('none');
    $detailBigpic.eq($(this).index()).find('.bigpic:first').show();
    $detailBigpic.eq($(this).index()).find('.con li:first').addClass('active');

});

$goodsDetail.on('click', '.showSizeBox span', function() {
    shopNumAll = $(this).data('num');
    if ($(this).data('num') > 0) {
        $('.showSizeBox:not(.none) span').removeClass('atcivec atcive').eq($(this).index()).addClass('atcive');
        $('.addcart').removeClass('none');
        $('.btn_sellout').addClass('none');
    } else {
        $('.showSizeBox:not(.none) span').removeClass('atcivec atcive').eq($(this).index()).addClass('atcivec');
        $('.addcart').addClass('none');
        $('.btn_sellout').removeClass('none');
    }
});

//撤销删除
$('.goBack').on('click', function() {
    delNum = $('.dev-revocation .goBack').index(this);
    selectArray = [];
    $('.dev-revocation tr').each(function(index) {
        if (delNum !== index) {
            countJSON = {
                productPrice: $(this).find('.productPrice').text(),
                productTitle: $(this).find('.title').text(),
                link: $(this).find('.title').attr('href'),
                productNum: $(this).data('productnum'),
                productSku: $(this).data('productsku')
            };
            selectArray.push(countJSON);
        }
    });
    dataJSON = {
        productSku: $(this).parents('tr').data('productsku'),
        buyNumber: $(this).parents('tr').data('productnum')
    };

    addcart(dataJSON, selectArray);
});

$goodsDetail.on('click', '.piclist li', function() {
    pacList = $(this).index();
    $('.detail-bigpic:not(.none) .piclist li').removeClass('active');
    $(this).addClass('active');
    $('.detail-bigpic:not(.none) .bigpic').hide().eq($(this).index()).show();
});

function isSollect() {
    $('.gift-wrapper .fold').show();
    if ($('.pre-sell-box input:checked').length === $('.pre-sell-box input[type="checkbox"]').length) {
        $('.per-list input[type="checkbox"]').attr('checked', true);
    }

    if ($('.common-sell-box input:checked').length === $('.common-sell-box input[type="checkbox"]').length) {
        $('.common-list input[type="checkbox"]').attr('checked', true);
    }

    $('.cart-page').each(function() {
        if ($(this).data('pageall') === 1) {
            $('.cart-btn-pre', this).hide();
            $('.cart-btn-next', this).hide();
        } else {
            $('.cart-btn-pre', this).hide();
        }
    });

    if ($('.pre-sell-box input:checked').length > 0 && $('.common-sell-box input:checked').length > 0) {
        $('.go_cash_tips').show();
        $('.btn_account_disabled').show();
        $('.btn_account').hide();
    } else {
        $('.go_cash_tips').hide();
        $('.btn_account').show();
        $('.btn_account_disabled').hide();
    }

    $('.pay-wapper tr').each(function() {
        if ($(this).data('pid')) {
            selectArray.push($(this).data('pid') + '');
        }

    });
    $.ajax({
        type: 'POST',
        url: '/cart/index/checkFav',
        data: {
            pidList: JSON.stringify(selectArray)
        }
    }).then(function(d) {
        yetCollect = '<span class="cart-yetremove-btn">已收藏</span>';
        collect = '<a href="javascript:void(0);" class="cart-remove-btn"><span>移入收藏</span></a>';
        $.each(d.data, function(key, val, index) {
            $('.pay-wapper tr').each(function() {
                if (Number($(this).data('pid')) === Number(key)) {
                    if (val) {
                        $(this).find('.cart-operation').append(yetCollect);
                    } else {
                        $(this).find('.cart-operation').append(collect);
                    }
                }
            });
        });
    });
}

isSollect();

$goodsDetail.on('click', '.pre, .next', function() {
    if ($(this).hasClass('next')) {
        if (pacList > $(this).siblings('.con').find('li').length - 2) {
            return false;
        }
        pacList++;
    } else {
        if (pacList < 1) {
            return false;
        }
        pacList--;
    }

    $(this).siblings('.con').find('li').removeClass('active').eq(pacList).addClass('active');
    $('.bigpic').hide().eq(pacList).show();
});

//结算
$('.btn_account').on('click', function() {
    understock = '';
    if ($('.pay-wapper input:checked').parents('tr').find('.tipNoStore').length > 0) {
        shopName = $('.pay-wapper input:checked').parents('tr').find('.tipNoStore');
        $.each(shopName.parents('.common-sell-box').find('.pay-pro-info a'), function() {
            understock += $(this).html();
        });
        new Alert(understock + '库存不足').show();
    } else {
        if ($('.zp').length > 0 && !$(this).attr('title')) {
            $(this).attr('title', '1');
            new Alert('您有赠品没有选择,请选择完再结算!').show();
        } else {
            if ($('input:checked').length > 0) {
                if ($('.pre-sell-box input:checked').length > 0) {
                    window.location.href = '/cart/index/orderEnsure?type=2';
                } else {
                    window.location.href = '/cart/index/orderEnsure?type=1';
                }
            } else {
                new Alert('请至少选择一件商品').show();
            }
        }
    }
});

function isCheck(obj, className) {
    selectArray = [];
    selected = obj.attr('checked') ? 'Y' : 'N';
    $('.' + className).each(function() {
        if ($(this).data('id')) {
            selectArray.push({
                product_sku: $(this).data('id'),
                selected: selected,
                buy_number: $(this).data('productnum'),
                goods_type: $(this).find('input[type="checkbox"]').data('goodstype')
            });
        }
    });
    choiceOut(selectArray);
}

$('.per-list').on('click', 'input[type="checkbox"]', function() {
    isCheck($(this), 'pre-sell-box');
});

$('.common-list').on('click', 'input[type="checkbox"]', function() {
    isCheck($(this), 'common-sell-box');
});