Your Name преди 3 години
родител
ревизия
e28c493e98

+ 6
- 25
src/pages/index/buildingDetail/components/SpecialPriceHouse/index.jsx Целия файл

@@ -1,8 +1,6 @@
1 1
 import React, { useState, useEffect, useRef } from 'react'
2 2
 import Taro from '@tarojs/taro'
3
-import { API_SPECIAL_ROOM_LIST } from '@/constants/api'
4 3
 import { ScrollView, Image } from '@tarojs/components'
5
-import { fetch } from '@/utils/request'
6 4
 import '@/assets/css/iconfont.css'
7 5
 import useTimer from './useTimer'
8 6
 import './index.scss'
@@ -11,38 +9,21 @@ const toW = n => `${Number(n / 10000).toFixed(1)}万`
11 9
 const itFmt = it => `${it.unitType} ${Number(it.currentPrice / it.area).toFixed(0)}元/㎡`
12 10
 
13 11
 export default function SpecialPriceHouse (props) {
14
-  const { Info } = props
15
-  const { buildingId } = Info || {}
16
-
17
-  const [list, setList] = useState([])
18
-  const [leftTime] = useTimer(list)
12
+  const { dataSource } = props
13
+  const [leftTime] = useTimer(dataSource)
19 14
 
20 15
   const handleMore = () => {
21 16
     Taro.navigateTo({ url: '/pages/index/specialPriceHouse/index' })
22 17
   }
23 18
 
24
-  useEffect(() => {
25
-    if (!buildingId) {
26
-      setList([])
27
-      return;
28
-    }
29
-
30
-    fetch({ url: API_SPECIAL_ROOM_LIST, method: 'get', params: { pageSize: 500, buildingId }, showToast: false}).then((res) => {
31
-      const { records } = res || {}
32
-      if (records && records.length) {
33
-        setList(records)
34
-      } else {
35
-        setList([])
36
-      }
37
-    })
38
-  }, [buildingId])
19
+  const len = dataSource ? dataSource.length : 0
39 20
 
40
-  return list.length > 0 && (
21
+  return len > 0 && (
41 22
     <view className='components SpecialPriceHouse'>
42 23
       <view className='Title flex-h'>
43 24
         <view className='flex-item'>
44 25
           <text>特价房源</text>
45
-          <text>{`(${list.length})`}</text>
26
+          <text>{`(${len})`}</text>
46 27
         </view>
47 28
         <text onClick={handleMore}>更多</text>
48 29
         <text className='iconfont icon-jiantouright'></text>
@@ -51,7 +32,7 @@ export default function SpecialPriceHouse (props) {
51 32
       <view className='List'>
52 33
         <ScrollView scrollX>
53 34
           {
54
-            list.map((item, index) => (
35
+            dataSource.map((item, index) => (
55 36
               <view className='ListItem' key={`List-${index}`}>
56 37
                 <text className='Tips'>{`${toW(item.thriftPrice)}`}</text>
57 38
                 <view className='Price'>

+ 4
- 0
src/pages/index/buildingDetail/components/SpecialPriceHouse/useTimer.js Целия файл

@@ -6,6 +6,10 @@ export default function useTimer(source) {
6 6
   const timerRef = useRef()
7 7
 
8 8
   useEffect(() => {
9
+    if (!source || !source.length) {
10
+      return;
11
+    }
12
+
9 13
     const ticker = () => {
10 14
       const now = (new Date()).valueOf()
11 15
 

+ 2
- 2
src/pages/index/buildingDetail/index.jsx Целия файл

@@ -4,7 +4,7 @@ import { ScrollView } from '@tarojs/components'
4 4
 import '@/assets/css/iconfont.css'
5 5
 import { useSelector } from 'react-redux'
6 6
 import { fetch } from '@/utils/request'
7
-import { API_ITEMS_DETAIL, API_SPECIAL_ROOM_LIST, API_PROJECT_TREND_LIST, API_ACTIVITY_GROUP, API_LIVE_LIST, API_NEWS_LIST } from '@/constants/api'
7
+import { API_ITEMS_DETAIL, API_PROJECT_TREND_LIST, API_ACTIVITY_GROUP, API_LIVE_LIST, API_NEWS_LIST } from '@/constants/api'
8 8
 import './index.scss'
9 9
 import DetailBottom from './components/DetailBottom/index'
10 10
 import Banner from './components/Banner/index'
@@ -137,7 +137,7 @@ export default withLayout((props) => {
137 137
 
138 138
                 {/* 特价房源 */}
139 139
                 <view className='SpecialPriceHouse' style={{minHeight: 0}}>
140
-                  <SpecialPriceHouse Info={DetailInfo}></SpecialPriceHouse>
140
+                  <SpecialPriceHouse dataSource={DetailInfo?.specialRoomList}></SpecialPriceHouse>
141 141
                 </view>
142 142
 
143 143
                 {/* 项目动态 */}