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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<template>
<!-- 弹出框表单 -->
<el-drawer
:title="title"
:visible.sync="open"
:direction="direction"
:destroy-on-close="true"
size="50%"
>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<Field
:span="20"
label="员工姓名"
prop="name"
v-model="form.name"
placeholder="请输入员工姓名"
/>
<Field
:span="20"
label="所属公司"
prop="companyIds"
v-model="form.companyIds"
:multiple="true"
type="select"
:enum-data="dict.companyIds"
placeholder="请输入所属公司"
/>
<Field
:span="20"
label="职位"
prop="positionId"
v-model="form.positionId"
type="select"
:enum-data="dict.positionId"
placeholder="请输入职位ID"
/>
<Field
:span="20"
label="联系电话"
prop="phoneNumber"
v-model="form.phoneNumber"
placeholder="请输入联系电话"
/>
<!-- <Field :span="20" label="员工状态" type="select" prop="staffStatus" v-model="form.staffStatus" :enum-data="dict.staffStatus" placeholder="请输入员工状态"/> -->
<Field :span="20" label="头像" prop="photoPath" placeholder="请输入照片"
><imageUpload v-model="form.photoPath" prePath="/file/preview" />
</Field>
<Field
:span="20"
label="邮件地址"
prop="email"
v-model="form.email"
placeholder="请输入邮件地址"
/>
<Field
:span="20"
label="备注"
prop="remark"
v-model="form.remark"
type="textarea"
placeholder="请输入备注"
/>
</el-row>
<form-buttons
@submit="submitForm"
v-if="pageInfo.type != 'view'"
noCancelBtn
/>
</el-form>
</el-drawer>
</template>
<script>
import form from "@/assets/mixins/formdialog";
export default {
name: "StaffDetail",
mixins: [form],
components: {},
created() {
this.changePath("staff");
},
data() {
var checkEmail = (rule, value, callback) => {
let mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
if (!value) {
//如果输入为空直接返回
callback();
} else {
//如果字符串 string 中含有与 RegExpObject 匹配的文本,则返回 true,否则返回 false。
if (mailReg.test(value)) {
//匹配成功返回
callback();
} else {
//匹配不成功返回错误显示
callback(
new Error("邮箱格式:xx@xx.xx,只含数字、大小写字母、下划线、横杠")
);
}
}
};
var checkPhone = (rule, value, callback) => {
let phoneReg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
if (!value) {
callback();
} else {
if (phoneReg.test(value)) {
callback();
} else {
callback(new Error("请输入正确格式的11位电话号码"));
}
}
};
return {
// 遮罩层
loading: true,
// 弹出层标题
title: "员工基本信息",
// 是否显示弹出层
open: false,
direction: "rtl",
toString: ["gender", "staffType", "staffStatus", "source", "positionId"],
toArrays: ["companyIds"],
toDate: ["birthday", "entryDate", "regularDate", "leaveDate"],
// 表单校验
rules: {
name: [
{ required: true, message: "请输入员工姓名", trigger: "blur" },
{ max: 64, message: "最多只能录入64个字符", trigger: "blur" },
],
positionId: [
{ required: true, message: "请选择职位", trigger: "blur" },
],
companyIds: [
{ required: true, message: "请选择所属企业", trigger: "blur" },
],
phoneNumber: [
{ required: true, message: "请输入联系电话", trigger: "blur" },
{ validator: checkPhone, trigger: "blur" },
{ max: 11, message: "最多只能录入11个字符", trigger: "blur" },
],
email: [{ validator: checkEmail, trigger: "blur" }],
},
};
},
methods: {
/** 编辑 */
edit(row) {
this.reset();
this.query = { id: row.id };
this.urls.currUrl = "staff/edit";
this.getData();
this.pageInfo.type = "edit";
this.title = "修改员工基本信息";
},
/** 新增 */
add(row) {
this.reset();
this.urls.currUrl = "staff/add";
this.getData();
this.pageInfo.type = "add";
this.title = "新增员工基本信息";
},
/** 查看*/
view(row) {
this.reset();
this.query = { id: row.id };
this.urls.currUrl = "staff/view";
this.getData();
this.pageInfo.type = "view";
this.title = "员工基本信息详细";
},
/**取消按钮 */
cancel() {
this.open = false;
},
/**获取数据后弹框 */
afterRender(data) {
this.open = true;
},
beforeSubmit(data) {
data.companyIds = data.companyIds.join(",");
return data;
},
afterSubmit(data) {
this.open = false;
this.$emit("ok");
},
// 表单重置
reset() {
this.form = {
name: "",
gender: 1,
birthday: null,
photoPath: "",
Email: "",
phoneNumber: "",
idCard: "",
workNum: "",
companyName: "",
positionId: null,
positionName: "",
staffType: 1,
staffStatus: 1,
source: 1,
registerPath: "",
entryDate: null,
regularDate: null,
leaveDate: null,
remark: "",
sumViews: 0,
viewsByDay: 0,
sendBusinessCardTimes: 0,
};
this.resetForm("form");
},
resetForm(refName) {
if (this.$refs[refName]) {
this.$refs[refName].resetFields();
}
},
},
};
</script>