许成详 6 anos atrás
pai
commit
ffd83cd0d0

+ 5
- 0
app.json Ver arquivo

19
     "navigationBarBackgroundColor": "#bb9c79",
19
     "navigationBarBackgroundColor": "#bb9c79",
20
     "navigationBarTitleText": "",
20
     "navigationBarTitleText": "",
21
     "navigationBarTextStyle":"white"
21
     "navigationBarTextStyle":"white"
22
+  },
23
+  "permission": {
24
+    "scope.userLocation": {
25
+      "desc": "您的位置将用于效果展示"
26
+    }
22
   }
27
   }
23
 }
28
 }

+ 3
- 0
config/api.js Ver arquivo

16
       methods: 'GET',
16
       methods: 'GET',
17
       url: `${BaseAPIURl}/api/wx/buildingDynamiceList`
17
       url: `${BaseAPIURl}/api/wx/buildingDynamiceList`
18
     }
18
     }
19
+  },
20
+  activity: {
21
+    
19
   }
22
   }
20
 }
23
 }
21
 
24
 

+ 1
- 1
config/baseUrl.js Ver arquivo

1
 module.exports.basePath = {
1
 module.exports.basePath = {
2
-  BASE_API_URL: 'https://api.jinchengjiaye.com/newnbapi',
2
+  BASE_API_URL: 'https://dev.jinchengjiaye.com/api',
3
   BASE_IMG_URL: 'https://whole-estate.oss-cn-beijing.aliyuncs.com/',
3
   BASE_IMG_URL: 'https://whole-estate.oss-cn-beijing.aliyuncs.com/',
4
 }
4
 }

+ 62
- 1
pages/components/Estate/index.js Ver arquivo

1
 //index.js
1
 //index.js
2
 //获取应用实例
2
 //获取应用实例
3
 const app = getApp()
3
 const app = getApp()
4
+const HttpSever = require('../../../utils/http.js').HttpSever;
5
+const $api = require('../../../config/api.js').$api;
4
 
6
 
5
 Component({
7
 Component({
6
   behaviors: [],
8
   behaviors: [],
28
     }]
30
     }]
29
   },
31
   },
30
   lifetimes: {},
32
   lifetimes: {},
31
-  ready: function() {},
33
+  ready: function() {
34
+    const _that = this
35
+    wx.getSetting({
36
+      success(res) {
37
+        if (!res.authSetting['scope.userLocation']) {
38
+          wx.authorize({
39
+            scope: 'scope.userLocation',
40
+            success() {
41
+              _that.ShowLocation()
42
+            }
43
+          })
44
+        } else {
45
+          _that.ShowLocation()
46
+        }
47
+      }
48
+    })
49
+  },
32
   pageLifetimes: {
50
   pageLifetimes: {
33
     show: function() {},
51
     show: function() {},
34
   },
52
   },
37
       wx.navigateTo({
55
       wx.navigateTo({
38
         url: '/pages/EstateDetail/index?id='
56
         url: '/pages/EstateDetail/index?id='
39
       })
57
       })
58
+    },
59
+    GetGreatCircleDistance(lat1, lng1, lat2, lng2) {
60
+      if (lat1 === lat2 && lng1 === lng2) {
61
+        return 0
62
+      }
63
+      var EARTH_RADIUS = 6378137.0//单位M
64
+      var PI = Math.PI
65
+      var radLat1 = lat1 * PI / 180.0
66
+      var radLat2 = lat2 * PI / 180.0
67
+      var a = radLat1 - radLat2
68
+      var b = lng1 * PI / 180.0 - lng2 * PI / 180.0
69
+      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)))
70
+      s = s * EARTH_RADIUS
71
+      s = Math.round(s * 10000) / 10000.0
72
+      console.log(s)
73
+      return s
74
+    },
75
+    ShowLocation() {
76
+      const _that = this
77
+      wx.getLocation({
78
+        type: 'wgs84',
79
+        success(res) {
80
+          console.log(res)
81
+          HttpSever.Ajax({
82
+            url: $api.building.list.url,
83
+            method: $api.building.list.method,
84
+          }).then((data) => {
85
+            const eslist = data.data.map(x => {
86
+              const distance = parseInt(_that.GetGreatCircleDistance(res.latitude, res.longitude, x.coordinate.split(',')[0], x.coordinate.split(',')[1] || res.longitude))
87
+              return {
88
+                buildingName: x.buildingName,
89
+                price: x.price,
90
+                address: x.address,
91
+                buildingImg: (x.buildingImg[0] || {}).url,
92
+                distance: distance / 1000
93
+              }
94
+            })
95
+            _that.setData({
96
+              EstateList: eslist
97
+            })
98
+          })
99
+        }
100
+      })
40
     }
101
     }
41
   }
102
   }
42
 })
103
 })

+ 4
- 4
pages/components/Estate/index.wxml Ver arquivo

9
     <text>附近楼盘</text>
9
     <text>附近楼盘</text>
10
     <view class="list">
10
     <view class="list">
11
       <view wx:for="{{EstateList}}" wx:for-item="item" wx:for-index="index" wx:key="key" bindtap="ListTap">
11
       <view wx:for="{{EstateList}}" wx:for-item="item" wx:for-index="index" wx:key="key" bindtap="ListTap">
12
-        <image mode="aspectFill" src="{{item.Img}}" class="centerLabel cover"></image>
13
-        <text class="price">均价:{{item.Price}}万/平</text>
14
-        <text class="name">{{item.Name}}</text>
12
+        <image mode="aspectFill" src="{{item.buildingImg}}" class="centerLabel cover"></image>
13
+        <text class="price">均价:{{item.price}}</text>
14
+        <text class="name">{{item.buildingName}}</text>
15
         <view class="address flex-h">
15
         <view class="address flex-h">
16
           <image mode="widthFix" src="/assets/images/icon8.png"></image>
16
           <image mode="widthFix" src="/assets/images/icon8.png"></image>
17
-          <text class="flex-item">{{item.Address}} 距您{{item.Distance}}km</text>
17
+          <text class="flex-item">{{item.address}} 距您{{item.distance}}km</text>
18
         </view>
18
         </view>
19
       </view>
19
       </view>
20
     </view>
20
     </view>

+ 2
- 5
utils/http.js Ver arquivo

2
 const $api = require('../config/api.js').$api;
2
 const $api = require('../config/api.js').$api;
3
 const $HttpSever = function () { }
3
 const $HttpSever = function () { }
4
 
4
 
5
-const app = getApp();
6
-
7
 $HttpSever.prototype = {
5
 $HttpSever.prototype = {
8
   /**
6
   /**
9
    *  通用请求方法
7
    *  通用请求方法
17
         url: config.url,
15
         url: config.url,
18
         method: config.method,
16
         method: config.method,
19
         data: {
17
         data: {
20
-          ...config.data,
21
-          openid: app.globalData.OpenID
18
+          ...config.data
22
         },
19
         },
23
         header: {
20
         header: {
24
           'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
21
           'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
25
         },
22
         },
26
         success(res) {
23
         success(res) {
27
           if (res.statusCode && res.statusCode === apiCode.common.successCode) {
24
           if (res.statusCode && res.statusCode === apiCode.common.successCode) {
28
-            resolve(res.data.message)
25
+            resolve(res.data)
29
           } else {
26
           } else {
30
             resolve(res.data.message + "失败")
27
             resolve(res.data.message + "失败")
31
           }
28
           }