Authored by 李奇

店铺装修修改

@@ -3,7 +3,6 @@ import Promise from '../../vendors/es6-promise'; @@ -3,7 +3,6 @@ import Promise from '../../vendors/es6-promise';
3 import commonModel from '../../models/common'; 3 import commonModel from '../../models/common';
4 import indexModel from '../../models/index/index'; 4 import indexModel from '../../models/index/index';
5 5
6 -// 获取应用实例  
7 const app = getApp(); 6 const app = getApp();
8 const router = global.router; 7 const router = global.router;
9 8
@@ -12,7 +11,22 @@ Page({ @@ -12,7 +11,22 @@ Page({
12 shopInfo: {}, 11 shopInfo: {},
13 shopBanner: '', 12 shopBanner: '',
14 shopProductList: [], 13 shopProductList: [],
15 - decorFloors: [] 14 + decorFloors: [],
  15 + floatFilter: false,
  16 + pageScrollTop: 0,
  17 + standInClientTop: 0,
  18 + disableDecide: false,
  19 + searchBarHeight: 0,
  20 + filterHeight: 0,
  21 + filterTrigger: false,
  22 +
  23 + gender: '',
  24 + order: '',
  25 + page: 1,
  26 + limit: 4,
  27 + totalPage: 1,
  28 + allLoaded: false,
  29 + showLoading: false
16 }, 30 },
17 onLoad: function() { 31 onLoad: function() {
18 32
@@ -38,18 +52,63 @@ Page({ @@ -38,18 +52,63 @@ Page({
38 } 52 }
39 }).catch(() => {}); 53 }).catch(() => {});
40 } 54 }
  55 +
  56 + // 记录
  57 + this.recordHeight();
  58 + },
  59 +
  60 + onPageScroll: function({scrollTop}) {
  61 + this._decideFloatFilter(scrollTop);
  62 + },
  63 +
  64 + onReachBottom: function() {
  65 + this._productList();
41 }, 66 },
42 67
43 getShopData: function(shopId) { 68 getShopData: function(shopId) {
44 this._shopInfo(shopId); 69 this._shopInfo(shopId);
45 this._shopDecor(shopId); 70 this._shopDecor(shopId);
46 - this._shopFavCount(shopId);  
47 }, 71 },
48 72
49 getShopProducts: function() { 73 getShopProducts: function() {
50 this._productList(); 74 this._productList();
51 }, 75 },
52 76
  77 + toSearch() {
  78 + router.go('productSearch');
  79 + },
  80 +
  81 + recordHeight: function() {
  82 + const query = wx.createSelectorQuery();
  83 +
  84 + query.select('.search-bar').boundingClientRect(rect => {
  85 + this.data.searchBarHeight = rect.bottom - rect.top;
  86 + }).exec();
  87 +
  88 + query.select('.header-filter').boundingClientRect(rect => {
  89 + this.data.filterHeight = rect.bottom - rect.top;
  90 + }).exec();
  91 + },
  92 +
  93 + // 筛选变更
  94 + filterChange: function(e) {
  95 + let {curSort, gender} = e.detail;
  96 +
  97 + this.data.order = curSort;
  98 + this.data.gender = gender;
  99 +
  100 + this._resetPage();
  101 + this.data.shopProductList = [];
  102 + this.data.filterTrigger = true;
  103 + this._productList();
  104 + },
  105 +
  106 + _resetPage: function() {
  107 + this.data.page = 1;
  108 + this.data.totalPage = 1;
  109 + this.data.allLoaded = false;
  110 + },
  111 +
53 // 店铺信息 112 // 店铺信息
54 _shopInfo: function(shopId) { 113 _shopInfo: function(shopId) {
55 const params = { 114 const params = {
@@ -82,7 +141,6 @@ Page({ @@ -82,7 +141,6 @@ Page({
82 141
83 indexModel.shopDecorator(params) 142 indexModel.shopDecorator(params)
84 .then(res => { 143 .then(res => {
85 -  
86 if (res.code === 200) { 144 if (res.code === 200) {
87 let floors = []; 145 let floors = [];
88 let modules = res.data.modules; 146 let modules = res.data.modules;
@@ -113,40 +171,20 @@ Page({ @@ -113,40 +171,20 @@ Page({
113 .catch(() => {}); 171 .catch(() => {});
114 }, 172 },
115 173
116 - // 店铺收藏  
117 - _shopFavCount: function(shopId) {  
118 - indexModel.shopFavCount({favIds: shopId}).then(res => {  
119 - const favCount = res.data[0].approximateCount || '2.1w'; 174 + // 商品列表
  175 + _productList: function(params = {}) {
  176 + if (this.data.allLoaded) {
  177 + return;
  178 + }
120 179
121 - this.setData({  
122 - favCount  
123 - }); 180 + this.setData({
  181 + showLoading: true
124 }); 182 });
125 - },  
126 -  
127 - // 筛选变更  
128 - filterChange: function(e) {  
129 - let params;  
130 - let {curSort, gender} = e.detail;  
131 -  
132 - this.data.order = curSort;  
133 - this.data.gender = gender;  
134 183
135 - params = {  
136 - gender,  
137 - order: curSort,  
138 - page: 1,  
139 - limit: 20  
140 - };  
141 - this.data.productList = [];  
142 -  
143 - params.setScrollPos = true;  
144 - this._productList(params);  
145 - },  
146 -  
147 - // 商品列表  
148 - _productList: function(params) {  
149 - params = params || {page: 1, pageNo: 20}; 184 + params.page = this.data.page;
  185 + params.limit = this.data.limit;
  186 + params.gender = this.data.gender;
  187 + params.order = this.data.order;
150 params.shop_id = app.getShopId(); 188 params.shop_id = app.getShopId();
151 189
152 indexModel.shopProductList(params).then(res => { 190 indexModel.shopProductList(params).then(res => {
@@ -169,16 +207,57 @@ Page({ @@ -169,16 +207,57 @@ Page({
169 list.push(item); 207 list.push(item);
170 }); 208 });
171 209
  210 + this.data.page += 1;
  211 + this.data.totalPage = res.data && res.data.page_total || 1;
  212 +
172 this.setData({ 213 this.setData({
173 - currentPage: params.page,  
174 - productList: this.data.shopProductList.concat(list),  
175 - totalPage: res.data && res.data.page_total || 0 214 + showLoading: false,
  215 + allLoaded: this.data.page > this.data.totalPage,
  216 + shopProductList: this.data.shopProductList.concat(list)
176 }); 217 });
  218 +
  219 + if (this.data.floatFilter && this.data.filterTrigger) {
  220 + let calcTop;
  221 +
  222 + calcTop = this.data.pageScrollTop + this.data.standInClientTop - this.data.searchBarHeight;
  223 + this.data.disableDecide = true;
  224 + wx.pageScrollTo({
  225 + scrollTop: calcTop,
  226 + duration: 10
  227 + });
  228 + setTimeout(() => {
  229 + this.data.disableDecide = false;
  230 + this.data.filterTrigger = false;
  231 + }, 200);
  232 + }
177 } 233 }
178 }).catch(() => {}); 234 }).catch(() => {});
179 }, 235 },
180 236
181 - toSearch() {  
182 - router.go('productSearch'); 237 + _decideFloatFilter: function(scrollTop) {
  238 + const query = wx.createSelectorQuery();
  239 + const serHeight = this.data.searchBarHeight;
  240 +
  241 + if (this.data.disableDecide) {
  242 + return;
  243 + }
  244 +
  245 + this.data.pageScrollTop = scrollTop;
  246 + query.select('.header-filter').boundingClientRect(rect => {
  247 + if (rect.top < serHeight && !this.data.floatFilter) {
  248 + this.setData({
  249 + floatFilter: true
  250 + });
  251 + }
  252 + }).exec();
  253 +
  254 + query.select('.filter-stand-in').boundingClientRect(rect => {
  255 + this.data.standInClientTop = rect.top;
  256 + if (rect.top > serHeight && this.data.floatFilter) {
  257 + this.setData({
  258 + floatFilter: false
  259 + });
  260 + }
  261 + }).exec();
183 } 262 }
184 }); 263 });
@@ -19,16 +19,17 @@ @@ -19,16 +19,17 @@
19 bindclickreport="resourceClickReport"> 19 bindclickreport="resourceClickReport">
20 </resources> 20 </resources>
21 <view class="product-list"> 21 <view class="product-list">
22 - <view class="header-filter">  
23 - <view class="filter {{floatFilter ? 'float' : ''}}"> 22 + <view class="header-filter {{floatFilter ? 'float' : ''}}">
  23 + <view class="filter">
24 <product-list-filter bind:sortchange="filterChange"></product-list-filter> 24 <product-list-filter bind:sortchange="filterChange"></product-list-filter>
25 </view> 25 </view>
26 </view> 26 </view>
  27 + <view class="filter-stand-in" hidden="{{!floatFilter}}"></view>
27 <view class="list"> 28 <view class="list">
28 <product-list 29 <product-list
29 bindproductclick="productClick" 30 bindproductclick="productClick"
30 - list="{{productList}}"  
31 - show-no-more="{{showNoMore}}" 31 + list="{{shopProductList}}"
  32 + show-no-more="{{allLoaded}}"
32 show-loading="{{showLoading}}"> 33 show-loading="{{showLoading}}">
33 </product-list> 34 </product-list>
34 </view> 35 </view>
@@ -101,3 +101,15 @@ @@ -101,3 +101,15 @@
101 .header-filter { 101 .header-filter {
102 border-bottom: 1px solid #eee; 102 border-bottom: 1px solid #eee;
103 } 103 }
  104 +
  105 +.header-filter.float {
  106 + position: fixed;
  107 + top: 95rpx;
  108 + left: 0;
  109 + right: 0;
  110 + z-index: 1;
  111 +}
  112 +
  113 +.filter-stand-in {
  114 + height: 88rpx;
  115 +}