Authored by 郭成尧

back

@@ -14,8 +14,8 @@ const domains = { @@ -14,8 +14,8 @@ const domains = {
14 liveApi: 'http://testapi.live.yohops.com:9999/', 14 liveApi: 'http://testapi.live.yohops.com:9999/',
15 singleApi: 'http://api-test3.yohops.com:9999/', 15 singleApi: 'http://api-test3.yohops.com:9999/',
16 16
17 - api: 'http://api.yoho.cn/',  
18 - service: 'http://service.yoho.cn/', 17 + api: 'http://api-test3.yohops.com:9999/',
  18 + service: 'http://service-test3.yohops.com:9999/',
19 global: 'http://api-global.yohobuy.com', 19 global: 'http://api-global.yohobuy.com',
20 20
21 // liveApi: 'http://api.live.yoho.cn/', 21 // liveApi: 'http://api.live.yoho.cn/',
1 -/*  
2 - * @Author: Targaryen  
3 - * @Date: 2017-04-26 17:22:32  
4 - * @Last Modified by: Targaryen  
5 - * @Last Modified time: 2017-04-26 17:45:28 1 +/**
  2 + * 逛首页
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/10
6 */ 5 */
7 -'use strict';  
8 require('guang/index.page.css'); 6 require('guang/index.page.css');
9 7
10 -const index = './index';  
11 -const IndexController = require(`${index}/controller`); 8 +let $ = require('yoho-jquery');
12 9
13 -new IndexController(); 10 +let info = require('./info');
  11 +let loadMore = info.loadMore;
  12 +
  13 +let $loadMoreInfo = $('#load-more-info');
  14 +let $loading = $(''),
  15 + $noMore = $('');
  16 +
  17 +let winH = $(window).height();
  18 +
  19 +let $infoList = $('#info-list'),
  20 + $infos = $infoList.children('.info-list'),
  21 + $nav = $('#guang-nav'),
  22 + $curNav = $nav.children('.focus'),
  23 + curType = $curNav.data('type');
  24 +
  25 +let getDynamicData = require('./list-dynamic');
  26 +
  27 +let state = {};
  28 +
  29 +require('common');
  30 +
  31 +if ($loadMoreInfo.length > 0) {
  32 + $loading = $loadMoreInfo.children('.loading');
  33 + $noMore = $loadMoreInfo.children('.no-more');
  34 +}
  35 +
  36 +info.initSwiper(curType);
  37 +
  38 +info.initInfosEvt($infoList);
  39 +
  40 +// 初始化各Nav下资讯加载的状态
  41 +(function() {
  42 + let gender = $('#gender').val();
  43 +
  44 + $nav.children('.guang-nav-item').each(function() {
  45 + let type = $(this).data('type'),
  46 + focus = $(this).hasClass('focus');
  47 +
  48 + state[type] = {
  49 + page: focus ? 2 : 1,
  50 + gender: gender,
  51 + type: type,
  52 + end: false
  53 + };
  54 + });
  55 +
  56 + getDynamicData.getDynamicData();
  57 +}());
  58 +$nav.bind('contextmenu', function() {
  59 + return false;
  60 +});
  61 +$nav.on('touchend touchcancel', function(e) {
  62 +
  63 + let $this = $(e.target).closest('.guang-nav-item'),
  64 + $content,
  65 + index;
  66 +
  67 + if ($this.hasClass('focus')) {
  68 + return;
  69 + }
  70 +
  71 + e.preventDefault();
  72 + index = $this.index();
  73 +
  74 + $this.addClass('focus');
  75 + $curNav.removeClass('focus');
  76 +
  77 + $content = $infos.eq(index);
  78 +
  79 + $curNav = $this;
  80 + curType = $this.data('type');
  81 +
  82 + // 当未加载数据时去请求数据
  83 + if (state[curType].page === 1) {
  84 +
  85 + // 无数据时隐藏正在加载和没有更多字样
  86 + $loading.addClass('hide');
  87 + $noMore.addClass('hide');
  88 +
  89 + state[curType].isTab = true;
  90 + loadMore($content, state[curType]);
  91 + } else {
  92 +
  93 + // 重置当前Tab的load-more
  94 + if (state[curType].end) {
  95 + $loading.addClass('hide');
  96 + $noMore.removeClass('hide');
  97 + } else {
  98 + $loading.removeClass('hide');
  99 + $noMore.addClass('hide');
  100 + }
  101 + }
  102 +
  103 + $infos.not('.hide').addClass('hide');
  104 + $content.removeClass('hide');
  105 +
  106 + if (state[curType].page === 1) {
  107 + window.rePosFooter();// 进入空内容时重新定位footer位置
  108 + }
  109 +});
  110 +
  111 +function scrollHandler() {
  112 + let $c = $infos.not('.hide');
  113 +
  114 + if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $c.height()) {
  115 + loadMore($c, state[curType]);
  116 + }
  117 +}
  118 +
  119 +// srcoll to load more
  120 +$(document).scroll(function() {
  121 + window.requestAnimationFrame(scrollHandler);
  122 +});
  123 +
  124 +$nav.on('touchstart', function(e) {
  125 + let target = e.target || e.srcElement;
  126 +
  127 + target.className = 'bytouch ' + target.className;
  128 +}).on('touchend touchcancel', function() {
  129 + $nav.find('li').removeClass('bytouch');
  130 +});