incident-substitution.component.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
  2. import { MainService } from '../../../services/main.service';
  3. import { Router, ActivatedRoute } from '@angular/router';
  4. import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx';
  5. import { NzMessageService } from 'ng-zorro-antd';
  6. import { ToolService } from 'src/app/services/tool.service';
  7. import { IncidentSubstitutionRedeployComponent } from '../incident-substitutio-redeploy/incident-substitution-redeploy.component';
  8. import { IncidentSubstitutionAssignComponent } from '../incident-substitutio-assign/incident-substitution-assign.component';
  9. import { IncidentSubstitutionUpgradeComponent } from '../incident-substitutio-upgrade/incident-substitution-upgrade.component';
  10. import { IncidentSubstitutionReassignComponent } from '../incident-substitutio-reassign/incident-substitution-reassign.component';
  11. @Component({
  12. selector: 'app-incident-substitution',
  13. templateUrl: './incident-substitution.component.html',
  14. styleUrls: ['./incident-substitution.component.less']
  15. })
  16. export class IncidentSubstitutionComponent implements OnInit {
  17. @ViewChild("osComponentRef1", {
  18. read: OverlayScrollbarsComponent,
  19. static: false,
  20. })
  21. osComponentRef1: OverlayScrollbarsComponent;
  22. @ViewChild(IncidentSubstitutionRedeployComponent, { static: false }) redeploy!: IncidentSubstitutionRedeployComponent;
  23. @ViewChild(IncidentSubstitutionAssignComponent, { static: false }) assign!: IncidentSubstitutionAssignComponent;
  24. @ViewChild(IncidentSubstitutionUpgradeComponent, { static: false }) upgrade!: IncidentSubstitutionUpgradeComponent;
  25. @ViewChild(IncidentSubstitutionReassignComponent, { static: false }) reassign!: IncidentSubstitutionReassignComponent;
  26. @Output() closeModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
  27. @Output() confirmModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性,当事件发生时,子组件利用该属性 emits(向上弹射)事件
  28. @Input() id: any;
  29. constructor(
  30. private mainService: MainService,
  31. private router: Router,
  32. private route: ActivatedRoute,
  33. private message: NzMessageService,
  34. private tool: ToolService,
  35. ) { }
  36. isLoading = false;
  37. // 初始化增删改按钮
  38. coopBtns: any = {};
  39. tabs:any[] = [
  40. // {id: 1, name: '转派', value: 'redeploy', num: ''},
  41. // {id: 2, name: '指派', value: 'assign', num: ''},
  42. // {id: 3, name: '升级', value: 'upgrade', num: ''},
  43. // {id: 4, name: '退回', value: 'reassign', num: ''},
  44. ]
  45. ngOnInit() {
  46. this.coopBtns = this.tool.initCoopBtns(this.route);
  47. console.log(this.coopBtns)
  48. this.operationAuthority();
  49. }
  50. // 点击tab
  51. activeTabValue:any;
  52. clickTbab(item){
  53. this.activeTabValue = item.value;
  54. }
  55. // 操作权限
  56. incidentData:any = {};
  57. maskFlag:any = false;
  58. operationAuthority(){
  59. this.maskFlag = this.message.loading("正在加载中..", {
  60. nzDuration: 0,
  61. }).messageId;
  62. this.mainService
  63. .getFetchData("simple/data", "incident", this.id)
  64. .subscribe((result) => {
  65. this.message.remove(this.maskFlag);
  66. this.maskFlag = false;
  67. this.incidentData = result.data || {};
  68. // 转派
  69. if(this.incidentData.state.value == 'handler' && this.incidentData.handlingPersonnelUser && this.incidentData.handlingPersonnelUser.id == this.tool.getCurrentUserId() && !this.coopBtns.assign && this.coopBtns.transfer){
  70. this.tabs.splice(0, 0, {id: 1, name: '转派', value: 'redeploy', num: ''});
  71. }
  72. // 指派
  73. if((this.incidentData.state.value == 'pending' || this.incidentData.state.value == 'handler' || this.incidentData.state.value == 'reassign') && this.coopBtns.assign){
  74. let index = this.tabs.findIndex(v => v.value === 'reassign');
  75. if(index < 0){
  76. this.tabs = [{id: 2, name: '指派', value: 'assign', num: ''}];
  77. }else{
  78. this.tabs.splice(index, 0, {id: 2, name: '指派', value: 'assign', num: ''});
  79. }
  80. }
  81. // 退回
  82. if(this.incidentData.state.value == 'pending' || this.incidentData.state.value == 'handler'){
  83. if(this.tabs.length){
  84. this.tabs.splice(this.tabs.length, 0, {id: 4, name: '退回', value: 'reassign', num: ''});
  85. }else{
  86. this.tabs = [{id: 4, name: '退回', value: 'reassign', num: ''}];
  87. }
  88. }
  89. this.clickTbab(this.tabs[0]);
  90. });
  91. }
  92. // 关闭弹窗
  93. hideModal() {
  94. this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
  95. }
  96. // 表单提交
  97. submitForm(): void {
  98. if(this.activeTabValue === 'redeploy'){
  99. // 转派
  100. for (const i in this.redeploy.validateForm.controls) {
  101. this.redeploy.validateForm.controls[i].markAsDirty();
  102. this.redeploy.validateForm.controls[i].updateValueAndValidity();
  103. }
  104. if (this.redeploy.validateForm.invalid) {
  105. return;
  106. }
  107. this.maskFlag = this.message.loading("正在加载中..", {
  108. nzDuration: 0,
  109. }).messageId;
  110. let postData = {
  111. incident: this.incidentData,
  112. }
  113. postData.incident.redeployRemark = this.redeploy.validateForm.value.redeployRemark;
  114. if(this.redeploy.validateForm.value.userId){
  115. // 派人
  116. postData.incident.assignee = this.redeploy.validateForm.value.userId;
  117. } else {
  118. // 派组
  119. postData.incident.candidateGroups = this.redeploy.validateForm.value.groupId;
  120. delete postData.incident.assignee;
  121. }
  122. postData.incident.candidateGroupId = this.redeploy.validateForm.value.groupId;
  123. this.mainService
  124. .flowPost("incident/task/redeploy", postData)
  125. .subscribe((result) => {
  126. this.message.remove(this.maskFlag);
  127. this.maskFlag = false;
  128. this.confirmModelHs.emit();
  129. if (result.state == 200) {
  130. this.message.success('转派成功');
  131. } else {
  132. this.message.error('转派失败');
  133. }
  134. });
  135. }else if(this.activeTabValue === 'assign'){
  136. // 指派
  137. for (const i in this.assign.validateForm.controls) {
  138. this.assign.validateForm.controls[i].markAsDirty();
  139. this.assign.validateForm.controls[i].updateValueAndValidity();
  140. }
  141. if (this.assign.validateForm.invalid) {
  142. return;
  143. }
  144. this.maskFlag = this.message.loading("正在加载中..", {
  145. nzDuration: 0,
  146. }).messageId;
  147. let postData = {
  148. incident: this.incidentData,
  149. }
  150. if(this.assign.validateForm.value.userId){
  151. // 派人
  152. postData.incident.assignee = this.assign.validateForm.value.userId;
  153. } else {
  154. // 派组
  155. postData.incident.candidateGroups = this.assign.validateForm.value.groupId;
  156. delete postData.incident.assignee;
  157. }
  158. postData.incident.candidateGroupId = this.assign.validateForm.value.groupId;
  159. postData.incident.duty = { id: this.assign.validateForm.value.dutyId };
  160. this.mainService
  161. .flowPost("incident/task/assign", postData)
  162. .subscribe((result) => {
  163. this.message.remove(this.maskFlag);
  164. this.maskFlag = false;
  165. this.confirmModelHs.emit();
  166. if (result.state == 200) {
  167. this.message.success('指派成功');
  168. } else {
  169. this.message.error('指派失败');
  170. }
  171. });
  172. }else if(this.activeTabValue === 'reassign'){
  173. // 退回
  174. for (const i in this.reassign.validateForm.controls) {
  175. this.reassign.validateForm.controls[i].markAsDirty();
  176. this.reassign.validateForm.controls[i].updateValueAndValidity();
  177. }
  178. if (this.reassign.validateForm.invalid) {
  179. return;
  180. }
  181. this.maskFlag = this.message.loading("正在加载中..", {
  182. nzDuration: 0,
  183. }).messageId;
  184. let postData = {
  185. incident: this.incidentData,
  186. }
  187. postData.incident.reassignRemark = this.reassign.validateForm.value.reassignRemark;
  188. this.mainService
  189. .flowPost("incident/task/reassign", postData)
  190. .subscribe((result) => {
  191. this.message.remove(this.maskFlag);
  192. this.maskFlag = false;
  193. this.confirmModelHs.emit();
  194. if (result.state == 200) {
  195. this.message.success('退回成功');
  196. } else {
  197. this.message.error('退回失败');
  198. }
  199. });
  200. }
  201. }
  202. }