details.js
14.5 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
import {
request
} from "../../request/index.js";
const a = getApp()
var WxParse = require('../../wxParse/wxParse.js');
var QQMapWX = require('../../qqmap/qqmap-wx-jssdk.min.js');
var qqmapsdk;
var timerPageA; // 计时器
var intPageATime = 0
Page({
data: {
imagesUrl: a.globalData.baseUrl,
time: 30 * 60 * 60 * 1000,
timeData: {},
four: 10,
content: '',
showDialog: false,
messageAlert: '',
names: '',
phone: '',
msg: '',
klist: [],
id: '',
type: '',
inviter_id: '',
time_data: '',
obj: '',
texts: 0,
code: '',
avatar_arr: [], // 头像数组
can_num: 0, // 参加人数
countDownNum: 5,
setTimeouttimer: false,
is_start: false,
timer: null,
personsun: 100,
timename: '',
// 保存的绑定4s店面数据存储
s4_id: '',
s4_name: '',
statusTop: a.globalData.statusHeight,
menuTop:'',//导航初始距离顶部
menuFixed:'',
video: '',
indicatorDots: true,
vertical: false,
autoplay: false,
interval: 2000,
duration: 500,
testlist: [],
numberpeople:0,
latitude: null,//纬度
longitude: null,//经度
is_exist: null,//是否有红包
},
onShow: function () {
console.log('页面再展示')
let that = this
var num = '';
for (var i = 0; i < 3; i++) {
num += Math.floor(Math.random() * 10);
}
that.setData({
personsun: num
})
that.countTime()
that.getCitied()//获取位置
},
onLoad: function (options) {
let that = this
let token = wx.getStorageSync('token')
console.log(options,wx.getStorageSync('user_id'))
if (options.scene) {
that.setData({
id: options.scene,
type: 2,
inviter_id: options.inviter_id
})
// wx.setStorageSync('s4_id', options.s4_id)
// wx.setStorageSync('s4_name', options.s4_name)
} else {
that.setData({
id: options.id,
type: options.type,
inviter_id: options.inviter_id
})
if (options.s4_id) {
wx.setStorageSync('s4_id', options.s4_id)
}
if (options.s4_name) {
wx.setStorageSync('s4_name', options.s4_name)
}
if (options.is_share) {
wx.setStorageSync('is_share', options.is_share)
}
// 改
// if (options.is_share == 1) {
// that.setData({
// is_share: options.is_share,
// id: options.id,
// type: options.type,
// })
// wx.setStorageSync('is_share', options.is_share)
// wx.setStorageSync('s4_id', options.s4_id)
// wx.setStorageSync('s4_name', options.s4_name)
// } else {
// that.setData({
// id: options.id,
// })
// }
}
if (!token) {
wx.showModal({
title: '提示',
content: '您尚未登录,请登录后操作',
success: function (res) {
if (res.confirm) {
// that.showModal()
// that.selectComponent('#lfyLogin').getLogin('hh')
wx.navigateTo({
url: '/pages/authorization/authorization?num=' + 1
})
that.gethuodong()
} else {
wx.switchTab({
url: '/pages/home/home'
})
}
}
})
} else {
that.gethuodong()
}
// 吸顶
var query = wx.createSelectorQuery()
query.select('#affix').boundingClientRect();
query.selectViewport().scrollOffset();
query.exec(function (res) {
that.setData({
menuTop: res[0].top
})
})
that.zhanshilist()
},
onPageScroll: function(e) {
if (this.data.menuFixed === (e.scrollTop > this.data.menuTop)) return;
// 当页面滚动距离scrollTop > menuTop菜单栏距离顶部的距离时,菜单栏固定定位
this.setData({
menuFixed: (e.scrollTop > this.data.menuTop)
})
},
goback() {
// if (wx.getStorageSync('is_share') == 1) {
// wx.reLaunch({
// url: '/pages/home/home'
// })
// } else {
// wx.navigateBack()
// }
wx.reLaunch({
url: '/pages/home/home'
})
},
// 分享朋友圈
onShareAppMessage: function (res) {
let that = this
let inviter_id = wx.getStorageSync('user_id')
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline'],
})
return {
title: '汽车互联网4S店全面的汽车电商服务体验,邀您一起参与',
path: '/pages/details/details?id=' + that.data.id + '&type=' + that.data.type + '&inviter_id=' + inviter_id
}
},
//分享好友
onShareTimeline() {
let that = this
let inviter_id = wx.getStorageSync('user_id')
return {
title: '汽车互联网4S店全面的汽车电商服务体验,邀您一起参与',
path: '/pages/details/details?id=' + that.data.id + '&type=' + that.data.type + '&inviter_id='+ inviter_id
}
},
async clickAttentn(s4_id) { // 点击关注
let that = this
try {
const {
data
} = await request({
url: 'api/index2/guan',
data: {
id: s4_id
}
})
if (data.code == 1) {
// a.popSuccessTest(data.msg)
} else {
a.popTest(data.msg)
}
} catch (err) {
// console.log(err);
that.setData({
msg: err.msg
})
that.popTest()
}
},
async zhanshilist() { // 展示列表
let that = this
try {
const {
data
} = await request({
url: 'api/active/applyActiveUserList',
data: {
id: that.data.id
}
})
if (data.code == 1) {
console.log(data)
that.setData({
testlist: data.data.data,
numberpeople: data.data.count
})
} else {
}
} catch (err) {
// console.log(err);
that.setData({
msg: err.msg
})
}
},
async gethuodong() {
let that = this
try {
const {
data: {
data
}
} = await request({
url: 'api/active/detail4s',
data: {
id: that.data.id,
type: that.data.type,
inviter_id: that.data.inviter_id
},
})
// console.log(data, "活动兴趣");
if (Number(data.start_time_num) > 0) { // 活动没开始
that.setData({
is_start: true,
time: data.start_time_num,
timename: '距开始还有',
is_exist: data.is_exist
})
} else if (Number(data.time_num) >= 0) {
that.countown()
that.setData({
is_start: false,
time: data.time_num,
timename: '距结束还有',
is_exist: data.is_exist
})
} else {
that.setData({
time: 0,
setTimeouttimer: true,
is_start: false,
})
}
// console.log(that.data.time);
that.setData({
klist: data,
time_data: data.time_num,
content: data.content,
content2: that.text(data.say),
avatar_arr: data.avatar_arr,
can_num: data.can_num,
video: data.video
})
if (data.is_guan_s4 == 0) {
that.clickAttentn(data.s4_id)
}
WxParse.wxParse('content', 'html', that.data.content, that, 5);
} catch (err) {
// console.log(err);
a.popTest(err.msg)
}
},
onChange(e) {
this.setData({
timeData: e.detail,
});
},
finish() {
this.setData({
time: 0,
is_start: false,
setTimeouttimer: true
})
},
toggleDialog(e) {
let id = this.data.id
let inviter_id = this.data.inviter_id
wx.navigateTo({
url: '/pages/distributionChanged/distributionChanged?id=' + id + '&inviter_id='+ inviter_id
})
},
GOcanvas() {
let id = this.data.id
let token = wx.getStorageSync("token")
if (token) {
wx.navigateTo({
url: '/pages/canvasA/canvasA?id=' + id + '&type=7'
})
} else {
this.getToken()
}
},
formSubmit(e) {
let phone = e.detail.value.phone
let that = this
if (!(/^1[3456789]\d{9}$/.test(phone))) {
if (phone.length >= 11) {
wx.showToast({
title: '手机号有误',
icon: 'none',
duration: 1300
})
}
} else {
that.setData({
obj: e.detail.value
})
// // console.log(that.data.obj);
that.getsubmit()
}
},
async getsubmit() {
let that = this
let obj = that.data.obj
try {
const {
data
} = await request({
url: 'api/active/baoMing',
data: {
name: obj.names,
phone: obj.phone,
id: that.data.id
}
})
that.setData({
msg: data.msg,
texts: 1
})
that.popSuccessTest()
// console.log(data);
setTimeout(() => {
that.toggleDialog()
}, 1000);
} catch (err) {
// console.log(err);
that.setData({
msg: err.msg
})
that.popMaskTest()
}
},
// 正则验证图标图片
text(details) {
var texts = ''; //待拼接的内容
while (details.indexOf('<img') != -1) { //寻找img 循环
texts += details.substring('0', details.indexOf('<img') + 4); //截取到<img前面的内容
details = details.substring(details.indexOf('<img') + 4); //<img 后面的内容
if (details.indexOf('style=') != -1 && details.indexOf('style=') < details.indexOf('>')) {
texts += details.substring(0, details.indexOf('style="') + 7) + "max-width:100%;height:auto;margin:0 auto;"; //从 <img 后面的内容 截取到style= 加上自己要加的内容
details = details.substring(details.indexOf('style="') + 7); //style后面的内容拼接
} else {
texts += ' style="max-width:100%;height:auto;margin:0 auto;" ';
}
}
while (details.indexOf('<td') != -1) { //寻找img 循环
texts += details.substring('0', details.indexOf('<td') + 4); //截取到<img前面的内容
details = details.substring(details.indexOf('<td') + 4); //<img 后面的内容
if (details.indexOf('style=') != -1 && details.indexOf('style=') < details.indexOf('>')) {
texts += details.substring(0, details.indexOf('style="') + 7) + "max-width:74!important;height:auto;margin:0 auto;"; //从 <img 后面的内容 截取到style= 加上自己要加的内容
details = details.substring(details.indexOf('style="') + 7); //style后面的内容拼接
} else {
texts += ' style="max-width:100%;height:auto;margin:0 auto;" ';
}
}
texts += details; //最后拼接的内容
return texts
},
onShareAppMessage: function (options) {
var that = this
let s4_id = wx.getStorageSync('s4_id')
let s4_name = wx.getStorageSync('s4_name')
let inviter_id = wx.getStorageSync('user_id')
console.log(s4_id, s4_name, '本地存储数据')
// 设置菜单中的转发按钮触发转发事件时的转发内容
var shareObj = {
title: "分享", // 默认是小程序的名称(可以写slogan等)
path: '/pages/details/details?id=' + that.data.id + '&type=' + that.data.type + '&s4_id=' + s4_id + '&s4_name=' + s4_name + '&is_share=1' + '&inviter_id='+ inviter_id , // 默认是当前页面,必须是以‘/’开头的完整路径
imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
success: function (res) {
console.log(res, '转发成功')
if (res.errMsg == 'shareAppMessage:ok') {
}
},
fail: function () {
// 转发失败之后的回调
if (res.errMsg == 'shareAppMessage:fail cancel') {
// 用户取消转发
} else if (res.errMsg == 'shareAppMessage:fail') {
// 转发失败,其中 detail message 为详细失败信息
}
},
};
return shareObj;
},
// 记录分享信息
record() {
console.log('123')
request({
url: '/api/new2/userOperateShare',
data: {
type: 2,
active_id: this.data.id
}
})
},
// 记录用户浏览时间
countTime() {
let that = this
// 计时过程
timerPageA = setTimeout(function () {
intPageATime = intPageATime + 1
wx.setStorage({
key: "timerPageA",
data: intPageATime
})
that.countTime();
}, 1000);
},
// 发送浏览时间
sendCountTime() {
let that = this
console.log(this.data.id,intPageATime)
request({
url: '/api/new2/userOperateTime',
data: {
type: 2,
active_id: this.data.id,
time: intPageATime,
lat: this.data.latitude,
lng: this.data.longitude,
}
})
},
popMaskTest() {
wx.showToast({
title: this.data.msg,
icon: 'none',
duration: 1300,
mask: true //是否有透明蒙层,默认为false
//如果有透明蒙层,弹窗的期间不能点击文档内容
})
},
popSuccessTest() {
wx.showToast({
title: this.data.msg,
icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
duration: 1300, //停留时间
})
},
bindistoken() {
this.gethuodong()
// console.log('我回来了');
},
countown() {
let that = this;
let countDownNum = that.data.countDownNum; //获取倒计时初始值
that.setData({
timer: setInterval(function () {
countDownNum--;
that.setData({
countDownNum: countDownNum
})
if (countDownNum == 0) {
clearInterval(that.data.timer);
that.setData({
countDownNum: 5,
setTimeouttimer: true
})
}
}, 1000)
})
},
//获取位置信息
getCitied() { // 获取城市信息
let that = this
wx.getLocation({
type: 'wgs84', //默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: function (res) {
console.log(res.latitude,res.longitude)
that.setData({
latitude: res.latitude,
longitude: res.longitude
})
}
})
return
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
clearTimeout(timerPageA);
console.log(intPageATime)
this.sendCountTime()
intPageATime = 0
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
clearTimeout(timerPageA);
this.sendCountTime()
console.log(intPageATime)
intPageATime = 0
},
})