Browse Source

newsbanner

xujing 5 years ago
parent
commit
2fd30457da
2 changed files with 105 additions and 57 deletions
  1. 7
    57
      src/pages/project/index.js
  2. 98
    0
      src/pages/project/newsbanner/index.js

+ 7
- 57
src/pages/project/index.js View File

3
 import './index.scss'
3
 import './index.scss'
4
 import ProjectItem from './item'
4
 import ProjectItem from './item'
5
 import Banner from './banner'
5
 import Banner from './banner'
6
+import Newsbanner from './newsbanner'
6
 import HelpGroupBanner from './swiper'
7
 import HelpGroupBanner from './swiper'
7
 // import ActivityItem from '../activity/item'
8
 // import ActivityItem from '../activity/item'
8
 import ready from '@utils/ready'
9
 import ready from '@utils/ready'
53
 
54
 
54
   componentWillMount() {
55
   componentWillMount() {
55
     ready.queue(() => {
56
     ready.queue(() => {
57
+
58
+      Taro.hideTabBar()
56
       this.getLocation()
59
       this.getLocation()
57
 
60
 
58
       Taro.setNavigationBarTitle({ title: this.props.userInfo.miniApp.name })
61
       Taro.setNavigationBarTitle({ title: this.props.userInfo.miniApp.name })
84
 
87
 
85
     if (this.props.curCity.id) {
88
     if (this.props.curCity.id) {
86
       ready.queue(() => {
89
       ready.queue(() => {
87
-        Taro.hideTabBar()
90
+        // Taro.hideTabBar()
88
         this.loadData()
91
         this.loadData()
89
       })
92
       })
90
     }
93
     }
229
     if (curCity.id) {
232
     if (curCity.id) {
230
       payload.cityId = curCity.id
233
       payload.cityId = curCity.id
231
     }
234
     }
232
-    // debugger
235
+
233
     this.setState({
236
     this.setState({
234
-      newsList: []
237
+      newsList: [{}]
235
     }, () => {
238
     }, () => {
236
       queryNewsList(payload).then(res => {
239
       queryNewsList(payload).then(res => {
237
         this.setState({
240
         this.setState({
241
     })
244
     })
242
   }
245
   }
243
 
246
 
244
-  // loadActivityList() {
245
-  //   const { curCity } = this.props
246
-  //   const payload = {
247
-  //     pageNumber: 1,
248
-  //     pageSize: 1
249
-  //   }
250
-  //   if (curCity.id) {
251
-  //     payload.cityId = curCity.id
252
-  //   }
253
-  //   queryActivityList(payload).then(res => {
254
-  //     this.setState({
255
-  //       activityList: res.list || []
256
-  //     }, () => {
257
-  //       console.log(this.state.activityList)
258
-  //     })
259
-  //   })
260
-  // }
261
 
247
 
262
   loadList() {
248
   loadList() {
263
     const { keywords } = this.state
249
     const { keywords } = this.state
283
           title: '当前城市暂无楼盘',
269
           title: '当前城市暂无楼盘',
284
           icon: 'none'
270
           icon: 'none'
285
         })
271
         })
286
-
287
       }
272
       }
288
-
289
       Taro.hideLoading()
273
       Taro.hideLoading()
290
       this.setState({
274
       this.setState({
291
         loaded: true
275
         loaded: true
643
                 }
627
                 }
644
 
628
 
645
               </View>
629
               </View>
646
-              {
647
-                newsList.length &&
648
-                <View style="background-color:#fff">
649
-                  <View className="notice-box">
650
-                    <View style="display: flex;align-items: center;">
651
-                      <Image className="notice-icon" src={require('@assets/notice.png')}></Image>
652
-                      <Swiper
653
-                        className='notice-swiper'
654
-                        circular
655
-                        autoplay
656
-                        interval="3000"
657
-                        onChange={this.changeCurrent.bind(this)}
658
-                        vertical="true"
659
-                      >
660
-                        {
661
-                          newsList.map((list, inx) => {
662
-                            return (
663
-                              <SwiperItem key={`news-${inx}`}>
664
-                                <View className="notice-text" onClick={this.handleNoticeClick.bind(this, list)}>
665
-                                  {list.newsName}
666
-                                </View>
667
-                              </SwiperItem>
668
-                            )
669
-                          })
670
-                        }
671
-                      </Swiper>
672
-                    </View>
673
-                    {newsList.length > 1 &&
674
-                      <View className="notice-more" onClick={this.toNewsList}>
675
-                        更多 <Text className="iconfont icon-more"></Text>
676
-                      </View>
677
-                    }
678
-                  </View>
679
-                </View>
680
-              }
630
+              <Newsbanner cityId={curCity.id} onClick={this.handleNoticeClick} onClickMore={this.toNewsList} />
681
 
631
 
682
               {/* 推荐楼盘 */}
632
               {/* 推荐楼盘 */}
683
               {this.renderProjectList()}
633
               {this.renderProjectList()}

+ 98
- 0
src/pages/project/newsbanner/index.js View File

1
+import Taro, { Component } from '@tarojs/taro'
2
+import { View, Swiper, SwiperItem, Image } from '@tarojs/components'
3
+import { queryNewsList } from '@services/news'
4
+
5
+export default class SwiperBanner extends Component {
6
+  static options = {
7
+    addGlobalClass: true,
8
+  };
9
+
10
+  state = {
11
+    lastCity: undefined,
12
+    list: [],
13
+    current: 0,
14
+  }
15
+
16
+  timer = null;
17
+
18
+  componentWillReceiveProps(nextProps) {
19
+    
20
+    if (nextProps.cityId != this.state.lastCity) {
21
+      const payload = {
22
+        pageNumber: 1,
23
+        pageSize: 999,
24
+        cityId: nextProps.cityId,
25
+      }
26
+
27
+      queryNewsList(payload).then(res => {
28
+        this.clearTimer()
29
+
30
+        this.setState({
31
+          list: res.records || [],
32
+          lastCity: nextProps.cityId,
33
+          current: 0,
34
+        }, () => {
35
+          if (this.state.list.length > 1) {
36
+            this.timer = setInterval(() => {
37
+              let current = this.state.current + 1
38
+              if (current >= this.state.list.length) {
39
+                current = 0
40
+              }
41
+  
42
+              this.setState({ current })
43
+            }, 3000)
44
+          }
45
+        })
46
+      })  
47
+    }
48
+  }
49
+
50
+  clearTimer = () => {
51
+    if (this.timer) {
52
+      clearInterval(this.timer)
53
+      this.timer = null
54
+    }
55
+
56
+  }
57
+
58
+  componentWillUnmount() {
59
+    this.clearTimer()
60
+  }
61
+
62
+  render() {
63
+    if (!this.state.list.length) return null;
64
+
65
+    return (
66
+      <View className="notice-box">
67
+        <View style="display: flex;align-items: center;">
68
+          <Image className="notice-icon" src={require('@assets/notice.png')}></Image>
69
+          <Swiper
70
+            className='notice-swiper'
71
+            circular
72
+            // autoplay
73
+            // interval="3000"
74
+            vertical="true"
75
+            current={this.state.current}
76
+          >
77
+            {
78
+              this.state.list.map((item, inx) => {
79
+                return (
80
+                  <SwiperItem key={`news-${inx}`}>
81
+                    <View className="notice-text" onClick={() => this.props.onClick(item)}>
82
+                      {item.newsName}
83
+                    </View>
84
+                  </SwiperItem>
85
+                )
86
+              })
87
+            }
88
+          </Swiper>
89
+        </View>
90
+        {this.state.list.length > 1 &&
91
+          <View className="notice-more" onClick={this.props.onClickMore}>
92
+            更多 <Text className="iconfont icon-more"></Text>
93
+          </View>
94
+        }
95
+      </View>
96
+    )
97
+  }
98
+}