Blame view

public/js/product/shop/shop.js 25.7 KB
王水玲 authored
1 2 3 4
/**
 * 品牌店铺首页
 */
王水玲 authored
5 6 7
var $ = require('yoho-jquery'),
    IScroll = require('yoho-iscroll/build/iscroll-probe'),
    lazyLoad = require('yoho-jquery-lazyload'),
8 9
    Swiper = require('yoho-swiper');
var bannerSwiper,
王水玲 authored
10 11 12 13 14 15
    multiSwiper,
    myScroll,
    imgH,
    nav1H,
    main1H,
    main1oH,
郭成尧 authored
16 17
    nav2H,
    main2oH,
王水玲 authored
18 19
    scH,
    $nav1 = $('#pos-nav'),
郭成尧 authored
20 21
    $nav2 = $('#pos-list'),
    sTop;
王水玲 authored
22
王水玲 authored
23 24 25
var tip = require('../../plugin/tip'),
    filter = require('../../plugin/filter'),
    loading = require('../../plugin/loading');
王水玲 authored
26 27

var $subNav = $('.home-sub-nav'),
王水玲 authored
28
    $collect = $('#collect'),
王水玲 authored
29 30 31 32 33 34 35 36
    $goodsContainer = $('#goods-container'),
    $goodsChildren = $goodsContainer.children(),
    $ngc = $($goodsChildren.get(0)),
    $pgc = $($goodsChildren.get(1)),
    $dgc = $($goodsChildren.get(2)),
    shopId = $('input[name="shop_id"]').val(),
    appVersion = $('input[name="app_version"]').val(),
    brand = $('input[name="brand"]').val(),
郭成尧 authored
37
    coverChannel = $('input[name="coverChannel"]').val(),
38 39
    favId = $('input[name="favId"]').val(),
    uid = $('input[name="uid"]').val();
王水玲 authored
40 41 42 43

var winH = $(window).height(),
    noResult = '<p class="no-result">未找到相关搜索结果</p>';
郭成尧 authored
44
require('../../common');
郭成尧 authored
45
zzzzzzz authored
46
// pagecache判断app设置cookie,判断是否收藏
郭成尧 authored
47
(function() {
郭成尧 authored
48 49 50 51 52 53
    var param = location.search;
    var isApp = param.indexOf('app_version') > -1 || param.indexOf('appVersion') > -1;

    if (isApp) {
        $.ajax({
            type: 'GET',
郭成尧 authored
54
            url: location.protocol + '//m.yohobuy.com/product/index/shopAppCookie',
郭成尧 authored
55 56 57
            xhrFields: {
                withCredentials: true
            },
郭成尧 authored
58
            error: function() {
郭成尧 authored
59 60 61 62 63 64 65
                tip.show('网络断开连接了~');
            }
        });
    }

    $.ajax({
        type: 'GET',
郭成尧 authored
66
        url: location.protocol + '//m.yohobuy.com/product/index/shopFav',
郭成尧 authored
67 68 69
        xhrFields: {
            withCredentials: true
        },
郭成尧 authored
70 71 72
        data: {
            shopId: $('.shopid').val(),
        },
郭成尧 authored
73
        success: function(data) {
郭成尧 authored
74 75 76 77
            if (data.collect) {
                $collect.attr('class', 'already-collect');
            }
        },
郭成尧 authored
78
        error: function() {
郭成尧 authored
79 80 81 82
            tip.show('网络断开连接了~');
        }
    });
}());
zzzzzzz authored
83
王水玲 authored
84 85
// 默认筛选条件
var defaultOpt = require('../../common/query-param');
王水玲 authored
86 87 88

var $listNav = $('#list-nav'),
郭成尧 authored
89
    // 导航数据信息
王水玲 authored
90 91 92 93 94 95 96 97
    navInfo = {
        new: {
            order: 1,
            reload: true,
            page: 1,
            end: false
        },
        hot: {
郭成尧 authored
98
            order: 1,
王水玲 authored
99 100 101 102 103
            reload: true,
            page: 1,
            end: false
        },
        newest: {
郝肖肖 authored
104
            order: 0,
王水玲 authored
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
            reload: true,
            page: 0,
            end: false
        },
        price: {
            order: 1,
            reload: true,
            page: 0,
            end: false
        },
        discount: {
            order: 1,
            reload: true,
            page: 0,
            end: false
        }
    },
郭成尧 authored
122
    $pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
王水玲 authored
123 124
    searching;
王水玲 authored
125
var viewType = 1, // 1-首页,2-上新,3-人气
王水玲 authored
126 127 128 129 130
    listCount = $('.category-list li').length,
    listModValue = 4 - listCount % 4,
    listIndex;

王水玲 authored
131 132 133 134
$('.main-wrap').css({
    position: 'static'
});
郭成尧 authored
135
// 焦点效果
王水玲 authored
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
if ($('.banner-swiper').find('li').size() > 1) {
    bannerSwiper = new Swiper('.banner-swiper', {
        lazyLoading: true,
        lazyLoadingInPrevNext: true,
        loop: true,
        autoplay: 3000,
        autoplayDisableOnInteraction: false,
        paginationClickable: true,
        slideElement: 'li',
        pagination: '.banner-top .pagination-inner'
    });
}

if ($('.multi-browse').find('li').size() > 1) {
    multiSwiper = new Swiper('.multi-browse', {
        lazyLoading: true,
        lazyLoadingInPrevNext: true,
        lazyLoadingOnTransitionStart: true,
        grabCursor: true,
        slidesPerView: 'auto',
        slideElement: 'li',
        watchSlidesVisibility: true
    });
}
郭成尧 authored
161
// 根据热门品类的个数来改变样式展示
王水玲 authored
162
//
郭成尧 authored
163
if ($('.category-list li').length % 4 !== 0) {
王水玲 authored
164 165 166
    $('.category-list li:last-child').addClass('category-list-last-li');
}
郭成尧 authored
167 168 169
if ($('.category-list li').length < 4) {
    $('.category-list').addClass('category-list-top-board');
    $('.category-list').find('.buriedpoint').addClass('category-list-only-one-row');
170
} else if ($('.category-list li').length >= 5) {
王水玲 authored
171 172 173 174 175 176
    for (listIndex = listModValue; listIndex >= 0; listIndex--) {
        $('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row');
    }
}

function getPageGoods(info) {
王水玲 authored
177
    var nav, navType;
王水玲 authored
178 179 180 181 182 183 184 185

    if (searching) {
        return;
    }

    navType = info.data.type;
    nav = navInfo[navType];
郭成尧 authored
186
    // 不需要重新加载并且数据请求结束
王水玲 authored
187 188 189 190 191
    if (nav.end) {

        return;
    }
郭成尧 authored
192 193 194 195
    if (info.data && coverChannel) {
        info.data.coverChannel = coverChannel;
    }
王水玲 authored
196 197 198
    searching = true;
    $.ajax({
        type: 'GET',
郭成尧 authored
199
        url: info.url,
王水玲 authored
200
        data: info.data,
郭成尧 authored
201
        success: function(data) {
郭成尧 authored
202
            if (data === ' ') {
王水玲 authored
203 204 205 206 207
                nav.end = true;
            }

            info.callBack(data);
        },
郭成尧 authored
208
        error: function() {
郭成尧 authored
209
            tip.show('网络断开连接了~');
王水玲 authored
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
            searching = false;
        }
    });
}

function getParam(req) {
    if (brand) {
        req.data.brand = brand;
    }

    if (shopId) {
        req.data.shop_id = shopId;
    }
}

function newData(callback) {
    var req = {};
郭成尧 authored
228
    req.url = location.protocol + '//m.yohobuy.com/product/search/search';
王水玲 authored
229
    req.data = {
郭成尧 authored
230
        type: 'new',
郭成尧 authored
231
        order: '0',
王水玲 authored
232
        page: navInfo.new.page,
233 234
        tagNew: '1',
        appVersion: appVersion
王水玲 authored
235 236 237 238
    };

    getParam(req);
郭成尧 authored
239
    req.callBack = function(data) {
王水玲 authored
240 241
        $('#new-arrival').append(data);
        navInfo.new.page++;
郭成尧 authored
242
        myScroll && myScroll.refresh();
王水玲 authored
243 244 245 246 247 248 249 250 251 252 253
        lazyLoad($('#new-arrival .lazy'));
        scH = $('#scroller').outerHeight();
        searching = false;
        callback && $.isFunction(callback) && callback();
    };
    getPageGoods(req);
}

function hotData(callback) {
    var req = {};
郭成尧 authored
254
    req.url = location.protocol + '//m.yohobuy.com/product/search/search';
王水玲 authored
255 256
    req.data = {
        type: 'hot',
郭成尧 authored
257
        order: '1',
王水玲 authored
258
        page: navInfo.hot.page,
259 260
        showTag: '1',
        appVersion: appVersion
王水玲 authored
261 262 263 264
    };

    getParam(req);
郭成尧 authored
265
    req.callBack = function(data) {
王水玲 authored
266 267
        $('#popularity').append(data);
        navInfo.hot.page++;
郭成尧 authored
268
        myScroll && myScroll.refresh();
王水玲 authored
269 270 271 272 273 274 275 276 277 278 279
        lazyLoad($('#popularity .lazy'));
        scH = $('#scroller').outerHeight();
        searching = false;
        callback && $.isFunction(callback) && callback();
    };
    getPageGoods(req);
}

function tabChange(dom, index) {
    var li = dom.eq(index);
郭成尧 authored
280 281
    dom.removeClass('active color');
    li.addClass('active color');
王水玲 authored
282 283 284
}

郭成尧 authored
285
// 首页导航
郭成尧 authored
286
(function(nav, posNav, main) {
郭成尧 authored
287
郭成尧 authored
288
    $(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function() {
王水玲 authored
289 290 291 292

        var index = $(this).index(),
            activeTab = $(this).attr('tab');
郭成尧 authored
293 294 295 296
        if (!$('.filter-mask').hasClass('hide')) {
            return;
        }
王水玲 authored
297 298 299 300 301 302 303 304 305 306 307 308
        $nav1.removeClass('fixed-top');
        tabChange($(nav + ' li'), index);
        tabChange($(posNav + ' li'), index);
        $(main).hide();
        $('#' + activeTab).fadeIn();
        if (activeTab === 'new-arrival') {
            newData();
            viewType = 2;
        } else if (activeTab === 'popularity') {
            hotData();
            viewType = 3;
        } else if (activeTab === 'home-page') {
郭成尧 authored
309 310
            $nav1.removeClass('fixed-top absolute');
            $nav2.removeClass('fixed-top absolute');
王水玲 authored
311
        }
郭成尧 authored
312
        myScroll && myScroll.refresh();
郭成尧 authored
313
        scH = $('#scroller').outerHeight();
王水玲 authored
314
        if (!$nav1.hasClass('hide')) {
郭成尧 authored
315
            myScroll && myScroll.scrollTo(0, 0 - imgH);
王水玲 authored
316 317 318
        }
        $nav1.addClass('hide');
    });
郭成尧 authored
319
}('#nav', '#pos-nav', '.main'));
王水玲 authored
320
郭成尧 authored
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
var theY;

/**
 * 筛选后内容变化,导致nav1位置错掉,重新计算确保位置正确显示
 */
function reNav1Pos() {
    var sTop = theY ? theY : 0;
    if (sTop < imgH + main1oH + nav1H) {
        if ($nav1.hasClass('hide')) {
            $nav1.removeClass('hide');
        }

        if (sTop < imgH + main1H) {
            tra = 'translate3d(0, ' + (-scH) + 'px, 0)';
            $nav1.addClass('fixed-top')
                .removeClass('absolute')
                .css({
                    transform: tra,
                    '-moz-transform': tra,
                    '-ms-transform': tra,
                    '-webkit-transform': tra
                });
        } else if (sTop < imgH + main1H + nav1H) {
            if ($('#home-page').is(':hidden')) {
                return false;
            }
            $nav1.addClass('absolute')
                .removeClass('fixed-top');
            tra = 'translate3d(0, ' + (imgH + main1H - sTop - scH) + 'px, 0)';
            $nav1.css({
                transform: tra,
                '-moz-transform': tra,
                '-ms-transform': tra,
                '-webkit-transform': tra
            });
        }
    } else {
        if (!$nav1.hasClass('hide')) {
            $nav1.addClass('hide');
        }
    }
}
郭成尧 authored
364 365

function scrollHandler() {
王水玲 authored
366 367 368
    var scrollCall,
        sTop = -this.y;
郭成尧 authored
369 370 371 372 373 374 375 376 377 378
    var tra;


    theY = sTop;
    if (sTop + winH > scH - 0.25 * $goodsContainer.height() - 50) {
        if ($pre !== undefined) {
            search({
                type: 'shop_id',
                id: shopId,
                brand: brand,
郭成尧 authored
379
                url: location.protocol + '//m.yohobuy.com/product/search/search',
郭成尧 authored
380 381 382 383 384
                nextPage: true
            });
        }
    }
王水玲 authored
385
    if (sTop + winH * 2 > scH) {
郭成尧 authored
386
        scrollCall = function() {
郭成尧 authored
387 388 389 390 391 392 393 394
            var translate = 'translate3d(0, ' + (-scH) + 'px, 0)';
            $nav1.css({
                transform: translate,
                '-moz-transform': translate,
                '-ms-transform': translate,
                '-webkit-transform': translate
            });
        };
王水玲 authored
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
        switch (viewType) {
            case 2:
                newData(scrollCall);
                break;
            case 3:
                hotData(scrollCall);
                break;
        }
    }

    if (sTop < imgH) {
        if (!$nav1.hasClass('hide')) {
            $nav1.addClass('hide');
        }
        if (!$nav2.hasClass('hide')) {
            $nav2.addClass('hide');
郭成尧 authored
411
        } // 滑动距离不到导航1
郭成尧 authored
412
    } else if (sTop < imgH + main1oH + nav1H) {
王水玲 authored
413 414 415 416 417
        if ($nav1.hasClass('hide')) {
            $nav1.removeClass('hide');
        }
        if (!$nav2.hasClass('hide')) {
            $nav2.addClass('hide');
郭成尧 authored
418
        } // 滑动距离不到导航2
王水玲 authored
419 420 421

        if (sTop < imgH + main1H) {
            if (!$nav1.hasClass('fixed-top')) {
郭成尧 authored
422
                tra = 'translate3d(0, ' + (-scH) + 'px, 0)';
王水玲 authored
423 424 425
                $nav1.addClass('fixed-top')
                    .removeClass('absolute')
                    .css({
郭成尧 authored
426 427 428 429
                        transform: tra,
                        '-moz-transform': tra,
                        '-ms-transform': tra,
                        '-webkit-transform': tra
王水玲 authored
430 431
                    });
            }
郭成尧 authored
432
        } else if (sTop < imgH + main1H + nav1H) {
王水玲 authored
433 434 435 436 437 438 439
            if ($('#home-page').is(':hidden')) {
                return false;
            }
            if (!$nav1.hasClass('absolute')) {
                $nav1.addClass('absolute')
                    .removeClass('fixed-top');
            }
郭成尧 authored
440
            tra = 'translate3d(0, ' + (imgH + main1H - sTop - scH) + 'px, 0)';
王水玲 authored
441
            $nav1.css({
郭成尧 authored
442 443 444 445
                transform: tra,
                '-moz-transform': tra,
                '-ms-transform': tra,
                '-webkit-transform': tra
王水玲 authored
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
            });
        }
    } else {
        if ($('#home-page').is(':hidden')) {
            return false;
        }

        if (!$nav1.hasClass('hide')) {
            $nav1.addClass('hide');
        }
        if ($nav2.hasClass('hide')) {
            $nav2.removeClass('hide');
        }

        if (sTop < scH) {
            if (!$nav2.hasClass('absolute')) {
                $nav2.addClass('absolute')
                    .removeClass('fixed-top');
            }
郭成尧 authored
465
            tra = 'translate3d(0, ' + (-scH) + 'px, 0)';
王水玲 authored
466
            $nav2.css({
郭成尧 authored
467 468 469 470
                transform: tra,
                '-moz-transform': tra,
                '-ms-transform': tra,
                '-webkit-transform': tra
王水玲 authored
471 472 473
            });
        }
    }
郭成尧 authored
474
}
郭成尧 authored
475
郭成尧 authored
476
document.addEventListener('touchmove', function(e) {
郭成尧 authored
477 478 479 480
    // sub classify不阻止默认事件
    if ($(e.target).closest('.sub-classify').length === 0) {
        e.preventDefault();
    }
王水玲 authored
481 482
}, false);
郭成尧 authored
483
/* if (!isIphone) {
郭成尧 authored
484 485
 return;
 }*/
郭成尧 authored
486 487

郭成尧 authored
488
// window ready 后重新refresh iscroll
郭成尧 authored
489
$(window).ready(function() {
郭成尧 authored
490
    myScroll && myScroll.refresh();
王水玲 authored
491 492 493
    imgH = $('#nav-top').outerHeight();
    nav1H = $('#nav').outerHeight();
    main1H = $('#nav-main').height();
郭成尧 authored
494 495 496
    main1oH = $('#nav-main').outerHeight(true);
    nav2H = $('#list-nav').outerHeight(true);
    main2oH = $('#goods-container').outerHeight(true);
郭成尧 authored
497 498 499 500 501 502 503 504


    myScroll = new IScroll('#wrapper', {
        probeType: 2,
        mouseWheel: false,
        click: true
    });
郭成尧 authored
505
    setTimeout(function() {
郭成尧 authored
506
        scH = $('#scroller').outerHeight();
郭成尧 authored
507
    }, 500);
郭成尧 authored
508 509

郭成尧 authored
510
    myScroll.on('scroll', scrollHandler);
郭成尧 authored
511
郭成尧 authored
512
    myScroll.on('scrollStart', function() {
郭成尧 authored
513 514 515 516 517 518 519

        // stop auto play when scroll
        bannerSwiper && bannerSwiper.stopAutoplay();

        multiSwiper && multiSwiper.stopAutoplay();
    });
郭成尧 authored
520
    myScroll.on('scrollEnd', function() {
郭成尧 authored
521 522 523 524 525 526

        // start auto play when scroll end
        bannerSwiper && bannerSwiper.startAutoplay();

        multiSwiper && multiSwiper.startAutoplay();
郭成尧 authored
527
        $('#scroller').trigger('scroll');
郭成尧 authored
528
        scrollHandler.bind(this)();
郭成尧 authored
529
    });
郭成尧 authored
530
    lazyLoad($('img.lazy'));
王水玲 authored
531 532 533 534 535 536 537 538 539 540 541 542 543 544
});

function bindGoodThumbClick() {
    $(document).trigger('rebindBpEvent');
}

function search(opt) {
    var setting = {},
        ext,
        att,
        nav, navType,
        page;

    if (searching) {
郭成尧 authored
545 546 547 548
        return;
    }

    if (!opt.url) {
郭成尧 authored
549
        opt.url = location.protocol + '//m.yohobuy.com/product/search/search';
王水玲 authored
550 551
    }
郭成尧 authored
552 553
    $pre = $listNav.find('.active').eq(0);
王水玲 authored
554 555
    if (!opt.nextPage) {
郭成尧 authored
556
        // 筛选项变更则重置reload为true
王水玲 authored
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
        for (att in navInfo) {
            if (navInfo.hasOwnProperty(att)) {
                navInfo[att].reload = true;
            }
        }

        $listNav.children('.active').removeClass('active');
        $pre.addClass('active');
        if (opt.hasOwnProperty('id')) {
            switch (opt.type) {
                case 'shop_id':
                    ext = {
                        shop_id: opt.id
                    };
                    break;
                case 'gender':
                    ext = {
                        gender: opt.id
                    };
郭成尧 authored
576 577

                    ext.coverChannel = opt.id;
王水玲 authored
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
                    break;
                case 'brand':
                    ext = {
                        brand: opt.id
                    };
                    break;
                case 'sort':
                    ext = {
                        sort: opt.id
                    };
                    break;
                case 'color':
                    ext = {
                        color: opt.id
                    };
                    break;
                case 'size':
                    ext = {
                        size: opt.id
                    };
                    break;
                case 'price':
                    ext = {
                        price: opt.id
                    };
                    break;
                case 'discount':
                    ext = {
                        discount: opt.id
                    };
                    break;
                case 'ageLevel':
                    ext = {
                        age_level: opt.id
                    };
                    break;
614 615
                default:
                    break;
王水玲 authored
616
            }
郭成尧 authored
617
            $.extend(defaultOpt, ext); // 扩展筛选项
王水玲 authored
618 619 620
        }
    }
郭成尧 authored
621
    // 导航类别
王水玲 authored
622 623 624 625 626 627 628 629 630 631 632 633 634 635
    if ($pre.hasClass('new')) {
        navType = 'newest';
    } else if ($pre.hasClass('price')) {
        navType = 'price';
    } else if ($pre.hasClass('discount')) {
        navType = 'discount';
    }
    nav = navInfo[navType];

    page = nav.page + 1;
    if (nav.reload) {
        page = 1;
    } else if (nav.end) {
郭成尧 authored
636
        // 不需要重新加载并且数据请求结束
王水玲 authored
637 638
        return;
    }
郭成尧 authored
639
郭成尧 authored
640
    // 封面图,defaultOpt对象也有可能包含coverChannel,但defaultOpt优先级高
郭成尧 authored
641 642 643 644
    if (coverChannel) {
        setting.coverChannel = coverChannel;
    }
王水玲 authored
645 646 647
    $.extend(setting, defaultOpt, {
        type: navType,
        order: nav.order,
郭成尧 authored
648 649
        page: page,
        appVersion: appVersion
王水玲 authored
650 651 652 653 654 655 656 657 658 659 660 661 662 663
    });

    if (brand) {
        setting.brand = brand;
    }
    if (shopId) {
        setting.shop_id = shopId;
    }

    searching = true;
    loading.showLoadingMask();

    $.ajax({
        type: 'GET',
郭成尧 authored
664
        url: opt.url ? opt.url : '',
王水玲 authored
665
        data: setting,
郭成尧 authored
666
        success: function(data) {
王水玲 authored
667 668 669 670 671 672 673 674 675 676 677 678 679
            var $container,
                num;

            switch (navType) {
                case 'newest':
                    $container = $ngc;
                    break;
                case 'price':
                    $container = $pgc;
                    break;
                case 'discount':
                    $container = $dgc;
                    break;
680 681
                default:
                    break;
王水玲 authored
682 683
            }
郭成尧 authored
684
            if (data === ' ') {
王水玲 authored
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
                nav.end = true;

                if (nav.reload) {
                    $container.html(noResult);
                }
            } else {
                if (nav.reload) {
                    $container.html(data);
                    lazyLoad($container.find('.lazy'));
                } else {
                    num = $container.find('.good-info').length;
                    $container.append(data);
                    lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy'));
                }
            }
郭成尧 authored
701 702
            scH = $('#scroller').outerHeight();
王水玲 authored
703 704 705 706 707 708 709 710
            nav.reload = false;
            nav.page = page;

            searching = false;
            loading.hideLoadingMask();

            window.rePosFooter();
郭成尧 authored
711
            myScroll && myScroll.refresh();
郭成尧 authored
712 713
            reNav1Pos();
王水玲 authored
714 715
            bindGoodThumbClick();
        },
郭成尧 authored
716
        error: function() {
王水玲 authored
717 718 719 720 721 722 723 724
            tip.show('网络断开连接了~');
            searching = false;
            loading.hideLoadingMask();
        }
    });
}

郭成尧 authored
725
$listNav.bind('contextmenu', function(e) {
王水玲 authored
726 727 728
    return false;
});
郭成尧 authored
729
$subNav.on('touchend touchcancel', function(e) {
王水玲 authored
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
    var $this = $(e.target).closest('li'),
        cname,
        nav,
        navType,
        $active;
    var bpIdData = $this.attr('data-bp-id') || '';

    e.preventDefault();
    $(document).trigger('shouldSendBpData', [bpIdData]);

    if (typeof $this === 'undefined' || $this.length === 0) {
        return;
    }

    if ($this.hasClass('filter')) {
郭成尧 authored
746
        // 筛选面板切换状态
王水玲 authored
747
        if ($this.hasClass('active')) {
郭成尧 authored
748
            $this.removeClass('active');
王水玲 authored
749
            filter.hideFilter();
郭成尧 authored
750
            myScroll && myScroll.enable();
王水玲 authored
751
        } else {
郭成尧 authored
752
            $this.addClass('active');
郭成尧 authored
753
            myScroll && myScroll.scrollTo(0, -(imgH + main1oH + nav1H));
郭成尧 authored
754 755 756 757 758

            theY = imgH + main1oH + nav1H;

            reNav1Pos();
王水玲 authored
759
            filter.showFilter();
郭成尧 authored
760 761 762 763 764 765 766

            if ($this.closest('.pos-list').length > 0) {
                $('.filter-mask').addClass('call-by-fix').css('top', '');
            } else {
                $('.filter-mask').removeClass('call-by-fix').css('top', $this.offset().top + nav1H);
            }
郭成尧 authored
767
            myScroll && myScroll.disable();
王水玲 authored
768 769
        }
    } else {
郭成尧 authored
770
郭成尧 authored
771
        filter.hideFilter();// 隐藏面板
郭成尧 authored
772
王水玲 authored
773 774 775 776 777 778 779 780 781 782 783
        if ($this.hasClass('new')) {
            cname = '.new';
            navType = 'newest';
        } else if ($this.hasClass('price')) {
            cname = '.price';
            navType = 'price';
        } else if ($this.hasClass('discount')) {
            cname = '.discount';
            navType = 'discount';
        }
郭成尧 authored
784
        myScroll && myScroll.enable();
郭成尧 authored
785
王水玲 authored
786 787 788 789
        nav = navInfo[navType];

        if ($this.hasClass('active')) {
郭成尧 authored
790
            // 最新无排序切换
王水玲 authored
791 792 793 794 795 796 797 798 799
            if ($this.hasClass('new')) {
                return;
            }

            if ($this.hasClass('price') || $this.hasClass('discount')) {
                $this = $subNav.find(cname);

                // 价格/折扣切换排序状态
                $this.find('.icon > .iconfont').toggleClass('cur');
郭成尧 authored
800 801
                nav.reload = true; // 重置reload,HTML会被替换为逆序的HTML
                nav.order = nav.order === 0 ? 1 : 0; // 切换排序
王水玲 authored
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816

                $goodsContainer.children('.container:not(.hide)').addClass('hide');

                switch (navType) {
                    case 'newest':
                        $ngc.removeClass('hide');
                        break;

                    case 'price':
                        $pgc.removeClass('hide');
                        break;

                    case 'discount':
                        $dgc.removeClass('hide');
                        break;
817 818
                    default:
                        break;
王水玲 authored
819 820 821 822 823 824 825 826
                }

            }
        } else {
            $active = $subNav.find('.active');

            if ($active.hasClass('filter')) {
郭成尧 authored
827
                // 若之前active项为筛选,则隐藏筛选面板
王水玲 authored
828 829 830
                filter.hideFilter();
            } else {
郭成尧 authored
831
                // 切换container显示
王水玲 authored
832 833 834 835 836 837 838 839 840 841 842 843 844 845
                $goodsContainer.children('.container:not(.hide)').addClass('hide');

                switch (navType) {
                    case 'newest':
                        $ngc.removeClass('hide');
                        break;

                    case 'price':
                        $pgc.removeClass('hide');
                        break;

                    case 'discount':
                        $dgc.removeClass('hide');
                        break;
846 847
                    default:
                        break;
王水玲 authored
848
                }
郭成尧 authored
849 850 851

                theY = imgH + main1oH + nav1H;
                reNav1Pos();
王水玲 authored
852 853 854 855 856 857 858 859 860 861 862
            }

            $subNav.children().removeClass('active');
            $subNav.find(cname).addClass('active');
        }

        if (nav.reload) {
            search({
                type: 'shop_id',
                id: shopId,
                brand: brand,
郭成尧 authored
863
                appVersion: appVersion,
郭成尧 authored
864
                url: location.protocol + '//m.yohobuy.com/product/search/search',
王水玲 authored
865 866 867 868 869 870 871
                nextPage: false
            });
        }
    }
    e.stopPropagation();
});
郭成尧 authored
872
filter.initFilter({
郭成尧 authored
873
    fCbFn: function(option) {
郭成尧 authored
874
        search(option);
郭成尧 authored
875
        myScroll && myScroll.enable();
郭成尧 authored
876
    },
郭成尧 authored
877
    hCbFn: function() {
王水玲 authored
878
郭成尧 authored
879
        // 切换active状态到$pre上
郭成尧 authored
880 881
        $pre.addClass('active');
        $pre.siblings('.filter').removeClass('active');
王水玲 authored
882
郭成尧 authored
883
        myScroll && myScroll.enable();
郭成尧 authored
884 885
    },
    missStatus: true
王水玲 authored
886 887
});
郭成尧 authored
888
$listNav.on('touchstart', 'li', function(e) {
王水玲 authored
889
    $(this).addClass('bytouch');
郭成尧 authored
890
}).on('touchend touchcancel', function() {
王水玲 authored
891
    $listNav.find('li').removeClass('bytouch');
郭成尧 authored
892
郭成尧 authored
893
    // myScroll && myScroll.refresh();
王水玲 authored
894 895
});
郭成尧 authored
896
$nav2.on('touchstart', 'li', function(e) {
王水玲 authored
897
    $(this).addClass('bytouch');
郭成尧 authored
898
}).on('touchend touchcancel', function() {
王水玲 authored
899
    $nav2.find('li').removeClass('bytouch');
郭成尧 authored
900
郭成尧 authored
901
    // myScroll && myScroll.refresh();
王水玲 authored
902 903
});
郭成尧 authored
904
// 底部导航点击
郭成尧 authored
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928
// function fotterClick(group) {
//     $(group + ' li').on('touchstart', function() {
//         $('.sub-group').addClass('hide');
//         $(this).find('.sub-group').removeClass('hide');
//     });
// }
//
// fotterClick('.shop-foot-wrapper');
//
// function stopPropagation(e) {
//     if (e.stopPropagation) {
//         e.stopPropagation();
//     } else {
//         e.cancelBubble = true;
//     }
// }
//
// $(document).bind('touchstart', function() {
//     $('.sub-group').addClass('hide');
// });
//
// $('#shop-category').bind('touchstart', function(e) {
//     // stopPropagation(e);
// });
王水玲 authored
929
930 931
$('.shop-foot-wrapper .buriedpoint').click(function() {
    var subGroup = $(this).find('.sub-group');
郭成尧 authored
932
    if (subGroup.hasClass('hide')) {
933
        subGroup.removeClass('hide');
郭成尧 authored
934
    } else {
935
        subGroup.addClass('hide');
王水玲 authored
936
    }
郭成尧 authored
937
});
郭成尧 authored
938
王水玲 authored
939
// 店铺收藏 || 取消收藏
郭成尧 authored
940
$collect.on('touchstart', function() {
王水玲 authored
941
    var opt;
王水玲 authored
942 943 944 945 946 947

    if (searching) {
        return;
    }
    searching = true;
948
    if ($collect.hasClass('already-collect')) {
王水玲 authored
949 950 951 952
        opt = 'cancel';
    } else {
        opt = 'ok';
    }
王水玲 authored
953
王水玲 authored
954
    $.ajax({
郭成尧 authored
955 956
        method: 'get',
        url: location.protocol + '//m.yohobuy.com' + '/product/opt/favoriteBrand',
王水玲 authored
957 958 959 960
        data: {
            id: favId ? favId : shopId,
            appVersion: appVersion,
            opt: opt,
郭成尧 authored
961 962
            type: 'shop',
            uid: uid
王水玲 authored
963
        },
郭成尧 authored
964 965 966
        xhrFields: {
            withCredentials: true
        },
郭成尧 authored
967
        success: function(data) {
968 969
            var url = '';
王水玲 authored
970
            if (data.code === 200) {
971 972
                if ($collect.hasClass('already-collect')) {
                    $collect.attr('class', 'not-collect');
郭成尧 authored
973
                    tip.show('店铺取消收藏成功');
王水玲 authored
974
                } else {
975
                    $collect.attr('class', 'already-collect');
郭成尧 authored
976
                    tip.show('店铺收藏成功');
王水玲 authored
977 978 979
                }
            }
郭成尧 authored
980
            if (data.code === 400) {
郭成尧 authored
981
                url = data.data;
郭成尧 authored
982 983 984 985
                if ($('#jump-login').length <= 0) {
                    $('body').append('<a href=\'' + url + '\'><span id="jump-login"><span></a>');
                }
                $('#jump-login').click();
王水玲 authored
986 987
            }
郭成尧 authored
988
            setTimeout(function() {
郭成尧 authored
989
                myScroll && myScroll.refresh();
王水玲 authored
990
                scH = $('#scroller').outerHeight();
郭成尧 authored
991
            }, 500);
王水玲 authored
992 993
            searching = false;
        },
郭成尧 authored
994
        error: function() {
王水玲 authored
995
            tip.show('网络断开连接了~');
王水玲 authored
996 997 998
            searching = false;
        }
    });
王水玲 authored
999
});