index.jsx 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import { useEffect, useRef, useState } from 'react'
  2. import Taro from '@tarojs/taro'
  3. import withLayout from '@/layout'
  4. import { Image, Map } from '@tarojs/components'
  5. import { getItemList } from '@/services/item'
  6. import { getImgURL } from '@/utils/image'
  7. import '@/assets/css/iconfont.css'
  8. import './index.scss'
  9. export default withLayout((props) => {
  10. const { city } = props
  11. const [ShowInfo, setShowInfo] = useState(false)
  12. const [list, setList] = useState([])
  13. const [markers, setMarkers] = useState([])
  14. const mapCtx = useRef()
  15. const [current, setCurrent] = useState({})
  16. const changeCity = () => {
  17. Taro.navigateTo({ url: '/pages/index/location/index' })
  18. }
  19. const handleMarker = (e) => {
  20. const { markerId } = e.detail
  21. const building = list[markerId - 1];
  22. setCurrent(building || {});
  23. setShowInfo(true)
  24. }
  25. const gotoDetail = () => {
  26. if (current.buildingId) {
  27. Taro.navigateTo({ url: `/pages/index/buildingDetail/index?id=${current.buildingId}` })
  28. }
  29. }
  30. const locationTo = () => {
  31. if (current.buildingId) {
  32. const loc = current.coordinate.split(',')
  33. Taro.openLocation({
  34. longitude: loc[0] - 0,
  35. latitude: loc[1] - 0,
  36. name: current.buildingName,
  37. address: current.address,
  38. scale: 12,
  39. })
  40. }
  41. }
  42. useEffect(() => {
  43. Taro.nextTick(() => {
  44. mapCtx.current = Taro.createMapContext('map-buildings')
  45. })
  46. }, [])
  47. useEffect(() => {
  48. if (city?.id) {
  49. // 先移除页面的 markers
  50. if (mapCtx.current && markers.length) {
  51. mapCtx.current.removeMarkers({ markerIds: markers.map(x => x.id) })
  52. setMarkers([])
  53. }
  54. getItemList({
  55. cityId: city.id,
  56. pageSize: 100,
  57. }).then((res) => {
  58. const { records } = res
  59. setList((records || []).filter(x => x.coordinate))
  60. })
  61. }
  62. }, [city?.id])
  63. useEffect(() => {
  64. if (!list.length) return;
  65. const mks = list.map((item, index) => {
  66. const loc = item.coordinate.split(',')
  67. return {
  68. id: index + 1,
  69. longitude: loc[0] - 0,
  70. latitude: loc[1] - 0,
  71. iconPath: '',
  72. width: 18,
  73. height: 27,
  74. callout: {
  75. content: item.buildingName,
  76. color: '#333333',
  77. fontSize: 14,
  78. display: 'ALWAYS',
  79. padding: 6,
  80. borderRadius: 2,
  81. borderColor: 'rgba(0,0,0, .1)',
  82. }
  83. }
  84. })
  85. const points = mks.map(it => ({ longitude: it.longitude, latitude: it.latitude }))
  86. setMarkers(mks)
  87. const t = setInterval(() => {
  88. if (mapCtx.current) {
  89. mapCtx.current.includePoints({ points, padding: [32] })
  90. clearInterval(t)
  91. }
  92. }, 300)
  93. return () => clearInterval(t)
  94. }, [list])
  95. return (
  96. <view className='Page findHouseFromMap'>
  97. {/* 地图 */}
  98. <view className='MapContainer'>
  99. <Map
  100. id='map-buildings'
  101. show-location
  102. scale={12}
  103. longitude={city?.lng}
  104. latitude={city?.lat}
  105. markers={markers}
  106. onMarkertap={handleMarker}
  107. onCallouttap={handleMarker}
  108. onTap={() => setShowInfo(false)}
  109. />
  110. </view>
  111. {/* 定位 */}
  112. <view className='Location' onClick={changeCity}>
  113. <text className='iconfont icon-dingwei'></text>
  114. <text>{city.name}</text>
  115. </view>
  116. {/* 分享 */}
  117. <button className='Share' openType='share'>
  118. <text className='iconfont icon-fenxiang'></text>
  119. <text>分 享</text>
  120. </button>
  121. {/* 附近楼盘 */}
  122. <view className={ShowInfo ? 'AroundBuilding active' : 'AroundBuilding'}>
  123. <view className='Go' onClick={locationTo}>
  124. <text>立即</text>
  125. <text>前往</text>
  126. </view>
  127. <view className='InfoContainer'>
  128. {/* <text className='Title' onClick={CutInfo(true)}>附近楼盘</text> */}
  129. <view className='InfoContent'>
  130. {
  131. !!current.buildingName &&
  132. <view className='Img' onClick={gotoDetail}>
  133. <Image mode='scaleToFill' src={getImgURL(current?.buildingListImg?.length ? current.buildingListImg[0].url : null)} className='centerLabel'></Image>
  134. {
  135. current?.panoramaList.length > 0 &&
  136. <Image mode='heightFix' className='Tips Vr' src={require('@/assets/index-icon18.png')} />
  137. }
  138. {
  139. current?.videoUrl !== null &&
  140. <Image mode='heightFix' className='Tips Video' src={require('@/assets/index-icon19.png')} />
  141. }
  142. </view>
  143. }
  144. <view className='Name flex-h'>
  145. <view className='flex-item'>
  146. <text>{current.buildingName}</text>
  147. </view>
  148. <text>{current.price}</text>
  149. </view>
  150. <text className='Address'>{current.address}</text>
  151. <view className='Tag'>
  152. {
  153. (current.buildingTag || []).map((item, index) => (
  154. <text key={`Tags-${index}`}>{item.tagName}</text>
  155. ))
  156. }
  157. </view>
  158. <view className='Views flex-h'>
  159. <view className='flex-item'>
  160. <text className='iconfont icon-fenxiang'></text>
  161. <text>{`${199 + (current.shareNum || 0)}次分享`}</text>
  162. </view>
  163. <view className='Icons'>
  164. {
  165. (current.uvList?.records || []).slice(0, 3).map((item, index) => (
  166. <view key={`uv-${index}`}>
  167. <Image mode='scaleToFill' className='centerLabel' src={item.photoOravatar} />
  168. </view>
  169. ))
  170. }
  171. </view>
  172. <text>{(current.uvList?.records || []).length > 0 ? '...' : ''}{`${199 + (current.pvNum || 0)}人围观`}</text>
  173. </view>
  174. </view>
  175. </view>
  176. </view>
  177. </view>
  178. )
  179. })