Your Name 3 년 전
부모
커밋
e28c493e98

+ 6
- 25
src/pages/index/buildingDetail/components/SpecialPriceHouse/index.jsx 파일 보기

1
 import React, { useState, useEffect, useRef } from 'react'
1
 import React, { useState, useEffect, useRef } from 'react'
2
 import Taro from '@tarojs/taro'
2
 import Taro from '@tarojs/taro'
3
-import { API_SPECIAL_ROOM_LIST } from '@/constants/api'
4
 import { ScrollView, Image } from '@tarojs/components'
3
 import { ScrollView, Image } from '@tarojs/components'
5
-import { fetch } from '@/utils/request'
6
 import '@/assets/css/iconfont.css'
4
 import '@/assets/css/iconfont.css'
7
 import useTimer from './useTimer'
5
 import useTimer from './useTimer'
8
 import './index.scss'
6
 import './index.scss'
11
 const itFmt = it => `${it.unitType} ${Number(it.currentPrice / it.area).toFixed(0)}元/㎡`
9
 const itFmt = it => `${it.unitType} ${Number(it.currentPrice / it.area).toFixed(0)}元/㎡`
12
 
10
 
13
 export default function SpecialPriceHouse (props) {
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
   const handleMore = () => {
15
   const handleMore = () => {
21
     Taro.navigateTo({ url: '/pages/index/specialPriceHouse/index' })
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
     <view className='components SpecialPriceHouse'>
22
     <view className='components SpecialPriceHouse'>
42
       <view className='Title flex-h'>
23
       <view className='Title flex-h'>
43
         <view className='flex-item'>
24
         <view className='flex-item'>
44
           <text>特价房源</text>
25
           <text>特价房源</text>
45
-          <text>{`(${list.length})`}</text>
26
+          <text>{`(${len})`}</text>
46
         </view>
27
         </view>
47
         <text onClick={handleMore}>更多</text>
28
         <text onClick={handleMore}>更多</text>
48
         <text className='iconfont icon-jiantouright'></text>
29
         <text className='iconfont icon-jiantouright'></text>
51
       <view className='List'>
32
       <view className='List'>
52
         <ScrollView scrollX>
33
         <ScrollView scrollX>
53
           {
34
           {
54
-            list.map((item, index) => (
35
+            dataSource.map((item, index) => (
55
               <view className='ListItem' key={`List-${index}`}>
36
               <view className='ListItem' key={`List-${index}`}>
56
                 <text className='Tips'>{`${toW(item.thriftPrice)}`}</text>
37
                 <text className='Tips'>{`${toW(item.thriftPrice)}`}</text>
57
                 <view className='Price'>
38
                 <view className='Price'>

+ 4
- 0
src/pages/index/buildingDetail/components/SpecialPriceHouse/useTimer.js 파일 보기

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

+ 2
- 2
src/pages/index/buildingDetail/index.jsx 파일 보기

4
 import '@/assets/css/iconfont.css'
4
 import '@/assets/css/iconfont.css'
5
 import { useSelector } from 'react-redux'
5
 import { useSelector } from 'react-redux'
6
 import { fetch } from '@/utils/request'
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
 import './index.scss'
8
 import './index.scss'
9
 import DetailBottom from './components/DetailBottom/index'
9
 import DetailBottom from './components/DetailBottom/index'
10
 import Banner from './components/Banner/index'
10
 import Banner from './components/Banner/index'
137
 
137
 
138
                 {/* 特价房源 */}
138
                 {/* 特价房源 */}
139
                 <view className='SpecialPriceHouse' style={{minHeight: 0}}>
139
                 <view className='SpecialPriceHouse' style={{minHeight: 0}}>
140
-                  <SpecialPriceHouse Info={DetailInfo}></SpecialPriceHouse>
140
+                  <SpecialPriceHouse dataSource={DetailInfo?.specialRoomList}></SpecialPriceHouse>
141
                 </view>
141
                 </view>
142
 
142
 
143
                 {/* 项目动态 */}
143
                 {/* 项目动态 */}