Authored by QC-L

添加无收藏的逻辑判断 review by 黄敬囿

@@ -23,22 +23,14 @@ export default class ProductList extends Component { @@ -23,22 +23,14 @@ export default class ProductList extends Component {
23 }); 23 });
24 } 24 }
25 25
26 - componentWillReceiveProps(newProps) {  
27 - let { list } = newProps; 26 + render() {
  27 + let { list } = this.props;
28 let newList = list.map((item) => { 28 let newList = list.map((item) => {
29 if (!item.price) { 29 if (!item.price) {
30 item.price = '' 30 item.price = ''
31 } 31 }
32 return item 32 return item
33 }) 33 })
34 -  
35 - this.setState({  
36 - newList: newList  
37 - })  
38 - }  
39 -  
40 - render() {  
41 - let {newList} = this.state;  
42 return ( 34 return (
43 <View className="product-list"> 35 <View className="product-list">
44 { 36 {
@@ -19,13 +19,13 @@ Page({ @@ -19,13 +19,13 @@ Page({
19 * 生命周期函数--监听页面加载 19 * 生命周期函数--监听页面加载
20 */ 20 */
21 onLoad: function (options) { 21 onLoad: function (options) {
22 - this.fetchCollectionList(); 22 +
23 }, 23 },
24 24
25 - fetchCollectionList: function () { 25 + fetchCollectionList: function (reload) {
26 let that = this; 26 let that = this;
27 let collectionInfo = that.data.collectionInfo; 27 let collectionInfo = that.data.collectionInfo;
28 - if (collectionInfo.isLoading || !collectionInfo.hasMore) { 28 + if ((collectionInfo.isLoading || !collectionInfo.hasMore) && !reload) {
29 return; 29 return;
30 } 30 }
31 collectionInfo.isLoading = true; 31 collectionInfo.isLoading = true;
@@ -49,7 +49,11 @@ Page({ @@ -49,7 +49,11 @@ Page({
49 .then(data => { 49 .then(data => {
50 if (data) { 50 if (data) {
51 let list = data.product_list; 51 let list = data.product_list;
  52 + if (reload) {
  53 + collectionInfo.collectionList = list;
  54 + } else {
52 collectionInfo.collectionList = collectionInfo.collectionList.concat(list); 55 collectionInfo.collectionList = collectionInfo.collectionList.concat(list);
  56 + }
53 collectionInfo.isLoading = false; 57 collectionInfo.isLoading = false;
54 collectionInfo.currentPage = data.page; 58 collectionInfo.currentPage = data.page;
55 59
@@ -88,7 +92,7 @@ Page({ @@ -88,7 +92,7 @@ Page({
88 * 生命周期函数--监听页面显示 92 * 生命周期函数--监听页面显示
89 */ 93 */
90 onShow: function () { 94 onShow: function () {
91 - 95 + this.fetchCollectionList(true);
92 }, 96 },
93 97
94 /** 98 /**
@@ -116,7 +120,7 @@ Page({ @@ -116,7 +120,7 @@ Page({
116 * 页面上拉触底事件的处理函数 120 * 页面上拉触底事件的处理函数
117 */ 121 */
118 onReachBottom: function () { 122 onReachBottom: function () {
119 - this.fetchCollectionList(); 123 + this.fetchCollectionList(false);
120 }, 124 },
121 125
122 /** 126 /**
1 { 1 {
2 "navigationBarBackgroundColor": "#ffffff", 2 "navigationBarBackgroundColor": "#ffffff",
3 "usingComponents": { 3 "usingComponents": {
4 - "product-list": "../../../components/product-list/index" 4 + "product-list": "../../../components/product-list/index",
  5 + "no-data-show-view": "../../../components/no-data-show-view/no-data-show-view"
5 } 6 }
6 } 7 }
@@ -5,5 +5,9 @@ @@ -5,5 +5,9 @@
5 <view wx:if="{{collectionInfo.collectionList.length > 0}}" class='collection-list'> 5 <view wx:if="{{collectionInfo.collectionList.length > 0}}" class='collection-list'>
6 <product-list list="{{collectionInfo.collectionList}}" __triggerObserer="{{ _triggerObserer }}"></product-list> 6 <product-list list="{{collectionInfo.collectionList}}" __triggerObserer="{{ _triggerObserer }}"></product-list>
7 </view> 7 </view>
8 - <view wx:else class='empty'>暂无数据</view> 8 + <block wx:else>
  9 + <view class='empty'>
  10 + <no-data-show-view emptyText="暂无收藏"></no-data-show-view>
  11 + </view>
  12 + </block>
9 </view> 13 </view>
@@ -252,7 +252,7 @@ export default class UserCenter extends Component { @@ -252,7 +252,7 @@ export default class UserCenter extends Component {
252 if (ret && ret.code === 200 && ret.data) { 252 if (ret && ret.code === 200 && ret.data) {
253 let list = this.state.list; 253 let list = this.state.list;
254 let num = ret.data.product_favorite_total; 254 let num = ret.data.product_favorite_total;
255 - list[2].num = num; 255 + list[1].num = num;
256 this.setState({ 256 this.setState({
257 list 257 list
258 }); 258 });