...
|
...
|
@@ -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();
|
|
|
}
|
|
|
}); |
...
|
...
|
|