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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>宝贝,因“喂”爱你</title>
<link rel="stylesheet" href="css/activity.css">
<link rel="stylesheet" href="css/toast.css">
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="js/toast.js"></script>
<script type="text/javascript" src="js/html2Json.js"></script>
<script type="text/javascript" src="js/pageJson.js"></script>
<script type="text/javascript" src="js/modalJson/shareModal.js"></script>
<script type="text/javascript" src="js/modalJson/voteModal.js"></script>
<script type="text/javascript" src="js/removeAttr.js"></script>
<script type="text/javascript" src="js/autoFontsize.min.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script type="text/javascript" th:inline="javascript">
// var data = [[${test}]];
</script>
<script type="text/javascript">
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '${appId!}', // 必填,公众号的唯一标识
timestamp:'${timestamp!}', // 必填,生成签名的时间戳
nonceStr: '${noncestr!}', // 必填,生成签名的随机串
signature: '${signature!}',// 必填,签名,见附录1
jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','startRecord','stopRecord','onVoiceRecordEnd','playVoice','pauseVoice','stopVoice','onVoicePlayEnd'
,'uploadVoice','downloadVoice','chooseImage','previewImage','uploadImage','downloadImage','translateVoice','openLocation'
,'getLocation','hideOptionMenu','showOptionMenu','hideMenuItems','showMenuItems','scanQRCode','chooseWXPay','addCard','chooseCard','openCard'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
</script>
</head>
<!-- th:text="${page}" -->
<body>
</body>
</html>
<script type="text/javascript">
// 公共变量
var xtoken = "123123";
var activityCode = "hdtbsztest1";
var pageNumber = "1";
var baseUrl = "http://space-api.check.icaremgt.com";
// 微信鉴权
$('body').prepend(json2html(indexObj));
$('body').prepend(json2html(shareModal));
$('body').prepend(json2html(voteModal));
$('body').prepend(json2html(voteEmptyModal));
$('#html-template-4').addClass('global-none')
$('#html-template-5').addClass('global-none')
$('#html-template-8').addClass('global-none')
var gb_player_loaded = false
var gb_rank_loaded = false
var gb_token = 'admin.725.fbbd4294a56047e7926b7ebab088ade4'
$(function(){
btnBindClick();// 绑定点击事件
getQueryString('');// 根据query参数控制排行榜显示
removeAttr();
getAjaxListSearch('player',1,function(playerListData){
getPlayerList(playerListData)
}) // 参赛选手列表
getAjaxListSearch('rank',1,function(rankListData){
getRangeList(rankListData)
}) // 排行榜列表
});
// 微信鉴权
function wxpermission() {
wx.ready(function(){
var shareData = {
title: "",
imgUrl: "",
desc: "",
link: ""
}
/**
*分享给朋友
*/
wx.onMenuShareAppMessage({
title: shareData.title, // 分享标题
desc: shareData.desc, // 分享描述
link: shareData.link, // 分享链接
imgUrl: shareData.imgUrl, // 分享图标
type: 'link', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
/**
*分享到朋友圈
*/
wx.onMenuShareTimeline({
title: shareData.title, // 分享标题
desc: shareData.desc, // 分享描述
link: shareData.link, // 分享链接
imgUrl: shareData.imgUrl, // 分享图标
success: function () {
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
});
}
// 元素点击事件绑定
function btnBindClick() {
// 参数选手
$("#act31528123692525").off("click").on("click",tabChange);
// 排行榜
$("#act3152823482970").off("click").on("click",tabChange);
// 搜索按钮
$("#act3152814816164").off("click").on('click',function(){
getAjaxListSearch('search',1,function(playerListData){
getPlayerList(playerListData)
})
});
// 参赛选手上一页
$('#act3152978551035').off('click').on('click',function(){
var page = parseInt($('#act61214527684747 .curpage').text())
if(page > 1) {
page -= 1
getAjaxListSearch('player',page,function(playerListData){
getPlayerList(playerListData)
}) // 参赛选手列表
}
})
// 参赛选手下一页
$('#act315291899997').off('click').on('click',function(){
var page = parseInt($('#act61214527684747 .curpage').text())
var total = parseInt($('#act61214527684747 .totalpage').text())
if(page < Math.ceil(total/10)) {
page = page + 1
getAjaxListSearch('player',page,function(playerListData){
getPlayerList(playerListData)
}) // 参赛选手列表
}
})
// 排行榜上一页
$('#act514245671026').off('click').on('click',function(){
var page = parseInt($('#act111398324601 .curpage').text())
if(page > 1) {
page -= 1
getAjaxListSearch('rank',page,function(rankListData){
getRangeList(rankListData)
}) // 参赛选手列表
}
})
// 排行榜下一页
$('#act5142157597939').off('click').on('click',function(){
var page = parseInt($('#act111398324601 .curpage').text())
var total = parseInt($('#act111398324601 .totalpage').text())
if(page < Math.ceil(total/10)) {
page = page + 1
getAjaxListSearch('rank',page,function(rankListData){
getRangeList(rankListData)
}) // 参赛选手列表
}
})
// 报名按钮
$("#act31527459124456").off("click").on("click",function(){
// window.location.href = '/signup.html'
transPage(activityCode,'2',xtoken);
});
// 继续投票
$('#act21728433893489').off("click").on('click',function(){
$('#html-template-4').fadeOut()
})
$('#html-template-4 .modal-close').off("click").on('click',function(){
$('#html-template-4').fadeOut()
})
// 我要拉票
$('#act2172989331265,#act5161551593534').off('click').on('click',function(){
$('#html-template-8').fadeIn()
})
// 查看排行
$('#act5161526928645').off('click').on('click',function(){
$('#html-template-5').fadeOut()
$("#user-list").hide();
$("#range-list").show();
})
$('#html-template-5 .modal-close').off("click").on('click',function(){
$('#html-template-5').fadeOut()
})
// 关闭分享弹出框
$("#html-template-8 .modal-close").off("click").on("click", function() {
$('#html-template-8').fadeOut()
});
// 排行榜
$("#act2165045664554").off('click').on("click", function(){
window.location.href = '/index.html'
});
// 选手主页
$("#act21650126678793").off("click").on("click", function(){
window.location.href = '/user.html'
});
// 活动秘籍
$("#act21650195017743").off("click").on("click", function(){
$('#html-template-8').fadeIn();
});
}
// 检索参数选手列表
function getAjaxListSearch(type,page,callback) {
var activityCode = getQueryString('activityCode')
if(type == 'player') {
if(gb_player_loaded) {
return
}
gb_player_loaded = true
var descs = 'createTime'
var searchVal = ''
}else if(type == 'rank') {
if(gb_rank_loaded) {
return
}
gb_rank_loaded = true
var descs = 'voteNum'
var searchVal = ''
}else if(type == 'search') {
if(gb_player_loaded) {
return
}
gb_player_loaded = true
var searchVal = $('.search-input.c-read-only').val()
var descs = 'createTime'
if(searchVal == '') {
showMessage('搜索关键词不能为空',3000,true);
return false
}
}
var params = {
descs:descs, // 降序排列
curPage:page?page:1,
pageSize:10,
activityCode:activityCode, // 活动id
name: searchVal // 搜索字段
}
$.ajax({
type: 'GET',
url: baseUrl + '/ACTIVITY/sz/search',
data: params,
success: function(data) {
if(data.status == 200) {
if(type == 'player' || type == 'search') {
var playerListData = data.result
if(typeof callback == "function") {
callback(playerListData)
}
if(type == 'search') {
$("#user-list").show();
$("#range-list").hide();
}
gb_player_loaded = false
}else if(type == 'rank') {
var rankListData = data.result
if(typeof callback == "function") {
callback(rankListData)
}
gb_rank_loaded = false
}
}
}
})
}
// 获取参赛选手列表
function getPlayerList(playerListData) {
var list = $("#user-list .vote-con");
list.hide()
var i = 0
var item = $(".item",list)[0];
var tempItem = list.clone();
// 清空子元素
tempItem.empty().show();
if(playerListData.records.length) {
for(;i < playerListData.records.length; i++){
// 序号替换
$('.number-icon',item).text(i+1);
// 图片url替换
$('img',item).attr('src',playerListData.records[i].imageUrl);
// 名称替换
$('.user-name',item).text(playerListData.records[i].name);
// 机构名称替换
$('.vote-struct',item).text('贵阳市乌当区新天社区卫生服务中心测试');
// 票数替换
$('.vote-num',item).text(playerListData.records[i].voteNum+'票');
// 投票点击事件
var cloneItem = $(item).clone();
cloneItem.find('.act-btn').attr('id',playerListData.records[i].id).on('click',voteClickFn);
// 参数选手点击事件
cloneItem.find('.item-photo').attr('id',playerListData.records[i].id).on('click',playPageFn);
tempItem.append(cloneItem);
}
$("#user-list").find('.vote-con').remove().end().prepend(tempItem);
$('#user-list .list-empty').hide()
$('#act61214527684747').parent('.navigation').show();
$('#act61214527684747 .curpage').text(playerListData.current)
$('#act61214527684747 .totalpage').text(playerListData.total)
}else {
$('#user-list .list-empty').show()
$('#act61214527684747').parent('.navigation').hide();
}
}
// 获取排行榜列表
function getRangeList(rankListData){
var list = $("#range-list tbody");
list.hide()
var tr = $("tr", list)[0];
var i = 0
var tempItem = list.clone();
// 清空子元素
tempItem.empty().show();
if(rankListData.records.length) {
for(;i < rankListData.records.length; i++){
// 替换序号 badge-no1
$('.number',tr).text(i+1);
// 前三名有特殊图标
if(i < 3) {
$('.number',tr).removeClass().addClass('number ' + ('badge-no'+(i+1)));
} else {
$('.number',tr).removeClass().addClass('number');
}
// 替换名字,图片
$('.table-info img',tr).attr('src',rankListData.records[i].imageUrl);
$('.cell-info h4', tr).text(rankListData.records[i].name);
// 票数
$('.ticket-total .text-red', tr).text(rankListData.records[i].voteNum);
// 添加点击事件
var cloneItem = $(tr).clone();
tempItem.append(cloneItem);
}
$("#range-list table").find('tbody').remove().end().prepend(tempItem);
$('#act111398324601').parent('.navigation').show();
$('#act111398324601 .curpage').text(rankListData.current)
$('#act111398324601 .totalpage').text(rankListData.total)
}else {
$('#act111398324601').parent('.navigation').hide();
}
}
// tab切换
function tabChange(){
var c_typename = $(this).attr("c_typename");
// 排行榜
if(c_typename === 'rangerListBtn') {
$("#user-list").hide();
$("#range-list").show();
} else {
$("#user-list").show();
$("#range-list").hide();
}
}
// 投票按钮
function voteClickFn(){
var id = $(this).attr('id');
var _this = $(this)
var params = {
userId: id
}
$.ajax({
type: 'PUT',
url: baseUrl + '/ACTIVITY/sz/vote',
data: params,
success: function(data) {
if(data.status == 200) {
$('#act1185354268270 span').text(data.result.voteNumDay)
$('#html-template-4').fadeIn()
_this.parent('.item-title').prev().find('.vote-num').text(data.result.voteNum + '票')
}else if(data.status == 201) {
$('#act51626389412499 span').text(5)
$('#html-template-5').fadeIn()
}
}
})
}
// 选手主页
function playPageFn() {
var id = $(this).attr('id');
var urlParam = '?id='+id;
transPage('3',activityCode,xtoken,urlParam);
}
// 获取URL中指定参数
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
// 页面跳转
function transPage(_pageNumber,_activityCode, _token, _urlParam){
var url = ''
if(typeof _urlParam !=='undefined' && _urlParam !== ''){
url = baseUrl + "/ACTIVITY/view/"+ _activityCode +"/" + _pageNumber + '?' + _urlParam;
}else {
url = baseUrl + "/ACTIVITY/view/"+ _activityCode +"/" + _pageNumber;
}
var _form = document.createElement('form');
_form.action = url;
_form.method = "post";
_form.style.display = "none";
var inputToken = document.createElement('input');
inputToken.value = _token;
inputToken.name = 'x-token';
_form.appendChild(inputToken);
document.body.appendChild(_form);
_form.submit();
}
</script>