|
@@ -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>
|