index.jsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { useCallback, useEffect, useMemo, useState } from 'react'
  2. import Taro from '@tarojs/taro'
  3. import { Map, CoverView } from '@tarojs/components'
  4. import '@/assets/css/iconfont.css'
  5. import './index.scss'
  6. const poiTypes = [
  7. { label: '交通', value: 'Transport', class: 'iconfont icon-jiaotong' },
  8. { label: '商业', value: 'Mall', class: 'iconfont icon-shangye' },
  9. { label: '学校', value: 'Edu', class: 'iconfont icon-xuexiao' },
  10. { label: '医院', value: 'Hospital', class: 'iconfont icon-yiyuan' },
  11. { label: '银行', value: 'Bank', class: 'iconfont icon-yinhang' },
  12. { label: '餐饮', value: 'Restaurant', class: 'iconfont icon-canyin' },
  13. ]
  14. export default function Periphery (props) {
  15. const { Info } = props
  16. const [pois, setPois] = useState([])
  17. const [markers, setMarkers] = useState([])
  18. const loc = useMemo(() => (Info?.coordinate ? Info.coordinate.split(',') : []), [Info?.coordinate])
  19. const countLen = useCallback((type) => {
  20. if (!Info) return 0;
  21. const tagLen = (Info[`building${type}`] || '').split(',').filter(Boolean).length
  22. const poiLen = pois.filter((poi) => poi.key === type).map((it) => (it.data ? it.data.length : 0)).reduce((acc, i) => (acc + i), 0)
  23. return tagLen + poiLen
  24. }, [Info, pois])
  25. const CutTab = () => {
  26. return () => {
  27. Taro.navigateTo({url: `/pages/index/buildingAround/index?id=${Info.buildingId}`})
  28. }
  29. }
  30. useEffect(() => {
  31. // 地图 marker
  32. if (Info?.coordinate) {
  33. const mks = []
  34. // 项目位置
  35. mks.push({
  36. id: -1,
  37. longitude: loc[0],
  38. latitude: loc[1],
  39. iconPath: '',
  40. width: 24,
  41. height: 36,
  42. customCallout: {
  43. anchorY: 0,
  44. anchorX: 0,
  45. display: 'ALWAYS',
  46. }
  47. })
  48. // pois
  49. if (Info?.mapJson) {
  50. const poiArr = JSON.parse(Info.mapJson).map((it) => ({ ...it, data: JSON.parse(it.data) }))
  51. setPois(poiArr)
  52. }
  53. setMarkers(mks)
  54. }
  55. }, [Info, loc])
  56. if (!Info?.coordinate) {
  57. return null
  58. }
  59. return (
  60. <view className='components Periphery'>
  61. <view className='Title flex-h'>
  62. <view className='flex-item'>
  63. <text>位置及周边配套</text>
  64. </view>
  65. </view>
  66. <view className='Map'>
  67. <view>
  68. <Map
  69. id='poi-around'
  70. show-location
  71. scale={12}
  72. markers={markers}
  73. longitude={loc[0]}
  74. latitude={loc[1]}
  75. // enable-enableScroll
  76. // enable-zoom
  77. >
  78. <CoverView slot='callout' className='marker-callout'>
  79. <CoverView markerId={-1} className='marker-project'>{Info.buildingName}</CoverView>
  80. </CoverView>
  81. </Map>
  82. </view>
  83. </view>
  84. <view className='List flex-h'>
  85. {
  86. poiTypes.map((item) => (
  87. <view className='flex-item' key={item.value} onClick={CutTab(item.value)}>
  88. <text className={item.class}></text>
  89. <text>{item.label}</text>
  90. <text>({countLen(item.value)})</text>
  91. </view>
  92. ))
  93. }
  94. </view>
  95. </view>
  96. )
  97. }