assets-product-management-prompt-modal.component.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
  2. import { MainService } from '../../services/main.service';
  3. import { ToolService } from 'src/app/services/tool.service';
  4. import { NzMessageService } from 'ng-zorro-antd';
  5. import { FormGroup, Validators, FormBuilder } from '@angular/forms';
  6. @Component({
  7. selector: 'app-assets-product-management-prompt-modal',
  8. templateUrl: './assets-product-management-prompt-modal.component.html',
  9. styleUrls: ['./assets-product-management-prompt-modal.component.less']
  10. })
  11. export class AssetsProductManagementPromptModalComponent implements OnInit {
  12. // 切换科室,切换弹窗
  13. hsLoading = false;
  14. historySpecimenList: any = [];
  15. currentHospital; //当前院区
  16. @Input() show: Boolean;
  17. @Input() id: Number;
  18. @Output() closeModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
  19. constructor(
  20. private mainService: MainService,
  21. private tool: ToolService,
  22. private message: NzMessageService,
  23. private fb: FormBuilder,
  24. ) { }
  25. ngOnInit() {
  26. this.currentHospital = this.tool.getCurrentHospital();
  27. this.getList();
  28. this.getIncidentCategoryList();
  29. }
  30. // 获取故障现象
  31. incidentCategoryList:any[] = [];
  32. getIncidentCategoryList(){
  33. let { hospital, type } = this.tool.getHospitalOrDuty();
  34. if(type === 'hospital' || type === 'department'){
  35. this.incidentCategoryList = [];
  36. return;
  37. };
  38. let postData = {
  39. hasThird: 'true',//只差有三级的故障现象列表
  40. category: {
  41. dutyIds: type === 'duty' ? hospital.id.toString() : undefined,
  42. },
  43. };
  44. this.mainService.incidentPost("listIncidentCategory", postData).subscribe(res => {
  45. let incidentCategoryList = res.data || [];
  46. incidentCategoryList = incidentCategoryList.map(v => ({...v, parentId: v.parent ? v.parent.id : undefined, label: v.category, value: v.id}));
  47. this.incidentCategoryList = this.tool.tranListToTreeDataLeaf(incidentCategoryList, undefined, "parentId");
  48. console.log(this.incidentCategoryList);
  49. })
  50. }
  51. // 编辑
  52. edit(e, data) {
  53. e.stopPropagation();
  54. console.log(data);
  55. this.initForm();
  56. this.modelName = "编辑";
  57. this.add = false;
  58. this.modal = true;
  59. this.coopData = data;
  60. this.validateForm.controls.alias.setValue(data.alias);
  61. this.validateForm.controls.incidentCategoryId.setValue(this.tool.tranListToTreeDataFindIdsLeaf(this.incidentCategoryList, data.incidentCategoryId));
  62. }
  63. // 新增弹框
  64. modelName = ""; //模态框名称
  65. modal: boolean = false; //新增/编辑模态框
  66. add: boolean; //true:新增;false:编辑
  67. validateForm: FormGroup; //新增/编辑表单
  68. coopData: any; //当前操作列
  69. addModal() {
  70. this.modelName = "新增";
  71. this.add = true; //新增
  72. this.modal = true;
  73. this.initForm();
  74. }
  75. //关闭新增/编辑弹框
  76. hideAddModal() {
  77. this.modal = false;
  78. this.initForm();
  79. }
  80. // 初始化新增form表单
  81. initForm() {
  82. this.validateForm = this.fb.group({
  83. alias: ['', [Validators.required, Validators.pattern(/\S/)]],
  84. incidentCategoryId: [null, [Validators.required]],
  85. });
  86. }
  87. // 新增/编辑表单提交
  88. btnLoading:boolean = false;
  89. submitAddForm(): void {
  90. for (const i in this.validateForm.controls) {
  91. this.validateForm.controls[i].markAsDirty();
  92. this.validateForm.controls[i].updateValueAndValidity();
  93. }
  94. if (this.validateForm.invalid) {
  95. return;
  96. }
  97. console.log(this.validateForm.value)
  98. this.btnLoading = true;
  99. let postData:any = {};
  100. if (this.add) {
  101. //增加
  102. postData = {
  103. // assetProductIncidentCategory: {
  104. hosId: this.currentHospital.id,
  105. alias: this.validateForm.value.alias,
  106. productId: this.id,
  107. incidentCategoryId: this.validateForm.value.incidentCategoryId.length ? this.validateForm.value.incidentCategoryId.slice(-1)[0] : undefined,
  108. // }
  109. };
  110. } else {
  111. //编辑
  112. postData = {
  113. // assetProductIncidentCategory:{
  114. ...this.coopData,
  115. ...{
  116. hosId: this.currentHospital.id,
  117. alias: this.validateForm.value.alias,
  118. productId: this.id,
  119. incidentCategoryId: this.validateForm.value.incidentCategoryId.length ? this.validateForm.value.incidentCategoryId.slice(-1)[0] : undefined,
  120. }
  121. // }
  122. };
  123. }
  124. console.log(postData);
  125. this.mainService
  126. .simplePost("addData", "assetProductIncidentCategory", postData)
  127. .subscribe((result) => {
  128. this.btnLoading = false;
  129. this.hideAddModal();
  130. let msg = "";
  131. if (this.add) {
  132. msg = "新增";
  133. } else {
  134. msg = "修改";
  135. }
  136. if (result.status == 200) {
  137. this.showPromptModal(msg, true, "");
  138. } else {
  139. this.showPromptModal(msg, false, result.msg);
  140. }
  141. });
  142. }
  143. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  144. promptContent: string; //操作提示框提示信息
  145. ifSuccess: boolean; //操作成功/失败
  146. promptInfo: string; //操作结果提示信息
  147. promptModalShow: boolean; //操作提示框是否展示
  148. showPromptModal(con, success, promptInfo?) {
  149. this.promptModalShow = false;
  150. this.promptContent = con;
  151. this.ifSuccess = success;
  152. this.promptInfo = promptInfo;
  153. setTimeout(() => {
  154. this.promptModalShow = true;
  155. }, 100);
  156. this.getList();
  157. }
  158. delModal: boolean = false; //删除模态框
  159. tipsMsg1: string; //提示框信息
  160. tipsMsg2: string; //操作后信息
  161. confirmDelType: string; //确认的类型(启用/停用,删除)
  162. confirmDelIsSwitch: boolean; //启用/停用
  163. showDelModal(
  164. e,
  165. data,
  166. tipsMsg1: string,
  167. tipsMsg2: string,
  168. type: string,
  169. isSwitch?: boolean
  170. ) {
  171. e.stopPropagation();
  172. this.confirmDelIsSwitch = isSwitch;
  173. this.confirmDelType = type;
  174. this.delModal = true;
  175. this.coopData = data;
  176. this.tipsMsg1 = tipsMsg1;
  177. this.tipsMsg2 = tipsMsg2;
  178. }
  179. // 隐藏删除框
  180. hideDelModal() {
  181. this.delModal = false;
  182. }
  183. // 确认删除
  184. confirmDel() {
  185. this.btnLoading = true;
  186. if (this.confirmDelType === "del") {
  187. //删除
  188. this.mainService
  189. .simplePost("rmvData", "assetProductIncidentCategory", [this.coopData.id])
  190. .subscribe((data) => {
  191. this.btnLoading = false;
  192. this.delModal = false;
  193. if (data.status == 200) {
  194. this.showPromptModal(this.tipsMsg2, true, "");
  195. } else {
  196. this.showPromptModal(this.tipsMsg2, false, data.msg);
  197. }
  198. });
  199. } else if (this.confirmDelType === "switch") {
  200. //启用/停用
  201. let postData = {
  202. // assetProductIncidentCategory:{
  203. ...this.coopData,
  204. ...{
  205. status: { key: 'product_category_status', value: this.confirmDelIsSwitch ? '0' : '1' },
  206. }
  207. // }
  208. };
  209. console.log(postData);
  210. this.mainService
  211. .simplePost("addData", "assetProductIncidentCategory", postData)
  212. .subscribe((data) => {
  213. this.btnLoading = false;
  214. this.delModal = false;
  215. if (data.status == 200) {
  216. this.showPromptModal(this.tipsMsg2, true, "");
  217. } else {
  218. this.showPromptModal(this.tipsMsg2, false, data.msg);
  219. }
  220. });
  221. }
  222. }
  223. // 关闭弹窗
  224. hideModal() {
  225. this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
  226. }
  227. // 获取列表数据
  228. getList() {
  229. let postData = {
  230. idx: 0,
  231. sum: 9999,
  232. assetProductIncidentCategory: {
  233. productId: this.id,
  234. hosId: this.currentHospital.id,
  235. }
  236. }
  237. this.hsLoading = true;
  238. this.mainService.getFetchDataList("data", "assetProductIncidentCategory", postData).subscribe(data => {
  239. this.hsLoading = false;
  240. this.historySpecimenList = data.list || [];
  241. })
  242. }
  243. }