hospital-add.component.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import { I18NService } from './../../../../core/i18n/i18n.service';
  2. import { BasedataHospitalHospitalNewComponent } from './../hospital-new/hospital-new.component';
  3. import { HospitalContacts } from 'app/entity/basedata/hospital-contacts';
  4. import { Hospital } from './../../../../entity/basedata/hospital';
  5. import { Component, OnInit, ViewChild, HostListener, Output, EventEmitter } from '@angular/core';
  6. import { FormGroup, Validators, FormBuilder } from '@angular/forms';
  7. import { NzNotificationService } from 'ng-zorro-antd';
  8. import { HospitalService } from 'app/services/basedata/hospital.service';
  9. import { messageShared } from '@shared/utils/message';
  10. @Component({
  11. selector: 'app-basedata-hospital-hospital-add',
  12. templateUrl: './hospital-add.component.html',
  13. styles: [
  14. `
  15. .base{
  16. position: absolute;
  17. bottom: 0px;
  18. width: 100%;
  19. border-top: 1px solid rgb(232, 232, 232);
  20. padding: 10px 16px;
  21. text-align: right;
  22. left: 0px;
  23. background: #fff;
  24. z-index:99;
  25. }
  26. .buttonDistance{
  27. margin-right:2%;
  28. }
  29. `
  30. ]
  31. })
  32. export class BasedataHospitalHospitalAddComponent implements OnInit {
  33. //元数据
  34. ngOnInit(): void {
  35. this.validateForm = this.fb.group({
  36. code: [null, [Validators.required]],
  37. name: [null, [Validators.required]],
  38. });
  39. // this.initHospital();
  40. this.hospitalContacts = [];
  41. }
  42. constructor(
  43. private nzNotificationService: NzNotificationService,
  44. private hospitalService: HospitalService,
  45. private fb: FormBuilder,
  46. private i18NService:I18NService
  47. ) { }
  48. // 表格加载状态
  49. isLoading = false
  50. drawerWidth = 1000;
  51. visible = false;
  52. validateForm: FormGroup;
  53. hospital: Hospital = {
  54. id: "",
  55. code: "",// 医院编码 (非空)
  56. name: "",// 医院名称 (非空)
  57. enable: "",// 是否停用
  58. delFlag: "",// 是否删除
  59. createBy: "",// 创建人
  60. createTime: null,// 创建时间
  61. updateBy: "",// 修改人
  62. updateTime: null,// 修改时间
  63. memo: "",// 备注
  64. HospitalContact: null,
  65. hospitalContacts: []// 医院联系人
  66. };
  67. enable = false;
  68. hospitalContacts: HospitalContacts[];
  69. @ViewChild("basedataHospitalHospitalNew") basedataHospitalHospitalNew: BasedataHospitalHospitalNewComponent
  70. @Output() afterSave = new EventEmitter();
  71. @HostListener('window:resize', ['$event'])
  72. onResize(event) {
  73. const width = event.target.innerWidth;
  74. if (width > 900) {
  75. this.drawerWidth = 900;
  76. } else {
  77. this.drawerWidth = width;
  78. }
  79. }
  80. //对<nz-form-control>标签逐一校验
  81. isLoadingSave=false;
  82. save(): void {
  83. this.isLoading = true
  84. this.hospital.hospitalContacts = this.hospitalContacts;
  85. if (this.enable) {
  86. this.hospital.enable = "1";
  87. } else {
  88. this.hospital.enable = "0";
  89. }
  90. for (const i in this.validateForm.controls) {
  91. this.validateForm.controls[i].markAsDirty();
  92. this.validateForm.controls[i].updateValueAndValidity();
  93. }
  94. //alert(JSON.""ify(this.hospital));
  95. //return;
  96. let valid = this.validateForm.valid;
  97. // 验证通过保存
  98. if (valid) {
  99. if (this.hospital.id == null || this.hospital.id == "") {
  100. this.isLoadingSave=true;
  101. this.hospitalService.addHospital(this.hospital).then((response) => {
  102. console.log(this.i18NService.fanyi("hospital.data.is"))
  103. console.log(response)
  104. if (response.success) {
  105. this.nzNotificationService.success(this.i18NService.fanyi("newsuccess"), "");
  106. this.afterSave.emit();
  107. // this.initHospital();
  108. this.isLoading = false
  109. this.isLoadingSave=false;
  110. this.close();
  111. } else {
  112. this.isLoading = false
  113. this.isLoadingSave=false;
  114. this.nzNotificationService.error(this.i18NService.fanyi("newfailure"), messageShared(this.i18NService,response.message));
  115. }
  116. })
  117. } else {
  118. this.isLoadingSave=true;
  119. this.hospitalService.editHospital(this.hospital).then((response) => {
  120. if (response.success) {
  121. this.isLoading = false;
  122. this.isLoadingSave=false;
  123. this.nzNotificationService.success(this.i18NService.fanyi("successful.revision"), "");
  124. this.afterSave.emit();
  125. // this.initHospital();
  126. this.close();
  127. } else {
  128. this.isLoading = false;
  129. this.isLoadingSave=false;
  130. this.nzNotificationService.error(this.i18NService.fanyi("modification.failed"),messageShared(this.i18NService,response.message));
  131. }
  132. })
  133. }
  134. }
  135. }
  136. open(): void {
  137. this.visible = true;//打开drawer并清除校验提示信息
  138. this.enable = false;
  139. this.hospitalContacts = [];
  140. for (const i in this.validateForm.controls) {
  141. this.validateForm.controls[i].reset();
  142. }
  143. }
  144. close(): void {
  145. this.visible = false;//关闭drawer
  146. }
  147. pushHospitalContacts(hospitalContact: HospitalContacts) {
  148. console.log("5555")
  149. var i = 0;
  150. this.hospitalContacts.forEach((obj) => {
  151. if (hospitalContact.contactPsn == obj.contactPsn) {
  152. i++;
  153. }
  154. })
  155. console.log("1")
  156. if (i > 0) {
  157. this.nzNotificationService.error(this.i18NService.fanyi("add.contact.failed"), this.i18NService.fanyi("hospital.contacts ") + hospitalContact.contactPsn + this.i18NService.fanyi("hospital.contarts.isdefault"));
  158. return;
  159. }
  160. console.log("2")
  161. this.hospitalContacts.push(hospitalContact);
  162. this.hospitalContacts = [...this.hospitalContacts];
  163. console.log("3")
  164. this.basedataHospitalHospitalNew.handleCancel();
  165. console.log("4")
  166. }
  167. confirmDel(contactPsn: string) {
  168. for (var i = 0; i < this.hospitalContacts.length; i++) {
  169. if (this.hospitalContacts[i].contactPsn == contactPsn) {
  170. this.hospitalContacts.splice(i, 1);
  171. this.hospitalContacts = [...this.hospitalContacts];
  172. break;
  173. }
  174. }
  175. }
  176. cancelDel() {
  177. }
  178. // hospital:Hospital = {
  179. // id: "",
  180. // code: "",// 医院编码
  181. // name: "",// 医院名称
  182. // enable: "",// 是否停用
  183. // memo: "",// 备注
  184. // hospitalContacts: []
  185. // }
  186. }