张延森 3 gadus atpakaļ
vecāks
revīzija
8aa9238365

+ 3
- 35
src/pages/index/buildingDetail/components/BasicInfo/index.jsx Parādīt failu

1
-import { useState, useEffect } from 'react'
2
-import Taro from '@tarojs/taro'
3
 import { ScrollView, Image } from '@tarojs/components'
1
 import { ScrollView, Image } from '@tarojs/components'
4
 import classNames from 'classnames'
2
 import classNames from 'classnames'
5
-import { favorProject, cancelFavorProject } from '@/services/item'
3
+import useFavor from '@/utils/hooks/useFavor'
6
 import '@/assets/css/iconfont.css'
4
 import '@/assets/css/iconfont.css'
7
 import './index.scss'
5
 import './index.scss'
8
 
6
 
10
   const { Info = {} } = props
8
   const { Info = {} } = props
11
   const { buildingId, isSave } = Info
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
   return (
13
   return (
46
     <view className='components BasicInfo'>
14
     <view className='components BasicInfo'>
50
         <view className='flex-item'>
18
         <view className='flex-item'>
51
           <text>{Info.buildingName}</text>
19
           <text>{Info.buildingName}</text>
52
         </view>
20
         </view>
53
-        <view className='Collect' onClick={handleFavor}>
21
+        <view className='Collect' onClick={() => handleFavor(buildingId)}>
54
           <text className={classNames(['iconfont icon-shoucang'], { active: isSaved })}></text>
22
           <text className={classNames(['iconfont icon-shoucang'], { active: isSaved })}></text>
55
           <text>{isSaved ? '取消收藏' : '收藏'}</text>
23
           <text>{isSaved ? '取消收藏' : '收藏'}</text>
56
         </view>
24
         </view>

+ 9
- 4
src/pages/index/buildingDetail/components/SpecialPriceHouse/index.jsx Parādīt failu

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

+ 1
- 1
src/pages/index/buildingDetail/components/SpecialPriceHouse/index.scss Parādīt failu

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

+ 42
- 0
src/utils/hooks/useFavor.js Parādīt failu

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
+}