|
@@ -2,7 +2,9 @@ import store from '../../store'
|
2
|
2
|
import create from '../../utils/create'
|
3
|
3
|
import getDistance from '../../utils/distance'
|
4
|
4
|
import fetch from '../../utils/http'
|
5
|
|
-import { get as getApi } from '../../config/api'
|
|
5
|
+import {
|
|
6
|
+ get as getApi
|
|
7
|
+} from '../../config/api'
|
6
|
8
|
|
7
|
9
|
const app = getApp()
|
8
|
10
|
|
|
@@ -12,33 +14,90 @@ create(store, {
|
12
|
14
|
title: '收藏的楼盘'
|
13
|
15
|
})
|
14
|
16
|
},
|
15
|
|
- onLoad () {
|
|
17
|
+ onLoad() {
|
16
|
18
|
const userInfo = app.globalData.UserInfo
|
17
|
|
- const { latitude, longitude } = this.store.data.location
|
18
|
|
-
|
19
|
|
- fetch({
|
20
|
|
- ...getApi('user.building', { openid: userInfo.openid }),
|
21
|
|
- query: { pageNum: 1, pageSize: 10 },
|
22
|
|
- }).then(({ data }) => {
|
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
|
|
-
|
32
|
|
- this.setData({ list })
|
33
|
|
- }).catch((err) => {
|
34
|
|
- wx.showToast({
|
35
|
|
- title: '获取列表失败',
|
36
|
|
- icon: 'none',
|
37
|
|
- })
|
|
19
|
+ let _self = this
|
|
20
|
+ wx.getSystemInfo({
|
|
21
|
+ success(res) {
|
|
22
|
+ _self.setData({
|
|
23
|
+ WindowHeight: res.windowHeight
|
|
24
|
+ })
|
|
25
|
+ }
|
38
|
26
|
})
|
|
27
|
+ this.GetList()
|
39
|
28
|
},
|
40
|
29
|
data: {
|
41
|
30
|
list: [],
|
|
31
|
+ PostData: {
|
|
32
|
+ pageNum: 1,
|
|
33
|
+ pageSize: 10
|
|
34
|
+ },
|
|
35
|
+ Total: 1,
|
|
36
|
+ IsLock: false,
|
|
37
|
+ IsNull: false,
|
|
38
|
+ WindowHeight: 0
|
|
39
|
+ },
|
|
40
|
+ GetList() {
|
|
41
|
+ if (!this.data.IsLock && this.data.Total > this.data.list.length) {
|
|
42
|
+ this.setData({
|
|
43
|
+ IsLock: true
|
|
44
|
+ })
|
|
45
|
+ let {
|
|
46
|
+ latitude,
|
|
47
|
+ longitude
|
|
48
|
+ } = this.store.data.location
|
|
49
|
+
|
|
50
|
+ let userInfo = app.globalData.UserInfo
|
|
51
|
+
|
|
52
|
+ fetch({
|
|
53
|
+ ...getApi('user.building', {
|
|
54
|
+ openid: userInfo.openid
|
|
55
|
+ }),
|
|
56
|
+ query: {
|
|
57
|
+ ...this.data.PostData
|
|
58
|
+ },
|
|
59
|
+ }).then(({
|
|
60
|
+ data
|
|
61
|
+ }) => {
|
|
62
|
+ const list = (data.records || []).map((it) => {
|
|
63
|
+ const [lat = 0, lon = 0] = it.coordinate.split(',')
|
|
64
|
+ return {
|
|
65
|
+ ...it,
|
|
66
|
+ distance: parseInt(getDistance(latitude, longitude, lat - 0, lon - 0))
|
|
67
|
+ }
|
|
68
|
+ })
|
|
69
|
+ let aArr = this.data.list || []
|
|
70
|
+ list.map((item) => {
|
|
71
|
+ aArr.push(item)
|
|
72
|
+ })
|
|
73
|
+ this.setData({
|
|
74
|
+ list: aArr,
|
|
75
|
+ Total: data.total,
|
|
76
|
+ PostData: {
|
|
77
|
+ ...this.data.PostData,
|
|
78
|
+ pageNum: this.data.PostData.pageNum + 1
|
|
79
|
+ }
|
|
80
|
+ })
|
|
81
|
+ this.setData({
|
|
82
|
+ IsNull: !this.data.list.length
|
|
83
|
+ })
|
|
84
|
+ setTimeout(() => {
|
|
85
|
+ this.setData({
|
|
86
|
+ IsLock: false
|
|
87
|
+ })
|
|
88
|
+ }, 300)
|
|
89
|
+ }).catch((err) => {
|
|
90
|
+ wx.showToast({
|
|
91
|
+ title: '获取列表失败',
|
|
92
|
+ icon: 'none',
|
|
93
|
+ })
|
|
94
|
+ setTimeout(() => {
|
|
95
|
+ this.setData({
|
|
96
|
+ IsLock: false
|
|
97
|
+ })
|
|
98
|
+ }, 300)
|
|
99
|
+ })
|
|
100
|
+ }
|
42
|
101
|
},
|
43
|
102
|
DeleteItem(e) { // 确认删除逻辑
|
44
|
103
|
const buildingId = e.target.dataset.index
|
|
@@ -50,14 +109,20 @@ create(store, {
|
50
|
109
|
content: '确认要删除当前记录?',
|
51
|
110
|
success(res) {
|
52
|
111
|
if (res.confirm) {
|
53
|
|
-
|
|
112
|
+
|
54
|
113
|
fetch({
|
55
|
|
- ...getApi('user.delBuilding', { openid: userInfo.openid }),
|
56
|
|
- query: { buildingId },
|
|
114
|
+ ...getApi('user.delBuilding', {
|
|
115
|
+ openid: userInfo.openid
|
|
116
|
+ }),
|
|
117
|
+ query: {
|
|
118
|
+ buildingId
|
|
119
|
+ },
|
57
|
120
|
}).then(() => {
|
58
|
121
|
const list = _self.data.list.filter(x => x.buildingId !== buildingId)
|
59
|
122
|
|
60
|
|
- _self.setData({ list })
|
|
123
|
+ _self.setData({
|
|
124
|
+ list
|
|
125
|
+ })
|
61
|
126
|
}).catch((err) => {
|
62
|
127
|
wx.showToast({
|
63
|
128
|
title: '删除失败',
|