张延森 3 年之前
父節點
當前提交
f6b224ea64

+ 118
- 19
src/pages/index/buildingAround/index.jsx 查看文件

1
-import { useState } from 'react'
1
+import { useState, useEffect, useRef } from 'react'
2
+import Taro from '@tarojs/taro'
2
 import withLayout from '@/layout'
3
 import withLayout from '@/layout'
3
-import { ScrollView } from '@tarojs/components'
4
+import { ScrollView, Map } from '@tarojs/components'
5
+import { fetch } from '@/utils/request'
6
+import { API_ITEMS_DETAIL } from '@/constants/api'
4
 import '@/assets/css/iconfont.css'
7
 import '@/assets/css/iconfont.css'
5
 import './index.scss'
8
 import './index.scss'
6
 
9
 
7
-export default withLayout(() => {
10
+export default withLayout((props) => {
11
+  const { router, city } = props
12
+  const { id } = router.params
8
 
13
 
9
-  const [NavList] = useState([
10
-    { name: '交通', id: 1 },
11
-    { name: '商业', id: 2 },
12
-    { name: '医院', id: 3 },
13
-    { name: '学校', id: 4 },
14
-    { name: '银行', id: 5 }
15
-  ])
14
+  const [DetailInfo, setDetailInfo] = useState({})
15
+  const [loc, setLoc] = useState([])
16
+  const [NavList, setNavList] = useState([])
16
   const [CurrentNavId, setCurrentNavId] = useState(1)
17
   const [CurrentNavId, setCurrentNavId] = useState(1)
17
   const [List, setList] = useState([{}, {}, {}, {}, {}, {}, {}, {}, {}])
18
   const [List, setList] = useState([{}, {}, {}, {}, {}, {}, {}, {}, {}])
18
   const [OtherList, setOtherList] = useState([{}, {}, {}, {}, {}, {}, {}, {}, {}])
19
   const [OtherList, setOtherList] = useState([{}, {}, {}, {}, {}, {}, {}, {}, {}])
20
+  const [markers, setMarkers] = useState([])
21
+  const mapCtx = useRef()
19
 
22
 
20
   const CutNav = (id) => {
23
   const CutNav = (id) => {
21
     return () => {
24
     return () => {
23
     }
26
     }
24
   }
27
   }
25
 
28
 
29
+  const locationTo = () => {
30
+    if (loc.length) {
31
+      Taro.openLocation({
32
+        longitude: loc[0],
33
+        latitude: loc[1],
34
+        name: DetailInfo.buildingName,
35
+        address: DetailInfo.address,
36
+      })
37
+    }
38
+  }
39
+
40
+  const handlePoi = (poi) => {
41
+    const [longitude, latitude] = poi.location.split(',').map(x => x ? x - 0 : undefined)
42
+
43
+    const marker = {
44
+      id: 1,
45
+      longitude,
46
+      latitude,
47
+      // iconPath: '',
48
+      width: 18,
49
+      height: 27,
50
+      callout: {
51
+        content: poi.name,
52
+        color: '#333333',
53
+        padding: 6,
54
+        display: 'ALWAYS',
55
+      }
56
+    }
57
+
58
+    const center = markers[0]
59
+    setMarkers([center, marker])
60
+
61
+    if (mapCtx.current) {
62
+      // 缩放地图,显示所有 marker
63
+      const points = [
64
+        {longitude: center.longitude, latitude: center.latitude},
65
+        {longitude: marker.longitude, latitude: marker.latitude}
66
+      ]
67
+      mapCtx.current.includePoints({ points, padding: [32] })
68
+    }
69
+  }
70
+
71
+  // 获取地图 Context
72
+  useEffect(() => {
73
+    Taro.nextTick(() => {
74
+      mapCtx.current = Taro.createMapContext('around-map')
75
+    })
76
+  }, [])
77
+
78
+  useEffect(() => {
79
+    // 获取楼盘信息
80
+    fetch({ url: `${API_ITEMS_DETAIL}/${id}`, spin: true }).then((res) => {
81
+      if (res?.coordinate) {
82
+        // 地图中心
83
+        const [longitude, latitude] = res.coordinate.split(',')
84
+        setLoc([longitude - 0, latitude - 0])
85
+        // 中心点标记
86
+        setMarkers([{
87
+          id: -1,
88
+          longitude,
89
+          latitude,
90
+          width: 18,
91
+          height: 27,
92
+          callout: {
93
+            content: res.buildingName,
94
+            color: '#333333',
95
+            padding: 6,
96
+            display: 'ALWAYS',
97
+          }
98
+        }])
99
+        setDetailInfo(res || {})
100
+        if (res.mapJson) {
101
+          const pois = JSON.parse(res.mapJson).map(poi => ({...poi, data: JSON.parse(poi.data)}))
102
+          setNavList(pois)
103
+          setCurrentNavId(pois[0].key)
104
+          setList(pois[0].data)
105
+        }
106
+        
107
+      } else {
108
+        Taro.showToast({
109
+          title: '当前楼盘未设置位置信息',
110
+          icon: 'none',
111
+        })
112
+      }
113
+    }).catch((err) => {
114
+      console.error(err)
115
+    })
116
+
117
+  }, [id])
118
+
26
   return (
119
   return (
27
     <view className='Page buildingAround'>
120
     <view className='Page buildingAround'>
28
 
121
 
29
       <view className='MapContainer'>
122
       <view className='MapContainer'>
30
         <view>
123
         <view>
31
-          
124
+          <Map
125
+            id='around-map'
126
+            showLocation
127
+            longitude={loc[0]}
128
+            latitude={loc[1]}
129
+            markers={markers}
130
+          />
32
         </view>
131
         </view>
33
       </view>
132
       </view>
34
 
133
 
37
 
136
 
38
           <view className='Title flex-h'>
137
           <view className='Title flex-h'>
39
             <view className='flex-item'>
138
             <view className='flex-item'>
40
-              <text>香颂·蔚澜半岛</text>
139
+              <text>{DetailInfo.buildingName}</text>
41
             </view>
140
             </view>
42
-            <view className='Go'>
141
+            <view className='Go' onClick={locationTo}>
43
               <text>前往</text>
142
               <text>前往</text>
44
               <text className='iconfont icon-qianwang'></text>
143
               <text className='iconfont icon-qianwang'></text>
45
             </view>
144
             </view>
48
           <view className='Address flex-h'>
147
           <view className='Address flex-h'>
49
             <text className='iconfont icon-dingwei'></text>
148
             <text className='iconfont icon-dingwei'></text>
50
             <view className='flex-item'>
149
             <view className='flex-item'>
51
-              <text>建邺区高庙路与保双街交叉路口</text>
150
+              <text>{DetailInfo.address}</text>
52
             </view>
151
             </view>
53
           </view>
152
           </view>
54
 
153
 
55
           <view className='Nav flex-h'>
154
           <view className='Nav flex-h'>
56
             {
155
             {
57
               NavList.map((item, index) => (
156
               NavList.map((item, index) => (
58
-                <view className={item.id === CurrentNavId ? 'flex-item active' : 'flex-item'} key={`NavItem-${index}`}>
59
-                  <text onClick={CutNav(item.id)}>{item.name}(12)</text>
157
+                <view className={item.key === CurrentNavId ? 'flex-item active' : 'flex-item'} key={item.key}>
158
+                  <text onClick={CutNav(item.key)}>{`${item.label}(${item.data.length})`}</text>
60
                 </view>
159
                 </view>
61
               ))
160
               ))
62
             }
161
             }
70
                 <view className='List'>
169
                 <view className='List'>
71
                   {
170
                   {
72
                     List.map((item, index) => (
171
                     List.map((item, index) => (
73
-                      <view className='flex-h' key={`ListItem-${index}`}>
172
+                      <view className='flex-h' key={`ListItem-${index}`} onClick={() => handlePoi(item)}>
74
                         <text>{index + 1}、</text>
173
                         <text>{index + 1}、</text>
75
                         <view className='flex-item'>
174
                         <view className='flex-item'>
76
-                          <text>南京地铁1号线</text>
175
+                          <text>{item.name}</text>
77
                         </view>
176
                         </view>
78
                         <text className='iconfont icon-dingwei'></text>
177
                         <text className='iconfont icon-dingwei'></text>
79
-                        <text className='distance'>200m</text>
178
+                        <text className='distance'>{`${item.distance}m`}</text>
80
                       </view>
179
                       </view>
81
                     ))
180
                     ))
82
                   }
181
                   }

+ 5
- 0
src/pages/index/buildingAround/index.scss 查看文件

15
       height: calc(100vh - 600px);
15
       height: calc(100vh - 600px);
16
       position: relative;
16
       position: relative;
17
       overflow: hidden;
17
       overflow: hidden;
18
+
19
+      map {
20
+        width: 100%;
21
+        height: 100%;
22
+      }
18
     }
23
     }
19
   }
24
   }
20
   >.TabContainer {
25
   >.TabContainer {

+ 4
- 6
src/pages/index/buildingDetail/components/Periphery/index.jsx 查看文件

30
     return tagLen + poiLen
30
     return tagLen + poiLen
31
   }, [Info, pois])
31
   }, [Info, pois])
32
 
32
 
33
-  const CutTab = () => {
34
-    return () => {
35
-      Taro.navigateTo({url: `/pages/index/buildingAround/index?id=${Info.buildingId}`})
36
-    }
33
+  const handleClick = () => {
34
+    Taro.navigateTo({url: `/pages/index/buildingAround/index?id=${Info.buildingId}`})
37
   }
35
   }
38
 
36
 
39
   useEffect(() => {
37
   useEffect(() => {
93
         </view>
91
         </view>
94
       </view>
92
       </view>
95
 
93
 
96
-      <view className='List flex-h'>
94
+      <view className='List flex-h' onClick={handleClick}>
97
         {
95
         {
98
           poiTypes.map((item) => (
96
           poiTypes.map((item) => (
99
-            <view className='flex-item' key={item.value} onClick={CutTab(item.value)}>
97
+            <view className='flex-item' key={item.value}>
100
               <text className={item.class}></text>
98
               <text className={item.class}></text>
101
               <text>{item.label}</text>
99
               <text>{item.label}</text>
102
               <text>({countLen(item.value)})</text>
100
               <text>({countLen(item.value)})</text>

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

62
       console.error(err)
62
       console.error(err)
63
     })
63
     })
64
 
64
 
65
-  }, [id, router.path])
65
+  }, [id])
66
 
66
 
67
   // 户型图
67
   // 户型图
68
   const houseTypeImages = (DetailInfo?.buildingApartment || []).filter(x => x.apartmentType === 'apart')
68
   const houseTypeImages = (DetailInfo?.buildingApartment || []).filter(x => x.apartmentType === 'apart')