add.component.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Component, OnInit } from '@angular/core';
  2. import { _HttpClient, ModalHelper } from '@delon/theme';
  3. // import { STColumn, STComponent } from '@delon/abc';
  4. // import { SFSchema } from '@delon/form';
  5. // 以下新增
  6. import { NzModalRef, NzMessageService, NzNotificationService, NzI18nService } from 'ng-zorro-antd';
  7. import { FormBuilder, Validators, FormGroup } from '@angular/forms';
  8. import { BaseCustomerIndustry } from 'app/entity/basedata/base-customer-industry';
  9. import { BaseCustomerIndustryService } from 'app/services/basedata/base-customer-industry.service';
  10. import { I18NService } from '@core';
  11. // import { NzInputNumberModule } from 'ng-zorro-antd/input-number';
  12. @Component({
  13. selector: 'app-basedata-merchants-industry-add',
  14. templateUrl: './add.component.html',
  15. })
  16. export class BasedataMerchantsIndustryAddComponent implements OnInit {
  17. constructor(
  18. private modal: NzModalRef,
  19. private fb: FormBuilder,
  20. private baseCustomerIndustryService: BaseCustomerIndustryService,
  21. private nzNotificationService: NzNotificationService,
  22. private i18NService: I18NService,
  23. ) {}
  24. ngOnInit(): void {
  25. //初始化表单
  26. this.validateForm = this.fb.group({
  27. code: [{ value: '', disabled: true }, []], //客商编码
  28. name: [null, [Validators.required]], //客商名称
  29. status: [null], //是否启用
  30. sort: ['number', [Validators.required]], //数字输入框 客商名称排序
  31. });
  32. //新增子集获取父节点id
  33. // if(this.parentId&&this.parentId!=="0"){
  34. this.baseCustomerIndustry.parentId = this.parentId;
  35. // }
  36. }
  37. validateForm!: FormGroup;
  38. parentId = '0'; //父级id
  39. status = true; //是否启用
  40. // 确定 按钮(添加一级)
  41. submitForm(): any {
  42. // console.log('----');
  43. return new Promise(resolve => {
  44. for (const i in this.validateForm.controls) {
  45. this.validateForm.controls[i].markAsDirty();
  46. this.validateForm.controls[i].updateValueAndValidity();
  47. }
  48. let valid = this.validateForm.valid;
  49. if (valid) {
  50. console.log('valid有效--->', valid);
  51. //格式化是否期用
  52. if (this.status) {
  53. this.baseCustomerIndustry.status = '1';
  54. } else {
  55. this.baseCustomerIndustry.status = '0';
  56. }
  57. this.baseCustomerIndustry.pkOrg = sessionStorage.getItem('pkOrg'); //组织
  58. this.baseCustomerIndustryService.add(this.baseCustomerIndustry).then(response => {
  59. if (response.success) {
  60. //保存成功
  61. this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
  62. this.modal.destroy();
  63. resolve();
  64. } else {
  65. //保存失败
  66. this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
  67. }
  68. });
  69. }
  70. });
  71. }
  72. //关闭
  73. close() {
  74. this.modal.destroy();
  75. }
  76. //实例化函数
  77. baseCustomerIndustry: BaseCustomerIndustry = {};
  78. }