[baozhangchao] vor 3 Jahren
Ursprung
Commit
ccdf1156ff

+ 6
- 1
src/app.config.js Datei anzeigen

@@ -10,6 +10,11 @@ export default {
10 10
     navigationBarBackgroundColor: '#fff',
11 11
     navigationBarTitleText: 'WeChat',
12 12
     navigationBarTextStyle: 'black'
13
-  }
13
+  },
14
+  permission: {
15
+    'scope.userLocation': {
16
+      desc: '您的位置信息将方便您更好的小程序体验'
17
+    }
18
+  },
14 19
 }
15 20
 

+ 21
- 0
src/app.js Datei anzeigen

@@ -13,6 +13,27 @@ class App extends Component {
13 13
   onLaunch (options) {
14 14
     // 登录获取人员信息
15 15
 
16
+    Taro.getLocation({
17
+      success (res) {
18
+        const location = `${res.longitude},${res.latitude}`
19
+        Taro.setStorageSync('location', location)
20
+
21
+      },
22
+      fail (err) {
23
+        console.error(err)
24
+        // reject(err)
25
+        Taro.showToast({
26
+          title: '获取定位失败',
27
+          icon: 'none',
28
+        })
29
+        // 默认邓州
30
+        const location = '112.087493,32.687609';
31
+        Taro.setStorageSync('location', location)
32
+
33
+
34
+      }
35
+    })
36
+
16 37
     const { logins } = store.getModel('userData').getState()
17 38
 
18 39
     Taro.login({

+ 38
- 6
src/pages/CheckDetails/index.jsx Datei anzeigen

@@ -1,16 +1,37 @@
1
-import { useState } from "react"
2
-import { Image, View, Text } from "@tarojs/components"
1
+import { useState, useEffect } from "react"
2
+import { Image, View, Text, Swiper, SwiperItem } from "@tarojs/components"
3 3
 import Taro from "@tarojs/taro"
4 4
 import CustomNav from "@/components/CustomNav"
5 5
 
6 6
 import ButtontWX from "@/components/ButtontWX"
7 7
 import decorate from "@/assets/icons/comm/decorate.png"
8 8
 import addresss from '@/assets/mineImgaes/addresss.png'//地址
9
+import { getMachineryInfo } from "@/services/homes"
10
+
11
+
9 12
 import './style.less'
10 13
 
11 14
 
12 15
 
13 16
 export default (props) => {
17
+  console.log("🚀 ~ file: index.jsx ~ line 14 ~ props", props)
18
+
19
+  const $instance = Taro.getCurrentInstance()
20
+  const { id, location } = $instance.router.params
21
+
22
+  const [carsInfo, setCarsInfo] = useState({})
23
+  const [imagesList, setImagesList] = useState([])
24
+
25
+  useEffect(() => {
26
+
27
+    getMachineryInfo(id, { location: location, attached: true }).then((e) => {
28
+      setImagesList(e.imagesList)
29
+      setCarsInfo(e)
30
+      console.log('e', e);
31
+    })
32
+
33
+  }, [$instance.router.params, id, location])
34
+  console.log("🚀 ~ file: index.jsx ~ line 23 ~ carsInfo", carsInfo)
14 35
 
15 36
 
16 37
   const startReserve = () => {
@@ -33,12 +54,23 @@ export default (props) => {
33 54
 
34 55
         <View >
35 56
 
36
-          <Image style={{ width: '100%' }} src='http://img3.jc001.cn/img/001/1/1512/15566fd0311736f.jpg' />
57
+          {/* <Image style={{ width: '100%' }} src='http://img3.jc001.cn/img/001/1/1512/15566fd0311736f.jpg' /> */}
58
+          <Swiper
59
+            mode='scaleToFill'
60
+            className='swiper-box-info'
61
+
62
+          >
63
+            {imagesList.map((item, inx) => (
64
+              <SwiperItem key={inx}>
65
+                <Image src={item.url} className='storeImageinfo' />
66
+              </SwiperItem>
67
+            ))}
68
+          </Swiper>
37 69
 
38 70
           <View className='CarsContent-TextBox'>
39 71
             <View className='CheckDetails-bottom-box-flaxBox-liftText'>
40
-              <View className='CheckDetails-bottom-box-flaxBox-liftText-Titles'>不知家收割机</View>
41
-              <View className='CheckDetails-bottom-box-flaxBox-liftText-price'>2188/<Text>公顷</Text></View>
72
+              <View className='CheckDetails-bottom-box-flaxBox-liftText-Titles'>{carsInfo?.name}</View>
73
+              <View className='CheckDetails-bottom-box-flaxBox-liftText-price'>{carsInfo?.price}/<Text>公顷</Text></View>
42 74
             </View>
43 75
             <View className='content-header-box-map-Info' onClick={() => goMapInfo('222888')}>
44 76
               <View className='content-header-box-map-Info-liftCentent'>
@@ -46,7 +78,7 @@ export default (props) => {
46 78
                 <View>距离当前位置8.8公里&gt;&gt;</View>
47 79
               </View>
48 80
             </View>
49
-            <View className='content-header-box-map-Info-carsName'>农机手小李的收割机</View>
81
+            <View className='content-header-box-map-Info-carsName'>{carsInfo?.orgName}</View>
50 82
             <View className='startReserve-centent'>
51 83
               <View className='articleTitle-box-Details'>
52 84
                 <Image src={decorate} />

+ 9
- 1
src/pages/CheckDetails/style.less Datei anzeigen

@@ -1,7 +1,15 @@
1
+.swiper-box-info {
2
+  height: calc(calc(100vw - 4vh) * 0.62);
3
+  // height: 37vh;
4
+  .storeImageinfo {
5
+    width: 100vw;
6
+  }
7
+}
8
+
1 9
 .CarsContent-TextBox {
2 10
   padding: 40px 30px;
3 11
   position: relative;
4
-  top: -9vh;
12
+  top: -6vh;
5 13
   background-color: #fff;
6 14
   border-radius: 40px 40px 0px 0px;
7 15
   .CheckDetails-bottom-box-flaxBox-liftText {

+ 1
- 0
src/pages/index/index.config.js Datei anzeigen

@@ -5,6 +5,7 @@ export default {
5 5
 
6 6
   styleIsolation: 'shared',
7 7
   enableShareAppMessage: true,
8
+  onReachBottomDistance: 1,
8 9
   disableScroll: true,
9 10
   usingComponents: {
10 11
     "mp-tabbar": "weui-miniprogram/tabbar/tabbar",

+ 73
- 28
src/pages/index/tabs/Homes.jsx Datei anzeigen

@@ -1,35 +1,80 @@
1 1
 
2 2
 import { View, Swiper, Image, SwiperItem, Text, Input } from "@tarojs/components"
3
+import { useEffect, useState, useMemo } from "react"
4
+import Taro, { useReachBottom } from "@tarojs/taro"
3 5
 import ButtontWX from '@/components/ButtontWX'
4
-import Taro from "@tarojs/taro"
5 6
 import addresss from '@/assets/mineImgaes/addresss.png'//地址
6 7
 import searchs from '@/assets/homesImgaes/searchs.png'//搜索图片
7 8
 import carsListImga from '@/assets/homesImgaes/carsListImga.png'//农机列表图片
8 9
 
10
+import { getHomeBanner, getMachinery, } from "@/services/homes"
11
+
9 12
 
10 13
 
11 14
 import './HomesCss/style.less'
12 15
 
13 16
 export default (props) => {
14
-  // const { SwiperItem } = Swiper
15
-
16
-  const carsList = [
17
-    { carsName: '联合收割机', carsUrl: 'http://img3.jc001.cn/img/001/1/1512/15566fd0311736f.jpg', jiage: '300', carsLocation: '3.9' },
18
-    { carsName: '水稻播种机', carsUrl: 'http://img3.jc001.cn/img/001/1/1512/15566fd031719b1.jpg', jiage: '300', carsLocation: '3.9' },
19
-    { carsName: '秸秆统一处理 型号:GB2312', carsUrl: 'http://img3.jc001.cn/img/001/1/1512/15566fd03201503.jpg', jiage: '免费', carsLocation: '3.9' },
20
-    { carsName: '花生稻子小麦收割一体机', carsUrl: 'http://img3.jc001.cn/img/001/1/1512/15566fd0324f649.jpg', jiage: '550', carsLocation: '3.9' },
21
-    { carsName: '拖拉机', carsUrl: 'https://image.cnhnb.com/image/jpg/miniapp/2020/03/26/ef945970d2cc4948b61d45ce57ac1179.jpg', jiage: '180', carsLocation: '3.9' },
22
-    { carsName: '自行车', carsUrl: 'https://image.cnhnb.com/image/jpg/miniapp/2020/03/26/e8745759793d48398f82e6658186686a.jpg', jiage: '20', carsLocation: '3.9' },
23
-  ]
24
-
25
-  const imglist = [
26
-    { url: 'https://profile.csdnimg.cn/3/1/5/0_qq_42551866' },
27
-    { url: 'https://profile.csdnimg.cn/3/1/5/0_qq_42551866' },
28
-    { url: 'https://profile.csdnimg.cn/3/1/5/0_qq_42551866' },
29
-    { url: 'https://profile.csdnimg.cn/3/1/5/0_qq_42551866' },
30
-    { url: 'https://profile.csdnimg.cn/3/1/5/0_qq_42551866' },
31
-    { url: 'https://profile.csdnimg.cn/3/1/5/0_qq_42551866' },
32
-  ]
17
+  const location = Taro.getStorageSync('location')
18
+  const [bannerHome, setBannerHome] = useState([])
19
+  const [carsList, setCarsList] = useState([])
20
+
21
+  let pageSize = 10;//每页加载的数据量
22
+  let pageNum = 1;//当前页
23
+  let totalPage = 0;//总页数
24
+  let resultData = [];
25
+
26
+  useEffect(() => {
27
+    getHomeBanner({ position: 'banner' }).then((e) => {
28
+      console.log('e', e);
29
+      // let bame = e.filter(ele => ele.position == "banner")
30
+      setBannerHome(e)
31
+    })
32
+    getMachinery(location, {
33
+      pageSize: 3,
34
+      pageNum: 1,
35
+    }).then((e) => {
36
+      setCarsList(e.records)
37
+    })
38
+
39
+  }, [])
40
+
41
+
42
+  useReachBottom(() => {
43
+    console.log('chufa',);
44
+
45
+    if (pageNum < totalPage) {
46
+      pageNum += 1;
47
+      //加载下一页
48
+      loadData()
49
+      console.log('chufa',);
50
+    } else {
51
+      Taro.showToast({
52
+        icon: "none",
53
+        title: '没有更多数据了',
54
+      })
55
+    }
56
+  }, [1])
57
+
58
+
59
+
60
+
61
+  const loadData = () => {
62
+    getMachinery(location, {
63
+      pageSize: pageSize,
64
+      pageNum: pageNum,
65
+    }).then((e) => {
66
+      pageNum = e.data.content.pageNum;
67
+      totalPage = e.data.content.totalPageNum;
68
+      resultData = e.data.content.rows;
69
+
70
+      setCarsList(e.records)
71
+    })
72
+  }
73
+
74
+
75
+  console.log("🚀 ~ file: Homes.jsx ~ line 36 ~ imglist ~ imglist", bannerHome)
76
+
77
+
33 78
 
34 79
   const handleSearch = (e) => {
35 80
     console.log(e.detail.value)
@@ -45,7 +90,7 @@ export default (props) => {
45 90
 
46 91
   }
47 92
   const goCarsInfo = (res) => {
48
-    Taro.navigateTo({ url: `/pages/CheckDetails/index?id=${res}` })
93
+    Taro.navigateTo({ url: `/pages/CheckDetails/index?id=${res}&location=${location}` })
49 94
 
50 95
   }
51 96
   const goMapInfo = (res) => {
@@ -74,9 +119,9 @@ export default (props) => {
74 119
         autoplay
75 120
         className='swiper-box'
76 121
       >
77
-        {imglist.map((item, inx) => (
122
+        {bannerHome.map((item, inx) => (
78 123
           <SwiperItem key={inx}>
79
-            <Image src={item.url} mode='widthFix' className='storeImage' />
124
+            <Image src={item.thumb} mode='widthFix' className='storeImage' />
80 125
           </SwiperItem>
81 126
         ))}
82 127
       </Swiper>
@@ -92,20 +137,20 @@ export default (props) => {
92 137
         carsList.map((item, index) => {
93 138
           return (
94 139
             <View key={index} className='carsListImga-bottom-box'>
95
-              <Image src={item.carsUrl} onClick={() => goCarsInfo(item.id)} />
140
+              <Image src={item.thumb} onClick={() => goCarsInfo(item.machineryId)} />
96 141
               <View className='carsListImga-bottom-box-flaxBox'>
97 142
                 <View className='carsListImga-bottom-box-flaxBox-liftText'>
98
-                  <View className='carsListImga-bottom-box-flaxBox-liftText-Titles'>{item.carsName}</View>
99
-                  <View className='carsListImga-bottom-box-flaxBox-liftText-price'>{item.jiage}/<Text>公顷</Text></View>
143
+                  <View className='carsListImga-bottom-box-flaxBox-liftText-Titles'>{item.name}</View>
144
+                  <View className='carsListImga-bottom-box-flaxBox-liftText-price'>{item.price}/<Text>公顷</Text></View>
100 145
                 </View>
101 146
                 <View className='carsListImga-bottom-box-flaxBox-rightBut'>
102 147
                   <ButtontWX onClick={startReserve} butText='预约' butWidth={80} butHeight={34} butFontSize={19} butBorderRadius={0} />
103 148
                 </View>
104 149
               </View>
105
-              <View className='content-header-box-map' onClick={() => goMapInfo(item.mapId)}>
150
+              <View className='content-header-box-map' onClick={() => goMapInfo(item.machineryId)}>
106 151
                 <View className='content-header-box-map-liftCentent'>
107 152
                   <Image src={addresss} />
108
-                  <View>距离当前位置{item.carsLocation}公里</View>
153
+                  <View>距离当前位置公里</View>
109 154
                 </View>
110 155
                 <View className='content-header-box-map-rightCentent'>进入地图&gt;&gt;</View>
111 156
               </View>

+ 6
- 6
src/pages/index/tabs/Mine.jsx Datei anzeigen

@@ -1,7 +1,7 @@
1 1
 
2 2
 import { View, Image } from "@tarojs/components"
3 3
 import Taro from "@tarojs/taro"
4
-import { useState, useEffect } from "react"
4
+import { useState, useEffect, useMemo } from "react"
5 5
 import UserCellBox from '@/components/UserCellBox'
6 6
 import addresss from '@/assets/mineImgaes/addresss.png'//地址
7 7
 import aboutUs from '@/assets/mineImgaes/aboutUs.png'//关于我们
@@ -29,12 +29,11 @@ export default (props) => {
29 29
   const $instance = Taro.getCurrentInstance()
30 30
 
31 31
 
32
-  useEffect(() => {
32
+  const userInfo = useMemo(() => {
33 33
     console.log($instance.router.params)
34 34
     if ($instance.router.params.userOk || person.phone) {
35 35
       setIsLoginBox(true)
36
-    } else {
37
-      console.log('没有',);
36
+      return { phone: person.phone, nickName: person.nickName }
38 37
     }
39 38
   }, [$instance.router.params, person])
40 39
 
@@ -49,6 +48,7 @@ export default (props) => {
49 48
     // setIsLoginBox(true)
50 49
   }
51 50
   const goToPages = (res) => {
51
+
52 52
     switch (res) {
53 53
       case 0:
54 54
         Taro.navigateTo({ url: '/pages/AboutUsPage/index' })
@@ -90,8 +90,8 @@ export default (props) => {
90 90
                 <View className='setPassword'>修改密码</View>
91 91
                 <Image className='User-Avatar-background-trueBox-userImg' src='https://profile.csdnimg.cn/3/1/5/0_qq_42551866' />
92 92
                 <View className='User-Avatar-background-trueBox-name'>
93
-                  <View >鲍zhangchao</View>
94
-                  <View >{person.phone}</View>
93
+                  <View >{userInfo.nickName}</View>
94
+                  <View >{userInfo.phone}</View>
95 95
                 </View>
96 96
 
97 97
               </View>

+ 25
- 0
src/services/homes.js Datei anzeigen

@@ -0,0 +1,25 @@
1
+
2
+import request from '@/utils/request'
3
+/**
4
+ * banner轮播图
5
+ * @param {*} data 
6
+ * @returns 
7
+ */
8
+export const getHomeBanner = (data) => request(`/banner`, { data, method: 'get' })
9
+
10
+/**
11
+ * 农机列表
12
+ * @param {*} data 
13
+ * @returns 
14
+ */
15
+export const getMachinery = (pram, data) => request(`/machinery?location=${pram}`, { data, method: 'get' })
16
+
17
+
18
+
19
+/**
20
+ * 农机详情
21
+ * @param {*} data 
22
+ * @returns 
23
+ */
24
+export const getMachineryInfo = (pram, data) => request(`/machinery-summary/${pram}`, { data, method: 'get' })
25
+

+ 3
- 1
src/utils/codeSegment.js Datei anzeigen

@@ -15,4 +15,6 @@ export function getQueryString (params) {
15 15
   })
16 16
 
17 17
   return arr.filter(Boolean).join('&')
18
-}
18
+}
19
+
20
+