tips-nearby-store-comp.js
5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import {
getBindtapData,
} from '../../utils/util';
let app = getApp();
Component({
properties: {
// 这里定义了innerText属性,属性值可以在组件使用时指定
innerText: {
type: String,
value: 'default value',
},
wishInfo: {
type: Object,
value: {},
},
location: {
type: Object,
value: {},
},
//是否选择模式
selectedMode: {
type: Boolean,
value: false
}
},
data: {
// 这里是一些组件内部数据
someData: {},
searchMode: 1, // 查询模式 1.根据位置自动查询 2.省市区查询
provinceId: "",
cityId: "",
districtId: "",
provinceList: [],
cityList: [],
districtList: [],
provinceIndex: 0,
cityIndex: 0,
districtIndex: 0,
addressList: [],
total: 0,
curAddress: null,
localCity: ""
},
methods: {
/**
* 请求门店地址
*/
queryShop() {
this.setData({
curAddress: ""
})
return new Promise((resolve, reject) => {
let {
location,
wishInfo,
provinceId,
cityId,
districtId,
} = this.data;
app.post({
url: app.api.storeQuery,
data: {
couponId: wishInfo.couponId,
latitude: location.latitude,
longitude: location.longitude,
provinceId: provinceId,
cityId: cityId,
districtId: districtId,
page: 1,
size: 100,
}
}).then((result) => {
this.setData({
addressList: result.list,
total: result.total,
localCity: result.city
})
resolve();
})
});
},
/**
* 选择地址 item
*/
onSelectHandler(evt) {
let item = getBindtapData(evt);
let index = getBindtapData(evt, "index");
let addressList = this.data.addressList;
addressList.forEach((element, idx) => {
element.selected = index == idx;
});
this.setData({
addressList: addressList,
curAddress: item
})
},
/**
* 提交门店
* 预约
*/
onSubmitHandler(evt) {
let curAddress = this.data.curAddress;
if (!curAddress) {
wx.showToast({
title: "请选择门店",
icon: 'none'
});
return;
}
let wishInfo = this.properties.wishInfo;
app.post({
url: app.api.wishbillStoreAppoint,
data: {
instanceCode: wishInfo.instanceCode,
storeCode: curAddress.storeCode,
storeName: curAddress.storeName,
storeAddress: curAddress.storeAddress,
latitude: curAddress.latitude,
longitude: curAddress.longitude
}
}).then((result) => {
this.triggerEvent('evtcomp', {
name: "_evt_submit_store_complete"
})
});
},
/**
* 显示位置
* @param {*} e
*/
onShowLocHandler(evt) {
let item = getBindtapData(evt);
wx.openLocation({
latitude: item.latitude, // 纬度,范围为-90~90,负数表示南纬
longitude: item.longitude, // 经度,范围为-180~180,负数表示西经
scale: 18, // 缩放比例
name: item.storeName, // 位置名
address: item.storeAddress, // 地址的详细说明
success: function (res) {
// success
}
})
},
// 转换成手动模式
onSearchHandModeHandler() {
this.setData({
searchMode: 2
});
this.queryShop();
},
// 转换为自动模式
onSearchAutoModeHandler() {
this.setData({
searchMode: 1,
provinceId: "",
cityId: "",
districtId: "",
})
this.queryShop();
},
getProvince() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.provinceQuery
}).then((result) => {
this.setData({
provinceList: result
})
console.log("getProvince result:", result);
})
});
},
getCity() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.cityQuery,
data: {
parentId: this.data.provinceId
}
}).then((result) => {
this.setData({
cityList: result
})
})
});
},
getDistrict() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.districtQuery,
data: {
parentId: this.data.cityId
}
}).then((result) => {
this.setData({
districtList: result
})
})
});
},
bindPickerChangeProvince(e) {
let index = e.detail.value;
this.setData({
provinceIndex: index,
provinceId: this.data.provinceList[index].id,
cityList: [],
cityIndex: -1,
districtList: [],
districtIndex: -1,
})
this.getCity();
},
bindPickerChangeCity(e) {
let index = e.detail.value;
this.setData({
cityIndex: index,
cityId: this.data.cityList[index].id,
districtList: [],
districtIndex: -1,
})
this.getDistrict();
},
bindPickerChangeDistrict(e) {
let index = e.detail.value;
this.setData({
districtIndex: index,
districtId: this.data.districtList[index].id,
})
this.queryShop();
},
// 这里是一个自定义方法
customMethod() {
this.triggerEvent('evtcomp', {
name: "_evt_custom"
})
},
// 隐藏蒙层
hideMask() {
this.triggerEvent('evtcomp', {
name: "_evt_hide_mask"
});
}
},
//
ready() {
this.getProvince();
}
})