foodDetails.jsx 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import Taro, { useShareAppMessage } from "@tarojs/taro";
  2. import CustomNav from "@/components/CustomNav";
  3. import withLayout from "@/layouts";
  4. import {
  5. getShopDetail,
  6. getShopPackage,
  7. getExtendContent,
  8. } from "@/services/home";
  9. import { getVerifyTargetList } from "@/services/payOrder";
  10. import { useState, useEffect, useRef } from "react";
  11. import { Button, View, Ad } from "@tarojs/components";
  12. import Star from "@/components/Star/Star.jsx";
  13. import NoData from '@/components/NoData'
  14. import Cards from "@/components/foodCards/foodCards.jsx";
  15. import SpinBox from "@/components/Spin/SpinBox";
  16. import TabIcon from "@/components/HorTabbar/TabIcon";
  17. import ax from "@/assets/icons/housemantj/onlove.png";
  18. import yysj from "@/assets/icons/housemantj/openTime.png";
  19. import dw from "@/assets/icons/housemantj/loc-o.png";
  20. import phoneImg from "@/assets/icons/housemantj/phone-o.png";
  21. import zhuandao from "@/assets/icons/housemantj/backTop.png";
  22. import titlezs from "@/assets/icons/housemantj/titleTip.png";
  23. import share from "@/assets/icons/housemantj/touristShare.png";
  24. import good from "@/assets/icons/housemantj/touristGood.png";
  25. import baozan from "@/assets/icons/housemantj/bgood.png";
  26. import weibaozan from "@/assets/icons/housemantj/unLike.png";
  27. import logo from "@/assets/icons/UserCenter/laba.png"
  28. import useSave from "@/utils/hooks/useSave";
  29. import useLike from "@/utils/hooks/useLike";
  30. import Extend from "../components/Extend/extend";
  31. import ImageList from "../components/ImageList";
  32. import "./foodDetails.less";
  33. export default withLayout((props) => {
  34. const { router, person, location } = props;
  35. const { id, subOrderId, scene } = props.router.params;
  36. useEffect(() => {
  37. if (id && (scene || subOrderId)) {
  38. getVerifyTargetList({
  39. shopId: id,
  40. isMine: true,
  41. isVerified: 0,
  42. }).then((res) => {
  43. if (res?.records?.length > 0) {
  44. Taro.navigateTo({
  45. url: `/pages/TobeShop/index?id=${id}&subOrderId=${subOrderId}`,
  46. });
  47. }
  48. });
  49. }
  50. }, [id, scene, subOrderId]);
  51. //商铺基础信息
  52. const [loading, setLoading] = useState(false)
  53. const [detail, setDetail] = useState({});
  54. //商铺套餐
  55. const [spackage, setPackage] = useState([]);
  56. //banner图集数组
  57. const [imglist, setimglist] = useState([]);
  58. const [isSaved, toggleSave] = useSave(detail.isSaved, "shop", id);
  59. const [isLike, toggleLike] = useLike(detail.isLike, "shop", id);
  60. //引导显隐
  61. const [guidance, setGuidance] = useState('shareOff')
  62. //引导显隐
  63. useEffect(() => {
  64. if (router.params.scene || router.params.enterType === "share") {
  65. setGuidance('shareOn')
  66. }
  67. }, [router.params.enterType, router.params.scene])
  68. //本店指南
  69. const [extend, setExtend] = useState([]);
  70. const openMap = () => {
  71. Taro.openLocation({
  72. longitude: log.current - 0,
  73. latitude: lat.current - 0,
  74. name: detail.shopName,
  75. address: detail.address,
  76. scale: 12,
  77. });
  78. };
  79. const log = useRef("");
  80. const lat = useRef("");
  81. const handlePhone = () => {
  82. if (!detail.phone) {
  83. Taro.showToast({
  84. title: '暂无商家联系方式',
  85. icon: 'none',
  86. })
  87. return;
  88. }
  89. Taro.makePhoneCall({
  90. phoneNumber: detail.phone
  91. })
  92. }
  93. useEffect(() => {
  94. if (id) {
  95. setLoading(true)
  96. getShopDetail(id, { location }).then((res) => {
  97. setDetail(res);
  98. log.current = res.locaton.toString().split(",")[0];
  99. lat.current = res.locaton.toString().split(",")[1];
  100. setimglist(res.imageList || []);
  101. setLoading(false)
  102. }).catch(() => setLoading(false));
  103. getShopPackage(id, { pageSize: 500 }).then((res) => {
  104. setPackage(res.records || []);
  105. });
  106. getExtendContent("shop", id, { pageSize: 500 }).then((res) => {
  107. setExtend(res.records || []);
  108. });
  109. }
  110. }, [id]);
  111. const star = parseFloat(
  112. (
  113. (detail.sweetScore + detail.environmentScore + detail.serviceScore) / 3).toFixed(1)
  114. );
  115. // 分享
  116. useShareAppMessage(() => {
  117. // setShareAppMessage('shareOff')
  118. return {
  119. title: detail.shopName,
  120. path: `/pages/details/foodDetails/foodDetails?id=${id}&subOrderId=${subOrderId}&enterType=share`,
  121. imageUrl: detail.poster,
  122. };
  123. });
  124. const [isScroll, setScroll] = useState(true)
  125. return (
  126. <view className='page-index'>
  127. {
  128. guidance === 'shareOn' ? <view className='index-navbar'>
  129. <add-tipsFood logo={logo} custom duration={-1} />
  130. <CustomNav title='十公里' noback />
  131. </view> :
  132. <view className='index-navbar'>
  133. <CustomNav title='十公里' />
  134. </view>
  135. }
  136. <SpinBox loading={loading} className='index-container' style={{ padding: '0 30rpx', background: '#F8F8F8' }}>
  137. <scroll-view
  138. scrollY={isScroll}
  139. style={{ height: '100%' }}
  140. >
  141. <view className='storeDetails'>
  142. <ImageList imglist={imglist} />
  143. <view className='storeJs'>
  144. <view style={{ overflow: "hidden" }}>
  145. <view className='storeName'>{detail.shopName}</view>
  146. <view className='sprice'>
  147. <text className='t1'>¥</text>
  148. {detail.averagePrice / 100}/人
  149. <view className='bzRight'>
  150. <image
  151. src={baozan}
  152. style={{
  153. width: "15px",
  154. height: "15px",
  155. marginRight: "11rpx",
  156. marginBottom: "-2px",
  157. }}
  158. />
  159. 爆赞{detail.likeNum}
  160. </view>
  161. </view>
  162. </view>
  163. <view className='appraise'>
  164. <Star star={star} />
  165. {star}
  166. <view style={{ float: "right", marginTop: "5px" }}>
  167. <text className='comment'>点评:</text>
  168. <text className='t1'>口味:{detail.sweetScore}</text>
  169. <text className='t1'>环境:{detail.environmentScore}</text>
  170. <text className='t1'>服务:{detail.serviceScore}</text>
  171. </view>
  172. </view>
  173. <view className='yysj'>
  174. <image src={yysj} className='yysjImg' />
  175. <text>营业时间:{detail.businessHours}</text>
  176. <view style={{ float: 'right', paddingLeft: '30rpx', borderLeft: '1px dotted #999' }} onClick={handlePhone}>
  177. <image src={phoneImg} style={{ width: '32rpx', height: '32rpx' }} />
  178. </view>
  179. </view>
  180. <view className='dpPosition' onClick={openMap}>
  181. <image src={dw} className='dwTip' />
  182. <view>
  183. {detail.address}
  184. <image src={zhuandao} className='zhuandao' />
  185. </view>
  186. </view>
  187. </view>
  188. </view>
  189. {
  190. spackage == '' && extend == "" ?
  191. <NoData /> :
  192. <>
  193. <view
  194. style={{
  195. position: "relative",
  196. display: spackage == "" ? "none" : "",
  197. }}
  198. >
  199. <view className='title'>
  200. <image src={titlezs} />
  201. <text>返现套餐</text>
  202. </view>
  203. {(spackage || []).map((item) => (
  204. <Cards scene={scene} id={id} setScroll={setScroll} subOrderId={subOrderId} key={item.packageId} editable='1' st={star} goshop='1' item={item} det={detail} />
  205. ))}
  206. </view>
  207. <view class='adContainer'>
  208. <Ad unit-id='adunit-a0f97bb7ec8ec7bb' ad-intervals='30' />
  209. </view>
  210. <view
  211. style={{
  212. display: extend == "" ? "none" : "",
  213. }}
  214. >
  215. <view className='title'>
  216. <image src={titlezs} />
  217. <text>本店指南</text>
  218. </view>
  219. <View style={{ background: '#FFF' }}>
  220. {(extend || []).map((item) => (
  221. <Extend key={item.extId} item={item} />
  222. ))}
  223. </View>
  224. </view>
  225. <view
  226. className='botton'
  227. >
  228. 这是我的底线
  229. </view>
  230. </>
  231. }
  232. </scroll-view>
  233. </SpinBox>
  234. <view className='index-tabber weui-tabbar' style={{ background: '#fff' }}>
  235. <view className='weui-tabbar__item'>
  236. <Button openType='share' className='purebtn'><TabIcon icon={share} text='分享' /></Button>
  237. </view>
  238. <view className='weui-tabbar__item' onClick={toggleLike}>
  239. <TabIcon icon={isLike > 0 ? baozan : weibaozan} text={isLike > 0 ? "已爆赞" : "爆赞"} />
  240. </view>
  241. <view className='weui-tabbar__item' onClick={toggleSave}>
  242. <TabIcon icon={isSaved > 0 ? ax : good} text={isSaved > 0 ? "已收藏" : "加入收藏"} />
  243. </view>
  244. </view>
  245. </view>
  246. );
  247. });