Authored by 李奇

商品列表修改

@@ -52,7 +52,7 @@ Page({ @@ -52,7 +52,7 @@ Page({
52 }); 52 });
53 }, 53 },
54 onReachBottom: function() { 54 onReachBottom: function() {
55 - this._productList(this.data.urlParams); 55 + this._productList();
56 }, 56 },
57 57
58 // 筛选变更 58 // 筛选变更
@@ -51,7 +51,7 @@ Page({ @@ -51,7 +51,7 @@ Page({
51 }); 51 });
52 }, 52 },
53 onReachBottom: function() { 53 onReachBottom: function() {
54 - this._productList(this.data.urlParams); 54 + this._productList();
55 }, 55 },
56 56
57 // 筛选变更 57 // 筛选变更
@@ -2,22 +2,23 @@ import wx from '../../../utils/wx'; @@ -2,22 +2,23 @@ import wx from '../../../utils/wx';
2 import Yas from '../../../common/yas'; 2 import Yas from '../../../common/yas';
3 import listModel from '../../../models/product/list'; 3 import listModel from '../../../models/product/list';
4 4
5 -const {windowHeight} = getApp().getSystemInfo();  
6 let yas; 5 let yas;
7 const app = getApp(); 6 const app = getApp();
  7 +const {windowHeight} = getApp().getSystemInfo();
8 8
9 Page({ 9 Page({
10 data: { 10 data: {
11 order: '', 11 order: '',
12 gender: '', 12 gender: '',
13 - searched: false,  
14 - productList: [],  
15 - showLoading: false,  
16 - showNoMore: false,  
17 - currentPage: 0, 13 +
  14 + // 原始参数
  15 + orgOps: {},
  16 +
  17 + page: 1,
  18 + limit: 20,
18 totalPage: 1, 19 totalPage: 1,
19 - urlParams: {},  
20 - showBackTop: false, 20 + allLoaded: false,
  21 + productList: [],
21 noResult: false, 22 noResult: false,
22 windowHeight 23 windowHeight
23 }, 24 },
@@ -31,12 +32,7 @@ Page({ @@ -31,12 +32,7 @@ Page({
31 }); 32 });
32 delete options.title; 33 delete options.title;
33 34
34 - options.shop_id = app.getShopId();  
35 -  
36 - this.setData({  
37 - urlParams: options  
38 - });  
39 - this.productList(options); 35 + this._productList();
40 36
41 yas = new Yas(); 37 yas = new Yas();
42 yas.pageOpenReport(); 38 yas.pageOpenReport();
@@ -54,38 +50,42 @@ Page({ @@ -54,38 +50,42 @@ Page({
54 }); 50 });
55 }, 51 },
56 onReachBottom: function() { 52 onReachBottom: function() {
57 - this.productList(this.data.urlParams); 53 + this._productList();
58 }, 54 },
59 - setBrandTitle: function(brandId) {  
60 - listModel.brandIntro(brandId).then(res => {  
61 - if (res.code === 200) {  
62 - wx.setNavigationBarTitle({  
63 - title: res.data.brand_name  
64 - });  
65 - }  
66 - })  
67 - .catch(() => {  
68 - wx.setNavigationBarTitle({  
69 - title: '商品列表'  
70 - });  
71 - }); 55 +
  56 + // 筛选变更
  57 + filterChange: function(e) {
  58 + let {curSort, gender} = e.detail;
  59 +
  60 + this.data.order = curSort;
  61 + this.data.gender = gender;
  62 +
  63 + this._resetPage();
  64 + this.data.productList = [];
  65 + this._productList();
72 }, 66 },
73 - productList: function(params = {}) {  
74 - params.page = this.data.currentPage + 1;  
75 67
76 - if (params.page > this.data.totalPage) {  
77 - return;  
78 - } 68 + _resetPage: function() {
  69 + this.data.page = 1;
  70 + this.data.totalPage = 1;
  71 + this.data.allLoaded = false;
  72 + },
79 73
80 - if (this.data.isLoading) { 74 + // 商品列表
  75 + _productList: function(params = {}) {
  76 + if (this.data.allLoaded) {
81 return; 77 return;
82 } 78 }
83 79
84 - this.data.isLoading = true;  
85 - wx.showLoading({title: '加载中'}); 80 + this.setData({
  81 + showLoading: true
  82 + });
  83 +
  84 + params.page = this.data.page;
  85 + params.limit = this.data.limit;
86 params.order = this.data.order; 86 params.order = this.data.order;
87 params.gender = this.data.gender; 87 params.gender = this.data.gender;
88 - params.limit = 20; 88 + params.shop_id = app.getShopId();
89 listModel.productList(params).then(res => { 89 listModel.productList(params).then(res => {
90 if (res.code === 200) { 90 if (res.code === 200) {
91 const keyAdapter = { 91 const keyAdapter = {
@@ -106,35 +106,15 @@ Page({ @@ -106,35 +106,15 @@ Page({
106 list.push(item); 106 list.push(item);
107 }); 107 });
108 108
109 - this.data.isLoading = false;  
110 - wx.hideLoading(); 109 + this.data.page += 1;
  110 + this.data.totalPage = res.data && res.data.page_total || 1;
  111 +
111 this.setData({ 112 this.setData({
112 showLoading: false, 113 showLoading: false,
113 - productList: this.data.productList.concat(list),  
114 - currentPage: params.page,  
115 - totalPage: res.data.page_total,  
116 - showNoMore: params.page === res.data.page_total,  
117 - noResult: !this.data.productList.concat(list).length  
118 - });  
119 -  
120 - if (params.resetScroll) {  
121 - wx.pageScrollTo({  
122 - scrollTop: 0,  
123 - duration: 10 114 + allLoaded: this.data.page > this.data.totalPage || params.limit > list.length,
  115 + productList: this.data.productList.concat(list)
124 }); 116 });
125 } 117 }
126 - }  
127 - });  
128 - },  
129 - sortChange: function(e) {  
130 - let {curSort, gender} = e.detail;  
131 -  
132 - this.data.gender = gender;  
133 - this.data.order = curSort;  
134 - this.data.currentPage = 0;  
135 - this.data.totalPage = 1;  
136 -  
137 - this.data.productList = [];  
138 - this.productList(Object.assign({resetScroll: true}, this.data.urlParams)); 118 + }).catch(() => {});
139 } 119 }
140 }); 120 });
1 <view class="list-container" style="min-height:{{windowHeight}}px;"> 1 <view class="list-container" style="min-height:{{windowHeight}}px;">
2 <view class="filter-view"> 2 <view class="filter-view">
3 - <product-list-filter bind:sortchange="sortChange" cur-gender="{{gender}}"></product-list-filter> 3 + <product-list-filter bind:sortchange="filterChange" cur-gender="{{gender}}"></product-list-filter>
4 </view> 4 </view>
5 <view class="list-view"> 5 <view class="list-view">
6 <view class="no-res" wx:if="{{noResult}}"> 6 <view class="no-res" wx:if="{{noResult}}">
@@ -8,9 +8,11 @@ @@ -8,9 +8,11 @@
8 <view class="no-res-txt">未搜索到任何相关商品</view> 8 <view class="no-res-txt">未搜索到任何相关商品</view>
9 </view> 9 </view>
10 <view wx:if="{{productList.length}}"> 10 <view wx:if="{{productList.length}}">
11 - <product-list list="{{productList}}" 11 + <product-list
  12 + list="{{productList}}"
12 show-loading="{{showLoading}}" 13 show-loading="{{showLoading}}"
13 - show-no-more="{{showNoMore}}"></product-list> 14 + show-no-more="{{allLoaded}}">
  15 + </product-list>
14 </view> 16 </view>
15 </view> 17 </view>
16 <copyright class="copy-right"></copyright> 18 <copyright class="copy-right"></copyright>
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 "compileType": "miniprogram", 10 "compileType": "miniprogram",
11 "libVersion": "1.9.1", 11 "libVersion": "1.9.1",
12 "appid": "wxe8bfc9b404772199", 12 "appid": "wxe8bfc9b404772199",
13 - "projectname": "有货官方-VANS", 13 + "projectname": "%E6%9C%89%E8%B4%A7%E5%AE%98%E6%96%B9-VANS",
14 "condition": { 14 "condition": {
15 "search": { 15 "search": {
16 "current": -1, 16 "current": -1,