张延森 3 anos atrás
pai
commit
8ef9a5d0d1

+ 13
- 8
src/pages/index/buildingDetail/components/SpecialPriceHouse/index.jsx Ver arquivo

1
-import React, { useState, useEffect } 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'
3
 import { API_SPECIAL_ROOM_LIST } from '@/constants/api'
4
 import { ScrollView, Image } from '@tarojs/components'
4
 import { ScrollView, Image } from '@tarojs/components'
5
 import { fetch } from '@/utils/request'
5
 import { fetch } from '@/utils/request'
6
 import '@/assets/css/iconfont.css'
6
 import '@/assets/css/iconfont.css'
7
+import useTimer from './useTimer'
7
 import './index.scss'
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
 export default function SpecialPriceHouse (props) {
13
 export default function SpecialPriceHouse (props) {
10
   const { Info } = props
14
   const { Info } = props
11
   const { buildingId } = Info || {}
15
   const { buildingId } = Info || {}
12
 
16
 
13
   const [list, setList] = useState([])
17
   const [list, setList] = useState([])
18
+  const [leftTime] = useTimer(list)
14
 
19
 
15
   const handleMore = () => {
20
   const handleMore = () => {
16
     Taro.navigateTo({ url: '/pages/index/specialPriceHouse/index' })
21
     Taro.navigateTo({ url: '/pages/index/specialPriceHouse/index' })
44
       </view>
49
       </view>
45
 
50
 
46
       <view className='List'>
51
       <view className='List'>
47
-        <ScrollView scroll-x={true}>
52
+        <ScrollView scrollX>
48
           {
53
           {
49
             list.map((item, index) => (
54
             list.map((item, index) => (
50
               <view className='ListItem' key={`List-${index}`}>
55
               <view className='ListItem' key={`List-${index}`}>
51
-                <text className='Tips'>省17.8万</text>
56
+                <text className='Tips'>{`${toW(item.thriftPrice)}`}</text>
52
                 <view className='Price'>
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
                 </view>
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
               </view>
64
               </view>
60
             ))
65
             ))
61
           }
66
           }

+ 32
- 0
src/pages/index/buildingDetail/components/SpecialPriceHouse/useTimer.js Ver arquivo

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 Ver arquivo

136
                 </view>
136
                 </view>
137
 
137
 
138
                 {/* 特价房源 */}
138
                 {/* 特价房源 */}
139
-                <view className='SpecialPriceHouse'>
139
+                <view className='SpecialPriceHouse' style={{minHeight: 0}}>
140
                   <SpecialPriceHouse Info={DetailInfo}></SpecialPriceHouse>
140
                   <SpecialPriceHouse Info={DetailInfo}></SpecialPriceHouse>
141
                 </view>
141
                 </view>
142
 
142