configuration-category.component.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute } from "@angular/router";
  3. import { Subject } from 'rxjs';
  4. import { debounceTime } from 'rxjs/operators';
  5. import { MainService } from "../../../services/main.service";
  6. import { Validators, FormGroup, FormBuilder } from '@angular/forms';
  7. import { ToolService } from 'src/app/services/tool.service';
  8. import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx';
  9. import cloneDeep from 'lodash-es/cloneDeep'
  10. @Component({
  11. selector: "app-configuration-category",
  12. templateUrl: "./configuration-category.component.html",
  13. styleUrls: ["./configuration-category.component.less"],
  14. })
  15. export class ConfigurationCategoryComponent implements OnInit {
  16. constructor(
  17. private route: ActivatedRoute,
  18. private mainService: MainService,
  19. private fb: FormBuilder,
  20. private tool: ToolService,
  21. ) {}
  22. @ViewChild("osComponentRef1", {
  23. read: OverlayScrollbarsComponent,
  24. static: false,
  25. })
  26. osComponentRef1: OverlayScrollbarsComponent;
  27. @ViewChild("osComponentRef2", {
  28. read: OverlayScrollbarsComponent,
  29. static: false,
  30. })
  31. osComponentRef2: OverlayScrollbarsComponent;
  32. @ViewChild("osComponentRef3", {
  33. read: OverlayScrollbarsComponent,
  34. static: false,
  35. })
  36. osComponentRef3: OverlayScrollbarsComponent;
  37. coopData: any = {}; //当前操作列
  38. currentHospital; //当前院区
  39. // 部门设置、全院设置
  40. hospitalConfig:any = 2;
  41. hospitalConfigList:any = [
  42. // { id: 1, name: '部门设置',},
  43. { id: 2, name: '全院设置',},
  44. ];
  45. changeInpSubject = new Subject(); //防抖
  46. debounceSubject = new Subject(); //防抖
  47. ngOnInit() {
  48. //防抖
  49. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  50. if(v[0] === 'user'){
  51. this.getUsers(v[1]);
  52. } else if(v[0] === 'group'){
  53. this.getGroups(v[1]);
  54. }
  55. });
  56. this.debounceSubject.pipe(debounceTime(500)).subscribe((v) => {
  57. if(v[0]){
  58. this.getCategoryList(v[0], v[1].id);
  59. }
  60. this.getCategoryConfigList(v[1].id);
  61. });
  62. this.currentHospital = this.tool.getCurrentHospital();
  63. // 故障现象
  64. setTimeout(() => {
  65. this.tableCategoryHeight = document.querySelector('#categoryTable').clientHeight - 8 - document.querySelector('#categoryTable .thead').clientHeight;
  66. }, 0)
  67. let { hospital, type } = this.tool.getHospitalOrDuty();
  68. if(type === 'duty'){
  69. // 是责任部门
  70. let flag = this.hospitalConfigList.some(v => v.id === 1);
  71. !flag && this.hospitalConfigList.unshift({ id: 1, name: '部门设置',});
  72. }
  73. this.getCategoryList(1);
  74. this.getHospitals(1);
  75. this.getHospitals(2);
  76. this.getPrioritys();
  77. this.getScores();
  78. }
  79. // 获取优先级
  80. priority_c_List: any = [];
  81. getPrioritys() {
  82. let postData = {
  83. priority: {},
  84. idx: 0,
  85. sum: 9999,
  86. };
  87. this.mainService
  88. .getFetchDataList("simple/data", "priority", postData)
  89. .subscribe((data) => {
  90. this.isLoading = false;
  91. this.priority_c_List = data.list || [];
  92. });
  93. }
  94. // 获取积分
  95. scoreList: any = [];
  96. getScores() {
  97. let postData = {
  98. dictionary: {
  99. key: "incident_category_score"
  100. },
  101. idx: 0,
  102. sum: 10,
  103. };
  104. this.mainService
  105. .getFetchDataList("simple/data", "dictionary", postData)
  106. .subscribe((data) => {
  107. this.isLoading = false;
  108. this.scoreList = data.list || [];
  109. });
  110. }
  111. // 边输边搜节流阀
  112. isLoading = false;
  113. changeInp(model, e) {
  114. this.isLoading = true;
  115. this.changeInpSubject.next([model, e]);
  116. }
  117. // 搜索
  118. // 获取用户
  119. userList: any = [];
  120. getUsers(keyword = '', isShowValue = false) {
  121. if((!this.validateConfigForm.value.groupId && this.validateConfigForm.value.userGroup === 1) || this.validateConfigForm.value.userGroup === 2){
  122. this.isLoading = false;
  123. this.userList = [];
  124. return;
  125. }
  126. let postData = {
  127. user: {
  128. name: keyword,
  129. simpleQuery: true,
  130. groupdata: { id: this.validateConfigForm.value.groupId },
  131. roleCodes: 'first-line support',
  132. engineer: 1,
  133. },
  134. idx: 0,
  135. sum: 10,
  136. };
  137. this.mainService
  138. .getFetchDataList("data", "user", postData)
  139. .subscribe((data) => {
  140. this.isLoading = false;
  141. let userList = data.list || [];
  142. if(isShowValue && this.coopData && this.coopData.userId){
  143. userList = userList.filter(v => v.id !== this.coopData.userId)
  144. userList.unshift(this.coopData.userDTO);
  145. }
  146. this.userList = userList;
  147. });
  148. }
  149. // 获取组
  150. groupList: any = []; //所有所属科室(搜索)
  151. getGroups(keyword = '', isShowValue = false) {
  152. if(!this.validateConfigForm.value.dutyId){
  153. this.isLoading = false;
  154. this.groupList = [];
  155. return;
  156. }
  157. let postData = {
  158. group2: {
  159. groupName: keyword,
  160. hospitals: this.validateConfigForm.value.dutyId,
  161. type: 3,
  162. },
  163. idx: 0,
  164. sum: 10,
  165. };
  166. this.mainService
  167. .getFetchDataList("data", "group2", postData)
  168. .subscribe((data) => {
  169. this.isLoading = false;
  170. let groupList = data.list || [];
  171. if(isShowValue && this.coopData && this.coopData.groupId){
  172. groupList = groupList.filter(v => v.id !== this.coopData.groupId)
  173. groupList.unshift(this.coopData.groupDTO);
  174. }
  175. this.groupList = groupList;
  176. });
  177. }
  178. // 点击故障现象
  179. activeCategory1:any = {};
  180. activeCategory2:any = {};
  181. activeCategory3:any = {};
  182. clickCategory(item, type:number){
  183. this.categoryConfigList = [];
  184. switch(type){
  185. case 1:
  186. this.categoryList2 = [];
  187. this.categoryList3 = [];
  188. this.activeCategory2 = {};
  189. this.activeCategory3 = {};
  190. break;
  191. case 2:
  192. this.categoryList3 = [];
  193. this.activeCategory3 = {};
  194. break;
  195. }
  196. this['activeCategory' + type] = item;
  197. console.log(this['activeCategory' + type])
  198. switch(type){
  199. case 1:
  200. this.categoryLoading2 = true;
  201. this.loading1 = true;
  202. this.debounceSubject.next([2, item]);
  203. break;
  204. case 2:
  205. this.categoryLoading3 = true;
  206. this.loading1 = true;
  207. this.debounceSubject.next([3, item]);
  208. break;
  209. case 3:
  210. this.loading1 = true;
  211. this.debounceSubject.next([0, item]);
  212. break;
  213. }
  214. }
  215. // 选择部门设置或全院设置
  216. changeHospitalConfig(e){
  217. console.log(e);
  218. this.getCategoryList(1);
  219. this.categoryList2 = [];
  220. this.categoryList3 = [];
  221. this.activeCategory1 = {};
  222. this.activeCategory2 = {};
  223. this.activeCategory3 = {};
  224. this.categoryConfigList = [];
  225. }
  226. // 获取当前选中的故障现象索引
  227. get currentCategoryIndex(){
  228. if(this.activeCategory3.id){
  229. return 3;
  230. }
  231. if(this.activeCategory2.id){
  232. return 2;
  233. }
  234. if(this.activeCategory1.id){
  235. return 1;
  236. }
  237. }
  238. // 获取当前选中的故障现象索引
  239. get currentCategory(){
  240. if(this.activeCategory3.id){
  241. return this.activeCategory3;
  242. }
  243. if(this.activeCategory2.id){
  244. return this.activeCategory2;
  245. }
  246. if(this.activeCategory1.id){
  247. return this.activeCategory1;
  248. }
  249. }
  250. // 获取当前选中的故障现象有没有子故障现象
  251. get currentChildrenCategoryList(){
  252. return this.currentCategoryIndex && this.currentCategoryIndex < 3 && this['categoryList' + (this.currentCategoryIndex + 1)].length;
  253. }
  254. categoryConfigList:any[] = [];
  255. getCategoryConfigList(parentId = 0) {
  256. this.loading1 = true;
  257. let postData = {
  258. idx: 0,
  259. sum: 9999,
  260. incidentCategoryConfig: {
  261. categoryId: parentId,
  262. dutyId: this.hospitalConfig === 1 ? this.currentHospital.id : undefined,
  263. },
  264. };
  265. this.mainService.getFetchDataList("simple/data", "incidentCategoryConfig", postData).subscribe(res => {
  266. this.loading1 = false;
  267. this.categoryConfigList = res.list || [];
  268. })
  269. }
  270. // 修改院区
  271. changeHospital(id){
  272. this.validateConfigForm.controls.dutyId.setValue(null);
  273. this.validateConfigForm.controls.userId.setValue(null);
  274. this.validateConfigForm.controls.groupId.setValue(null);
  275. // this.dutyList = [];
  276. this.userList = [];
  277. this.groupList = [];
  278. // this.getHospitals(2, id);
  279. }
  280. // 获取院区
  281. hospitalList: any = [];
  282. dutyList: any = [];
  283. getHospitals(type:number, parentId?) {
  284. if(type === 1){
  285. this.isLoading = false;
  286. this.hospitalList = this.tool.getHospitalList().filter(v => !v.parent);
  287. return;
  288. }
  289. // if(type === 2 && !parentId){
  290. // this.isLoading = false;
  291. // this.dutyList = [];
  292. // return;
  293. // }
  294. let postData = {
  295. hospital: {
  296. // parent: { id: parentId },
  297. type: { key: 'hospital_type', value: '6' },
  298. },
  299. idx: 0,
  300. sum: 9999,
  301. };
  302. this.mainService
  303. .getFetchDataList("data", "hospital", postData)
  304. .subscribe((data) => {
  305. this.isLoading = false;
  306. this.dutyList = data.list || [];
  307. });
  308. }
  309. // 修改责任部门
  310. changeDuty(id){
  311. this.validateConfigForm.controls.userId.setValue(null);
  312. this.validateConfigForm.controls.groupId.setValue(null);
  313. this.userList = [];
  314. this.groupList = [];
  315. this.getGroups();
  316. }
  317. // 一级故障现象
  318. loading1:boolean = false;
  319. tableCategoryHeight:number = 0;
  320. categoryList1: any[] = [];
  321. categoryList2: any[] = [];
  322. categoryList3: any[] = [];
  323. categoryLoading1:boolean = false;
  324. categoryLoading2:boolean = false;
  325. categoryLoading3:boolean = false;
  326. getCategoryList(type:number, parentId = 0, isEdit = false, isOnly = false) {
  327. setTimeout(() => {
  328. this['categoryLoading' + type] = true;
  329. }, 0)
  330. let postData = {
  331. category: {
  332. hierarchy: type === 1 ? 1 : undefined,
  333. dutyIds: this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined,
  334. parent: type === 1 ? undefined : { id: parentId },
  335. },
  336. };
  337. this.mainService.incidentPost("listIncidentCategory", postData).subscribe(res => {
  338. this['categoryLoading' + type] = false;
  339. this['categoryList' + type] = res.data || [];
  340. this['categoryListP' + type] = cloneDeep(this['categoryList' + type]);
  341. if(isEdit){
  342. this['activeCategory' + type] = this['categoryList' + type].find(v => v.id == this['activeCategory' + type].id);
  343. }
  344. if(isOnly){
  345. this['activeCategory' + type] = this['categoryList' + type].find(v => v.id == this.validateCategoryForm.value['category' + type]);
  346. }
  347. })
  348. }
  349. // 弹窗-故障现象查询
  350. categoryListP1: any[] = [];
  351. categoryListP2: any[] = [];
  352. categoryListP3: any[] = [];
  353. getCategoryListP(type:number, parentId = 0) {
  354. this.isLoading = true;
  355. let postData = {
  356. category: {
  357. hierarchy: type === 1 ? 1 : undefined,
  358. dutyIds: this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined,
  359. parent: type === 1 ? undefined : { id: parentId },
  360. },
  361. };
  362. this.mainService.incidentPost("listIncidentCategory", postData).subscribe(res => {
  363. this.isLoading = false;
  364. this['categoryListP' + type] = res.data || [];
  365. })
  366. }
  367. // 新增故障现象弹框
  368. modelName = ""; //模态框名称
  369. add: boolean; //true:新增;false:编辑
  370. modalCategory: boolean = false; //新增/编辑模态框
  371. coopType: number = 0;
  372. addCategoryModal(type:number) {
  373. this.coopType = type;
  374. this.modelName = "新增";
  375. this.add = true; //新增
  376. this.modalCategory = true;
  377. this.initCategoryForm();
  378. }
  379. //关闭新增/编辑弹框
  380. hideCategoryModal() {
  381. this.modalCategory = false;
  382. }
  383. // 初始化新增form表单
  384. validateCategoryForm: FormGroup; //新增/编辑表单
  385. initCategoryForm(isEdit = false) {
  386. if(isEdit){
  387. if(this.coopType === 1){
  388. this.validateCategoryForm = this.fb.group({
  389. name: [null, [Validators.required]],//名称
  390. });
  391. }else if(this.coopType === 2){
  392. this.validateCategoryForm = this.fb.group({
  393. category1: [null, [Validators.required]],//一级故障现象
  394. name: [null, [Validators.required]],//名称
  395. });
  396. }else if(this.coopType === 3){
  397. this.validateCategoryForm = this.fb.group({
  398. category1: [null, [Validators.required]],//一级故障现象
  399. category2: [null, [Validators.required]],//二级故障现象
  400. name: [null, [Validators.required]],//名称
  401. });
  402. }
  403. }else{
  404. this.validateCategoryForm = this.fb.group({
  405. name: [null, [Validators.required]],//名称
  406. });
  407. }
  408. console.log(this.validateCategoryForm.controls)
  409. }
  410. // 编辑
  411. editCategory(type, data) {
  412. console.log(data);
  413. this.coopType = type;
  414. this.modelName = "编辑";
  415. this.add = false;
  416. this.modalCategory = true;
  417. this.initCategoryForm(true);
  418. this.coopData = data;
  419. this.validateCategoryForm.controls.name.setValue(data.category);
  420. if(type === 2){
  421. this.categoryListP1 = cloneDeep(this.categoryList1);
  422. this.validateCategoryForm.controls.category1.setValue(this.activeCategory1.id);
  423. }else if(type === 3){
  424. this.categoryListP1 = cloneDeep(this.categoryList1);
  425. this.categoryListP2 = cloneDeep(this.categoryList2);
  426. this.validateCategoryForm.controls.category1.setValue(this.activeCategory1.id);
  427. this.validateCategoryForm.controls.category2.setValue(this.activeCategory2.id);
  428. }
  429. }
  430. // 删除
  431. deleteType; //删除类型
  432. removeCategory(type, data) {
  433. this.deleteType = type;
  434. this.showDelModal(data,'您确认要删除吗?','删除','delCategory');
  435. }
  436. // 新增/编辑表单提交
  437. btnLoading: boolean = false; //提交按钮loading状态
  438. submitCategoryForm(): void {
  439. for (const i in this.validateCategoryForm.controls) {
  440. this.validateCategoryForm.controls[i].markAsDirty();
  441. this.validateCategoryForm.controls[i].updateValueAndValidity();
  442. }
  443. if (this.validateCategoryForm.invalid) {
  444. return;
  445. }
  446. console.log(this.validateCategoryForm.value);
  447. this.btnLoading = true;
  448. // -----------------------------------
  449. if(this.add){
  450. // 新增
  451. let postData:any = {
  452. category: {
  453. hosId: this.currentHospital.id,
  454. parent: this.coopType === 1 ? undefined : this['activeCategory' + (this.coopType - 1)],
  455. category: this.validateCategoryForm.value.name,
  456. hierarchy: this.coopType,
  457. dutyIds: this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined,
  458. },
  459. };
  460. this.mainService
  461. .incidentPost("checkIncidentCategory", postData)
  462. .subscribe((result) => {
  463. if (result.status == 200) {
  464. this.submitCategoryAddForm();
  465. } else if(result.status == 502) {
  466. this.btnLoading = false;
  467. this.showDelModal(null, result.msg, '', 'relevance');
  468. } else {
  469. this.btnLoading = false;
  470. this.showPromptModal('新增', false, result.msg);
  471. }
  472. });
  473. }else{
  474. // 编辑
  475. console.log(this['activeCategory' + this.coopType])
  476. //编辑
  477. let postData = {
  478. incidentCategory: {
  479. ...this.coopData,
  480. parent: this.coopType === 1 ? undefined : (this.coopType === 2 ? { id: this.validateCategoryForm.value.category1 } : { id: this.validateCategoryForm.value.category2 }),
  481. category: this.validateCategoryForm.value.name,
  482. }
  483. };
  484. console.log(postData);
  485. this.mainService
  486. .coopData("updData", "incidentCategory", postData)
  487. .subscribe((result) => {
  488. this.btnLoading = false;
  489. this.hideCategoryModal();
  490. if (result.status == 200) {
  491. this.showPromptModal('编辑', true, '');
  492. } else {
  493. this.showPromptModal('编辑', false, result.msg);
  494. }
  495. });
  496. }
  497. // -----------------------------------
  498. }
  499. delModal: boolean = false; //删除模态框
  500. tipsMsg1: string; //提示框信息
  501. tipsMsg2: string; //操作后信息
  502. confirmDelType: string; //确认的类型(启用/停用,删除)
  503. showDelModal(
  504. data,
  505. tipsMsg1: string,
  506. tipsMsg2: string,
  507. type: string,
  508. ) {
  509. this.confirmDelType = type;
  510. this.delModal = true;
  511. this.coopData = data;
  512. this.tipsMsg1 = tipsMsg1;
  513. this.tipsMsg2 = tipsMsg2;
  514. }
  515. // 隐藏删除框
  516. hideDelModal() {
  517. this.delModal = false;
  518. }
  519. // 确认删除
  520. confirmDel() {
  521. this.btnLoading = true;
  522. if (this.confirmDelType === "relevance") {
  523. //新增故障现象-关联
  524. this.btnLoading = false;
  525. this.delModal = false;
  526. this.submitCategoryAddForm();
  527. } else if (this.confirmDelType === "delConfig") {
  528. //删除-关联
  529. this.mainService
  530. .simplePost("rmvData", "incidentCategoryConfig", [this.coopData.id])
  531. .subscribe((data) => {
  532. this.btnLoading = false;
  533. this.delModal = false;
  534. if (data.status == 200) {
  535. this.showPromptModal(this.tipsMsg2, true, "");
  536. } else {
  537. this.showPromptModal(this.tipsMsg2, false, data.msg);
  538. }
  539. });
  540. } else if (this.confirmDelType === "delCategory") {
  541. //删除-故障现象
  542. this.mainService
  543. .deleteIncidentCategory({categoryId: this.coopData.id})
  544. .subscribe((data:any) => {
  545. this.btnLoading = false;
  546. this.delModal = false;
  547. if (data.status == 200) {
  548. this['activeCategory' + this.deleteType] = {};
  549. this.categoryConfigList = [];
  550. this.showPromptModal(this.tipsMsg2, true, "", this.deleteType);
  551. } else {
  552. this.showPromptModal(this.tipsMsg2, false, data.msg);
  553. }
  554. });
  555. } else if (this.confirmDelType === "copy") {
  556. //向下复制-关联
  557. let postData:any = {
  558. type: this.hospitalConfig === 1 ? 'duty': 'hospital',
  559. category: this.currentCategory,
  560. };
  561. postData.category.dutyIds = this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined;
  562. this.mainService
  563. .incidentPost("copyIncidentCategoryConfig", postData)
  564. .subscribe((data) => {
  565. this.btnLoading = false;
  566. this.delModal = false;
  567. if (data.status == 200) {
  568. this.showPromptModal(this.tipsMsg2, true, "");
  569. } else {
  570. this.showPromptModal(this.tipsMsg2, false, data.msg);
  571. }
  572. });
  573. }
  574. }
  575. submitCategoryAddForm(): void {
  576. let postData:any = {};
  577. if (this.add) {
  578. //增加
  579. console.log(this['activeCategory' + this.coopType])
  580. postData = {
  581. category: {
  582. hosId: this.currentHospital.id,
  583. parent: this.coopType === 1 ? undefined : this['activeCategory' + (this.coopType - 1)],
  584. category: this.validateCategoryForm.value.name,
  585. hierarchy: this.coopType,
  586. dutyIds: this.hospitalConfig === 1 ? this.currentHospital.id.toString() : undefined,
  587. },
  588. };
  589. } else {
  590. //编辑
  591. // postData = {
  592. // category: {
  593. // hosId: this.currentHospital.id,
  594. // parent: this.coopType === 1 ? undefined : { id: this.coopData.id },
  595. // category: this.validateCategoryForm.value.name,
  596. // hierarchy: this.coopType,
  597. // },
  598. // };
  599. }
  600. this.mainService
  601. .incidentPost("addIncidentCategory", postData)
  602. .subscribe((result) => {
  603. this.btnLoading = false;
  604. this.hideCategoryModal();
  605. let msg = "";
  606. if (this.add) {
  607. msg = "新增";
  608. } else {
  609. msg = "修改";
  610. }
  611. if (result.status == 200) {
  612. this.showPromptModal(msg, true, '');
  613. } else {
  614. this.showPromptModal(msg, false, result.msg);
  615. }
  616. });
  617. }
  618. // ------------------------------
  619. // 新增故障现象-关联弹框
  620. modalConfig: boolean = false; //新增/编辑模态框
  621. addConfigModal() {
  622. this.modelName = "新增";
  623. this.add = true; //新增
  624. this.modalConfig = true;
  625. this.initConfigForm();
  626. this.requiredConfigChange('userId', true);
  627. }
  628. //关闭新增/编辑弹框
  629. hideConfigModal() {
  630. this.modalConfig = false;
  631. }
  632. // 初始化新增form表单
  633. validateConfigForm: FormGroup; //新增/编辑表单
  634. initConfigForm() {
  635. this.validateConfigForm = this.fb.group({
  636. hosId: [null, [Validators.required]],//院区
  637. dutyId: [null, [Validators.required]],//责任部门
  638. priority: [null, [Validators.required]],//优先级
  639. score: [null, [Validators.required]],//积分
  640. userGroup: [1, [Validators.required]],//分配方式
  641. userId: [null],//维修人
  642. groupId: [null, [Validators.required]],//维修组
  643. });
  644. console.log(this.validateConfigForm.controls)
  645. }
  646. // 选择人|组
  647. changeUserGroup(id){
  648. this.validateConfigForm.controls.userId.setValue(null);
  649. this.validateConfigForm.controls.groupId.setValue(null);
  650. this.userList = [];
  651. if(id === 1){
  652. // 人
  653. this.requiredConfigChange('userId', true);
  654. }else if(id === 2){
  655. // 组
  656. this.requiredConfigChange('userId', false);
  657. }
  658. }
  659. // 编辑
  660. editConfig(data) {
  661. console.log(data);
  662. this.modelName = "编辑";
  663. this.add = false;
  664. this.modalConfig = true;
  665. this.initConfigForm();
  666. this.coopData = data;
  667. this.validateConfigForm.controls.hosId.setValue(data.hosId);
  668. this.validateConfigForm.controls.dutyId.setValue(data.dutyId);
  669. this.validateConfigForm.controls.priority.setValue(data.priority);
  670. this.validateConfigForm.controls.score.setValue(data.score ? data.score.id : null);
  671. this.validateConfigForm.controls.userGroup.setValue(data.userGroup);
  672. this.validateConfigForm.controls.userId.setValue(data.userId);
  673. this.validateConfigForm.controls.groupId.setValue(data.groupId);
  674. if(data.userGroup === 1){
  675. this.requiredConfigChange('userId', true);
  676. }else if(data.userGroup === 2){
  677. this.requiredConfigChange('userId', false);
  678. }
  679. // data.hosId && this.getHospitals(2, data.hosId);
  680. data.dutyId && this.getUsers('', true);
  681. data.dutyId && this.getGroups('', true);
  682. }
  683. // 修改组
  684. changeGroup(id){
  685. this.validateConfigForm.controls.userId.setValue(null);
  686. this.getUsers();
  687. }
  688. // 新增/编辑表单提交
  689. submitConfigForm(): void {
  690. for (const i in this.validateConfigForm.controls) {
  691. this.validateConfigForm.controls[i].markAsDirty();
  692. this.validateConfigForm.controls[i].updateValueAndValidity();
  693. }
  694. if (this.validateConfigForm.invalid) {
  695. return;
  696. }
  697. console.log(this.validateConfigForm.value);
  698. this.btnLoading = true;
  699. let postData:any = {};
  700. let categoryId = this.activeCategory3.id || this.activeCategory2.id || this.activeCategory1.id;
  701. if (this.add) {
  702. //增加
  703. postData = {
  704. incidentCategoryConfig: {
  705. categoryId,
  706. priority: this.validateConfigForm.value.priority,
  707. score: { id: this.validateConfigForm.value.score },
  708. dutyId: this.validateConfigForm.value.dutyId,
  709. userGroup: this.validateConfigForm.value.userGroup,
  710. groupId: this.validateConfigForm.value.groupId || undefined,
  711. userId: this.validateConfigForm.value.userGroup === 1 ? this.validateConfigForm.value.userId : undefined,
  712. hosId: this.hospitalConfig === 1 ? this.currentHospital.id : this.validateConfigForm.value.hosId,
  713. }
  714. };
  715. } else {
  716. //编辑
  717. postData = {
  718. incidentCategoryConfig: {
  719. ...this.coopData,
  720. ...{
  721. categoryId,
  722. priority: this.validateConfigForm.value.priority,
  723. score: { id: this.validateConfigForm.value.score },
  724. userGroup: this.validateConfigForm.value.userGroup,
  725. groupId: this.validateConfigForm.value.groupId || undefined,
  726. userId: this.validateConfigForm.value.userGroup === 1 ? this.validateConfigForm.value.userId : undefined,
  727. }
  728. }
  729. };
  730. }
  731. console.log(postData);
  732. this.mainService
  733. .coopData("addData", "incidentCategoryConfig", postData)
  734. .subscribe((result) => {
  735. this.btnLoading = false;
  736. this.hideConfigModal();
  737. let msg = "";
  738. if (this.add) {
  739. msg = "新增";
  740. } else {
  741. msg = "修改";
  742. }
  743. if (result.status == 200) {
  744. this.showPromptModal(msg, true, '');
  745. } else {
  746. this.showPromptModal(msg, false, result.msg);
  747. }
  748. });
  749. }
  750. requiredConfigChange(name: string, required: boolean): void {
  751. if (!required) {
  752. this.validateConfigForm.get(name)!.clearValidators();
  753. this.validateConfigForm.get(name)!.markAsPristine();
  754. } else {
  755. this.validateConfigForm.get(name)!.setValidators(Validators.required);
  756. this.validateConfigForm.get(name)!.markAsDirty();
  757. }
  758. this.validateConfigForm.get(name)!.updateValueAndValidity();
  759. }
  760. // 修改故障现象
  761. changeOneCategory(id){
  762. this.validateCategoryForm.controls.category2.setValue(null);
  763. this.getCategoryListP(2, id);
  764. }
  765. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  766. promptContent: string; //操作提示框提示信息
  767. ifSuccess: boolean; //操作成功/失败
  768. promptInfo: string; //操作结果提示信息
  769. promptModalShow: boolean; //操作提示框是否展示
  770. showPromptModal(con, success, promptInfo?, deleteType?) {
  771. this.promptModalShow = false;
  772. this.promptContent = con;
  773. this.ifSuccess = success;
  774. this.promptInfo = promptInfo;
  775. setTimeout(() => {
  776. this.promptModalShow = true;
  777. }, 100);
  778. if(con === '编辑'){
  779. if(success){
  780. if(this.coopType === 1){
  781. this.getCategoryList(1, 0, true);
  782. }else if(this.coopType === 2){
  783. this.getCategoryList(1, 0, false, true);
  784. this.getCategoryList(2, this.validateCategoryForm.value.category1, true);
  785. }else if(this.coopType === 3){
  786. this.getCategoryList(1, 0, false, true);
  787. this.getCategoryList(2, this.validateCategoryForm.value.category1, false, true);
  788. this.getCategoryList(3, this.validateCategoryForm.value.category2, true);
  789. }
  790. }
  791. }else{
  792. if(deleteType){
  793. this.getCategoryList(deleteType, deleteType === 1 ? undefined : this['activeCategory' + (deleteType - 1)].id);
  794. }else{
  795. if(this.coopType !== 0){
  796. this.getCategoryList(this.coopType, this.coopType === 1 ? undefined : this['activeCategory' + (this.coopType - 1)].id);
  797. }else{
  798. this.getCategoryList(this.currentCategoryIndex, this.currentCategoryIndex === 1 ? undefined : this['activeCategory' + (this.currentCategoryIndex - 1)].id);
  799. }
  800. if(this.activeCategory3.id || this.activeCategory2.id || this.activeCategory1.id){
  801. this.getCategoryConfigList(this.activeCategory3.id || this.activeCategory2.id || this.activeCategory1.id);
  802. }
  803. }
  804. }
  805. }
  806. }