foodDetails.jsx 8.9KB

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