李志伟 3 years ago
parent
commit
294ac2d9df

+ 62
- 0
src/pages/details/components/ImageList/index.jsx View File

1
+import Taro from "@tarojs/taro";
2
+import { Image, Swiper, SwiperItem, View, Text } from "@tarojs/components";
3
+import { useState} from "react";
4
+import { compressImage } from '@/utils'
5
+import './style.less'
6
+
7
+//详情页面上面的滑动图集
8
+export default (props) => {
9
+  const { imglist } = props
10
+  const [swiperHeight, setSwiperHeight] = useState()
11
+  const [swiperImgHeightList, setSwiperImgHeightList] = useState([])
12
+  const [swiperImgWidthList, setSwiperImgWidthList] = useState([])
13
+  const handleImageOnLoad = (e, inx) => {
14
+    const { detail } = e;
15
+    const { height, width } = detail || {}
16
+    if (height) {
17
+      const heightList = swiperImgHeightList.slice()
18
+      heightList[inx] = height
19
+      setSwiperImgHeightList(heightList)
20
+      const widthList = swiperImgWidthList.slice()
21
+      widthList[inx] = width
22
+      setSwiperImgWidthList(widthList)
23
+      if (!swiperHeight && inx === 0) {
24
+        let { screenWidth } = Taro.getSystemInfoSync()
25
+        let nowHeight = (screenWidth - 30) * height / width
26
+        setSwiperHeight(`${nowHeight}px`)
27
+      }
28
+    }
29
+  }
30
+
31
+  const [index, setIndex] = useState(0);
32
+  const handchange = (e) => {
33
+    const inx = e.detail.current
34
+    setIndex(inx);
35
+    const height = swiperImgHeightList[inx]
36
+    const width = swiperImgWidthList[inx]
37
+    let { screenWidth } = Taro.getSystemInfoSync()
38
+    let nowHeight = (screenWidth - 30) * height / width
39
+    setSwiperHeight(nowHeight ? `${nowHeight}px` : 'auto')
40
+  };
41
+  return (
42
+    <View className='huadong'>
43
+      <Swiper
44
+        circular
45
+        className='swiper'
46
+        onChange={handchange}
47
+        style={{ height: swiperHeight }}
48
+      >
49
+        {imglist.map((item, inx) => (
50
+          <SwiperItem key={inx}>
51
+            <Image src={compressImage(item.url)} mode='widthFix' className='storeImage' onLoad={(e) => handleImageOnLoad(e, inx)} />
52
+          </SwiperItem>
53
+        ))}
54
+      </Swiper>
55
+      <View className='tpPage'>
56
+        <Text>
57
+          {index + 1}/{imglist.length}
58
+        </Text>
59
+      </View>
60
+    </View>
61
+  )
62
+}

+ 27
- 0
src/pages/details/components/ImageList/style.less View File

1
+.huadong{    
2
+  position: relative;
3
+  .swiper {
4
+    transition: all 0.3s linear;
5
+    .storeImage {
6
+      border-radius: 22px;
7
+      width: 100%;
8
+      height: 100%;
9
+    }
10
+  }
11
+  .tpPage {
12
+    position: absolute;
13
+    right: 20px;
14
+    bottom: 20px;
15
+    background: #000000;
16
+    border-radius: 16px;
17
+    font-size: 24px;
18
+    color: #ffffff;
19
+    padding: 0 7px;
20
+    opacity: 0.4;
21
+    line-height: 32px;
22
+    padding: 7px 8px 8px 7px;
23
+    text {
24
+      opacity: 0.64;
25
+    }
26
+  }  
27
+}

+ 7
- 32
src/pages/details/foodDetails/foodDetails.jsx View File

8
 } from "@/services/home";
8
 } from "@/services/home";
9
 import { getVerifyTargetList } from "@/services/payOrder";
9
 import { getVerifyTargetList } from "@/services/payOrder";
10
 import { useState, useEffect, useRef } from "react";
10
 import { useState, useEffect, useRef } from "react";
11
-import { Button, Swiper, SwiperItem, View, Ad } from "@tarojs/components";
12
-import { compressImage } from '@/utils'
11
+import { Button,View, Ad } from "@tarojs/components";
13
 import Star from "@/components/Star/Star.jsx";
12
 import Star from "@/components/Star/Star.jsx";
14
 import NoData from '@/components/NoData'
13
 import NoData from '@/components/NoData'
15
 import Cards from "@/components/foodCards/foodCards.jsx";
14
 import Cards from "@/components/foodCards/foodCards.jsx";
28
 import useSave from "@/utils/hooks/useSave";
27
 import useSave from "@/utils/hooks/useSave";
29
 import useLike from "@/utils/hooks/useLike";
28
 import useLike from "@/utils/hooks/useLike";
30
 import Extend from "../components/Extend/extend";
29
 import Extend from "../components/Extend/extend";
30
+import ImageList from "../components/ImageList";
31
 import logo from "./laba.png";
31
 import logo from "./laba.png";
32
-
33
 import "./foodDetails.less";
32
 import "./foodDetails.less";
34
 
33
 
35
 export default withLayout((props) => {
34
 export default withLayout((props) => {
36
   const { router, person, location } = props;
35
   const { router, person, location } = props;
37
   const { id, subOrderId, scene } = props.router.params;
36
   const { id, subOrderId, scene } = props.router.params;
38
 
37
 
39
-
40
   useEffect(() => {
38
   useEffect(() => {
41
     if (id && (scene || subOrderId)) {
39
     if (id && (scene || subOrderId)) {
42
       getVerifyTargetList({
40
       getVerifyTargetList({
60
   const [spackage, setPackage] = useState([]);
58
   const [spackage, setPackage] = useState([]);
61
   //banner图集数组
59
   //banner图集数组
62
   const [imglist, setimglist] = useState([]);
60
   const [imglist, setimglist] = useState([]);
63
-  const [index, setIndex] = useState(0);
64
-  const handchange = (e) => {
65
-    setIndex(e.detail.current);
66
-  };
67
 
61
 
68
   const [isSaved, toggleSave] = useSave(detail.isSaved, "shop", id);
62
   const [isSaved, toggleSave] = useSave(detail.isSaved, "shop", id);
69
   const [isLike, toggleLike] = useLike(detail.isLike, "shop", id);
63
   const [isLike, toggleLike] = useLike(detail.isLike, "shop", id);
143
   const [isScroll, setScroll] = useState(true)
137
   const [isScroll, setScroll] = useState(true)
144
   return (
138
   return (
145
     <view className='page-index'>
139
     <view className='page-index'>
146
-
147
       {
140
       {
148
         guidance === 'shareOn' ? <view className='index-navbar'>
141
         guidance === 'shareOn' ? <view className='index-navbar'>
149
           <add-tipsFood logo={logo} custom duration={-1} />
142
           <add-tipsFood logo={logo} custom duration={-1} />
153
             <CustomNav title='十公里' />
146
             <CustomNav title='十公里' />
154
           </view>
147
           </view>
155
       }
148
       }
156
-
157
       <SpinBox loading={loading} className='index-container' style={{ padding: '0 30rpx', background: '#F8F8F8' }}>
149
       <SpinBox loading={loading} className='index-container' style={{ padding: '0 30rpx', background: '#F8F8F8' }}>
158
         <scroll-view
150
         <scroll-view
159
           scrollY={isScroll}
151
           scrollY={isScroll}
160
           style={{ height: '100%' }}
152
           style={{ height: '100%' }}
161
         >
153
         >
162
           <view className='storeDetails'>
154
           <view className='storeDetails'>
163
-            <View className='huadong'>
164
-              <Swiper
165
-                circular
166
-                className='swiper'
167
-                onChange={handchange}
168
-              >
169
-                {imglist.map((item, inx) => (
170
-                  <SwiperItem key={inx}>
171
-                    <image src={compressImage(item.url)} mode='aspectFit' className='storeImage' />
172
-                  </SwiperItem>
173
-                ))}
174
-              </Swiper>
175
-              <view className='tpPage'>
176
-                <text>
177
-                  {index + 1}/{imglist.length}
178
-                </text>
179
-              </view>
180
-            </View>
155
+            <ImageList imglist={imglist} />
181
             <view className='storeJs'>
156
             <view className='storeJs'>
182
               <view style={{ overflow: "hidden" }}>
157
               <view style={{ overflow: "hidden" }}>
183
                 <view className='storeName'>{detail.shopName}</view>
158
                 <view className='storeName'>{detail.shopName}</view>
254
                     <image src={titlezs} />
229
                     <image src={titlezs} />
255
                     <text>本店指南</text>
230
                     <text>本店指南</text>
256
                   </view>
231
                   </view>
257
-                  <View style={{background:'#FFF'}}>
258
-                  {(extend || []).map((item) => (
259
-                    <Extend key={item.extId} item={item} />
260
-                  ))}
232
+                  <View style={{ background: '#FFF' }}>
233
+                    {(extend || []).map((item) => (
234
+                      <Extend key={item.extId} item={item} />
235
+                    ))}
261
                   </View>
236
                   </View>
262
                 </view>
237
                 </view>
263
                 <view
238
                 <view

+ 1
- 28
src/pages/details/foodDetails/foodDetails.less View File

1
 .storeDetails {
1
 .storeDetails {
2
   background-color: #fff;
2
   background-color: #fff;
3
   border-radius: 12px;
3
   border-radius: 12px;
4
-  margin-bottom: 20px;
5
-  .huadong{    
6
-    position: relative;
7
-    .swiper {
8
-      height: calc((100vw - 60px) * 0.6);
9
-      .storeImage {
10
-        border-radius: 22px;
11
-        width: 100%;
12
-        height: 100%;
13
-      }
14
-    }
15
-    .tpPage {
16
-      position: absolute;
17
-      right: 20px;
18
-      bottom: 20px;
19
-      background: #000000;
20
-      border-radius: 16px;
21
-      font-size: 24px;
22
-      color: #ffffff;
23
-      padding: 0 7px;
24
-      opacity: 0.4;
25
-      line-height: 32px;
26
-      padding: 7px 8px 8px 7px;
27
-      text {
28
-        opacity: 0.64;
29
-      }
30
-    }  
31
-  }
4
+  margin-bottom: 20px;  
32
   .storeJs {
5
   .storeJs {
33
     padding: 20px;
6
     padding: 20px;
34
     .storeName {
7
     .storeName {

+ 3
- 25
src/pages/details/mjDetails/sceneryDetails.jsx View File

3
 import dw from '@/assets/icons/housemantj/loc-o.png'
3
 import dw from '@/assets/icons/housemantj/loc-o.png'
4
 import titlejd from '@/assets/icons/housemantj/goodTourist.png'
4
 import titlejd from '@/assets/icons/housemantj/goodTourist.png'
5
 import titlems from '@/assets/icons/housemantj/goodFood.png'
5
 import titlems from '@/assets/icons/housemantj/goodFood.png'
6
-import { compressImage } from '@/utils'
7
 import share from '@/assets/icons/housemantj/touristShare.png'
6
 import share from '@/assets/icons/housemantj/touristShare.png'
8
 import good from '@/assets/icons/housemantj/touristGood.png'
7
 import good from '@/assets/icons/housemantj/touristGood.png'
9
 import baozan from '@/assets/icons/housemantj/bgood.png'
8
 import baozan from '@/assets/icons/housemantj/bgood.png'
14
 import TabIcon from '@/components/HorTabbar/TabIcon'
13
 import TabIcon from '@/components/HorTabbar/TabIcon'
15
 import { useState, useEffect } from 'react'
14
 import { useState, useEffect } from 'react'
16
 import { getTouristDetail, getExtendContent, getRecommendList } from '@/services/home'
15
 import { getTouristDetail, getExtendContent, getRecommendList } from '@/services/home'
17
-import { Swiper, SwiperItem, Button, View, Ad } from '@tarojs/components';
16
+import { Button, View, Ad } from '@tarojs/components';
18
 import useSave from "@/utils/hooks/useSave"
17
 import useSave from "@/utils/hooks/useSave"
19
 import useLike from "@/utils/hooks/useLike"
18
 import useLike from "@/utils/hooks/useLike"
20
 import Cards from '@/components/foodCards/foodCards.jsx'
19
 import Cards from '@/components/foodCards/foodCards.jsx'
21
 import Taro, { useShareAppMessage } from '@tarojs/taro'
20
 import Taro, { useShareAppMessage } from '@tarojs/taro'
22
 import Extend from '../components/Extend/extend'
21
 import Extend from '../components/Extend/extend'
22
+import ImageList from "../components/ImageList";
23
 import logo from "../foodDetails/laba.png";
23
 import logo from "../foodDetails/laba.png";
24
 
24
 
25
 import './sceneryDetails.less'
25
 import './sceneryDetails.less'
34
 
34
 
35
   //banner图集数组
35
   //banner图集数组
36
   const [imglist, setimglist] = useState([])
36
   const [imglist, setimglist] = useState([])
37
-  const [index, setIndex] = useState(0)
38
-  const handchange = (e) => {
39
-    setIndex(e.detail.current)
40
-  }
41
 
37
 
42
   //本店指南
38
   //本店指南
43
   const [extend, setExtend] = useState([])
39
   const [extend, setExtend] = useState([])
114
       <SpinBox loading={loading} className='index-container' style={{ padding: '0 30rpx', background: '#F8F8F8' }}>
110
       <SpinBox loading={loading} className='index-container' style={{ padding: '0 30rpx', background: '#F8F8F8' }}>
115
         <scroll-view scrollY style={{ height: '100%' }}>
111
         <scroll-view scrollY style={{ height: '100%' }}>
116
           <view className='storeDetails'>
112
           <view className='storeDetails'>
117
-            <View className='huadong'>
118
-              <Swiper
119
-                className='swiper'
120
-                circular
121
-                onChange={handchange}
122
-              >
123
-                {
124
-                  imglist.map((item) => (
125
-                    <SwiperItem>
126
-                      <image src={compressImage(item.url)} mode='aspectFit' className='storeImage' />
127
-                    </SwiperItem>
128
-                  ))}
129
-              </Swiper>
130
-              <view className='tpPage'>
131
-                <text>
132
-                  {index + 1}/{imglist.length}
133
-                </text>
134
-              </view>
135
-            </View>
113
+            <ImageList imglist={imglist} />
136
 
114
 
137
             <view className='storeJs'>
115
             <view className='storeJs'>
138
               <view className='introduce'>
116
               <view className='introduce'>

+ 1
- 28
src/pages/details/mjDetails/sceneryDetails.less View File

1
 .storeDetails {
1
 .storeDetails {
2
   background-color: #fff;
2
   background-color: #fff;
3
   border-radius: 12px;
3
   border-radius: 12px;
4
-  margin-bottom: 20px;
5
-  .huadong{    
6
-    position: relative;
7
-    .swiper {
8
-      height: calc((100vw - 60px) * 0.6);
9
-      .storeImage {
10
-        border-radius: 22px;
11
-        width: 100%;
12
-        height: 100%;
13
-      }
14
-    }
15
-    .tpPage {
16
-      position: absolute;
17
-      right: 20px;
18
-      bottom: 20px;
19
-      background: #000000;
20
-      border-radius: 16px;
21
-      font-size: 24px;
22
-      color: #ffffff;
23
-      padding: 0 7px;
24
-      opacity: 0.4;
25
-      line-height: 32px;
26
-      padding: 7px 8px 8px 7px;
27
-      text {
28
-        opacity: 0.64;
29
-      }
30
-    }  
31
-  }
4
+  margin-bottom: 20px;  
32
   .storeJs {
5
   .storeJs {
33
     padding: 22px;
6
     padding: 22px;
34
     .introduce {
7
     .introduce {