edit
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
<div class="modal-title">{{ i.id === 0 ? '添加员工' : '编辑员工' }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<sf #sf [compact]="true" [ui]="ui" [schema]="schema" [button]="'none'">
|
||||
<sf #sf [ui]="ui" [schema]="schema" [button]="'none'">
|
||||
<ng-template sf-template="account" let-me let-ui="ui" let-schema="schema">
|
||||
<sv-container labelWidth="1">
|
||||
<sv label="">
|
||||
|
||||
@ -29,32 +29,31 @@ export class SystemStaffStaffModalComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.i?.id !== 0) {
|
||||
this.i.roleIds = this.i.roleId !== '' ? this.i.roleId.split(',') : [];
|
||||
if (this.i?.userId !== 0) {
|
||||
// this.i.roleIds = this.i.roleId !== '' ? this.i.roleId.split(',') : [];
|
||||
}
|
||||
|
||||
|
||||
this.initSF(this.i);
|
||||
}
|
||||
initSF(staff: any) {
|
||||
console.log(staff);
|
||||
this.schema = {
|
||||
properties: {
|
||||
name: {
|
||||
staffName: {
|
||||
title: '员工姓名',
|
||||
type: 'string',
|
||||
maxLength: 32,
|
||||
ui: { widget: staff?.name ? 'text' : 'string', placeholder: '请输入员工姓名' },
|
||||
ui: { widget: staff?.appUserId ? 'text' : 'string', placeholder: '请输入员工姓名' },
|
||||
default: staff.name
|
||||
},
|
||||
phone: {
|
||||
telephone: {
|
||||
title: '手机号码',
|
||||
type: 'string',
|
||||
format: 'mobile',
|
||||
maxLength: 11,
|
||||
ui: { widget: staff?.phone ? 'text' : 'string', placeholder: '请输入员工手机号' },
|
||||
default: staff.phone
|
||||
ui: { widget: staff?.appUserId ? 'text' : 'string', placeholder: '请输入员工手机号' },
|
||||
default: staff.telephone
|
||||
},
|
||||
roleIds: {
|
||||
roleId: {
|
||||
title: '角色',
|
||||
type: 'string',
|
||||
ui: {
|
||||
@ -80,7 +79,7 @@ export class SystemStaffStaffModalComponent implements OnInit {
|
||||
default: staff?.roleIds
|
||||
}
|
||||
},
|
||||
required: ['name', 'phone', 'roleIds']
|
||||
required: ['staffName', 'telephone']
|
||||
};
|
||||
this.ui = {
|
||||
'*': {
|
||||
@ -91,54 +90,36 @@ export class SystemStaffStaffModalComponent implements OnInit {
|
||||
}
|
||||
|
||||
sure() {
|
||||
if (!this.sf.value.roleIds || this.sf.value.roleIds.length === 0) {
|
||||
this.service.msgSrv.error('员工角色不能为空!');
|
||||
return;
|
||||
}
|
||||
this.roleNames = [];
|
||||
this.roleList.forEach((item: { id: any; roleName: string }) => {
|
||||
this.sf.value.roleIds.forEach((ele: any) => {
|
||||
if (ele === item.id) {
|
||||
this.roleNames.push(item.roleName);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (this.i.id === 0) {
|
||||
// if (!this.sf.value.roleIds || this.sf.value.roleIds.length === 0) {
|
||||
// this.service.msgSrv.error('员工角色不能为空!');
|
||||
// return;
|
||||
// }
|
||||
if (this.i.userId === 0) {
|
||||
const params: any = {
|
||||
...this.sf.value,
|
||||
roleId: this.sf.value.roleIds,
|
||||
roleNames: this.roleNames.join(','),
|
||||
telephone: this.sf.value.phone,
|
||||
staffName: this.sf.value.name
|
||||
enterpriseId: 0,
|
||||
roleId: []
|
||||
};
|
||||
// this.service.request(this.service.$api_addStaff, params).subscribe((res) => {
|
||||
// console.log(res);
|
||||
// if (res) {
|
||||
// this.service.msgSrv.success('保存成功!');
|
||||
// this.modal.close(true);
|
||||
// }
|
||||
// // this.showInviteFlag = true;
|
||||
// // this.inviteCode = res.inviteCode;
|
||||
// });
|
||||
this.service.request(this.service.$api_add_staff, params).subscribe(res => {
|
||||
if (res) {
|
||||
this.service.msgSrv.success('保存成功!');
|
||||
this.modal.close(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const params: any = {
|
||||
appUserId: this.i.appUserId,
|
||||
staffName: this.sf.value.name,
|
||||
roleId: this.sf.value.roleIds,
|
||||
telephone: this.i.telephone
|
||||
...this.sf.value,
|
||||
roleId: []
|
||||
};
|
||||
// this.service.request(this.service.$api_editorStaff, params).subscribe((res) => {
|
||||
// this.service.msgSrv.success('编辑成功!');
|
||||
// // this.loadMyIdentity();
|
||||
// this.modal.close(true);
|
||||
// });
|
||||
this.service.request(this.service.$api_edit_staff, params).subscribe(res => {
|
||||
if (res) {
|
||||
this.service.msgSrv.success('编辑成功!');
|
||||
this.modal.close(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
loadMyIdentity() {
|
||||
this.enterpriseSrv.loadEnterpises().subscribe((data: any[]) => {
|
||||
this.enterpriseSrv.setCache(data);
|
||||
});
|
||||
}
|
||||
|
||||
close() {
|
||||
this.modal.destroy();
|
||||
|
||||
Reference in New Issue
Block a user