Authored by QC-L

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

... ... @@ -23,22 +23,14 @@ export default class ProductList extends Component {
});
}
componentWillReceiveProps(newProps) {
let { list } = newProps;
render() {
let { list } = this.props;
let newList = list.map((item) => {
if (!item.price) {
item.price = ''
}
return item
})
this.setState({
newList: newList
})
}
render() {
let {newList} = this.state;
return (
<View className="product-list">
{
... ...
... ... @@ -19,13 +19,13 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.fetchCollectionList();
},
fetchCollectionList: function () {
fetchCollectionList: function (reload) {
let that = this;
let collectionInfo = that.data.collectionInfo;
if (collectionInfo.isLoading || !collectionInfo.hasMore) {
if ((collectionInfo.isLoading || !collectionInfo.hasMore) && !reload) {
return;
}
collectionInfo.isLoading = true;
... ... @@ -49,7 +49,11 @@ Page({
.then(data => {
if (data) {
let list = data.product_list;
collectionInfo.collectionList = collectionInfo.collectionList.concat(list);
if (reload) {
collectionInfo.collectionList = list;
} else {
collectionInfo.collectionList = collectionInfo.collectionList.concat(list);
}
collectionInfo.isLoading = false;
collectionInfo.currentPage = data.page;
... ... @@ -88,7 +92,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.fetchCollectionList(true);
},
/**
... ... @@ -116,7 +120,7 @@ Page({
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.fetchCollectionList();
this.fetchCollectionList(false);
},
/**
... ...
{
"navigationBarBackgroundColor": "#ffffff",
"usingComponents": {
"product-list": "../../../components/product-list/index"
"product-list": "../../../components/product-list/index",
"no-data-show-view": "../../../components/no-data-show-view/no-data-show-view"
}
}
\ No newline at end of file
... ...
... ... @@ -5,5 +5,9 @@
<view wx:if="{{collectionInfo.collectionList.length > 0}}" class='collection-list'>
<product-list list="{{collectionInfo.collectionList}}" __triggerObserer="{{ _triggerObserer }}"></product-list>
</view>
<view wx:else class='empty'>暂无数据</view>
<block wx:else>
<view class='empty'>
<no-data-show-view emptyText="暂无收藏"></no-data-show-view>
</view>
</block>
</view>
... ...
... ... @@ -252,7 +252,7 @@ export default class UserCenter extends Component {
if (ret && ret.code === 200 && ret.data) {
let list = this.state.list;
let num = ret.data.product_favorite_total;
list[2].num = num;
list[1].num = num;
this.setState({
list
});
... ...