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
var userDialog = {
data: function () {
var checkTelephone = function (rule, value, callback) {
if (value === '') {
callback(new Error('不能为空'))
} else {
if (!isMobile(value)) {
callback(new Error('手机号错误'))
}
callback()
}
}
return {
width: 'middle',
form: {
id: '',
username: '',
realname: '',
deptName: '',
roleId: '',
email: '',
telephone: '',
companyControl: []
},
props: [
{
label: '登录名',
prop: 'username',
inputType: 'input'
},
{
label: '真实姓名',
prop: 'realname',
inputType: 'input'
},
{
label: '所属单位',
prop: 'deptName',
inputType: 'select',
options: []
},
{
label: '选择角色',
prop: 'roleId',
inputType: 'select',
options: []
},
{
label: '邮箱',
prop: 'email',
inputType: 'input'
},
{
label: '电话',
prop: 'telephone',
inputType: 'input'
},
{
label: '管理部门',
prop: 'companyControl',
inputType: 'tree'
}
],
rules: {
username: [
{ required: true, message: '不能为空', trigger: 'blur' }
],
realname: [
{ required: true, message: '不能为空', trigger: 'blur' }
],
deptName: [
{ required: true, message: '不能为空', trigger: 'change' }
],
roleId: [
{ required: true, message: '不能为空', trigger: 'change' }
],
email: [
{ required: true, message: '不能为空', trigger: 'blur' },
{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
],
telephone: [
{ required: true, message: '不能为空', trigger: 'blur' },
{ validator: checkTelephone, trigger: 'blur' }
]
},
oldRules: {}
}
},
created: function () {
this.getDeptName()
this.getRole()
this.getTree()
this.oldRules = clonedeep(this.rules)
},
methods: {
// 所属单位数据
getDeptName: function () {
var self = this
api({
url: '/system/user/deptName',
type: 'get',
successFuc: function (res) {
self.setOptions('deptName', self.props, res.data)
}
})
},
// 选择角色数据
getRole: function () {
var self = this
api({
url: '/system/user/role',
type: 'get',
successFuc: function (res) {
self.setOptions('roleId', self.props, res.data)
}
})
},
// 管理部门
getTree: function () {
var self = this
api({
url: '/system/user/companyControl',
type: 'get',
successFuc: function (res) {
self.setOptions('companyControl', self.props, res.data)
}
})
},
// Dialog 打开的回调
openDialogHandle: function () {
var self = this
this.$nextTick(function () {
if (self.title1 === CONFIG.DETAIL) {
self.$refs.userDetail.openInitTree('companyControl')
} else {
self.$refs.userForm.openInitTree('companyControl')
}
if (self.title1 === CONFIG.EDIT || self.title1 === CONFIG.ADD) {
self.clearValidate('userForm')
}
if (self.title1 === CONFIG.EDIT) {
self.validate('userForm')
}
})
},
// Dialog 关闭的回调
closeDialogHandle: function () {
if (this.title1 === CONFIG.EDIT || this.title1 === CONFIG.ADD) {
this.clearForm('userForm')
this.$refs.userForm.clearTree('companyControl')
}
},
// 确定
confirmHandle: function () {
this.$refs.userForm.submitHandle()
},
submitHandle: function () {
this.close('userDialog')
},
deptNameSelectChangeHandle: function (val) {
console.log(val)
},
// 取消
cancelHandle: function () {
this.close('userDialog')
}
}
}