张延森 3 年前
父节点
当前提交
8ef9a5d0d1

+ 13
- 8
src/pages/index/buildingDetail/components/SpecialPriceHouse/index.jsx 查看文件

@@ -1,16 +1,21 @@
1
-import React, { useState, useEffect } from 'react'
1
+import React, { useState, useEffect, useRef } from 'react'
2 2
 import Taro from '@tarojs/taro'
3 3
 import { API_SPECIAL_ROOM_LIST } from '@/constants/api'
4 4
 import { ScrollView, Image } from '@tarojs/components'
5 5
 import { fetch } from '@/utils/request'
6 6
 import '@/assets/css/iconfont.css'
7
+import useTimer from './useTimer'
7 8
 import './index.scss'
8 9
 
10
+const toW = n => `${Number(n / 10000).toFixed(1)}万`
11
+const itFmt = it => `${it.unitType} ${Number(it.currentPrice / it.area).toFixed(0)}元/㎡`
12
+
9 13
 export default function SpecialPriceHouse (props) {
10 14
   const { Info } = props
11 15
   const { buildingId } = Info || {}
12 16
 
13 17
   const [list, setList] = useState([])
18
+  const [leftTime] = useTimer(list)
14 19
 
15 20
   const handleMore = () => {
16 21
     Taro.navigateTo({ url: '/pages/index/specialPriceHouse/index' })
@@ -44,18 +49,18 @@ export default function SpecialPriceHouse (props) {
44 49
       </view>
45 50
 
46 51
       <view className='List'>
47
-        <ScrollView scroll-x={true}>
52
+        <ScrollView scrollX>
48 53
           {
49 54
             list.map((item, index) => (
50 55
               <view className='ListItem' key={`List-${index}`}>
51
-                <text className='Tips'>省17.8万</text>
56
+                <text className='Tips'>{`${toW(item.thriftPrice)}`}</text>
52 57
                 <view className='Price'>
53
-                  <text>867.3万</text>
54
-                  <text>888.1万</text>
58
+                  <text>{toW(item.currentPrice)}</text>
59
+                  <text>{toW(item.originalPrice)}</text>
55 60
                 </view>
56
-                <text className='Time'>距结束还有06天10时14分</text>
57
-                <text className='HouseType'>4室2厅2卫 23433元/㎡</text>
58
-                <text className='DoorNumber'>1#-5单元-401</text>
61
+                <text className='Time'>{`距结束还有 ${leftTime[index] ? leftTime[index][1] : ''}`}</text>
62
+                <text className='HouseType'>{itFmt(item)}</text>
63
+                <text className='DoorNumber'>{item.roomName}</text>
59 64
               </view>
60 65
             ))
61 66
           }

+ 32
- 0
src/pages/index/buildingDetail/components/SpecialPriceHouse/useTimer.js 查看文件

@@ -0,0 +1,32 @@
1
+import { useEffect, useRef, useState } from "react";
2
+import { formateLeftTime } from '@/utils/tools'
3
+
4
+export default function useTimer(source) {
5
+  const [list, setList] = useState([])
6
+  const timerRef = useRef()
7
+
8
+  useEffect(() => {
9
+    const ticker = () => {
10
+      const now = (new Date()).valueOf()
11
+
12
+      const arr = source.map((it) => {
13
+        const dt = (new Date(it.endTime)).valueOf()
14
+        const ss = dt - now
15
+
16
+        return [
17
+          it[0],
18
+          formateLeftTime(ss, 'min'),
19
+        ]
20
+      })
21
+
22
+      setList(arr)
23
+    }
24
+
25
+    ticker()
26
+    timerRef.current = setInterval(ticker, 1000 * 60)
27
+
28
+    return () => clearInterval(timerRef.current)
29
+  }, [source])
30
+
31
+  return [list]
32
+}

+ 1
- 1
src/pages/index/buildingDetail/index.jsx 查看文件

@@ -136,7 +136,7 @@ export default withLayout((props) => {
136 136
                 </view>
137 137
 
138 138
                 {/* 特价房源 */}
139
-                <view className='SpecialPriceHouse'>
139
+                <view className='SpecialPriceHouse' style={{minHeight: 0}}>
140 140
                   <SpecialPriceHouse Info={DetailInfo}></SpecialPriceHouse>
141 141
                 </view>
142 142