sceneryDetails.jsx 6.9KB

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