Authored by baoss

资讯列表页修改

@@ -9,6 +9,13 @@ export default { @@ -9,6 +9,13 @@ export default {
9 return result && result.data || []; 9 return result && result.data || [];
10 }); 10 });
11 }, 11 },
  12 + getAllCmsListByPage(param) {
  13 + return api.get({
  14 + url: '/CmsInfoController/getAllCmsListByPage',
  15 + api: 'store',
  16 + data: param
  17 + });
  18 + },
12 getListCategory(param) { 19 getListCategory(param) {
13 return api.get({ 20 return api.get({
14 url: '/CmsInfoController/getCmsListByCategory', 21 url: '/CmsInfoController/getCmsListByCategory',
@@ -8,39 +8,16 @@ let yas; @@ -8,39 +8,16 @@ let yas;
8 8
9 Page({ 9 Page({
10 data: { 10 data: {
11 - navIndex: 0, // 默认选中的位置  
12 - newsNav: [],  
13 - newsItem: [] 11 + page: 1,
  12 + limit: 20,
  13 + end: false,
  14 + newsList: []
14 }, 15 },
15 onLoad: function(options) { 16 onLoad: function(options) {
16 yas = new Yas(app); 17 yas = new Yas(app);
17 yas.pageOpenReport(); 18 yas.pageOpenReport();
  19 + this.getAllCmsListByPage();
18 20
19 - return newsModel.getAllCmsCategory().then(result => {  
20 - result.push({  
21 - id: -1,  
22 - categoryName: '有货精选'  
23 - });  
24 -  
25 - let navIndex = parseInt(`0${options.nav}`, 10);  
26 - let tcategoryId = 0;  
27 - let newsItem = [];  
28 - let newsNav = result.map((nav, index) => {  
29 - newsItem.push({ page: 1, end: false, data: [] }); // init  
30 -  
31 - if (navIndex === index) {  
32 - tcategoryId = nav.id;  
33 - }  
34 -  
35 - return {  
36 - id: nav.id,  
37 - name: nav.categoryName  
38 - };  
39 - });  
40 -  
41 - this.setData({ newsNav, newsItem, navIndex });  
42 - return this.getListCategory(tcategoryId, navIndex);  
43 - });  
44 }, 21 },
45 onShareAppMessage: function(res) { 22 onShareAppMessage: function(res) {
46 let pages = getCurrentPages(); 23 let pages = getCurrentPages();
@@ -57,7 +34,7 @@ Page({ @@ -57,7 +34,7 @@ Page({
57 34
58 return { 35 return {
59 title: params.TITLE, // 分享标题 36 title: params.TITLE, // 分享标题
60 - path: `pages/cms/news?nav=${this.data.navIndex}`, 37 + path: `pages/cms/news`,
61 success: function() { 38 success: function() {
62 yas.report('YB_SHARE_RESULT_L', params); // 首页分享上报 39 yas.report('YB_SHARE_RESULT_L', params); // 首页分享上报
63 }, 40 },
@@ -67,60 +44,16 @@ Page({ @@ -67,60 +44,16 @@ Page({
67 } 44 }
68 }; 45 };
69 }, 46 },
70 - getYohoShrewd: function(index) {  
71 - let newsItem = this.data.newsItem; 47 + getAllCmsListByPage: function() {
  48 + let newsData = this.data;
72 49
73 - return newsModel.getGuangList({  
74 - page: newsItem[index].page || 1,  
75 - limit: 20  
76 - }).then(result => {  
77 - if (result.code !== 200) {  
78 - return result;  
79 - }  
80 -  
81 - result = result && result.data && result.data.list && result.data.list.artList || [];  
82 -  
83 - if (result.length <= 0) {  
84 - newsItem[index].end = true;  
85 - } else {  
86 - result = result.map(item => {  
87 - return {  
88 - id: item.id,  
89 - title: item.title,  
90 - pic: item.src,  
91 - miniParams: {  
92 - app: 'yohobuy',  
93 - page: 'guangDetail',  
94 - data: {  
95 - id: item.id  
96 - }  
97 - }  
98 - };  
99 - });  
100 -  
101 - newsItem[index].data = newsItem[index].data.concat(result);  
102 - newsItem[index].page = ++newsItem[index].page;  
103 - }  
104 -  
105 - this.setData({newsItem});  
106 - return result;  
107 - }).catch({});  
108 - },  
109 - getListCategory: function(id, index) {  
110 - let newsItem = this.data.newsItem;  
111 -  
112 - if (newsItem[index].end) { 50 + if (newsData.end) {
113 return Promise.resolve({ code: 200, data: [], message: '' }); 51 return Promise.resolve({ code: 200, data: [], message: '' });
114 } 52 }
115 53
116 - if (id === -1) {  
117 - return this.getYohoShrewd(index);  
118 - }  
119 -  
120 - return newsModel.getListCategory({  
121 - page: newsItem[index].page || 1,  
122 - limit: 20,  
123 - categoryId: id 54 + return newsModel.getAllCmsListByPage({
  55 + page: newsData.page || 1,
  56 + limit: newsData.limit,
124 }).then(result => { 57 }).then(result => {
125 if (result.code !== 200) { 58 if (result.code !== 200) {
126 return result; 59 return result;
@@ -129,35 +62,22 @@ Page({ @@ -129,35 +62,22 @@ Page({
129 result = result && result.data && result.data.rows || []; 62 result = result && result.data && result.data.rows || [];
130 63
131 if (result.length <= 0) { 64 if (result.length <= 0) {
132 - newsItem[index].end = true; 65 + newsData.end = true;
133 } else { 66 } else {
134 result = result.map(item => { 67 result = result.map(item => {
135 return Object.assign({}, item, {url: `/pages/cms/newsDetail?id=${item.id}`}); 68 return Object.assign({}, item, {url: `/pages/cms/newsDetail?id=${item.id}`});
136 }); 69 });
137 70
138 - newsItem[index].data = newsItem[index].data.concat(result);  
139 - newsItem[index].page = ++newsItem[index].page; 71 + newsData.newsList = newsData.newsList.concat(result);
  72 + newsData.page = ++newsData.page;
140 } 73 }
141 74
142 - this.setData({ newsItem }); 75 + this.setData(newsData);
143 return result; 76 return result;
144 }).catch({}); 77 }).catch({});
145 }, 78 },
146 - tapNav: function(e) {  
147 - let dataset = e.detail.dataset || {};  
148 79
149 - wx.showLoading({  
150 - title: '正在加载中...'  
151 - });  
152 -  
153 - return this.getListCategory(dataset.id, dataset.index).then(() => {  
154 - wx.hideLoading();  
155 - this.setData({ navIndex: dataset.index });  
156 - });  
157 - },  
158 tapLoadMore: function() { 80 tapLoadMore: function() {
159 - let index = this.data.navIndex;  
160 -  
161 - this.getListCategory(this.data.newsNav[index].id, index); 81 + this.getAllCmsListByPage();
162 } 82 }
163 }); 83 });
@@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
2 "navigationBarTitleText": "MKT", 2 "navigationBarTitleText": "MKT",
3 "usingComponents": { 3 "usingComponents": {
4 "my-scroll-view": "/components/my-scroll-view/index", 4 "my-scroll-view": "/components/my-scroll-view/index",
5 - "my-scroll-nav": "/components/my-scroll-nav/index",  
6 "load-more": "/components/load-more/index", 5 "load-more": "/components/load-more/index",
7 "news-item": "/components/news-item/news-item" 6 "news-item": "/components/news-item/news-item"
8 } 7 }
1 -<wxs src="../../wxs/helper.wxs" module="helper" />  
2 1
3 -<my-scroll-nav defaultIndex="{{navIndex}}" navs="{{newsNav}}" bindtapNav="tapNav"></my-scroll-nav>  
4 <my-scroll-view class="news-page" 2 <my-scroll-view class="news-page"
5 isTop="true" 3 isTop="true"
6 isShare="true" 4 isShare="true"
7 bindtapLoadMore="tapLoadMore"> 5 bindtapLoadMore="tapLoadMore">
8 <view class="news-container"> 6 <view class="news-container">
9 - <view class="news-list" wx:for="{{newsItem}}" wx:key="index" hidden="{{index !== navIndex}}">  
10 - <news-item newItem="{{item.data}}" wx:if="{{item.data.length}}"></news-item>  
11 - <load-more end="{{item.end}}"></load-more> 7 + <view class="news-list">
  8 + <news-item newItem="{{newsList}}" wx:if="{{newsList.length}}"></news-item>
  9 + <load-more end="{{end}}"></load-more>
12 </view> 10 </view>
13 </view> 11 </view>
14 </my-scroll-view> 12 </my-scroll-view>