inspection-configuration.component.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  4. import { MainService } from "../../services/main.service";
  5. import { ToolService } from "../../services/tool.service";
  6. import { NzMessageService } from 'ng-zorro-antd';
  7. import { Subject } from 'rxjs';
  8. import { debounceTime } from 'rxjs/operators';
  9. @Component({
  10. selector: "app-inspection-configuration",
  11. templateUrl: "./inspection-configuration.component.html",
  12. styleUrls: ["./inspection-configuration.component.less"],
  13. })
  14. export class InspectionConfigurationComponent implements OnInit {
  15. constructor(
  16. private fb: FormBuilder,
  17. private mainService: MainService,
  18. private route: ActivatedRoute,
  19. private router: Router,
  20. private tool: ToolService,
  21. private message: NzMessageService,
  22. ) {}
  23. listOfData: any[] = []; //表格数据
  24. pageIndex: number = 1; //表格当前页码
  25. pageSize: number = 10; //表格每页展示条数
  26. listLength: number = 10; //表格总数据量
  27. modal: boolean = false; //新增/编辑模态框
  28. add: boolean; //true:新增;false:编辑
  29. validateForm: FormGroup; //新增/编辑表单
  30. coopData: any; //当前操作列
  31. currentHospital; //当前院区
  32. btnLoading: boolean = false; //提交按钮loading状态
  33. promptContent: string; //操作提示框提示信息
  34. ifSuccess: boolean; //操作成功/失败
  35. promptInfo: string; //操作结果提示信息
  36. promptModalShow: boolean; //操作提示框是否展示
  37. nextSchemeName = ""; //下一个开启的方案名称
  38. modelName = ""; //模态框名称
  39. changeInpSubject = new Subject(); //防抖
  40. ngOnInit() {
  41. //防抖
  42. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  43. if(v[0] === 'repairDept'){
  44. this.getRepairDeptList(v[1]);
  45. }else if(v[0] === 'category'){
  46. this.getCategoryList(v[1]);
  47. }else if(v[0] === 'priority'){
  48. this.getPriorityList(v[1]);
  49. }else if(v[0] === 'group'){
  50. this.getGroupList(v[1]);
  51. }else if(v[0] === 'user'){
  52. this.getUserList(v[1]);
  53. }
  54. });
  55. this.currentHospital = this.tool.getCurrentHospital();
  56. this.coopBtns = this.tool.initCoopBtns(this.route);
  57. this.initForm();
  58. this.getList(1);
  59. }
  60. // 初始化增删改按钮
  61. coopBtns: any = {};
  62. // 边输边搜节流阀
  63. isLoading = false;
  64. changeInp(type, e) {
  65. this.isLoading = true;
  66. this.changeInpSubject.next([type, e]);
  67. }
  68. // 获取报修科室
  69. repairDeptList: any = [];
  70. getRepairDeptList(keyWord) {
  71. let postData:any = {
  72. department: {
  73. searchType: 1,// 简单查询
  74. flag: 1,
  75. keyWord,
  76. cascadeHosId: this.currentHospital.id,
  77. },
  78. idx: 0,
  79. sum: 20,
  80. };
  81. this.mainService
  82. .getFetchDataList("data", "department", postData)
  83. .subscribe((data) => {
  84. this.repairDeptList = data.list;
  85. this.isLoading = false;
  86. });
  87. }
  88. // 获取维修组
  89. groupList: any = [];
  90. getGroupList(keyWord) {
  91. let postData:any = {
  92. group2: {
  93. type: 3,
  94. groupName: keyWord,
  95. hospitals: this.currentHospital.id,
  96. },
  97. idx: 0,
  98. sum: 20,
  99. };
  100. this.mainService
  101. .getFetchDataList("simple/data", "group2", postData)
  102. .subscribe((data) => {
  103. this.groupList = data.list;
  104. this.isLoading = false;
  105. });
  106. }
  107. // 获取维修人
  108. userList: any = [];
  109. getUserList(keyWord) {
  110. let postData:any = {
  111. user: {
  112. simpleQuery: true,// 简单查询
  113. name: keyWord,
  114. groupdata: {
  115. id: this.validateForm.value.groupId,
  116. },
  117. roleCodes: "first-line support",
  118. engineer: 1,
  119. },
  120. idx: 0,
  121. sum: 20,
  122. };
  123. this.mainService
  124. .getFetchDataList("simple/data", "user", postData)
  125. .subscribe((data) => {
  126. this.userList = data.list;
  127. this.isLoading = false;
  128. });
  129. }
  130. // 获取故障现象
  131. categoryList: any = [];
  132. getCategoryList(keyWord) {
  133. let dutyIds;
  134. let { hospital, type } = this.tool.getHospitalOrDuty();
  135. if(type === 'duty'){
  136. // 是责任部门
  137. dutyIds = hospital.id.toString();
  138. }else{
  139. this.categoryList = [];
  140. this.isLoading = false;
  141. return;
  142. }
  143. let postData:any = {
  144. category: {
  145. category: keyWord,
  146. selectType: 'mutlQuery',
  147. hierarchy: 3,//只差有三级的故障现象列表
  148. dutyIds,
  149. },
  150. };
  151. this.mainService
  152. .incidentPost("listIncidentCategory", postData)
  153. .subscribe((data) => {
  154. this.categoryList = data.data;
  155. this.isLoading = false;
  156. });
  157. }
  158. // 获取优先级
  159. priorityList: any = [];
  160. getPriorityList(keyWord) {
  161. let postData:any = {
  162. priority: {},
  163. idx: 0,
  164. sum: 9999,
  165. };
  166. this.mainService
  167. .getFetchDataList("data", "priority", postData)
  168. .subscribe((data) => {
  169. this.priorityList = data.list;
  170. this.isLoading = false;
  171. });
  172. }
  173. // 表格数据
  174. loading1 = false;
  175. getList(type) {
  176. if (type == 1) {
  177. this.pageIndex = 1;
  178. }
  179. let data = {
  180. idx: this.pageIndex - 1,
  181. sum: this.pageSize,
  182. inspectionForm: {
  183. hosId: this.currentHospital.id,
  184. },
  185. };
  186. this.loading1 = true;
  187. this.mainService
  188. .getFetchDataList("simple/data", "inspectionForm", data)
  189. .subscribe((data) => {
  190. this.loading1 = false;
  191. if (data.status == 200) {
  192. this.listOfData = data.list;
  193. this.listLength = data.totalNum;
  194. }else{
  195. this.message.error(data.msg || "请求数据失败");
  196. }
  197. });
  198. }
  199. // 新增弹框
  200. addModal() {
  201. this.modelName = "新增";
  202. this.add = true; //新增
  203. this.modal = true;
  204. this.initForm();
  205. }
  206. //关闭新增/编辑弹框
  207. hideAddModal() {
  208. this.modal = false;
  209. this.initForm();
  210. }
  211. // 初始化新增form表单
  212. initForm() {
  213. this.validateForm = this.fb.group({
  214. name: ['', [Validators.required, Validators.pattern(/\S/)]],
  215. showOrder: [0, [Validators.required]],
  216. createOrder: [0],
  217. repairDeptId: [null],
  218. categoryId: [null],
  219. priorityId: [null],
  220. userGroup: [null],
  221. groupId: [null],
  222. userId: [null],
  223. });
  224. }
  225. // 新增/编辑表单提交
  226. submitForm(): void {
  227. for (const i in this.validateForm.controls) {
  228. this.validateForm.controls[i].markAsDirty();
  229. this.validateForm.controls[i].updateValueAndValidity();
  230. }
  231. if (this.validateForm.invalid) {
  232. return;
  233. }
  234. this.btnLoading = true;
  235. let data:any = {};
  236. if (this.add) {
  237. //增加
  238. data = {
  239. name: this.validateForm.value.name,
  240. showOrder: this.validateForm.value.showOrder,
  241. createOrder: this.validateForm.value.createOrder,
  242. repairDeptId: this.validateForm.value.repairDeptId || undefined,
  243. categoryId: this.validateForm.value.categoryId || undefined,
  244. priorityId: this.validateForm.value.priorityId || undefined,
  245. userGroup: this.validateForm.value.userGroup || undefined,
  246. groupId: this.validateForm.value.groupId || undefined,
  247. userId: this.validateForm.value.userId || undefined,
  248. hosId: this.currentHospital.id,
  249. };
  250. } else {
  251. //编辑
  252. data = {
  253. ...this.coopData,
  254. ...{
  255. name: this.validateForm.value.name,
  256. showOrder: this.validateForm.value.showOrder,
  257. createOrder: this.validateForm.value.createOrder,
  258. repairDeptId: this.validateForm.value.repairDeptId || undefined,
  259. categoryId: this.validateForm.value.categoryId || undefined,
  260. priorityId: this.validateForm.value.priorityId || undefined,
  261. userGroup: this.validateForm.value.userGroup || undefined,
  262. groupId: this.validateForm.value.groupId || undefined,
  263. userId: this.validateForm.value.userId || undefined,
  264. }
  265. };
  266. }
  267. this.mainService
  268. .simplePost("addData", "inspectionForm", data)
  269. .subscribe((result) => {
  270. this.btnLoading = false;
  271. this.hideAddModal();
  272. this.initForm();
  273. if (result.status == 200) {
  274. if (this.add) {
  275. this.listLength++;
  276. this.router.navigateByUrl(`/main/inspectionConfigurationItem/${result.data.id}`);
  277. } else {
  278. this.showPromptModal("编辑", true, "");
  279. }
  280. } else {
  281. let msg = "";
  282. if (this.add) {
  283. msg = "新增";
  284. } else {
  285. msg = "修改";
  286. }
  287. this.showPromptModal(msg, false, result.msg);
  288. }
  289. });
  290. }
  291. // 编辑
  292. edit(data) {
  293. console.log(data);
  294. this.modelName = "编辑";
  295. this.add = false;
  296. this.modal = true;
  297. this.coopData = data;
  298. this.validateForm.controls.name.setValue(data.name); //名称
  299. this.validateForm.controls.showOrder.setValue(data.showOrder);
  300. if(data.showOrder == 1){
  301. this.validateForm.controls.createOrder.setValue(data.createOrder);
  302. data.repairDeptDTO && (this.repairDeptList = [data.repairDeptDTO]);
  303. this.validateForm.controls.repairDeptId.setValue(data.repairDeptId);
  304. this.requiredChange('repairDeptId', data.createOrder == 1);
  305. data.categoryDTO && (this.categoryList = [data.categoryDTO]);
  306. this.validateForm.controls.categoryId.setValue(data.categoryId);
  307. this.requiredChange('categoryId', data.createOrder == 1);
  308. data.priorityDTO && (this.priorityList = [data.priorityDTO]);
  309. this.validateForm.controls.priorityId.setValue(data.priorityId);
  310. if(data.createOrder == 1){
  311. this.validateForm.controls.userGroup.setValue(data.userGroup);
  312. data.groupDTO && (this.groupList = [data.groupDTO]);
  313. this.validateForm.controls.groupId.setValue(data.groupId);
  314. this.requiredChange('groupId', (data.userGroup == 1 || data.userGroup == 2 || data.userGroup == 3));
  315. data.userDTO && (this.userList = [data.userDTO]);
  316. this.validateForm.controls.userId.setValue(data.userId);
  317. this.requiredChange('userId', data.userGroup == 3);
  318. }
  319. }else{
  320. this.requiredChange('createOrder', false);
  321. this.validateForm.controls.createOrder.setValue(0);
  322. }
  323. }
  324. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  325. showPromptModal(con, success, promptInfo?) {
  326. this.promptModalShow = false;
  327. this.promptContent = con;
  328. this.ifSuccess = success;
  329. this.promptInfo = promptInfo;
  330. setTimeout(() => {
  331. this.promptModalShow = true;
  332. }, 100);
  333. this.getList(0);
  334. }
  335. // 跳转到配置项
  336. toItem(data){
  337. this.router.navigateByUrl(`/main/inspectionConfigurationItem/${data.id}`);
  338. }
  339. requiredChange(field, required: boolean): void {
  340. if (!required) {
  341. this.validateForm.get(field)!.clearValidators();
  342. this.validateForm.get(field)!.markAsPristine();
  343. } else {
  344. this.validateForm.get(field)!.setValidators(Validators.required);
  345. this.validateForm.get(field)!.markAsDirty();
  346. }
  347. this.validateForm.get(field)!.updateValueAndValidity();
  348. }
  349. changeShowOrder(value){
  350. this.requiredChange('createOrder', value == 1);
  351. this.validateForm.controls.createOrder.setValue(0);
  352. this.validateForm.controls.repairDeptId.setValue(null);
  353. this.repairDeptList = [];
  354. this.validateForm.controls.categoryId.setValue(null);
  355. this.categoryList = [];
  356. this.validateForm.controls.priorityId.setValue(null);
  357. this.priorityList = [];
  358. this.requiredChange('userGroup', false);
  359. this.validateForm.controls.userGroup.setValue(null);
  360. this.requiredChange('groupId', false);
  361. this.validateForm.controls.groupId.setValue(null);
  362. this.groupList = [];
  363. this.requiredChange('userId', false);
  364. this.validateForm.controls.userId.setValue(null);
  365. this.userList = [];
  366. }
  367. changeCreateOrder(value){
  368. this.requiredChange('repairDeptId', value == 1);
  369. this.requiredChange('categoryId', value == 1);
  370. this.requiredChange('userGroup', value == 1);
  371. this.validateForm.controls.userGroup.setValue(value == 1 ? 1 : null);
  372. this.requiredChange('groupId', (this.validateForm.value.userGroup == 1 || this.validateForm.value.userGroup == 2 || this.validateForm.value.userGroup == 3));
  373. this.validateForm.controls.groupId.setValue(null);
  374. this.groupList = [];
  375. this.requiredChange('userId', this.validateForm.value.userGroup == 3);
  376. this.validateForm.controls.userId.setValue(null);
  377. this.userList = [];
  378. }
  379. changeUserGroup(value){
  380. this.requiredChange('groupId', (value == 1 || value == 2 || value == 3));
  381. this.validateForm.controls.groupId.setValue(null);
  382. this.groupList = [];
  383. this.requiredChange('userId', value == 3);
  384. this.validateForm.controls.userId.setValue(null);
  385. this.userList = [];
  386. }
  387. delModal: boolean = false; //删除模态框
  388. tipsMsg1: string; //提示框信息
  389. tipsMsg2: string; //操作后信息
  390. confirmDelType: string; //确认的类型(启用/停用,删除)
  391. showDelModal(
  392. data,
  393. tipsMsg1: string,
  394. tipsMsg2: string,
  395. type: string,
  396. ) {
  397. this.confirmDelType = type;
  398. this.delModal = true;
  399. this.coopData = data;
  400. this.tipsMsg1 = tipsMsg1;
  401. this.tipsMsg2 = tipsMsg2;
  402. }
  403. // 隐藏删除框
  404. hideDelModal() {
  405. this.delModal = false;
  406. }
  407. // 确认删除
  408. confirmDel() {
  409. this.btnLoading = true;
  410. if (this.confirmDelType === "del") {
  411. //删除
  412. this.mainService
  413. .simplePost("rmvData", "inspectionForm", [this.coopData.id])
  414. .subscribe((data) => {
  415. this.btnLoading = false;
  416. this.delModal = false;
  417. if (data.status == 200) {
  418. this.showPromptModal(this.tipsMsg2, true, "");
  419. } else {
  420. this.showPromptModal(this.tipsMsg2, false, data.msg);
  421. }
  422. });
  423. } else if (this.confirmDelType === "publish") {
  424. //发布
  425. let data = {
  426. formId: this.coopData.id,
  427. };
  428. this.mainService
  429. .inspectionPost("formPublish", data)
  430. .subscribe((result) => {
  431. this.btnLoading = false;
  432. this.delModal = false;
  433. if (result.status == 200) {
  434. this.showPromptModal(this.tipsMsg2, true, "");
  435. } else {
  436. this.showPromptModal(this.tipsMsg2, false, result.msg);
  437. }
  438. });
  439. }
  440. }
  441. }