LotteryConfig.vue
4.98 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
<template>
<el-dialog
:visible="visible"
:append-to-body="true"
width="400px"
@close="$emit('update:visible', false)"
class="c-LotteryConfig"
>
<div class="c-LotteryConfigtitle" slot="title">
<span :style="{ fontSize: '16px', marginRight: '20px' }">
抽奖配置
</span>
<el-button size="mini" @click="addLottery">增加奖项</el-button>
<el-button size="mini" type="primary" @click="onSubmit"
>保存配置</el-button
>
<el-button size="mini" @click="$emit('update:visible', false)"
>取消</el-button
>
</div>
<div class="container">
<el-form ref="form" :model="form" label-width="90px" size="mini">
<el-form-item label="抽奖标题">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="抽奖总人数">
<el-input
type="number"
v-model="form.number"
:min="1"
:step="1"
></el-input>
</el-form-item>
<el-form-item label="特等奖">
<el-input
type="number"
v-model="form.specialAward"
:min="0"
:step="1"
></el-input>
</el-form-item>
<el-form-item label="一等奖">
<el-input
type="number"
v-model="form.firstPrize"
:min="0"
:step="1"
></el-input>
</el-form-item>
<el-form-item label="二等奖">
<el-input
type="number"
v-model="form.secondPrize"
:min="0"
:step="1"
></el-input>
</el-form-item>
<el-form-item label="三等奖">
<el-input
type="number"
v-model="form.thirdPrize"
:min="0"
:step="1"
></el-input>
</el-form-item>
<el-form-item label="四等奖">
<el-input
type="number"
v-model="form.fourthPrize"
:min="0"
:step="1"
></el-input>
</el-form-item>
<el-form-item label="五等奖">
<el-input
type="number"
v-model="form.fifthPrize"
:min="0"
:step="1"
></el-input>
</el-form-item>
<el-form-item
:label="newitem.name"
v-for="newitem in storeNewLottery"
:key="newitem.key"
>
<el-input
type="number"
:min="0"
:step="1"
v-model="form[newitem.key]"
@change="
val => {
form[newitem.key] = Number(val);
}
"
></el-input>
</el-form-item>
</el-form>
</div>
<el-dialog
:visible.sync="showAddLottery"
:append-to-body="true"
width="300px"
class="dialog-showAddLottery"
>
<div class="add-title" slot="title">增加奖项</div>
<el-form ref="newLottery" :model="newLottery" size="mini">
<el-form-item label="奖项名称">
<el-input v-model="newLottery.name"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="addHandler">增加奖项</el-button>
<el-button @click="showAddLottery = false">取消</el-button>
</el-form-item>
</el-form>
</el-dialog>
</el-dialog>
</template>
<script>
import { setData, configField } from '@/helper/index';
import { randomNum } from '@/helper/algorithm';
export default {
name: 'LotteryConfig',
props: {
visible: Boolean
},
computed: {
form: {
get() {
return this.$store.state.config;
},
set(val) {
this.$store.commit('setConfig', val);
}
},
storeNewLottery() {
return this.$store.state.newLottery;
}
},
data() {
return {
showAddLottery: false,
newLottery: { name: '' }
};
},
methods: {
onSubmit() {
setData(configField, this.form);
this.$emit('update:visible', false);
this.$message({
message: '保存成功',
type: 'success'
});
this.$nextTick(() => {
this.$emit('resetconfig');
});
},
addLottery() {
this.showAddLottery = true;
},
randomField() {
const str = 'abcdefghijklmnopqrstuvwxyz';
let fieldStr = '';
for (let index = 0; index < 10; index++) {
fieldStr += str.split('')[randomNum(1, 27) - 1];
}
return `${fieldStr}${Date.now()}`;
},
addHandler() {
const field = this.randomField();
const data = {
key: field,
name: this.newLottery.name
};
this.$store.commit('setNewLottery', data);
this.showAddLottery = false;
}
}
};
</script>
<style lang="scss">
.c-LotteryConfig {
.el-dialog__body {
height: 340px;
.container {
height: 100%;
overflow-y: auto;
padding: 0 10px;
}
}
}
.dialog-showAddLottery {
.el-dialog {
height: 186px;
}
}
</style>