configuration-dictionary.component.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. import { Component, OnInit, ViewChild, Input } from "@angular/core";
  2. import { ActivatedRoute } from "@angular/router";
  3. import { MainService } from "../../../services/main.service";
  4. import { Validators, FormGroup, FormBuilder, FormControl } from '@angular/forms';
  5. import { ToolService } from 'src/app/services/tool.service';
  6. import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx';
  7. import { NzMessageService } from 'ng-zorro-antd';
  8. import { v4 as uuidv4, validate as uuidValidate } from 'uuid';
  9. import { Subject } from 'rxjs';
  10. import { debounceTime } from 'rxjs/operators';
  11. @Component({
  12. selector: "app-configuration-dictionary",
  13. templateUrl: "./configuration-dictionary.component.html",
  14. styleUrls: ["./configuration-dictionary.component.less"],
  15. })
  16. export class ConfigurationDictionaryComponent implements OnInit {
  17. constructor(
  18. private route: ActivatedRoute,
  19. private mainService: MainService,
  20. private fb: FormBuilder,
  21. private tool: ToolService,
  22. private message: NzMessageService,
  23. ) {}
  24. @ViewChild("osComponentRef1", {
  25. read: OverlayScrollbarsComponent,
  26. static: false,
  27. })
  28. osComponentRef1: OverlayScrollbarsComponent;
  29. @ViewChild("osComponentRef2", {
  30. read: OverlayScrollbarsComponent,
  31. static: false,
  32. })
  33. osComponentRef2: OverlayScrollbarsComponent;
  34. changeCommonInpSubject = new Subject();
  35. hosId:any;
  36. ngOnInit() {
  37. this.activeDictionaryKey = this.dictionaryKeyList[0];
  38. this.hosId = this.tool.getCurrentHospital().id;
  39. this.getDictionaryList();
  40. this.initDictionaryForm();
  41. this.getHosList();
  42. }
  43. // 数据字典key列表
  44. @Input() dictionaryKeyList: any[] = [];
  45. // 点击数据字典key
  46. activeDictionaryKey:any;
  47. clickDictionaryKey(item){
  48. this.activeDictionaryKey = item;
  49. if(item.key=='business_type'){
  50. setTimeout(() => {
  51. this.tablePriorityHeight = document.querySelector('#priorityTable').clientHeight - document.querySelector('#priorityTable .list-template__top').clientHeight - 8 - document.querySelector('#priorityTable .thead').clientHeight;
  52. }, 100)
  53. this.getCommonFaultsList();
  54. }else{
  55. this.getDictionaryList();
  56. }
  57. }
  58. btnLoading: boolean = false; //提交按钮loading状态
  59. // ------------------------------
  60. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  61. promptContent: string; //操作提示框提示信息
  62. ifSuccess: boolean; //操作成功/失败
  63. promptInfo: string; //操作结果提示信息
  64. promptModalShow: boolean; //操作提示框是否展示
  65. showPromptModal(con, success, promptInfo?) {
  66. this.promptModalShow = false;
  67. this.promptContent = con;
  68. this.ifSuccess = success;
  69. this.promptInfo = promptInfo;
  70. setTimeout(() => {
  71. this.promptModalShow = true;
  72. }, 100);
  73. if(this.activeDictionaryKey.key=='business_type'){
  74. this.getCommonFaultsList();
  75. }else{
  76. this.getDictionaryList();
  77. }
  78. }
  79. coopData: any = {}; //当前操作列
  80. delModal: boolean = false; //删除模态框
  81. tipsMsg1: string; //提示框信息
  82. tipsMsg2: string; //操作后信息
  83. confirmDelType: string; //确认的类型(启用/停用,删除)
  84. showDelModal(
  85. data,
  86. tipsMsg1: string,
  87. tipsMsg2: string,
  88. type: string,
  89. ) {
  90. this.confirmDelType = type;
  91. this.delModal = true;
  92. this.coopData = data;
  93. this.tipsMsg1 = tipsMsg1;
  94. this.tipsMsg2 = tipsMsg2;
  95. }
  96. // 隐藏删除框
  97. hideDelModal() {
  98. this.delModal = false;
  99. }
  100. // 确认删除
  101. confirmDel() {
  102. this.btnLoading = true;
  103. if (this.confirmDelType === "delDictionary") {
  104. //删除-数据字典
  105. this.mainService
  106. .simplePost("rmvData", "dictionary", [this.coopData.id])
  107. .subscribe((data) => {
  108. this.btnLoading = false;
  109. this.delModal = false;
  110. if (data.status == 200) {
  111. this.mainService.clearDictionary();
  112. this.showPromptModal(this.tipsMsg2, true, "");
  113. } else {
  114. this.showPromptModal(this.tipsMsg2, false, data.msg);
  115. }
  116. });
  117. }
  118. }
  119. // 初始化数据字典新增form表单
  120. validateDictionaryForm: FormGroup; //新增/编辑表单
  121. dictionaryList: any = [];
  122. initDictionaryForm() {
  123. this.validateDictionaryForm = this.fb.group({
  124. // name: [null, [Validators.required]],//键
  125. // value: [null, [Validators.required]],//值
  126. // orders: [null, [Validators.required]],//排序号
  127. });
  128. console.log(this.validateDictionaryForm.controls)
  129. }
  130. // 获取数据字典数据
  131. maskFlag: any = false;
  132. initTyepe:boolean = false;
  133. getDictionaryList() {
  134. this.initTyepe = false
  135. let postData = {
  136. idx: 0,
  137. sum: 9999,
  138. dictionary: {
  139. key: this.activeDictionaryKey.key,
  140. }
  141. }
  142. this.maskFlag = this.message.loading("正在加载中..", {
  143. nzDuration: 0,
  144. }).messageId;
  145. this.mainService.getFetchDataList('simple/data','dictionary',postData).subscribe(data => {
  146. this.message.remove(this.maskFlag);
  147. this.maskFlag = false;
  148. let list = data.list || [];
  149. if(list.length){
  150. if(this.activeDictionaryKey.key == 'alarm_urgency'){
  151. this.dictionaryList = list.map(v => {
  152. return {
  153. id: v.id,
  154. name: v.name || null,
  155. value: v.value || null,
  156. orders: v.orders || null,
  157. system: v.system || false,
  158. extra1: v.extra1 || null,
  159. }
  160. });
  161. }else{
  162. this.dictionaryList = list.map(v => {
  163. return {
  164. id: v.id,
  165. name: v.name || null,
  166. value: v.value || null,
  167. orders: v.orders || null,
  168. system: v.system || false,
  169. }
  170. });
  171. }
  172. }else{
  173. if(this.activeDictionaryKey.key == 'alarm_urgency'){
  174. this.dictionaryList = [
  175. {
  176. id: uuidv4(),
  177. name: null,
  178. value: null,
  179. orders: null,
  180. system: false,
  181. extra1: null,
  182. }
  183. ];
  184. }else{
  185. this.dictionaryList = [
  186. {
  187. id: uuidv4(),
  188. name: null,
  189. value: null,
  190. orders: null,
  191. system: false,
  192. }
  193. ];
  194. }
  195. }
  196. // 动态添加表单
  197. this.dictionaryList.forEach((obj, i) => {
  198. for (const key in obj) {
  199. if(key !== 'id' && key !== 'system'){
  200. if(this.activeDictionaryKey.key === 'incident_status' || this.activeDictionaryKey.key === 'incident_degree'){
  201. this.validateDictionaryForm.addControl(key + '_' + obj.id, new FormControl({value: obj[key], disabled: true}, [Validators.required]))
  202. }else if(this.activeDictionaryKey.key === 'alarm_urgency'){
  203. this.validateDictionaryForm.addControl(key + '_' + obj.id, new FormControl({value: obj[key], disabled: key === 'value' ? obj.system : false}, []))
  204. }else{
  205. this.validateDictionaryForm.addControl(key + '_' + obj.id, new FormControl({value: obj[key], disabled: key === 'value' ? obj.system : false}, [Validators.required]))
  206. }
  207. }
  208. }
  209. })
  210. setTimeout(_=>{
  211. this.initTyepe = true
  212. },1000)
  213. })
  214. }
  215. // 添加数据字典
  216. addField(i:number): void{
  217. let obj:any = {}
  218. if(this.activeDictionaryKey.key == 'alarm_urgency'){
  219. obj = {
  220. id: uuidv4(),
  221. name: null,
  222. value: null,
  223. orders: null,
  224. system: false,
  225. extra1:null,
  226. };
  227. }else{
  228. obj = {
  229. id: uuidv4(),
  230. name: null,
  231. value: null,
  232. orders: null,
  233. system: false,
  234. };
  235. }
  236. // 动态添加表单
  237. for (const key in obj) {
  238. console.log(key + '_' + obj.id)
  239. if(key !== 'id' && key !== 'system'){
  240. if(key !== 'extra1'){
  241. this.validateDictionaryForm.addControl(key + '_' + obj.id, new FormControl(null, [Validators.required]))
  242. }else{
  243. this.validateDictionaryForm.addControl(key + '_' + obj.id, new FormControl(null, []))
  244. }
  245. }
  246. }
  247. this.dictionaryList.splice(i + 1, 0, obj);
  248. }
  249. // 删除
  250. removeField(obj, i:number): void {
  251. if(uuidValidate(obj.id)){
  252. this.dictionaryList.splice(i, 1);
  253. this.dictionaryList = [...this.dictionaryList];
  254. // 动态删除表单
  255. for (const key in obj) {
  256. this.validateDictionaryForm.removeControl(key + '_' + obj.id);
  257. }
  258. }else{
  259. this.showDelModal(obj,'您确认要删除吗?','删除','delDictionary')
  260. }
  261. }
  262. // 保存数据字典
  263. saveDictionary(): void {
  264. for (const i in this.validateDictionaryForm.controls) {
  265. this.validateDictionaryForm.controls[i].markAsDirty();
  266. this.validateDictionaryForm.controls[i].updateValueAndValidity();
  267. }
  268. if (this.validateDictionaryForm.invalid) {
  269. return;
  270. }
  271. console.log(this.validateDictionaryForm.value);
  272. let postData:any = {};
  273. //增加
  274. postData = [];
  275. let rawValueObj = this.validateDictionaryForm.getRawValue();
  276. for (let i = 0; i < this.dictionaryList.length; i++) {
  277. postData.push({
  278. id: uuidValidate(this.dictionaryList[i].id) ? undefined : this.dictionaryList[i].id,
  279. name: rawValueObj['name_' + this.dictionaryList[i].id],
  280. value: rawValueObj['value_' + this.dictionaryList[i].id],
  281. orders: rawValueObj['orders_' + this.dictionaryList[i].id],
  282. extra1: this.activeDictionaryKey.key == 'alarm_urgency' ? rawValueObj['extra1_' + this.dictionaryList[i].id]: undefined,
  283. system: uuidValidate(this.dictionaryList[i].id) ? false : this.dictionaryList[i].system,
  284. key: this.activeDictionaryKey.key,
  285. })
  286. }
  287. this.btnLoading = true;
  288. this.mainService
  289. .simplePost("addListData", "dictionary", postData)
  290. .subscribe((result) => {
  291. this.btnLoading = false;
  292. if (result.status == 200) {
  293. this.mainService.clearDictionary();
  294. this.showPromptModal('保存', true, '');
  295. } else {
  296. this.showPromptModal('保存', false, result.msg || '');
  297. }
  298. });
  299. }
  300. // 获取院区
  301. hospitalList:any = [];
  302. getHosList() {
  303. let data = {
  304. idx: 0,
  305. sum: 99999,
  306. };
  307. this.mainService
  308. .getFetchDataList("data", "hospital", data)
  309. .subscribe((data) => {
  310. this.hospitalList = data.list || [];
  311. });
  312. }
  313. // 选择院区
  314. taskTypeList:any = [];
  315. changeHos(e){
  316. this.validatePriorityForm.controls.taskTypeIds.setValue(null);
  317. this.getTsakTypeList('add');
  318. }
  319. // 获取任务类型
  320. userList:any = [];
  321. getTsakTypeList(type, obj?) {
  322. let data = {
  323. idx: 0,
  324. sum: 99999,
  325. taskType:{
  326. simpleQuery:true,
  327. hosIds: this.validatePriorityForm.value.hosId
  328. }
  329. };
  330. this.mainService
  331. .getFetchDataList("configuration", "taskType", data)
  332. .subscribe((data) => {
  333. this.taskTypeList = data.list || [];
  334. if(type=='edit'){
  335. this.validatePriorityForm.controls.taskTypeIds.setValue(obj);
  336. }
  337. });
  338. }
  339. // 新增优先级弹框
  340. modelName = ""; //模态框名称
  341. modalPriority: boolean = false; //新增/编辑模态框
  342. add: boolean; //true:新增;false:编辑
  343. addPriorityModal() {
  344. this.modelName = "新增";
  345. this.add = true; //新增
  346. this.modalPriority = true;
  347. this.initForm();
  348. }
  349. //关闭新增/编辑弹框
  350. hidePriorityModal() {
  351. this.modalPriority = false;
  352. }
  353. isLoading:boolean = false;
  354. // 编辑
  355. edit(data) {
  356. this.modelName = "编辑";
  357. this.add = false;
  358. this.modalPriority = true;
  359. this.initForm();
  360. this.coopData = data;
  361. this.validatePriorityForm.controls.hosId.setValue(data.hospitalDTO.id);
  362. this.validatePriorityForm.controls.businessName.setValue(data.businessName?data.businessName:null);
  363. this.validatePriorityForm.controls.businessCode.setValue(data.businessCode);
  364. let taskType = data.taskTypeIds.split(',')
  365. taskType = taskType.map(i=>{
  366. return parseInt(i)
  367. })
  368. this.getTsakTypeList('edit', taskType);
  369. }
  370. // 新增/编辑表单提交
  371. submitPriorityForm(): void {
  372. for (const i in this.validatePriorityForm.controls) {
  373. this.validatePriorityForm.controls[i].markAsDirty();
  374. this.validatePriorityForm.controls[i].updateValueAndValidity();
  375. }
  376. if (this.validatePriorityForm.invalid) {
  377. return;
  378. }
  379. console.log(this.validatePriorityForm.value);
  380. this.btnLoading = true;
  381. let postData:any = {};
  382. if (this.add) {
  383. //增加
  384. postData = {
  385. businessTaskType:{
  386. hosId: this.validatePriorityForm.value.hosId,
  387. businessName: this.validatePriorityForm.value.businessName || undefined,
  388. businessCode: this.validatePriorityForm.value.businessCode,
  389. taskTypeIds: this.validatePriorityForm.value.taskTypeIds.toString(),
  390. }
  391. };
  392. } else {
  393. //编辑
  394. postData = {
  395. businessTaskType:{
  396. ...this.coopData,
  397. hosId: this.validatePriorityForm.value.hosId,
  398. businessName: this.validatePriorityForm.value.businessName || undefined,
  399. businessCode: this.validatePriorityForm.value.businessCode,
  400. taskTypeIds: this.validatePriorityForm.value.taskTypeIds.toString(),
  401. }
  402. };
  403. }
  404. this.mainService
  405. .dataPost(this.add ? "addData": "updData", "businessTaskType", postData)
  406. .subscribe((result) => {
  407. this.btnLoading = false;
  408. this.hidePriorityModal();
  409. let msg = "";
  410. if (this.add) {
  411. msg = "新增";
  412. } else {
  413. msg = "修改";
  414. }
  415. if (result.status == 200) {
  416. this.showPromptModal(msg, true, '');
  417. } else {
  418. this.showPromptModal(msg, false, result.msg);
  419. }
  420. });
  421. }
  422. // 初始化新增form表单
  423. validatePriorityForm: FormGroup; //新增/编辑表单
  424. initForm() {
  425. this.validatePriorityForm = this.fb.group({
  426. hosId: [null, [Validators.required]],
  427. businessName: [null, [Validators.required]],
  428. businessCode: [null, [Validators.required]],
  429. taskTypeIds: [null, [Validators.required]],
  430. });
  431. }
  432. // 获取列表
  433. loading1:boolean = false;
  434. commonFaultsList: any[] = []; //表格数据
  435. tablePriorityHeight:number = 0;
  436. getCommonFaultsList() {
  437. let data = {
  438. idx: 0,
  439. sum: 99999,
  440. // businessTaskType: {
  441. // hosId: this.hosId
  442. // },
  443. };
  444. this.loading1 = true;
  445. this.mainService
  446. .getFetchDataList("simple/data", "businessTaskType", data)
  447. .subscribe((data) => {
  448. this.loading1 = false;
  449. data.list.forEach(i=>{
  450. i.taskTypeName = i.taskTypeDTOS.map(i=>{
  451. return i.taskName
  452. }).toString()
  453. })
  454. this.commonFaultsList = data.list || [];
  455. });
  456. }
  457. // 删除业务类型
  458. showBusinessModal(data){
  459. this.coopData = data
  460. this.delBusinessModal = true;
  461. }
  462. // 隐藏删除框
  463. delBusinessModal:boolean = false;
  464. hideBusinessModal() {
  465. this.delBusinessModal = false;
  466. }
  467. // 确认删除
  468. confirmBusiness() {
  469. this.btnLoading = true;
  470. this.mainService
  471. .simplePost("rmvData", "businessTaskType", [this.coopData.id])
  472. .subscribe((data) => {
  473. this.btnLoading = false;
  474. this.delBusinessModal = false;
  475. if (data.status == 200) {
  476. this.showPromptModal(this.tipsMsg2, true, "");
  477. } else {
  478. this.showPromptModal(this.tipsMsg2, false, data.msg);
  479. }
  480. });
  481. }
  482. }