-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting.html
361 lines (361 loc) · 10.5 KB
/
setting.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>奖项设置</title>
<link rel="stylesheet" href="css/reset.css" />
<link
rel="stylesheet"
href="js/[email protected]/lib/theme-chalk/index.css"
/>
<script src="js/polyfill.min.js"></script>
<script src="js/vue.min.js"></script>
<script src="js/[email protected]/lib/index.js"></script>
<script src="js/member.js"></script>
<style>
.el-input {
width: 120px;
}
.el-table {
margin-bottom: 10px;
}
* {
cursor: initial;
}
.awards,
.members {
width: 80%;
margin: auto;
margin-top: 50px;
}
h1 {
font-size: 30px;
text-align: center;
line-height: 1.5;
margin-bottom: 20px;
}
h1 span {
font-size: 16px;
}
a {
text-decoration: underline;
cursor: pointer;
}
</style>
</head>
<body>
<div id="app">
<div class="awards">
<h1>奖项设置 <span>(请按抽奖顺序添加)</span></h1>
<el-table :data="tableData" style="width: 100%">
<el-table-column
:prop="item.prop"
:label="item.label"
width="180"
v-for="(item, index) in columns"
:key="index"
>
<template slot-scope="scope">
<div>
<div v-if="scope.row.editing[item.prop]">
<el-input
size="mini"
v-model="scope.row[item.prop]"
@blur="onSaveCell(scope.row, item.prop)"
></el-input>
</div>
<div
v-else
@dblclick="onEditCell(scope.row, item.prop, $event)"
>
{{ scope.row[item.prop] || '(请填写)' }}
</div>
</div>
</template>
</el-table-column>
<el-table-column prop="address" label="操作">
<template slot-scope="scope">
<el-button
size="small"
@click="onAdd(scope.row, scope.$index)"
type="primary"
>增加</el-button
>
<el-button
size="small"
@click="onRemove(scope.row, scope.$index)"
type="danger"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<el-button
size="small"
type="primary"
@click="onAdd(null, -1)"
v-show="tableData.length===0"
>增加</el-button
>
<span>每个奖项每次抽取人数:</span>
<el-select size="small" v-model="batchNumber" @change="onChange">
<el-option
v-for="index in 20"
:key="index"
:label="index"
:value="index"
></el-option>
</el-select>
<el-button size="small" type="danger" @click="onReset"
>重置中奖结果</el-button
>
<a href="./index.html">去抽奖</a>
</div>
<div class="members">
<h1>参与人员列表(共{{memberSource.length}}人)</h1>
<el-table :data="memberSource" style="width: 100%" stripe>
<el-table-column
:prop="item.prop"
:label="item.label"
width="180"
v-for="(item, index) in memberColumns"
:key="index"
>
<template slot-scope="scope">
<div>
<div v-if="scope.row.editing[item.prop]">
<el-input
size="mini"
v-model="scope.row[item.prop]"
@blur="onSaveCell(scope.row, item.prop)"
></el-input>
</div>
<div
v-else
@dblclick="onEditCell(scope.row, item.prop, $event)"
>
{{ scope.row[item.prop] || '(请填写)' }}
</div>
</div>
</template>
</el-table-column>
<el-table-column prop="address" label="操作">
<template slot-scope="scope">
<el-button
size="small"
@click="onRemoveMember(scope.row, scope.$index)"
type="danger"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<el-button size="small" @click="onAddMember" type="primary"
>增加</el-button
>
<el-button size="small" type="warning" @click="onImport">重置</el-button>
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
dialogVisible: false,
batchNumber: 20,
columns: [
{
prop: 'name',
label: '名称',
},
{
prop: 'count',
label: '数量',
},
{
prop: 'award',
label: '奖品',
},
],
memberColumns: [
{
prop: 'name',
label: '姓名',
},
{
prop: 'id',
label: '工号',
},
],
tableData: [
{
name: '特等奖',
count: 1,
editing: {},
},
{
name: '一等奖',
count: 1,
editing: {},
},
],
memberSource: [],
},
computed: {
awards: function() {
return this.tableData
.filter(function(item) {
return item.name && item.count;
})
.map(function(item) {
return {
name: item.name,
count: item.count,
award: item.award,
};
});
},
members: function() {
return this.memberSource
.filter(function(item) {
return item.name && item.id;
})
.map(function(item) {
return {
name: item.name,
id: item.id,
};
});
},
},
methods: {
onReset: function() {
var vm = this;
this.$confirm(
'重置会清空所有抽奖结果,无法撤销!',
'确定要重置吗?',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
).then(function() {
localStorage.removeItem('players');
localStorage.removeItem('result');
});
},
onChange: function(value) {
console.log(value);
localStorage.setItem('batchNumber', value);
},
onSaveCell: function(row, key) {
this.$set(row.editing, key, false);
this.saveData();
},
onEditCell: function(row, key, e) {
this.$set(row.editing, key, true);
const parent = e.target.parentNode;
this.$nextTick(function() {
// console.log(parent.innerHTML, row)
parent.querySelector('input').focus();
});
},
onAdd: function(row, index) {
console.log(row, index);
this.tableData.splice(index + 1, 0, {
editing: {
name: true,
},
});
},
onRemove: function(row, index) {
this.tableData.splice(index, 1);
this.saveData();
},
onAddMember: function() {
this.memberSource.push({
editing: {
name: true,
},
});
},
onRemoveMember: function(row, index) {
var vm = this;
this.$confirm('删除不可撤销!可重新添加', '确定删除吗?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(function() {
vm.memberSource.splice(index, 1);
vm.saveData();
});
},
onImport: function() {
var vm = this;
this.$confirm('重新导入会覆盖现有人员列表', '确定重置吗?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(function() {
vm.memberSource = window.members.map(function(item) {
return {
name: item.name,
id: item.id,
editing: {},
};
});
vm.saveData();
});
},
saveData: function() {
localStorage.setItem('awards', JSON.stringify(this.awards));
localStorage.setItem('members', JSON.stringify(this.members));
localStorage.setItem(
'batchNumber',
JSON.stringify(this.batchNumber)
);
},
},
created: function() {
var awards = JSON.parse(localStorage.getItem('awards')) || [
{
name: '二等奖',
award: '办公室一日游',
count: 25,
},
{
name: '一等奖',
award: 'BMW X5',
count: 10,
},
{
name: '特等奖',
award: '深圳湾一号',
count: 1,
},
];
var members =
JSON.parse(localStorage.getItem('members')) || window.members;
this.batchNumber = +localStorage.getItem('batchNumber') || 20;
this.tableData = awards.map(function(item) {
return {
name: item.name,
count: item.count,
award: item.award,
editing: {},
};
});
this.memberSource = members.map(function(item) {
return {
name: item.name,
id: item.id,
editing: {},
};
});
this.saveData();
},
});
</script>
</body>
</html>