foodDetails.jsx 9.8KB

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