嗨森逛PC管理端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
high-web/src/app/admin/recharge-order/user-edit/user-edit.component.ts

122 lines
3.8 KiB

import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '_@angular_forms@9.0.7@@angular/forms';
import {environment} from '../../../../environments/environment';
import {AgentService} from '../../../services/agent.service';
import {NzMessageService} from '_ng-zorro-antd@9.3.0@ng-zorro-antd';
import {ActivatedRoute} from '_@angular_router@9.0.7@@angular/router';
import {ValidatorsService} from '../../../services/validators.service';
@Component({
selector: 'app-user-edit',
templateUrl: './user-edit.component.html',
styleUrls: ['./user-edit.component.scss']
})
export class UserEditComponent implements OnInit {
validateForm!: FormGroup;
data: any;
editFlag = false;
id: number;
passwordVisible = false;
logoFile = [];
WEB_SERVE_URL = environment.baseUrl;
userId: number;
time;
constructor(
private fb: FormBuilder,
private agent: AgentService,
private message: NzMessageService, // 信息提示
private activatedRoute: ActivatedRoute,
) {
}
ngOnInit(): void {
this.activatedRoute.queryParams.subscribe(queryParams => {
if (queryParams.agentId != null) {
this.editFlag = true;
this.id = queryParams.agentId;
this.getDetails(queryParams.agentId);
}
});
this.validateForm = this.fb.group({
loginName: [null, [Validators.required, ValidatorsService.maxLength(20)]],
password: [null, [Validators.required]],
agentName: [null, [Validators.required]],
type: [2],
agentUser: [null, [Validators.required, ValidatorsService.maxLength(50)]],
agentPhone: [null, [Validators.required, ValidatorsService.maxLength(50)]],
agentAddress: [null, [Validators.required, ValidatorsService.maxLength(80)]],
secUser: {},
});
}
// 返回
getBack() {
history.back();
}
// 重置
public resetForm(): void {
this.validateForm.reset();
}
// 课程保存
public getSave(): void {
// tslint:disable-next-line:forin
for (const i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
if (this.validateForm.controls[i].errors != null) {
this.message.error('必填项不能为空');
return;
}
}
this.validateForm.value['secUser']['loginName'] = this.validateForm.value.loginName;
this.validateForm.value['secUser']['password'] = this.validateForm.value.password;
if (this.logoFile.length !== 0) {
if (this.logoFile[0]['response'] != null) {
this.validateForm.value.logo = this.logoFile[0]['response']['return_data'][0];
} else {
this.validateForm.value.logo = this.logoFile[0].name;
}
}
if (this.editFlag) {
this.validateForm.value.id = this.id;
this.agent.updateAgent(this.validateForm.value, data => {
if (data['return_code'] === '000000') {
this.getBack();
this.message.success('修改成功');
} else {
this.message.create('error', '修改失败');
}
});
} else {
this.agent.insertAgent(this.validateForm.value, data => {
if (data['return_code'] === '000000') {
this.getBack();
this.message.success('添加成功');
} else {
this.message.create('error', data['return_msg']);
}
});
}
}
public getDetails(id) {
this.agent.findByAgentId(id, data => {
console.log(data);
if (data['return_code'] === '000000') {
data['return_data'].loginName = data['return_data'].secUser.loginName;
data['return_data'].password = data['return_data'].secUser.password;
this.validateForm.patchValue(data['return_data']);
} else {
this.message.create('error', data['return_msg']);
}
});
}
}