Authored by baoss

资讯列表页修改

... ... @@ -9,6 +9,13 @@ export default {
return result && result.data || [];
});
},
getAllCmsListByPage(param) {
return api.get({
url: '/CmsInfoController/getAllCmsListByPage',
api: 'store',
data: param
});
},
getListCategory(param) {
return api.get({
url: '/CmsInfoController/getCmsListByCategory',
... ...
... ... @@ -8,39 +8,16 @@ let yas;
Page({
data: {
navIndex: 0, // 默认选中的位置
newsNav: [],
newsItem: []
page: 1,
limit: 20,
end: false,
newsList: []
},
onLoad: function(options) {
yas = new Yas(app);
yas.pageOpenReport();
this.getAllCmsListByPage();
return newsModel.getAllCmsCategory().then(result => {
result.push({
id: -1,
categoryName: '有货精选'
});
let navIndex = parseInt(`0${options.nav}`, 10);
let tcategoryId = 0;
let newsItem = [];
let newsNav = result.map((nav, index) => {
newsItem.push({ page: 1, end: false, data: [] }); // init
if (navIndex === index) {
tcategoryId = nav.id;
}
return {
id: nav.id,
name: nav.categoryName
};
});
this.setData({ newsNav, newsItem, navIndex });
return this.getListCategory(tcategoryId, navIndex);
});
},
onShareAppMessage: function(res) {
let pages = getCurrentPages();
... ... @@ -57,7 +34,7 @@ Page({
return {
title: params.TITLE, // 分享标题
path: `pages/cms/news?nav=${this.data.navIndex}`,
path: `pages/cms/news`,
success: function() {
yas.report('YB_SHARE_RESULT_L', params); // 首页分享上报
},
... ... @@ -67,60 +44,16 @@ Page({
}
};
},
getYohoShrewd: function(index) {
let newsItem = this.data.newsItem;
getAllCmsListByPage: function() {
let newsData = this.data;
return newsModel.getGuangList({
page: newsItem[index].page || 1,
limit: 20
}).then(result => {
if (result.code !== 200) {
return result;
}
result = result && result.data && result.data.list && result.data.list.artList || [];
if (result.length <= 0) {
newsItem[index].end = true;
} else {
result = result.map(item => {
return {
id: item.id,
title: item.title,
pic: item.src,
miniParams: {
app: 'yohobuy',
page: 'guangDetail',
data: {
id: item.id
}
}
};
});
newsItem[index].data = newsItem[index].data.concat(result);
newsItem[index].page = ++newsItem[index].page;
}
this.setData({newsItem});
return result;
}).catch({});
},
getListCategory: function(id, index) {
let newsItem = this.data.newsItem;
if (newsItem[index].end) {
if (newsData.end) {
return Promise.resolve({ code: 200, data: [], message: '' });
}
if (id === -1) {
return this.getYohoShrewd(index);
}
return newsModel.getListCategory({
page: newsItem[index].page || 1,
limit: 20,
categoryId: id
return newsModel.getAllCmsListByPage({
page: newsData.page || 1,
limit: newsData.limit,
}).then(result => {
if (result.code !== 200) {
return result;
... ... @@ -129,35 +62,22 @@ Page({
result = result && result.data && result.data.rows || [];
if (result.length <= 0) {
newsItem[index].end = true;
newsData.end = true;
} else {
result = result.map(item => {
return Object.assign({}, item, {url: `/pages/cms/newsDetail?id=${item.id}`});
});
newsItem[index].data = newsItem[index].data.concat(result);
newsItem[index].page = ++newsItem[index].page;
newsData.newsList = newsData.newsList.concat(result);
newsData.page = ++newsData.page;
}
this.setData({ newsItem });
this.setData(newsData);
return result;
}).catch({});
},
tapNav: function(e) {
let dataset = e.detail.dataset || {};
wx.showLoading({
title: '正在加载中...'
});
return this.getListCategory(dataset.id, dataset.index).then(() => {
wx.hideLoading();
this.setData({ navIndex: dataset.index });
});
},
tapLoadMore: function() {
let index = this.data.navIndex;
this.getListCategory(this.data.newsNav[index].id, index);
this.getAllCmsListByPage();
}
});
... ...
... ... @@ -2,7 +2,6 @@
"navigationBarTitleText": "MKT",
"usingComponents": {
"my-scroll-view": "/components/my-scroll-view/index",
"my-scroll-nav": "/components/my-scroll-nav/index",
"load-more": "/components/load-more/index",
"news-item": "/components/news-item/news-item"
}
... ...
<wxs src="../../wxs/helper.wxs" module="helper" />
<my-scroll-nav defaultIndex="{{navIndex}}" navs="{{newsNav}}" bindtapNav="tapNav"></my-scroll-nav>
<my-scroll-view class="news-page"
isTop="true"
isShare="true"
bindtapLoadMore="tapLoadMore">
<view class="news-container">
<view class="news-list" wx:for="{{newsItem}}" wx:key="index" hidden="{{index !== navIndex}}">
<news-item newItem="{{item.data}}" wx:if="{{item.data.length}}"></news-item>
<load-more end="{{item.end}}"></load-more>
<view class="news-list">
<news-item newItem="{{newsList}}" wx:if="{{newsList.length}}"></news-item>
<load-more end="{{end}}"></load-more>
</view>
</view>
</my-scroll-view>
... ...