Showing
1 changed file
with
18 additions
and
25 deletions
@@ -11,7 +11,6 @@ require('./shop/coupon'); | @@ -11,7 +11,6 @@ require('./shop/coupon'); | ||
11 | 11 | ||
12 | let Tab = require('plugin/tab'); | 12 | let Tab = require('plugin/tab'); |
13 | let defaultOpt = require('../common/query-param'); | 13 | let defaultOpt = require('../common/query-param'); |
14 | -let defaultOptCopy = {}; | ||
15 | 14 | ||
16 | let $goodsContainer = $('#goods-container'); | 15 | let $goodsContainer = $('#goods-container'); |
17 | let $fsgc = $goodsContainer.children('.firstscreen-goods'); | 16 | let $fsgc = $goodsContainer.children('.firstscreen-goods'); |
@@ -22,6 +21,7 @@ let $pgc = $goodsContainer.children('.price-goods'); | @@ -22,6 +21,7 @@ let $pgc = $goodsContainer.children('.price-goods'); | ||
22 | let $dgc = $goodsContainer.children('.discount-goods'); | 21 | let $dgc = $goodsContainer.children('.discount-goods'); |
23 | let $listNav = $('#list-nav'); // 筛选项列表 | 22 | let $listNav = $('#list-nav'); // 筛选项列表 |
24 | let $pre = $listNav.find('.active'); // 记录进入筛选前的active项,初始为选中项 | 23 | let $pre = $listNav.find('.active'); // 记录进入筛选前的active项,初始为选中项 |
24 | +let $filterBody = $('.filter-body'); | ||
25 | 25 | ||
26 | let allGoodsTabClickTimes = 0; | 26 | let allGoodsTabClickTimes = 0; |
27 | 27 | ||
@@ -59,32 +59,22 @@ let navInfo = { | @@ -59,32 +59,22 @@ let navInfo = { | ||
59 | }; | 59 | }; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | - * 判断两个对象是否相等 | ||
63 | - * @param {*} a | ||
64 | - * @param {*} b | 62 | + * 处理筛选参数 |
65 | */ | 63 | */ |
66 | -function isObjectValueEqual(a, b) { | ||
67 | - let aProps = Object.getOwnPropertyNames(a); | ||
68 | - let bProps = Object.getOwnPropertyNames(b); | 64 | +function handleChoseFilter() { |
65 | + $.each($filterBody.find('.chosed'), function(index, elem) { | ||
66 | + let choseOpt = {}; | ||
69 | 67 | ||
70 | - if (aProps.length != bProps.length) { // eslint-disable-line | ||
71 | - return false; | ||
72 | - } | ||
73 | - | ||
74 | - for (let i = 0; i < aProps.length; i++) { | ||
75 | - let propName = aProps[i]; | ||
76 | - | ||
77 | - if (a[propName] !== b[propName]) { | ||
78 | - return false; | ||
79 | - } | ||
80 | - } | ||
81 | - return true; | 68 | + choseOpt[$(elem).parent().data('type')] = $(elem).data('id'); |
69 | + Object.assign(defaultOpt, choseOpt); | ||
70 | + }); | ||
82 | } | 71 | } |
83 | 72 | ||
84 | /** | 73 | /** |
85 | * 获取商品列表 | 74 | * 获取商品列表 |
86 | */ | 75 | */ |
87 | function getGoodsList() { | 76 | function getGoodsList() { |
77 | + handleChoseFilter(); | ||
88 | console.log('ok'); | 78 | console.log('ok'); |
89 | } | 79 | } |
90 | 80 | ||
@@ -92,16 +82,17 @@ function getGoodsList() { | @@ -92,16 +82,17 @@ function getGoodsList() { | ||
92 | * 加载筛选数据 | 82 | * 加载筛选数据 |
93 | */ | 83 | */ |
94 | function getFilter() { | 84 | function getFilter() { |
95 | - if (allGoodsTabClickTimes === 0 || !isObjectValueEqual(defaultOptCopy, defaultOpt)) { | ||
96 | - // 第一次点进来或者改变了筛选参数时调用 | 85 | + if (allGoodsTabClickTimes === 0) { |
86 | + // 第一次点进来调用 | ||
97 | 87 | ||
98 | - defaultOptCopy = $.extend(true, {}, defaultOpt); | ||
99 | - allGoodsTabClickTimes++; | ||
100 | $.ajax({ | 88 | $.ajax({ |
101 | type: 'GET', | 89 | type: 'GET', |
102 | url: location.protocol + '//m.yohobuy.com/product/search/filter', | 90 | url: location.protocol + '//m.yohobuy.com/product/search/filter', |
103 | data: defaultOpt, | 91 | data: defaultOpt, |
104 | success: function(data) { | 92 | success: function(data) { |
93 | + if (data) { // 判断需要再严禁些,确定数据正常后再 ++ | ||
94 | + allGoodsTabClickTimes++; | ||
95 | + } | ||
105 | $goodsContainer.append(data); | 96 | $goodsContainer.append(data); |
106 | 97 | ||
107 | // 初始化filter&注册filter回调 | 98 | // 初始化filter&注册filter回调 |
@@ -114,12 +105,14 @@ function getFilter() { | @@ -114,12 +105,14 @@ function getFilter() { | ||
114 | $pre.siblings('.filter').removeClass('active'); | 105 | $pre.siblings('.filter').removeClass('active'); |
115 | } | 106 | } |
116 | }); | 107 | }); |
108 | + | ||
109 | + $filterBody = $('.filter-body'); | ||
117 | } | 110 | } |
118 | }); | 111 | }); |
119 | } | 112 | } |
120 | } | 113 | } |
121 | 114 | ||
122 | -// 绑定 getfilter 方法,在点击全部商品时调用 | 115 | +// 绑定 getfilter 方法,在点击全部商品 Tab 时调用 |
123 | Tab.prototype.getfilter = getFilter; | 116 | Tab.prototype.getfilter = getFilter; |
124 | Tab.prototype.getgoodslist = getGoodsList; | 117 | Tab.prototype.getgoodslist = getGoodsList; |
125 | 118 | ||
@@ -140,7 +133,7 @@ $listNav.on('touchend touchcancel', function(e) { | @@ -140,7 +133,7 @@ $listNav.on('touchend touchcancel', function(e) { | ||
140 | if ($this.hasClass('active')) { | 133 | if ($this.hasClass('active')) { |
141 | filter.hideFilter(); | 134 | filter.hideFilter(); |
142 | 135 | ||
143 | - // 点击筛选钱的active项回复active | 136 | + // 点击筛选前的 active 项恢复 active |
144 | $pre.addClass('active'); | 137 | $pre.addClass('active'); |
145 | $this.removeClass('active'); | 138 | $this.removeClass('active'); |
146 | } else { | 139 | } else { |
-
Please register or login to post a comment