addIntegralRuleConfig.vue
2.44 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
<template>
<el-dialog :title="$t('integralRule.addConfigTitle')" :visible.sync="visible" width="50%" @close="handleClose">
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-form-item :label="$t('integralRule.configName')" prop="configId">
<el-select v-model="form.configId" :placeholder="$t('integralRule.configPlaceholder')" style="width: 100%">
<el-option v-for="item in configOptions" :key="item.configId" :label="item.configName"
:value="item.configId" />
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="handleSubmit">{{ $t('common.confirm') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { saveIntegralRuleConfig, listIntegralConfig } from '@/api/scm/integralRuleApi'
import { getCommunityId } from '@/api/community/communityApi'
export default {
name: 'AddIntegralRuleConfig',
props: {
ruleId: {
type: String,
required: true
}
},
data() {
return {
visible: false,
form: {
configId: '',
ruleId: ''
},
rules: {
configId: [
{ required: true, message: this.$t('integralRule.configRequired'), trigger: 'change' }
]
},
configOptions: []
}
},
methods: {
async open() {
this.visible = true
this.form.ruleId = this.ruleId
await this.fetchConfigOptions()
},
async fetchConfigOptions() {
try {
const { data } = await listIntegralConfig({
page: 1,
row: 100,
communityId: getCommunityId()
})
this.configOptions = data
} catch (error) {
this.$message.error(this.$t('common.fetchError'))
}
},
handleClose() {
this.$refs.form.resetFields()
},
async handleSubmit() {
this.$refs.form.validate(async valid => {
if (!valid) return
try {
const {code,msg} = await saveIntegralRuleConfig(this.form)
if(code != 0){
this.$message.error(msg)
return
}
this.$message.success(this.$t('common.operationSuccess'))
this.visible = false
this.$emit('success')
} catch (error) {
this.$message.error(error.message || this.$t('common.addFailed'))
}
})
}
}
}
</script>