-
Notifications
You must be signed in to change notification settings - Fork 1
/
vote.html
183 lines (178 loc) · 7.55 KB
/
vote.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1">
<meta name="format-detection" content="telephone=no" />
<meta name="format-detection" content="telephone=no,email=no">
<title>艾臣安全门窗年会节目投票</title>
<style>
*{margin:0; padding: 0; box-sizing: border-box;-webkit-tap-highlight-color: rgba(0, 0, 0, 0);-webkit-touch-callout: none;}
[v-cloak]{display: none !important;}
img{max-width: 100%;}
body{background:#f4cc26;color: #1b1717;font-size: 16px;line-height: 1.6; -webkit-user-select:none;}
.l-flex-h, .l-flex-hc, .l-flex-hvc, .l-flex-v, .l-flex-vc, .l-flex-vhc{display: -webkit-box;display: -ms-flexbox;display: flex; box-sizing: border-box; }
.l-flex-h, .l-flex-hc, .l-flex-hvc {-ms-flex-flow: row nowrap;flex-flow: row nowrap; }
.l-flex-v, .l-flex-vc, .l-flex-vhc { -ms-flex-flow: column nowrap;flex-flow: column nowrap; }
.l-flex-h {-webkit-box-align: strecth;-ms-flex-align: strecth;align-items: strecth; }
.l-flex-hc, .l-flex-hvc {-webkit-box-align: center;-ms-flex-align: center;align-items: center; }
.l-flex-hvc {-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center; }
.l-flex-vc, .l-flex-vhc{-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center; }
.l-flex-vhc {-webkit-box-align: center;-ms-flex-align: center;align-items: center; }
[class*='l-flex-'] > .l-rest {-webkit-box-flex: 1;-ms-flex: 1;flex: 1; }
.l-btn{ -webkit-appearance: none; border: none; background-color: rgba(255, 136, 6, 0.8); color: #fff; border-radius: 3px; box-shadow: 0px 2px 0px rgb(193, 104, 8), 0px 2px 4px rgba(0,0,0,.7); font-size: 14px; width: 70px; text-align: center; padding: 5px 0;}
.l-btn:active{outline: 0;}
.l-btn:active{background-color: rgb(226, 121, 6);box-shadow: 0px 2px 0px rgb(193, 104, 8), 0px 1px 3px rgba(0,0,0,.7);}
button.l-btn[disabled]{box-shadow: 0px 3px 0px rgb(181, 181, 180), 0px 3px 3px rgba(181, 181, 181, 0.9); top: 1px; background-color: #dedede; color: #929292; text-shadow: 1px 1px #fff; }
.l-btn.l-active{background-color: rgb(226, 121, 6) !important; color: #fff !important; box-shadow: none !important; text-shadow: none !important; }
.l-vote-list{margin:20px;}
.l-vote-list li{margin:20px 0;}
.l-vote-list li .l-rest{font-weight: 500;}
.l-result-tip{position: fixed;top:0;left: 0;bottom: 0;right: 0; background-color: rgba(0,0,0, 0.8);padding: 0 20px;}
.l-result-tip p{color: #fff;font-size: 28px;}
</style>
<script type="text/javascript" src="./js/vue.min.js"></script>
</head>
<body>
<div id="app" class="l-app">
<img src="images/img-01.jpg" alt="">
<p style="padding: 0 55px; margin-top: -40px;">点击“投票”按钮,给你喜欢的节目投上宝贵的一票,每人只能投三票。</p>
<!-- 投票列表 -->
<ul class="l-vote-list">
<li class="l-flex-hc" v-for="item in showList" >
<span v-text="$index+1+'、'"></span>
<div class="l-rest">
<span v-text="item.name+'- '+item.dept"></span>
</div>
<button class="l-btn" :disabled="voteNum >= 3 || item.state > 0" :class="{'l-active': item.state === 2}" @click="vote(item)" v-text="stateStr[item.state]">投票</button>
</li>
</ul>
<br>
</div>
<div v-cloak class="l-result-tip l-flex-vhc" v-if="voteNum >= 3">
<img src="images/img-02.png" alt="">
<br>
<p>投票结果请看大屏幕</p>
</div>
<script type="text/javascript">
var isWechat = /micromessenger/i.test(navigator.userAgent);
var getArgs = function(url) {
if(typeof url !== 'string') url = window.location.href
url = decodeURIComponent(url)
var pos = url.indexOf('?'),
pos2 = url.lastIndexOf('#'),
qs = pos > -1 ? url.substring(pos+1, pos2 <= pos ? url.length : pos2) : '',
items = qs.split('&')
var args = {},
arg = null,
name = null,
value = null
for(var i=0, splitPos = 0, item=null; i<items.length; i++){
item = items[i]
splitPos = item.indexOf('=')
name = item.substring(0, splitPos)
value = item.substring(splitPos+1)
args[name] = value
}
return args
};
</script>
<script>
document.body.addEventListener('touchstart', function () {});
var url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc8123454324da8b0&redirect_uri='+window.location.href+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
var code = getArgs().code || '';
if(!code && isWechat){
window.location.replace(url);
}
</script>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script>
// var wxOpenId = Math.random().toString('16');
var wxOpenId = '';
var voteIds = window.localStorage.getItem('_vote_ids');
// 微信授权
if(code && isWechat){
$.getJSON('http://test.aylsonclub.com/ym/wx/frame/getByCode', {
code: code
}, function (response) {
if(response.success && response.data){
wxOpenId = response.data.openid + '|' + response.data.nickname;
}else{
// alert(response.message);
}
});
}
var vm = new Vue({
el: document.body,
data: function(){
return {
stateStr: ['投票', '投票中', '已投票'],
voteIds: voteIds ? voteIds.split(',') : [],
voteNum: Number(window.localStorage.getItem('_vote_num')) || 0,
showList: []
}
},
ready: function(){
this.getVote();
},
methods: {
// 节目列表
getVote: function(){
var self = this;
$.getJSON('http://test.aylsonclub.com/ym/ym/getProgramList', function(response){
if(response.success){
if(!response.data[0].startVoteTime){
window.localStorage.setItem('_vote_num', '');
window.localStorage.setItem('_vote_ids', '');
self.voteNum = 0;
self.voteIds = [];
}
var tempList= [];
for (var i = 0; i < response.data.length; i++) {
var item = response.data[i];
item.state = 0;
if (self.voteIds.indexOf(item.id+'') !== -1) {
item.state = 2;
}
tempList.push(item);
}
self.showList = tempList;
}
});
},
// 开始投票
vote: function(program){
var self = this;
if(self.voteNum >= 3 || program.state > 0) return;
if(!wxOpenId){
alert('获取不到微信信息,请重新进入页面授权');
return;
}
var promise = new Promise(function(resolve){
program.state = 1;
$.post('http://test.aylsonclub.com/ym/ym/vote', {
programId: program.id,
voterId: wxOpenId
}, function(response){
resolve();
window.localStorage.setItem('_vote_num', ++self.voteNum);
if(!response.success){
program.state = 0;
window.localStorage.setItem('_vote_num', --self.voteNum < 0 ? 0 : self.voteNum);
alert(response.message);
}else{
program.state = 2;
self.voteIds.push(program.id);
window.localStorage.setItem('_vote_ids', self.voteIds.join());
}
}, 'json');
});
return promise;
}
}
})
</script>
</body>
</html>