|
@@ -9,99 +9,134 @@ import util from '../../utils/util'; |
|
@@ -9,99 +9,134 @@ import util from '../../utils/util'; |
|
9
|
const {regeneratorRuntime} = global
|
9
|
const {regeneratorRuntime} = global
|
|
10
|
Page({
|
10
|
Page({
|
|
11
|
|
11
|
|
|
12
|
- /**
|
|
|
|
13
|
- * 页面的初始数据
|
|
|
|
14
|
- */
|
|
|
|
15
|
- data: {
|
12
|
+ /**
|
|
|
|
13
|
+ * 页面的初始数据
|
|
|
|
14
|
+ */
|
|
|
|
15
|
+ data: {},
|
|
16
|
|
16
|
|
|
17
|
- },
|
17
|
+ /**
|
|
|
|
18
|
+ * 生命周期函数--监听页面加载
|
|
|
|
19
|
+ */
|
|
|
|
20
|
+ onLoad: function (options) {
|
|
18
|
|
21
|
|
|
19
|
- /**
|
|
|
|
20
|
- * 生命周期函数--监听页面加载
|
|
|
|
21
|
- */
|
|
|
|
22
|
- onLoad: function (options) {
|
22
|
+ },
|
|
23
|
|
23
|
|
|
24
|
- },
|
24
|
+ /**
|
|
|
|
25
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
|
26
|
+ */
|
|
|
|
27
|
+ onReady: function () {
|
|
25
|
|
28
|
|
|
26
|
- /**
|
|
|
|
27
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
|
28
|
- */
|
|
|
|
29
|
- onReady: function () {
|
29
|
+ },
|
|
30
|
|
30
|
|
|
31
|
- },
|
31
|
+ /**
|
|
|
|
32
|
+ * 生命周期函数--监听页面显示
|
|
|
|
33
|
+ */
|
|
|
|
34
|
+ onShow: function () {
|
|
32
|
|
35
|
|
|
33
|
- /**
|
|
|
|
34
|
- * 生命周期函数--监听页面显示
|
|
|
|
35
|
- */
|
|
|
|
36
|
- onShow: function () {
|
36
|
+ },
|
|
37
|
|
37
|
|
|
38
|
- },
|
38
|
+ /**
|
|
|
|
39
|
+ * 生命周期函数--监听页面隐藏
|
|
|
|
40
|
+ */
|
|
|
|
41
|
+ onHide: function () {
|
|
39
|
|
42
|
|
|
40
|
- /**
|
|
|
|
41
|
- * 生命周期函数--监听页面隐藏
|
|
|
|
42
|
- */
|
|
|
|
43
|
- onHide: function () {
|
43
|
+ },
|
|
44
|
|
44
|
|
|
45
|
- },
|
45
|
+ /**
|
|
|
|
46
|
+ * 生命周期函数--监听页面卸载
|
|
|
|
47
|
+ */
|
|
|
|
48
|
+ onUnload: function () {
|
|
46
|
|
49
|
|
|
47
|
- /**
|
|
|
|
48
|
- * 生命周期函数--监听页面卸载
|
|
|
|
49
|
- */
|
|
|
|
50
|
- onUnload: function () {
|
50
|
+ },
|
|
51
|
|
51
|
|
|
52
|
- },
|
|
|
|
53
|
-
|
|
|
|
54
|
- //在Page({})中使用下列代码
|
|
|
|
55
|
- //数据回填方法
|
|
|
|
56
|
- backfill: function (e) {
|
|
|
|
57
|
- var id = e.currentTarget.id;
|
|
|
|
58
|
- for (var i = 0; i < this.data.suggestion.length;i++){
|
|
|
|
59
|
- if(i == id){
|
|
|
|
60
|
- console.log(this.data.suggestion[i])
|
|
|
|
61
|
- let pages=getCurrentPages();
|
|
|
|
62
|
- let p=pages[pages.length-2];
|
|
|
|
63
|
- p.setSuggestion(this.data.suggestion[i])
|
|
|
|
64
|
- //util.cache('suggestion',this.data.suggestion[i]);
|
|
|
|
65
|
- this.setData({
|
|
|
|
66
|
- backfill: this.data.suggestion[i].title
|
|
|
|
67
|
- });
|
|
|
|
68
|
- wx.navigateBack();
|
|
|
|
69
|
- }
|
52
|
+ //在Page({})中使用下列代码
|
|
|
|
53
|
+ //数据回填方法
|
|
|
|
54
|
+ backfill: function (e) {
|
|
|
|
55
|
+ var id = e.currentTarget.id;
|
|
|
|
56
|
+ for (var i = 0; i < this.data.suggestion.length; i++) {
|
|
|
|
57
|
+ if (i == id) {
|
|
|
|
58
|
+ console.log(this.data.suggestion[i])
|
|
|
|
59
|
+ let pages = getCurrentPages();
|
|
|
|
60
|
+ let p = pages[pages.length - 2];
|
|
|
|
61
|
+ p.setSuggestion(this.data.suggestion[i])
|
|
|
|
62
|
+ //util.cache('suggestion',this.data.suggestion[i]);
|
|
|
|
63
|
+ this.setData({
|
|
|
|
64
|
+ backfill: this.data.suggestion[i].title
|
|
|
|
65
|
+ });
|
|
|
|
66
|
+ wx.navigateBack();
|
|
70
|
}
|
67
|
}
|
|
71
|
- },
|
|
|
|
72
|
-
|
|
|
|
73
|
- //触发关键词输入提示事件
|
|
|
|
74
|
- getsuggest: function(e) {
|
|
|
|
75
|
- var _this = this;
|
|
|
|
76
|
- //调用关键词提示接口
|
|
|
|
77
|
- qqmapsdk.getSuggestion({
|
|
|
|
78
|
- //获取输入框值并设置keyword参数
|
|
|
|
79
|
- keyword: e.detail.value, //用户输入的关键词,可设置固定值,如keyword:'KFC'
|
|
|
|
80
|
- //region:'北京', //设置城市名,限制关键词所示的地域范围,非必填参数
|
|
|
|
81
|
- success: function(res) {//搜索成功后的回调
|
|
|
|
82
|
- console.log(res);
|
|
|
|
83
|
- var sug = [];
|
|
|
|
84
|
- for (var i = 0; i < res.data.length; i++) {
|
|
|
|
85
|
- sug.push({ // 获取返回结果,放到sug数组中
|
|
|
|
86
|
- title: res.data[i].title,
|
|
|
|
87
|
- id: res.data[i].id,
|
|
|
|
88
|
- addr: res.data[i].address,
|
|
|
|
89
|
- city: res.data[i].city,
|
|
|
|
90
|
- district: res.data[i].district,
|
|
|
|
91
|
- latitude: res.data[i].location.lat,
|
|
|
|
92
|
- longitude: res.data[i].location.lng
|
|
|
|
93
|
- });
|
|
|
|
94
|
- }
|
|
|
|
95
|
- _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
|
|
|
|
96
|
- suggestion: sug
|
68
|
+ }
|
|
|
|
69
|
+ },
|
|
|
|
70
|
+ inputVal:'',
|
|
|
|
71
|
+ //触发关键词输入提示事件
|
|
|
|
72
|
+ getsuggest: function (e) {
|
|
|
|
73
|
+ var _this = this;
|
|
|
|
74
|
+ //调用关键词提示接口
|
|
|
|
75
|
+ this.inputVal=e.detail.value;
|
|
|
|
76
|
+ qqmapsdk.getSuggestion({
|
|
|
|
77
|
+ //获取输入框值并设置keyword参数
|
|
|
|
78
|
+ keyword: e.detail.value, //用户输入的关键词,可设置固定值,如keyword:'KFC'
|
|
|
|
79
|
+ //region:'北京', //设置城市名,限制关键词所示的地域范围,非必填参数
|
|
|
|
80
|
+ success: function (res) {//搜索成功后的回调
|
|
|
|
81
|
+ console.log(res);
|
|
|
|
82
|
+ var sug = [];
|
|
|
|
83
|
+ for (var i = 0; i < res.data.length; i++) {
|
|
|
|
84
|
+ sug.push({ // 获取返回结果,放到sug数组中
|
|
|
|
85
|
+ title: res.data[i].title,
|
|
|
|
86
|
+ id: res.data[i].id,
|
|
|
|
87
|
+ addr: res.data[i].address,
|
|
|
|
88
|
+ city: res.data[i].city,
|
|
|
|
89
|
+ district: res.data[i].district,
|
|
|
|
90
|
+ latitude: res.data[i].location.lat,
|
|
|
|
91
|
+ longitude: res.data[i].location.lng
|
|
97
|
});
|
92
|
});
|
|
98
|
- },
|
|
|
|
99
|
- fail: function(error) {
|
|
|
|
100
|
- console.error(error);
|
|
|
|
101
|
- },
|
|
|
|
102
|
- complete: function(res) {
|
|
|
|
103
|
- console.log(res);
|
|
|
|
104
|
}
|
93
|
}
|
|
105
|
- });
|
94
|
+ _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
|
|
|
|
95
|
+ suggestion: sug
|
|
|
|
96
|
+ });
|
|
|
|
97
|
+ },
|
|
|
|
98
|
+ fail: function (error) {
|
|
|
|
99
|
+ console.error(error);
|
|
|
|
100
|
+ },
|
|
|
|
101
|
+ complete: function (res) {
|
|
|
|
102
|
+ console.log('getsuggest',res);
|
|
|
|
103
|
+ }
|
|
|
|
104
|
+ });
|
|
|
|
105
|
+ },
|
|
|
|
106
|
+ nearby_search: function () {
|
|
|
|
107
|
+ var _this = this;
|
|
|
|
108
|
+ // 调用接口
|
|
|
|
109
|
+ let location='';
|
|
|
|
110
|
+ if(this.data.suggestion.length>0){
|
|
|
|
111
|
+ location=this.data.suggestion[0]
|
|
106
|
}
|
112
|
}
|
|
|
|
113
|
+ qqmapsdk.search({
|
|
|
|
114
|
+ keyword: this.inputVal, //搜索关键词
|
|
|
|
115
|
+ page_size:50,
|
|
|
|
116
|
+ location:location,
|
|
|
|
117
|
+ success: function (res) { //搜索成功后的回调
|
|
|
|
118
|
+ var mks = []
|
|
|
|
119
|
+ for (var i = 0; i < res.data.length; i++) {
|
|
|
|
120
|
+ mks.push({ // 获取返回结果,放到mks数组中
|
|
|
|
121
|
+ title: res.data[i].title,
|
|
|
|
122
|
+ id: res.data[i].id,
|
|
|
|
123
|
+ addr: res.data[i].address,
|
|
|
|
124
|
+ city: res.data[i].city,
|
|
|
|
125
|
+ district: res.data[i].district,
|
|
|
|
126
|
+ latitude: res.data[i].location.lat,
|
|
|
|
127
|
+ longitude: res.data[i].location.lng,
|
|
|
|
128
|
+ })
|
|
|
|
129
|
+ }
|
|
|
|
130
|
+ _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
|
|
|
|
131
|
+ suggestion:mks,
|
|
|
|
132
|
+ });
|
|
|
|
133
|
+ },
|
|
|
|
134
|
+ fail: function (res) {
|
|
|
|
135
|
+ console.log(res);
|
|
|
|
136
|
+ },
|
|
|
|
137
|
+ complete: function (res) {
|
|
|
|
138
|
+ console.log('nearby_search',res);
|
|
|
|
139
|
+ }
|
|
|
|
140
|
+ });
|
|
|
|
141
|
+ },
|
|
107
|
}) |
142
|
}) |