sceneryDetails.jsx 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import CustomNav from '@/components/CustomNav'
  2. import ax from '@/assets/icons/housemantj/onlove.png'
  3. import dw from '@/assets/icons/housemantj/地址.png'
  4. import titlejd from '@/assets/icons/housemantj/推荐景点.png'
  5. import titlems from '@/assets/icons/housemantj/推荐美食.png'
  6. import showMore from '@/assets/icons/housemantj/查看更多.png'
  7. import share from '@/assets/icons/housemantj/景点分享.png'
  8. import good from '@/assets/icons/housemantj/景点爆赞.png'
  9. import baozan from '@/assets/icons/housemantj/爆赞.png'
  10. import weibaozan from '@/assets/icons/housemantj/未赞.png'
  11. import withLayout from '@/layouts'
  12. import { useState, useEffect, useRef } from 'react'
  13. import { getTouristDetail, getExtendContent, getRecommendList } from '@/services/home'
  14. import { Swiper, SwiperItem,Button } from '@tarojs/components';
  15. import useSave from "@/utils/hooks/useSave"
  16. import useLike from "@/utils/hooks/useLike"
  17. import Cards from '@/components/foodCards/foodCards.jsx'
  18. import Taro,{ useShareAppMessage } from '@tarojs/taro'
  19. import Extend from '../components/Extend/extend'
  20. import './sceneryDetails.less'
  21. export default withLayout((props) => {
  22. const { router, person } = props
  23. const { id, distance, location } = props.router.params
  24. const [detail, setDetail] = useState({})
  25. const [isSaved, toggleSave] = useSave(detail.isSaved, 'tourist', id)
  26. const [isLike, toggleLike] = useLike(detail.isLike, 'tourist', id)
  27. //banner图集数组
  28. const [imglist, setimglist] = useState([])
  29. const [index, setIndex] = useState(0)
  30. const handchange = (e) => {
  31. setIndex(e.detail.current)
  32. }
  33. //本店指南
  34. const [extend, setExtend] = useState([])
  35. //当前指南总数
  36. const [newextNum, setNewextNum] = useState(0)
  37. //全部指南个数
  38. const [AllextNum, setAllextNum] = useState(0)
  39. //指南当前页数
  40. const [epage, setepage] = useState(2)
  41. const extendMore = () => {
  42. setepage(epage + 1)
  43. getExtendContent('tourist', id, { pageNum: epage }).then((res) => {
  44. setExtend([...extend, ...res.records])
  45. setNewextNum(newextNum + res.records.length)
  46. })
  47. }
  48. // 推荐套餐列表
  49. const [recommend, setRecommend] = useState([])
  50. const openMap = () => {
  51. Taro.openLocation({
  52. longitude: log.current - 0,
  53. latitude: lat.current - 0,
  54. name: detail.touristName,
  55. address: detail.address,
  56. scale: 12,
  57. })
  58. }
  59. const log = useRef('')
  60. const lat = useRef('')
  61. useEffect(() => {
  62. getTouristDetail(id).then((res) => {
  63. log.current = (res.locaton).toString().split(',')[0]
  64. lat.current = (res.locaton).toString().split(',')[1]
  65. setDetail(res)
  66. setimglist(res.imageList || [])
  67. })
  68. getExtendContent('tourist', id).then((res) => {
  69. setExtend(res.records || [])
  70. setAllextNum(res.total)
  71. setNewextNum(res.records.length)
  72. })
  73. getRecommendList({ location: location }).then((res) => {
  74. setRecommend(res || [])
  75. })
  76. }, [])
  77. // 分享
  78. useShareAppMessage(()=>{
  79. return {
  80. title: detail.touristName,
  81. path: `/pages/details/mjDetails/sceneryDetails?id=${id}`,
  82. imageUrl: detail.poster,
  83. }
  84. })
  85. return (
  86. <view className='page-index'>
  87. <view className='index-navbar'>
  88. <CustomNav title='十公里' />
  89. </view>
  90. <view style={{ overflow: 'auto', padding: '0 30rpx', background: '#F8F8F8' }}>
  91. <scroll-view scroll-y="true" scroll-view='true' bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll">
  92. <view className='storeDetails'>
  93. <Swiper
  94. className='.swiper'
  95. circular
  96. current={index}
  97. onChange={handchange}
  98. >
  99. {
  100. imglist.map((item) =>
  101. <SwiperItem>
  102. <image src={item.url} className='storeImage' >
  103. <view className='tpPage'>
  104. <text>{index + 1}/{imglist.length}</text>
  105. </view>
  106. </image>
  107. </SwiperItem>
  108. )
  109. }
  110. </Swiper>
  111. <view className='storeJs'>
  112. <view className='introduce'>
  113. <text className='storeName'>{detail.touristName}</text>
  114. </view>
  115. <view className='bz'>
  116. <image src={baozan} style={{ width: '15px', height: '15px', marginRight: '10px', marginBottom: '-2px' }} />
  117. <text className='bzRight'>爆赞{detail.likeNum}</text>
  118. </view>
  119. <view className='wz'>{detail.address}</view>
  120. <view className='dpPosition' onClick={openMap}>
  121. <image src={dw} className='dwTip' />
  122. <view className='distance'>{distance}公里</view>
  123. </view>
  124. </view>
  125. </view>
  126. <view className='jdjs'>
  127. <view>{detail.description}</view>
  128. <view className='line'></view>
  129. <view className='sc' onClick={toggleSave}>
  130. <image className='scTip' src={isSaved > 0 ? ax : good} /><text>{isSaved > 0 ? '已收藏' : '加入收藏'}</text>
  131. </view>
  132. </view>
  133. <view style={{ position: 'relative', display: extend == '' ? 'none' : '' }}>
  134. <view className='title'>
  135. <image src={titlejd} />景点介绍
  136. </view>
  137. {extend?.map((item) => <Extend item={item} />)}
  138. <view className='showMore' style={{ display: newextNum == AllextNum ? 'none' : '' }} onClick={extendMore}>
  139. <view>点击查看更多</view>
  140. <image src={showMore} className='moreTip' />
  141. </view>
  142. </view>
  143. <view style={{ position: 'relative', display: recommend == '' ? 'none' : '' }}>
  144. <view className='title'>
  145. <image src={titlems} />老板推荐好吃的
  146. </view>
  147. {recommend?.map((item) => <Cards item={item} />)}
  148. </view>
  149. <view className='bottom'>已经到底了~</view>
  150. </scroll-view>
  151. </view>
  152. <view className='bottomTab'>
  153. <Button openType='share' className='sharebtn'>分享</Button>
  154. <view className='tab'>
  155. <image className='share' src={share} />分享
  156. </view>
  157. <view className='tab' onClick={toggleLike}>
  158. <image className='good' src={isLike > 0 ? baozan : weibaozan} />{isLike > 0 ? '已爆赞' : '爆赞'}
  159. </view>
  160. <view className='tab' onClick={toggleSave}>
  161. <image className='collection' src={isSaved > 0 ? ax : good} />{isSaved > 0 ? '已收藏' : '加入收藏'}
  162. </view>
  163. </view>
  164. </view>
  165. )
  166. })