许成详 6 years ago
parent
commit
ffd83cd0d0
6 changed files with 77 additions and 11 deletions
  1. 5
    0
      app.json
  2. 3
    0
      config/api.js
  3. 1
    1
      config/baseUrl.js
  4. 62
    1
      pages/components/Estate/index.js
  5. 4
    4
      pages/components/Estate/index.wxml
  6. 2
    5
      utils/http.js

+ 5
- 0
app.json View File

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

+ 3
- 0
config/api.js View File

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

+ 1
- 1
config/baseUrl.js View File

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

+ 62
- 1
pages/components/Estate/index.js View File

@@ -1,6 +1,8 @@
1 1
 //index.js
2 2
 //获取应用实例
3 3
 const app = getApp()
4
+const HttpSever = require('../../../utils/http.js').HttpSever;
5
+const $api = require('../../../config/api.js').$api;
4 6
 
5 7
 Component({
6 8
   behaviors: [],
@@ -28,7 +30,23 @@ Component({
28 30
     }]
29 31
   },
30 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 50
   pageLifetimes: {
33 51
     show: function() {},
34 52
   },
@@ -37,6 +55,49 @@ Component({
37 55
       wx.navigateTo({
38 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 View File

@@ -9,12 +9,12 @@
9 9
     <text>附近楼盘</text>
10 10
     <view class="list">
11 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 15
         <view class="address flex-h">
16 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 18
         </view>
19 19
       </view>
20 20
     </view>

+ 2
- 5
utils/http.js View File

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