zjxpcyc 6 years ago
parent
commit
cd28a4e86d

+ 17
- 0
app.js View File

63
       }
63
       }
64
     })
64
     })
65
 
65
 
66
+    wx.getLocation({
67
+      type: 'wgs84',
68
+      success(res) {
69
+        const { latitude, longitude } = res;
70
+
71
+        if (store && store.update) {
72
+          store.data.location = { latitude, longitude }
73
+          store.update()
74
+        } else {
75
+          setTimeout(() => {
76
+            store.data.location = { latitude, longitude }
77
+            store.update()
78
+          }, 2000)
79
+        }
80
+      }
81
+    })
82
+
66
     fetch({
83
     fetch({
67
       url: $api.dict.list.url,
84
       url: $api.dict.list.url,
68
       method: $api.dict.list.method,
85
       method: $api.dict.list.method,

+ 11
- 1
pages/MyCollectEstateList/index.js View File

1
 import store from '../../store'
1
 import store from '../../store'
2
 import create from '../../utils/create'
2
 import create from '../../utils/create'
3
+import getDistance from '../../utils/distance'
3
 import fetch from '../../utils/http'
4
 import fetch from '../../utils/http'
4
 import { get as getApi } from '../../config/api'
5
 import { get as getApi } from '../../config/api'
5
 
6
 
13
   },
14
   },
14
   onLoad () {
15
   onLoad () {
15
     const userInfo = app.globalData.UserInfo
16
     const userInfo = app.globalData.UserInfo
17
+    const { latitude, longitude } = this.store.data.location
16
 
18
 
17
     fetch({
19
     fetch({
18
       ...getApi('user.building', { openid: userInfo.openid }),
20
       ...getApi('user.building', { openid: userInfo.openid }),
19
       query: { pageNum: 1, pageSize: 10 },
21
       query: { pageNum: 1, pageSize: 10 },
20
     }).then(({ data }) => {
22
     }).then(({ data }) => {
21
-      const list = data.records || []
23
+      const list = (data.records || []).map((it) => {
24
+        const [ lat = 0, lon = 0 ] = it.coordinate.split(',')
25
+
26
+        return {
27
+          ...it,
28
+          distance: parseInt(getDistance(latitude, longitude, lat - 0, lon - 0))
29
+        }
30
+      })
31
+
22
       this.setData({ list })
32
       this.setData({ list })
23
     }).catch((err) => {
33
     }).catch((err) => {
24
       wx.showToast({
34
       wx.showToast({

+ 1
- 1
pages/MyCollectEstateList/index.wxml View File

16
           </view>
16
           </view>
17
           <text>{{item.name}}</text>
17
           <text>{{item.name}}</text>
18
           <text>{{item.address}}</text>
18
           <text>{{item.address}}</text>
19
-          <text>距您{{item.Distance}}km</text>
19
+          <text>距您{{item.distance}}km</text>
20
           <text class="price">均价:<text>{{item.price}}</text>/平</text>
20
           <text class="price">均价:<text>{{item.price}}</text>/平</text>
21
         </view>
21
         </view>
22
       </view>
22
       </view>

+ 2
- 2
pages/components/Mine/index.js View File

7
   behaviors: [],
7
   behaviors: [],
8
   properties: {},
8
   properties: {},
9
   data: {
9
   data: {
10
-    userInfo: null,
10
+    userInfo: {},
11
     UserSetList: [{
11
     UserSetList: [{
12
       value: '个人资料',
12
       value: '个人资料',
13
       icon: '/assets/images/icon16.png',
13
       icon: '/assets/images/icon16.png',
69
       }
69
       }
70
     },
70
     },
71
     signup(e) {      
71
     signup(e) {      
72
-      signUp(e.detail.userInfo, app).then(() => {
72
+      signUp(e.detail.userInfo, app).then((dt) => {
73
         wx.showToast({
73
         wx.showToast({
74
           title: '注册成功',
74
           title: '注册成功',
75
           icon: 'success',
75
           icon: 'success',

+ 1
- 0
store.js View File

3
 export default {
3
 export default {
4
   data: {
4
   data: {
5
     userInfo: {},
5
     userInfo: {},
6
+    location: {},
6
   },
7
   },
7
   globalData: '',
8
   globalData: '',
8
 }
9
 }

+ 16
- 0
utils/distance.js View File

1
+
2
+export default function getDistance(lat1, lng1, lat2, lng2) {
3
+  if (lat1 === lat2 && lng1 === lng2) {
4
+    return 0
5
+  }
6
+  var EARTH_RADIUS = 6378137.0//单位M
7
+  var PI = Math.PI
8
+  var radLat1 = lat1 * PI / 180.0
9
+  var radLat2 = lat2 * PI / 180.0
10
+  var a = radLat1 - radLat2
11
+  var b = lng1 * PI / 180.0 - lng2 * PI / 180.0
12
+  var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)))
13
+  s = s * EARTH_RADIUS
14
+  s = Math.round(s * 10000) / 10000.0
15
+  return s/100
16
+}

+ 1
- 0
utils/signup.js View File

17
       // 更新 store
17
       // 更新 store
18
       store.data.userInfo.avatar = userInfo.avatarUrl
18
       store.data.userInfo.avatar = userInfo.avatarUrl
19
       store.data.userInfo.name = userInfo.nickName
19
       store.data.userInfo.name = userInfo.nickName
20
+      store.data.userInfo.hasReg = 1
20
       store.update()
21
       store.update()
21
   
22
   
22
       // 更新 globalData
23
       // 更新 globalData