dialogReg.vue
3.86 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
<template>
<el-dialog
:title="title"
:visible.sync="dialogVisible"
:before-close="handleClose"
width="720px"
custom-class="reg-dialog-admin"
:close-on-click-modal="false"
v-if="dialogVisible"
:append-to-body="true"
:lock-scroll="false"
>
<el-form
ref="regForm"
:model="regForm"
label-width="120px"
class="reg-dialog-form"
:rules="rules"
>
<el-form-item label="用户名:" prop="loginName">
<el-input
v-model="regForm.loginName"
:disabled="!!regForm.userId"
requred
maxlength="10"
placeholder="请输入用户名"
clearable
:show-word-limit="true"
></el-input>
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="姓名:" prop="userName">
<el-input
v-model="regForm.userName"
placeholder="请输入姓名"
maxlength="8"
:show-word-limit="true"
clearable
></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="角色:" prop="roleId">
<el-select v-model="regForm.roleId" placeholder="请选择">
<el-option
:label="role.roleName"
:value="role.roleId"
v-for="(role,index) in baseData.roles"
:key="index"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer">
<el-button @click="submit" type="primary" :loading="$store.state.d2admin.loading.value" class="button-submit">提交</el-button>
<el-button @click="handleClose" type="plain" class="button-submit">取消</el-button>
</div>
</el-dialog>
</template>
<script>
import notice from '@/common/notice'
import util from '@/libs/util'
export default {
name: 'DialogReg',
props: {
isVisible: {
type: Boolean,
default: false
},
editData: {
type: Object,
default: null
},
verify: {
type: Function,
default: null
}
},
watch: {
editData: {
handler: function(value) {
if (!value || !value.data) return
const { data } = value
const { title, submit } = data
this.title = title
this.submitFunction = submit
delete value.data
Object.assign(this.regForm, value)
},
immediate: true
}
},
computed: {
dialogVisible() {
if (!this.isVisible) {
util.resetForm.call(this, 'regForm')
}
return this.isVisible
}
},
data() {
return {
regForm: {
loginName: '',
userName: '',
roleId: ''
},
title: '',
submitFunction: null,
rules: Object.freeze({
loginName: [
{ required: true, message: '用户名不能为空', trigger: ['blur'] }
],
userName: [
{ required: true, message: '姓名不能为空', trigger: ['blur'] }
],
roleId: [{ required: true, message: '角色不能为空', trigger: ['blur'] }]
})
}
},
methods: {
handleClose(done) {
this.$event.$emit('e-reg-dialog-close', false)
},
// 提交注册或审核数据
submit() {
this.$refs.regForm.validate(vaild => {
if (vaild) {
var __p = this.regForm
this.submitFunction(__p).then(res => {
const { operateStatus } = res
if (operateStatus) {
notice.okTips(`${this.title}成功!`)
this.$refs.regForm.resetFields()
this.$event.$emit('e-reg-dialog-close', true)
} else {
notice.errorTips(`${this.title}失败!`)
}
})
}
})
}
},
mounted() {
}
}
</script>