张延森 преди 5 години
родител
ревизия
30ab265e46
променени са 8 файла, в които са добавени 243 реда и са изтрити 57 реда
  1. 4
    4
      config/prod.js
  2. 8
    1
      project.config.json
  3. BIN
      src/assets/icons/marker.png
  4. BIN
      src/assets/icons/marker_checked.png
  5. 60
    0
      src/components/amap/PoiAround.js
  6. 1
    0
      src/lib/amap-wx.js
  7. 71
    52
      src/pages/project/detail/index.js
  8. 99
    0
      src/utils/amap.js

+ 4
- 4
config/prod.js Целия файл

@@ -3,10 +3,10 @@ module.exports = {
3 3
     NODE_ENV: '"production"'
4 4
   },
5 5
   defineConstants: {
6
-    // HOST: '"https://dev.jinchengjiaye.com"',
7
-    // WSS_HOST: '"wss://dev.jinchengjiaye.com"',
8
-    HOST: '"https://lt.pawoma.cn"',
9
-    WSS_HOST: '"wss://lt.pawoma.cn"',
6
+    HOST: '"https://dev.jinchengjiaye.com"',
7
+    WSS_HOST: '"wss://dev.jinchengjiaye.com"',
8
+    // HOST: '"https://lt.pawoma.cn"',
9
+    // WSS_HOST: '"wss://lt.pawoma.cn"',
10 10
   },
11 11
   weapp: {},
12 12
   h5: {}

+ 8
- 1
project.config.json Целия файл

@@ -2,7 +2,7 @@
2 2
 	"miniprogramRoot": "dist/",
3 3
 	"projectname": "mini-chengjiao",
4 4
 	"description": "知与行",
5
-	"appid": "wxd9ee3a9480a4e544",
5
+	"appid": "wxda1f84b79b3edeb3",
6 6
 	"setting": {
7 7
 		"urlCheck": false,
8 8
 		"es6": false,
@@ -59,6 +59,13 @@
59 59
 					"pathName": "pages/activity/detail/assistance",
60 60
 					"query": "id=85",
61 61
 					"scene": null
62
+				},
63
+				{
64
+					"id": -1,
65
+					"name": "pages/project/detail/index",
66
+					"pathName": "pages/project/detail/index",
67
+					"query": "id=93e6d86b8b48e3ea359084e3ceaf2d03",
68
+					"scene": null
62 69
 				}
63 70
 			]
64 71
 		}

BIN
src/assets/icons/marker.png Целия файл


BIN
src/assets/icons/marker_checked.png Целия файл


+ 60
- 0
src/components/amap/PoiAround.js Целия файл

@@ -0,0 +1,60 @@
1
+import Taro, { Component } from '@tarojs/taro'
2
+import { Map } from '@tarojs/components'
3
+
4
+const makerIcon = require('@assets/icons/marker.png')
5
+const makerCheckedIcon = require('@assets/icons/marker_checked.png')
6
+
7
+
8
+export default class PoiAround extends Component {
9
+
10
+  state = {
11
+    current: undefined,
12
+  }
13
+
14
+  markerTap = false
15
+
16
+  handleTap = (e) => {
17
+    const inx = e.markerId
18
+    this.markerTap = true
19
+    this.setState({ current: inx }, () => {
20
+      const marker = this.props.markers.filter((_, i) => i=== inx)[0]
21
+      this.props.onMarkerClick && this.props.onMarkerClick(marker)
22
+    })
23
+  }
24
+
25
+  render() {
26
+    const { current } = this.state
27
+    const markers =  (this.props.markers || []).map((marker, index) => {
28
+      return {
29
+        id: marker.id,
30
+        latitude: marker.latitude,
31
+        longitude: marker.longitude,
32
+        iconPath: index === current && this.markerTap ? makerCheckedIcon : makerIcon,
33
+        width: marker.width,
34
+        height: marker.height,
35
+        alpha: 0.7,
36
+        title: index + 1,
37
+        label: {
38
+          content: index + 1,
39
+          // borderRadius: 1000,
40
+          color: '#fff',
41
+          bgColor: '#f00',
42
+          textAlign: 'center',
43
+        },
44
+      }
45
+    })
46
+
47
+    this.markerTap = false
48
+
49
+    return this.props.longitude && (
50
+      <Map
51
+        showLocation
52
+        scale={12}
53
+        markers={markers}
54
+        longitude={this.props.longitude}
55
+        latitude={this.props.latitude}
56
+        onMarkerTap={this.handleTap}
57
+      />
58
+    )
59
+  }
60
+}

+ 1
- 0
src/lib/amap-wx.js
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 71
- 52
src/pages/project/detail/index.js Целия файл

@@ -4,7 +4,7 @@ import './index.scss'
4 4
 import Banner from '../banner'
5 5
 import HelpGroupBanner from '../swiper'
6 6
 import Poster from './poster'
7
-import ActivityItem from '../../activity/item'
7
+import PoiAround from '@components/amap/PoiAround'
8 8
 import BackHomeBtn from '@components/BackHomeBtn'
9 9
 import {
10 10
   addItemUv,
@@ -20,6 +20,7 @@ import 'dayjs/locale/zh-cn' // 按需加载
20 20
 import ready from '@utils/ready'
21 21
 import Notice from '@components/Notice'
22 22
 import { getDownloadURL, getThumbnail } from '@utils/tools'
23
+import { getPoiAround } from '@utils/amap'
23 24
 import { connect } from '@tarojs/redux'
24 25
 import { dispatchProjectDetail } from '@actions/project'
25 26
 import getUserPhone from '@utils/getUserPhone'
@@ -47,25 +48,8 @@ export default class Index extends Component {
47 48
     helpList: [],
48 49
     groupList: [],
49 50
     statusOpts: ['待定', '在建', '在售'],
50
-    circumOpts: [
51
-      {
52
-        name: '交通',
53
-        id: 'buildingTransport'
54
-      },
55
-      {
56
-        name: '教育',
57
-        id: 'buildingEdu'
58
-      },
59
-      {
60
-        name: '医疗',
61
-        id: 'buildingHospital'
62
-      },
63
-      {
64
-        name: '商业',
65
-        id: 'buildingMall'
66
-      }
67
-    ],
68
-    curTab: 'buildingTransport',
51
+    circumOpts: [],
52
+    curTab: 'Transport',
69 53
     recordId: null,
70 54
     posterShow: 'none'
71 55
   }
@@ -76,8 +60,7 @@ export default class Index extends Component {
76 60
       const router = Taro.getStorageSync('router')
77 61
       const id = this.$router.params.id || router.query.id
78 62
       // const id='82b54f4a1f5b981df572253792afbfa1' 
79
-      console.info('project-1:', router)
80
-      console.info('project-2:', this.$router)
63
+
81 64
       this.setState({
82 65
         buildingId: id
83 66
       }, () => {
@@ -109,6 +92,15 @@ export default class Index extends Component {
109 92
     const { recordId } = this.state
110 93
     recordId && updatePoint(recordId)
111 94
   }
95
+
96
+  loadMapAround(building) {
97
+    const [lat, lng] = (building.coordinate || '').split(',')
98
+
99
+    if (!lat || !lng) return Promise.reject()
100
+
101
+    return getPoiAround({ lng, lat})
102
+  }
103
+
112 104
   loadHelpGroupList() {
113 105
     const { buildingId } = this.state
114 106
     queryHelpGroup({ buildingId: buildingId }).then(res => {
@@ -131,7 +123,7 @@ export default class Index extends Component {
131 123
   }
132 124
 
133 125
   loadDetail() {
134
-    const { buildingId, circumOpts } = this.state
126
+    const { buildingId } = this.state
135 127
     const { dispatchProjectDetail } = this.props
136 128
     this.setState({
137 129
       loaded: false,
@@ -142,25 +134,32 @@ export default class Index extends Component {
142 134
     })
143 135
 
144 136
     dispatchProjectDetail(buildingId).then(res => {
145
-      circumOpts.map(item => {
146
-        let arr = res[item.id] ? res[item.id].split(',') : []
147
-        item.content = arr
148
-        item.num = arr.length
149
-      })
137
+      this.loadMapAround(res).then(data => {
138
+        const newCircumOpts = data.map((item) => {
139
+          const dtKey = `building${item.key}`
140
+          const manualDt = res[dtKey] ? res[dtKey].split(',') : []
141
+
142
+          return {
143
+            ...item,
144
+            manualDt,
145
+            num: manualDt.length + item.poisData.length
146
+          }
147
+        })
150 148
 
151
-      this.setState({
152
-        loaded: true,
153
-        circumOpts,
154
-        isSaved: res.isSave
155
-      }, () => {
156
-        if (res.posters && res.posters.length) {
157
-          this.setState({
158
-            posterShow: 'flex'
159
-          })
160
-        }
149
+        this.setState({
150
+          loaded: true,
151
+          circumOpts: newCircumOpts,
152
+          isSaved: res.isSave
153
+        }, () => {
154
+          if (res.posters && res.posters.length) {
155
+            this.setState({
156
+              posterShow: 'flex'
157
+            })
158
+          }
159
+        })
160
+
161
+        Taro.hideToast()
161 162
       })
162
-      Taro.hideToast()
163
-      // WxParse.wxParse('article', 'html', res.remark, this.$scope, 0)
164 163
     })
165 164
   }
166 165
 
@@ -487,6 +486,11 @@ export default class Index extends Component {
487 486
       url: `/pages/project/floor/index`
488 487
     })
489 488
   }
489
+
490
+  handleMarkerTap = (marker) => {
491
+
492
+  }
493
+
490 494
   renderBottomMenu() {
491 495
     const { userInfo: { person: { personType } } } = this.props
492 496
     const { posterShow } = this.state
@@ -613,7 +617,8 @@ export default class Index extends Component {
613 617
   rendercircum() {
614 618
     const { curTab, circumOpts } = this.state
615 619
     const { projectDetail } = this.props
616
-    const panel = circumOpts.filter(item => item.id === curTab)[0]
620
+    const panel = circumOpts.filter(item => item.key === curTab)[0]
621
+    const [lat, lng] = (projectDetail.coordinate || '').split(',')
617 622
 
618 623
     return (
619 624
       <View className="section circum">
@@ -625,25 +630,39 @@ export default class Index extends Component {
625 630
             {
626 631
               circumOpts.map(item => (
627 632
                 <Text
628
-                  key={item.id}
629
-                  className={curTab === item.id ? 'selected item' : 'item'}
630
-                  onClick={this.HandleCircumTabClick.bind(this, item.id)}>{item.name}({item.num})</Text>
633
+                  key={item.key}
634
+                  className={curTab === item.key ? 'selected item' : 'item'}
635
+                  onClick={this.HandleCircumTabClick.bind(this, item.key)}>{item.label}({item.num})</Text>
631 636
               ))
632 637
             }
633 638
           </View>
634 639
 
635 640
           <View className='map'>
636
-            <Image src={getThumbnail(projectDetail.mapImg)} className='map__img' mode="widthFix"></Image>
641
+            <PoiAround markers={panel.markers} longitude={lng} latitude={lat} onMarkerClick={this.handleMarkerTap}/>
637 642
           </View>
638 643
           <ScrollView className="body" scrollY >
639
-            {
640
-              panel.content.map((text, index) => (
641
-                <View className="row" key={index}>
642
-                  {text}</View>
643
-              ))
644
-            }
644
+            <View class="">
645
+              <View></View>
646
+              {
647
+                panel.poisData.map((poi, inx) => (
648
+                  <View className="row flex" key={`poi-${inx}`}>
649
+                    <View>{inx + 1}</View>
650
+                    <View>{poi.name}</View>
651
+                    <View>{poi.distance} m</View>
652
+                  </View>
653
+                ))
654
+              }
655
+            </View>
656
+            <View class="">              
657
+              <View>其他</View>
658
+              {
659
+                panel.manualDt.map((text, index) => (
660
+                  <View className="row" key={`mt-${index}`}>{text}</View>
661
+                ))
662
+              }
663
+            </View>
645 664
           </ScrollView>
646
-          <Button className='map-more-btn' onClick={this.openMap.bind(this)}>查看全部配套</Button>
665
+          <Button className='map-more-btn' onClick={this.openMap.bind(this)}>立即前往</Button>
647 666
         </View>
648 667
       </View>
649 668
     )

+ 99
- 0
src/utils/amap.js Целия файл

@@ -0,0 +1,99 @@
1
+/**
2
+ * 高德地图
3
+ * 
4
+ * POI 类型下载 https://lbs.amap.com/api/webservice/guide/api/search/#around
5
+ * 
6
+ */
7
+const amapLib = require('../lib/amap-wx');
8
+const myAmapKey = '766411323b66f7e876f428d8a23aa83c'
9
+const amap = new amapLib.AMapWX({ key: myAmapKey })
10
+
11
+// key 值会被拿到 building 表中 组合为字段名
12
+const POI_TYPES = [
13
+  {
14
+    key: 'Transport',
15
+    label: '交通',
16
+    types: ['150100', '150200', '150300', '150400', '150500', '150600'],
17
+  },
18
+  {
19
+    key: 'Mall',
20
+    label: '商业',
21
+    types: ['060100', '060200', '060300', '060400', '060500', '060600',
22
+            '060700', '060800', '060900', '061000', '061100', '061200',
23
+            '061300', '061400', '080100', '080200', '080300', '080400',
24
+            '080500', '080600'],
25
+  },
26
+  {
27
+    key: 'Edu',
28
+    label: '学校',
29
+    types: ['141200'],
30
+  },
31
+  {
32
+    key: 'Hospital',
33
+    label: '医院',
34
+    types: ['090100', '090200', '090300', '090400', '090500', '090600', '090700'],
35
+  },
36
+  {
37
+    key: 'Bank',
38
+    label: '银行',
39
+    types: ['160100'],
40
+  },
41
+  {
42
+    key: 'Restaurant',
43
+    label: '餐饮',
44
+    types: ['050100', '050200', '050300', '050400', '050500', '050600',
45
+            '050700', '050800', '050900'],
46
+  },
47
+]
48
+
49
+const getPrefix = str => str.substr(0, 4)
50
+
51
+export function getPoiAround(params) {
52
+  const {
53
+    lng,
54
+    lat
55
+  } = params || {}
56
+
57
+  return new Promise((resolve, reject) => {
58
+    const querytypes = POI_TYPES.reduce((acc, item) => ([ ...acc, ...item.types ]), []).join('|')
59
+    const location = `${lng},${lat}`
60
+    const iconPath = undefined
61
+    const iconPathSelected = undefined
62
+    const resultList = []
63
+
64
+    // 成功回调
65
+    // https://lbs.amap.com/api/webservice/guide/api/search/#around
66
+    const successCall = poiType => res => {
67
+      resultList.push({
68
+        key: poiType.key,
69
+        label: poiType.label,
70
+        poisData: res.poisData,
71
+        markers: res.markers
72
+      })
73
+
74
+      if (resultList.length === POI_TYPES.length) {
75
+        resolve(resultList)
76
+      }
77
+    }
78
+
79
+    // 失败回调
80
+    // https://lbs.amap.com/api/webservice/guide/tools/info/
81
+    const failCall = poiType => info => {
82
+      console.error(poiType, info)
83
+      reject(info)
84
+    }
85
+
86
+    POI_TYPES.forEach((pt) => {
87
+      const querytypes = pt.types.join('|')
88
+
89
+      amap.getPoiAround({
90
+        querytypes,
91
+        location,
92
+        iconPath,
93
+        iconPathSelected,
94
+        success: successCall(pt),
95
+        fail: failCall(pt),
96
+      })
97
+    })
98
+  })
99
+}