张延森 3 years ago
parent
commit
8aa9238365

+ 3
- 35
src/pages/index/buildingDetail/components/BasicInfo/index.jsx View File

@@ -1,8 +1,6 @@
1
-import { useState, useEffect } from 'react'
2
-import Taro from '@tarojs/taro'
3 1
 import { ScrollView, Image } from '@tarojs/components'
4 2
 import classNames from 'classnames'
5
-import { favorProject, cancelFavorProject } from '@/services/item'
3
+import useFavor from '@/utils/hooks/useFavor'
6 4
 import '@/assets/css/iconfont.css'
7 5
 import './index.scss'
8 6
 
@@ -10,37 +8,7 @@ export default function BasicInfo (props) {
10 8
   const { Info = {} } = props
11 9
   const { buildingId, isSave } = Info
12 10
 
13
-  const [isSaved, setIsSaved] = useState(false)
14
-
15
-  useEffect(() => { setIsSaved(isSave) }, [isSave])
16
-  
17
-  const handleFavor = () => {
18
-    if (isSaved) {
19
-      cancelFavorProject(buildingId).then(() => {
20
-        setIsSaved(false)
21
-        Taro.showToast({
22
-          title: '已取消收藏',
23
-          icon: 'none',
24
-        })
25
-      })
26
-    } else {
27
-      favorProject(buildingId).then(() => {
28
-        setIsSaved(true)
29
-        Taro.showToast({
30
-          title: '收藏成功',
31
-          icon: 'none',
32
-        })
33
-      })
34
-    }
35
-    // savePoint({
36
-    //   event: 'save',
37
-    //   eventType: 'building',
38
-    //   propertyName: '项目收藏',
39
-    //   data: '{}'
40
-    // }).then(res => {
41
-    //   console.log('活动项目收藏')
42
-    // })
43
-  }
11
+  const [isSaved, handleFavor] = useFavor(isSave)
44 12
 
45 13
   return (
46 14
     <view className='components BasicInfo'>
@@ -50,7 +18,7 @@ export default function BasicInfo (props) {
50 18
         <view className='flex-item'>
51 19
           <text>{Info.buildingName}</text>
52 20
         </view>
53
-        <view className='Collect' onClick={handleFavor}>
21
+        <view className='Collect' onClick={() => handleFavor(buildingId)}>
54 22
           <text className={classNames(['iconfont icon-shoucang'], { active: isSaved })}></text>
55 23
           <text>{isSaved ? '取消收藏' : '收藏'}</text>
56 24
         </view>

+ 9
- 4
src/pages/index/buildingDetail/components/SpecialPriceHouse/index.jsx View File

@@ -1,4 +1,5 @@
1 1
 import React, { useState, useEffect } from 'react'
2
+import Taro from '@tarojs/taro'
2 3
 import { API_SPECIAL_ROOM_LIST } from '@/constants/api'
3 4
 import { ScrollView, Image } from '@tarojs/components'
4 5
 import { fetch } from '@/utils/request'
@@ -11,6 +12,10 @@ export default function SpecialPriceHouse (props) {
11 12
 
12 13
   const [list, setList] = useState([])
13 14
 
15
+  const handleMore = () => {
16
+    Taro.navigateTo({ url: '/pages/index/specialPriceHouse/index' })
17
+  }
18
+
14 19
   useEffect(() => {
15 20
     if (!buildingId) {
16 21
       setList([])
@@ -27,14 +32,14 @@ export default function SpecialPriceHouse (props) {
27 32
     })
28 33
   }, [buildingId])
29 34
 
30
-  return (
35
+  return list.length > 0 && (
31 36
     <view className='components SpecialPriceHouse'>
32
-
33 37
       <view className='Title flex-h'>
34 38
         <view className='flex-item'>
35
-          <text>特价房源(5)</text>
39
+          <text>特价房源</text>
40
+          <text>{`(${list.length})`}</text>
36 41
         </view>
37
-        <text>更多</text>
42
+        <text onClick={handleMore}>更多</text>
38 43
         <text className='iconfont icon-jiantouright'></text>
39 44
       </view>
40 45
 

+ 1
- 1
src/pages/index/buildingDetail/components/SpecialPriceHouse/index.scss View File

@@ -7,7 +7,7 @@
7 7
     padding: 0 30px;
8 8
     >.flex-item {
9 9
       >text {
10
-        display: block;
10
+        display: inline-block;
11 11
         font-size: 34px;
12 12
         color: #333;
13 13
         line-height: 1;

+ 42
- 0
src/utils/hooks/useFavor.js View File

@@ -0,0 +1,42 @@
1
+import { useEffect, useState } from 'react'
2
+import Taro from '@tarojs/taro'
3
+import { favorProject, cancelFavorProject } from '@/services/item'
4
+
5
+export default function(eventType, saved) {
6
+  const [isSaved, setIsSaved] = useState(saved)
7
+
8
+  useEffect(() => setIsSaved(saved), [saved])
9
+
10
+  const handleSave = (buildingId) => {
11
+    if (isSaved) {
12
+      cancelFavorProject(buildingId).then(() => {
13
+        setIsSaved(false)
14
+        Taro.showToast({
15
+          title: '已取消收藏',
16
+          icon: 'none',
17
+        })
18
+      })
19
+    } else {
20
+      favorProject(buildingId).then(() => {
21
+        setIsSaved(true)
22
+        Taro.showToast({
23
+          title: '收藏成功',
24
+          icon: 'none',
25
+        })
26
+      })
27
+    }
28
+    // savePoint({
29
+    //   event: 'save',
30
+    //   eventType: type,
31
+    //   propertyName: '项目收藏',
32
+    //   data: '{}'
33
+    // })
34
+  }
35
+
36
+  switch (eventType) {
37
+    case 'building':
38
+      return [isSaved, handleSave];
39
+    default:
40
+      return [];
41
+  }
42
+}