LotteryConfig.vue
4.24 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
<template>
<el-dialog
:visible="visible"
:append-to-body="true"
width="400px"
:lock-scroll="true"
@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>
<el-form ref="form" :model="form" label-width="100px" 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"></el-input>
</el-form-item>
<el-form-item label="特等奖人数">
<el-input type="number" v-model="form.specialAward"></el-input>
</el-form-item>
<el-form-item label="一等奖人数">
<el-input type="number" v-model="form.firstPrize"></el-input>
</el-form-item>
<el-form-item label="二等奖人数">
<el-input type="number" v-model="form.secondPrize"></el-input>
</el-form-item>
<el-form-item label="三等奖人数">
<el-input type="number" v-model="form.thirdPrize"></el-input>
</el-form-item>
<el-form-item label="四等奖人数">
<el-input type="number" v-model="form.fourthPrize"></el-input>
</el-form-item>
<el-form-item label="五等奖人数">
<el-input type="number" v-model="form.fifthPrize"></el-input>
</el-form-item>
<el-form-item
:label="newitem.name"
v-for="newitem in storeNewLottery"
:key="newitem.key"
>
<el-input
type="number"
v-model="form[newitem.key]"
@change="
val => {
form[newitem.key] = Number(val);
}
"
></el-input>
</el-form-item>
</el-form>
<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.$emit('resetconfig');
this.$message({
message: '保存成功',
type: 'success'
});
},
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;
overflow-y: auto;
}
}
.dialog-showAddLottery {
.el-dialog {
height: 186px;
}
}
</style>