Tool.vue
5.47 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
<template>
<div id="tool">
<el-button @click="startHandler" size="mini">{{
running ? '停止' : '开始'
}}</el-button>
<el-button size="mini" @click="resetConfig">
重置
</el-button>
<el-dialog
:append-to-body="true"
:visible.sync="showSetwat"
class="setwat-dialog"
width="400px"
>
<el-form ref="form" :model="form" label-width="80px" size="mini">
<el-form-item label="抽取奖项">
<el-select v-model="form.category" placeholder="请选取本次抽取的奖项">
<el-option
:label="item.label"
:value="item.value"
v-for="(item, index) in categorys"
:key="index"
></el-option>
</el-select>
</el-form-item>
<el-form-item label=" " v-if="form.category">
<span>
共
<span class="colorred">{{ config[form.category] }}</span>
名
</span>
<span :style="{ marginLeft: '20px' }">
剩余
<span class="colorred">{{ remain }}</span>
名
</span>
</el-form-item>
<el-form-item label="抽取方式">
<el-select v-model="form.mode" placeholder="请选取本次抽取方式">
<el-option label="抽1人" :value="1"></el-option>
<el-option label="抽5人" :value="5"></el-option>
<el-option label="一次抽取完" :value="0"></el-option>
<el-option label="自定义" :value="99"></el-option>
</el-select>
</el-form-item>
<el-form-item label="抽取人数" v-if="form.mode === 99">
<el-input
v-model="form.qty"
type="number"
:clearable="true"
:min="1"
:max="remain ? remain : 100"
:step="1"
></el-input>
</el-form-item>
<el-form-item label="全员参与">
<el-switch v-model="form.allin"></el-switch>
<span :style="{ fontSize: '12px' }">
(开启后将在全体成员[无论有无中奖]中抽奖)
</span>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">立即抽奖</el-button>
<el-button @click="showSetwat = false">取消</el-button>
</el-form-item>
</el-form>
</el-dialog>
</div>
</template>
<script>
import { clearData, conversionCategoryName } from '@/helper/index';
export default {
props: {
running: Boolean
},
computed: {
config: {
get() {
return this.$store.state.config;
}
},
remain() {
return (
this.config[this.form.category] -
(this.result[this.form.category]
? this.result[this.form.category].length
: 0)
);
},
result() {
return this.$store.state.result;
},
categorys() {
const options = [];
for (const key in this.config) {
if (this.config.hasOwnProperty(key)) {
const item = this.config[key];
if (item > 0) {
let name = conversionCategoryName(key);
name &&
options.push({
label: name,
value: key
});
}
}
}
return options;
}
},
data() {
return {
showSetwat: false,
form: {
category: '',
mode: 1,
qty: 1,
allin: false
}
};
},
methods: {
resetConfig() {
this.$confirm('此操作将重置所有数据,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
clearData();
this.$store.commit('setClearStore');
this.$emit('resetConfig');
this.$message({
type: 'success',
message: '重置成功!'
});
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消'
});
});
},
onSubmit() {
if (!this.form.category) {
return this.$message.error('请选择本次抽取的奖项');
}
if (this.remain <= 0) {
return this.$message.error('该奖项剩余人数不足');
}
if (this.form.mode === 99) {
if (this.form.qty <= 0) {
return this.$message.error('必须输入本次抽取人数');
}
if (this.form.qty > this.remain) {
return this.$message.error('本次抽奖人数已超过本奖项的剩余人数');
}
}
if (this.form.mode === 1 || this.form.mode === 5) {
if (this.form.mode > this.remain) {
return this.$message.error('本次抽奖人数已超过本奖项的剩余人数');
}
}
this.showSetwat = false;
this.$emit(
'toggle',
Object.assign({}, this.form, { remain: this.remain })
);
},
startHandler() {
if (this.running) {
this.$emit('toggle');
} else {
this.showSetwat = true;
}
}
}
};
</script>
<style lang="scss">
#tool {
position: fixed;
width: 60px;
height: 500px;
top: 50%;
right: 20px;
transform: translateY(-50%);
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.el-button + .el-button {
margin-top: 20px;
margin-left: 0px;
}
}
.setwat-dialog {
.colorred {
color: red;
font-weight: bold;
}
}
</style>