examineCertificate.js
7.64 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
// pack-activity/pack/examineCertificate.js
import App from '../../utils/api'
Page({
/**
* 页面的初始数据
*/
data: {
id: '',
detail: {
qrcode: null,
},
sellerObj: {
sellername: '',
seller_image: '',
real_address: '',
cateStr: '',
},
certificateDetail: {},
exp_date: {},
is_time: false, //是否继续执行
timeList: [], //定时器列表
timers: null,
distance:'',
},
stopWaiting() {
for (var i = 0; i < this.data.timeList.length; i++) {
clearTimeout(this.data.timeList[i]); //清除了所有定时器
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
id: options.id
})
console.log('options',{...options});
this.getDetail('1')
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
getDetail(num) {
App.Activity.GetOrderRechargeByid({
id: this.data.id
}).then(res => {
let detail = res.data;
let exp_date = detail.exp_date ? JSON.parse(detail.exp_date) : '';
let use = detail.activity.use ? JSON.parse(detail.activity.use) : {};
use.images = use && use.images ? JSON.parse(use.images) : '';
let date = Date.now() * 1;
if (date > detail.etime) {
detail.is_expire = '0';
} else {
detail.is_expire = '1';
}
detail.use = use;
this.setData({
detail,
exp_date
})
console.log('detail', {...detail});
console.log('exp_date', {...exp_date});
if (detail.is_examine == '0') {
this.setData({
is_time: true,
detail,
exp_date
})
this.myUpdate()
} else {
this.setData({
is_time: false,
detail,
exp_date
})
wx.showModal({
title: '已核销',
cancelText: '取消',
confirmText: '朕知道了',
content: '核销成功!',
success: function (res) {
if (res.confirm) { //这里是点击了确定以后
wx.reLaunch({
url: '/pages/me/coupon_news'
})
}
}
})
}
if (num == '1') {
this.getSeller(res.data.sellerid)
}
})
},
// 关注公众号
wananchi() {
wx.navigateTo({
url: '/pages/me/wananchi'
})
},
// 轮询查询是否核销
myUpdate() {
var is_time = this.data.is_time //是否继续执行
console.log('is_time', is_time)
if (!is_time) {
console.log('已核销!轮询停止')
clearTimeout(this.timers)
} else {
console.log("继续轮询");
this.timers = setTimeout(() => {
this.getDetail()
}, 5000);
}
},
// 获取商家信息
getSeller(sid) {
let that = this;
App.Customer.GetSellerDetail({
sid,
}).then(res => {
let data = res.data;
let cate = data.cate;
let cateStr;
if (cate && cate.length > 0) {
cateStr = [];
cate.some(cate => {
cateStr.push(cate);
if (cateStr.length > 2) {
return true
}
})
cateStr = cateStr.join('/')
}
let distance = '';
let latitude = '';
let longitude = '';
let sellerObj = {
sellername: data.sellername,
sid: data.id,
seller_image: data.seller_image,
real_address: data.real_address,
is_parking: data.is_parking,
average: data.average,
is_online_reserve: data.is_online_reserve,
phone: data.phone,
cateStr,
}
wx.getLocation({
type: 'wgs84', // 返回可以用于 wx.openLocation 的经纬度
success: function (res) {
latitude = res.latitude; // 纬度
longitude = res.longitude; // 经度
console.log(`当前的纬度: ${latitude}, 当前的经度: ${longitude}`);
if (latitude && longitude) {
console.log('dddddd',latitude, longitude, data.lat, data.long);
distance = that.getDistance(latitude, longitude, data.lat, data.long);
console.log('distancedistancedistance');
distance = parseInt(distance)
if (distance > 1000) {
distance = (distance / 1000).toFixed(2) + 'km'
} else {
distance += 'm';
}
that.setData({
distance
})
}
},
fail: function (err) {
console.error('获取位置失败:', err);
}
});
this.setData({
sellerObj
})
console.log('sellerObj', {
...sellerObj
});
})
},
// 拨打电话
callPhone() {
wx.makePhoneCall({
phoneNumber: this.data.sellerObj.phone
})
},
// 申请退款
subscribeDrawback() {
clearTimeout(this.timers)
wx.navigateTo({
url: '/pack-activity/pack/subscribeDrawback?detail=' + JSON.stringify(this.data.detail),
})
},
// 跳转到商家详情
getReserve() {
clearTimeout(this.timers)
wx.reLaunch({
url: '/pages/reserve/shopHome?id=' + this.data.detail.sellerid
})
},
// 计算2点之间的距离
getDistance(lat1, lon1, lat2, lon2) {
const R = 6371e3; // 地球半径(米)
// 将经纬度转换为弧度
const φ1 = lat1 * Math.PI / 180; // 纬度1
const φ2 = lat2 * Math.PI / 180; // 纬度2
const Δφ = (lat2 - lat1) * Math.PI / 180; // 纬度差
const Δλ = (lon2 - lon1) * Math.PI / 180; // 经度差
// Haversine 公式
const a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const distance = R * c; // 计算距离(米)
return distance; // 返回距离
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
clearTimeout(this.timers)
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
clearTimeout(this.timers)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})