index.js
9.7 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
//index.js
//获取应用实例
const app = getApp();
// 引入SDK核心类
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
Page({
data: {
is_bingding: false,
imgUrls: [],
cur: 0,
currentSwiper: 0,
autoplay: true, //是否自动轮播
interval: 2000, //间隔时间
duration: 3000, //滑动时间
this_week_test_info: {},
past_test_info: [],
is_buy: false,
student_id: '',
page_number:1,
has_more:true,
},
//获取购买背景图
getBuyCard() {
let url = '/portal/Index/buy';
let header = {
"XX-token": wx.getStorageSync('token')
};
app.post(url, {}, {}).then((res) => {
// console.log('获取购买背景图',res);
this.setData({buy_card: res.info})
})
},
//判断手机号是否绑定
checkMobile() {
let url = '/portal/Index/check_mobile';
let header = {
"XX-token": wx.getStorageSync('token')
};
app.post(url, {},header).then((res) => {
// console.log(res);
if(res.is_binding) {
this.setData({is_bingding: true})
}else {
this.setData({is_bingding: false})
}
})
},
swiperChange: function (e) { //切换轮播图
// console.log(e, e.detail.current, this.data.currentSwiper, this.data.cur)
this.setData({
currentSwiper: e.detail.current,
})
},
//首次登录小程序,跳转到认证手机页面
goPhoneCode() {
wx.navigateTo({url: '/pages/index/phone-code/phone-code?from_index=' + true})
},
//点击购买畅玩卡
goBuyCard() {
wx.navigateTo({url: '/pages/my/buyCard/buyCard?from_index=' + true})
},
//点击进入活动详情
goTestDetail(e) {
// console.log(e);
const is_the_week = e.currentTarget.dataset.is_the_week;
const id = e.currentTarget.dataset.id;
wx.navigateTo({
url: './activity-detail/activity-detail?is_the_week=' + is_the_week +
'&id=' + id
})
},
//前往预约
goAppointment(e) {
const id = e.currentTarget.dataset.id;
// console.log('实验室id', id);
wx.navigateTo({url: './go-appointment/go-appointment?experiment_id=' + id})
},
//获取轮播图
getSlideImage() {
let params = {};
if(wx.getStorageSync('city') === '') {
params = {
city: '北京',
};
}else {
params = {
city: this.data.city,
};
}
let url = '/portal/Index/index';
let header = {
"XX-token": wx.getStorageSync('token')
};
app.post(url, params, header).then((res) => {
// console.log('轮播图',res);
this.setData({imgUrls: res.list})
})
},
//获取本周实验
getTheWeekTest() {
let url = '/portal/Index/now';
app.post(url, {},{}).then((res) => {
// console.log(res);
this.setData({this_week_test_info: res})
// console.log(this.data.this_week_test_info);
})
},
//查看本周实验详情
goDetail() {
wx.navigateTo({url: '/pages/index/activity-detail/activity-detail?test_id=' + this.data.this_week_test_info.id})
},
//获取往期实验
getPastWeekTest() {
if(!this.data.has_more) return;
this.setData({has_more: false});
let url = '/portal/Index/history';
let params = {
page: this.data.page_number,
}
app.post(url, params,{}).then((res) => {
// console.log('获取往期实验',res);
if(res.this_page < res.total_page) {
this.setData({has_more: true});
}
// console.log('list', list);
this.setData({past_test_info: this.data.past_test_info.concat(res.list)});
// console.log(this.data.this_week_test_info);
})
},
//查看往期实验详情
goPastDetail(e) {
const id = e.currentTarget.dataset.id;
wx.navigateTo({url: '/pages/index/activity-detail/activity-detail?test_id=' + id})
},
//打卡页面获取位置授权
getExperiment() {
const self = this;
if (wx.getStorageSync('city')) {//如果第一次授权过
wx.getLocation({
type: 'wgs84',
success(res) {
let params = {
city: wx.getStorageSync('city'),
lat: res.latitude,//纬度
lng: res.longitude,//经度
};
self.postPosition(params);
}
});
} else {//重新调起授权
console.log('获取当前城市');
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {//非初始化进入该页面,且未授权
wx.showModal({
title: '是否授权当前位置',
content: '需要获取您的地理位置,请确认授权,否则无法完成打卡',
success: function (res) {
if (res.cancel) {
self.setData({
isshowCIty: false
})
wx.showToast({
title: '授权失败',
icon: 'none',
duration: 1000
})
} else if (res.confirm) {
wx.openSetting({
success: function (dataAu) {
if (dataAu.authSetting["scope.userLocation"] == true) {
wx.showToast({
title: '授权成功',
icon: 'success',
duration: 1000
})
//再次授权,调用getLocationt的API
getLocation(self);
} else {
wx.showToast({
title: '授权失败',
icon: 'none',
duration: 1000
})
}
}
})
}
}
})
} else if (res.authSetting['scope.userLocation'] == undefined) {//初始化进入
getLocation(self);
} else { //授权后默认加载
// getLocation(self);
}
}
})
}
},
onLoad: function (options) {
const self = this;
// self.setData({is_bingding: +options.is_bingding?+options.is_bingding:''});
wx.showLoading({title:'加载中',mask:true});
self.setData({is_bingding: app.globalData.is_bingding});
setTimeout(function () {
wx.hideLoading()
}, 1000);
console.log('is_bingding', self.data.is_bingding);
// console.log('options',options);
// self.checkMobile();
self.getTheWeekTest();
self.getPastWeekTest();
self.getBuyCard();
//获取当前城市
wx.getLocation({
type: 'wgs84',
success: function(res) {
// console.log(res);
// 实例化API核心类
var demo = new QQMapWX({
key: 'CLVBZ-KHZKP-KWLDW-VDJTA-QVUST-XOBVO' // 必填
});
// 调用接口
demo.reverseGeocoder({
location: {
latitude: res.latitude,//纬度
longitude: res.longitude//经度
},
success: function (res) {
// console.log('获取城市',res.result.address_component.city);
self.setData({city: res.result.address_component.city});
wx.setStorageSync('city', res.result.address_component.city);
self.getSlideImage();
},
fail: function (res) {
console.log(res);
},
complete: function (res) {
// console.log(res);
}
});
}
});
},
onShow() {
// console.log('show-globalData',app.globalData.is_bingding,typeof(app.globalData.is_bingding));
this.checkMobile();
},
onReachBottom: function () {
const self = this;
if(self.data.has_more) {
self.data.page_number ++;
self.getPastWeekTest();
}else {
wx.showToast({
title: '没有更多数据了~',
icon: 'none'
});
}
// console.log('上拉加载');
},
});