distribution-search-more.component.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. import { Subject } from 'rxjs';
  2. import { debounceTime } from 'rxjs/operators';
  3. import { ToolService } from '../../../../services/tool.service';
  4. import { Component, OnInit, Output, Input } from '@angular/core';
  5. import { FormGroup, FormBuilder, Validators } from '@angular/forms';
  6. import { EventEmitter } from '@angular/core';
  7. import { MainService } from 'src/app/services/main.service';
  8. @Component({
  9. selector: 'app-distribution-search-more',
  10. templateUrl: './distribution-search-more.component.html',
  11. styleUrls: ['./distribution-search-more.component.less']
  12. })
  13. export class DistributionSearchMoreComponent implements OnInit {
  14. @Output() submitEvent = new EventEmitter();
  15. @Output() cancelEvent = new EventEmitter();
  16. @Input() fieldConfig: any = { fields: [], config: [] };
  17. @Input() hosId: any;
  18. @Input() parentDutyId: any;
  19. @Input() dutyId: any;
  20. @Input() queryType: any;
  21. validateForm: FormGroup;//表单
  22. searchTimerSubject = new Subject();
  23. constructor(
  24. private fb: FormBuilder,
  25. private tool: ToolService,
  26. private mainService: MainService,
  27. ) { }
  28. minuteClose:any;
  29. specialList:any = [
  30. {name:'是',id:1},
  31. {name:'否',id:0}
  32. ]
  33. overtimeList:any = [
  34. {name:'是',id:1},
  35. {name:'否',id:0}
  36. ]
  37. abnormalList:any = [
  38. {name:'是',id:1},
  39. {name:'否',id:0}
  40. ]
  41. ngOnInit() {
  42. this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
  43. let fun = v[0];
  44. fun.call(this, v[1]);
  45. });
  46. this.initForm();
  47. this.getSourceList();
  48. this.getSourceDataList();
  49. this.getWorkHourEvaluateList();
  50. this.getTimeFrameList();
  51. }
  52. // 隐藏模态框
  53. hideModal() {
  54. this.cancelEvent.emit()
  55. }
  56. // 初始化form表单
  57. initForm() {
  58. this.groupList = this.fieldConfig.fields.groupDTO ? [this.fieldConfig.fields.groupDTO] : [];
  59. this.userList = this.fieldConfig.fields.userDTO ? [this.fieldConfig.fields.userDTO] : [];
  60. this.statisticsTypeList = this.fieldConfig.fields.statisticsTypeDTO ? [this.fieldConfig.fields.statisticsTypeDTO] : [];
  61. this.buildingList = this.fieldConfig.fields.buildingDTO ? [this.fieldConfig.fields.buildingDTO] : [];
  62. this.taskTypeList = this.fieldConfig.fields.taskTypeDTO ? [this.fieldConfig.fields.taskTypeDTO] : [];
  63. this.deptList = this.fieldConfig.fields.deptDTO ? [this.fieldConfig.fields.deptDTO] : [];
  64. this.sourceList = this.fieldConfig.fields.sourceDTO ? [this.fieldConfig.fields.sourceDTO] : [];
  65. this.specialList = [{name:'是',id:1},{name:'否',id:0}];
  66. this.overtimeList = [{name:'是',id:1},{name:'否',id:0}];
  67. this.abnormalList = [{name:'是',id:1},{name:'否',id:0}];
  68. this.evaluateList = this.fieldConfig.fields.evaluateDTO ? [this.fieldConfig.fields.evaluateDTO] : [];
  69. this.executeUserList = this.fieldConfig.fields.executeUserDTO ? [this.fieldConfig.fields.executeUserDTO] : [];
  70. this.timeFrameList = this.fieldConfig.fields.timeFrameDTO ? [this.fieldConfig.fields.timeFrameDTO] : [];
  71. this.validateForm = this.fb.group({
  72. groupId: [this.fieldConfig.fields.groupId || null],
  73. userId: [this.fieldConfig.fields.userId === undefined ? null : this.fieldConfig.fields.userId],
  74. statisticsTypeId: [this.fieldConfig.fields.statisticsTypeId || null],
  75. buildingId: [this.fieldConfig.fields.buildingId || null],
  76. taskTypeId: [this.fieldConfig.fields.taskTypeDTO ? this.fieldConfig.fields.taskTypeDTO.id : null],
  77. deptId: [this.fieldConfig.fields.deptDTO ? this.fieldConfig.fields.deptDTO.id : null],
  78. sourceId: [this.fieldConfig.fields.sourceId || null],
  79. minuteClose: [this.fieldConfig.fields.minuteClose || null],
  80. specialId: [this.fieldConfig.fields.specialDTO ? this.fieldConfig.fields.specialDTO.id : null],
  81. overtimeId: [this.fieldConfig.fields.overtimeDTO ? this.fieldConfig.fields.overtimeDTO.id : null],
  82. abnormalId: [this.fieldConfig.fields.abnormalDTO ? this.fieldConfig.fields.abnormalDTO.id : null],
  83. evaluateId: [this.fieldConfig.fields.evaluateId || null],
  84. executeUserId: [this.fieldConfig.fields.executeUserId || null],
  85. codeNum: [this.fieldConfig.fields.codeNum || null],
  86. timeFrameId: [this.fieldConfig.fields.timeFrameDTO ? this.fieldConfig.fields.timeFrameDTO.id : null],
  87. });
  88. }
  89. // 表单提交
  90. submitForm(): void {
  91. for (const i in this.validateForm.controls) {
  92. this.validateForm.controls[i].markAsDirty({ onlySelf: true });
  93. this.validateForm.controls[i].updateValueAndValidity();
  94. }
  95. if (this.validateForm.invalid) return;
  96. let fields:any = {}
  97. if(this.fieldConfig.config.group){
  98. fields.groupId = this.validateForm.value.groupId;
  99. fields.groupDTO = this.groupList.find(item => item.id == this.validateForm.value.groupId);
  100. }
  101. if(this.fieldConfig.config.groupAndUser){
  102. fields.groupId = this.validateForm.value.groupId;
  103. fields.groupDTO = this.groupList.find(item => item.id == this.validateForm.value.groupId);
  104. fields.userId = this.validateForm.value.userId;
  105. fields.userDTO = this.userList.find(item => item.id == this.validateForm.value.userId);
  106. }
  107. if(this.fieldConfig.config.statisticsType){
  108. fields.statisticsTypeId = this.validateForm.value.statisticsTypeId;
  109. fields.statisticsTypeDTO = this.statisticsTypeList.find(item => item.id == this.validateForm.value.statisticsTypeId);
  110. }
  111. if(this.fieldConfig.config.building){
  112. fields.buildingId = this.validateForm.value.buildingId;
  113. fields.buildingDTO = this.buildingList.find(item => item.id == this.validateForm.value.buildingId);
  114. }
  115. if(this.fieldConfig.config.taskType){
  116. fields.taskTypeId = this.validateForm.value.taskTypeId;
  117. fields.taskTypeDTO = this.taskTypeList.find(item => item.id == this.validateForm.value.taskTypeId);
  118. }
  119. if(this.fieldConfig.config.dept){
  120. fields.deptId = this.validateForm.value.deptId;
  121. fields.deptDTO = this.deptList.find(item => item.id == this.validateForm.value.deptId);
  122. }
  123. if(this.fieldConfig.config.source){
  124. fields.sourceId = this.validateForm.value.sourceId;
  125. fields.sourceDTO = this.sourceList.find(item => item.name == this.validateForm.value.sourceId);
  126. }
  127. if(this.fieldConfig.config.minute){
  128. fields.minuteClose = this.validateForm.value.minuteClose;
  129. fields.minuteDTO = this.validateForm.value.minuteClose;
  130. }
  131. if(this.fieldConfig.config.special){
  132. fields.specialId = this.validateForm.value.specialId;
  133. fields.specialDTO = this.specialList.find(item => item.id == this.validateForm.value.specialId);
  134. }
  135. if(this.fieldConfig.config.overtime){
  136. fields.overtimeId = this.validateForm.value.overtimeId;
  137. fields.overtimeDTO = this.overtimeList.find(item => item.id == this.validateForm.value.overtimeId);
  138. }
  139. if(this.fieldConfig.config.abnormal){
  140. fields.abnormalId = this.validateForm.value.abnormalId;
  141. fields.abnormalDTO = this.abnormalList.find(item => item.id == this.validateForm.value.abnormalId);
  142. }
  143. if(this.fieldConfig.config.evaluate){
  144. fields.evaluateId = this.validateForm.value.evaluateId;
  145. fields.evaluateDTO = this.evaluateList.find(item => item.id == this.validateForm.value.evaluateId);
  146. }
  147. if(this.fieldConfig.config.executeUser){
  148. fields.executeUserId = this.validateForm.value.executeUserId;
  149. fields.executeUserDTO = this.executeUserList.find(item => item.id == this.validateForm.value.executeUserId);
  150. }
  151. if(this.fieldConfig.config.code){
  152. fields.codeNum = this.validateForm.value.codeNum;
  153. fields.codeNumDTO = this.validateForm.value.codeNum;
  154. }
  155. if(this.fieldConfig.config.timeFrame){
  156. fields.timeFrameId = this.validateForm.value.timeFrameId;
  157. fields.timeFrameDTO = this.timeFrameList.find(item => item.id == this.validateForm.value.timeFrameId);
  158. }
  159. this.submitEvent.emit(fields);
  160. this.hideModal();
  161. }
  162. get getHosId(){
  163. return this.parentDutyId || this.dutyId || this.hosId;
  164. }
  165. // 防抖
  166. isLoading = false;
  167. isSelecting:boolean = false; // 是否在选中状态
  168. searchTimer(fun, e) {
  169. if (this.isSelecting) {
  170. this.isSelecting = false; // 重置标志
  171. return; // 跳过处理
  172. }
  173. this.isLoading = true;
  174. this.searchTimerSubject.next([fun, e]);
  175. }
  176. // 设置标志
  177. setIsSelecting(flag){
  178. this.isSelecting = flag; // 设置标志
  179. }
  180. // =================分组===================
  181. // 分组搜索
  182. changeGroupInp(e) {
  183. this.searchTimer(this.getGroupList, e);
  184. }
  185. // 获取分组列表
  186. groupList:any[] = [];
  187. getGroupList(keyword?){
  188. let postData: any = {
  189. idx: 0,
  190. sum: 20,
  191. group2: {
  192. statisticalHosId: this.getHosId,
  193. groupName: keyword,
  194. type: 1,
  195. },
  196. };
  197. this.isLoading = true;
  198. this.mainService.getFetchDataList("simple/data", "group2", postData).subscribe(result => {
  199. this.isLoading = false;
  200. if(result.status == 200){
  201. this.groupList = result.list || [];
  202. }else{
  203. this.groupList = [];
  204. }
  205. });
  206. }
  207. openChangeGroup(flag){
  208. flag && this.setIsSelecting(false);
  209. flag && this.getGroupList();
  210. }
  211. changeGroup(id){
  212. this.setIsSelecting(true);
  213. this.userList = [];
  214. this.validateForm.controls.userId.setValue(null);
  215. this.getUserList();
  216. }
  217. // =================人员===================
  218. // 人员搜索
  219. changeUserInp(e) {
  220. this.searchTimer(this.getUserList, e);
  221. }
  222. // 获取人员列表
  223. userList:any[] = [];
  224. getUserList(keyword = ''){
  225. if(!this.validateForm.value.groupId){
  226. this.isLoading = false;
  227. this.userList = [];
  228. return;
  229. }
  230. let postData: any = {
  231. idx: 0,
  232. sum: 20,
  233. user: {
  234. name: keyword,
  235. simpleQuery: true,
  236. groupdata: { id: this.validateForm.value.groupId },
  237. },
  238. };
  239. this.isLoading = true;
  240. this.mainService.getFetchDataList("simple/data", "user", postData).subscribe(result => {
  241. this.isLoading = false;
  242. if(result.status == 200){
  243. this.userList = result.list || [];
  244. }else{
  245. this.userList = [];
  246. }
  247. });
  248. }
  249. openChangeUser(flag){
  250. flag && this.setIsSelecting(false);
  251. flag && this.getUserList();
  252. }
  253. // =================统计分类===================
  254. // 获取统计分类列表
  255. statisticsTypeList:any[] = [];
  256. getSourceList(){
  257. this.mainService.getDictionary("list", "statistics_date_type").subscribe(result => {
  258. this.statisticsTypeList = result;
  259. });
  260. }
  261. // =================楼栋===================
  262. // 楼栋搜索
  263. changeBuildingInp(e) {
  264. this.searchTimer(this.getBuildingList, e);
  265. }
  266. // 获取楼栋列表
  267. buildingList:any[] = [];
  268. getBuildingList(keyword?){
  269. let postData: any = {
  270. idx: 0,
  271. sum: 20,
  272. building: {
  273. simpleQuery: true,
  274. buildingName: keyword,
  275. statisticalHosId:this.getHosId,
  276. },
  277. };
  278. this.isLoading = true;
  279. this.mainService.getFetchDataList("simple/data", "building", postData).subscribe(result => {
  280. this.isLoading = false;
  281. if(result.status == 200){
  282. this.buildingList = result.list || [];
  283. }else{
  284. this.buildingList = [];
  285. }
  286. });
  287. }
  288. openChangeBuilding(flag){
  289. flag && this.setIsSelecting(false);
  290. flag && this.getBuildingList();
  291. }
  292. // =================任务类型===================
  293. // 任务类型搜索
  294. changeTaskTypeInp(e) {
  295. this.searchTimer(this.getTaskTypeList, e);
  296. }
  297. // 获取任务类型列表
  298. taskTypeList:any[] = [];
  299. getTaskTypeList(keyword?){
  300. let postData: any = {
  301. idx: 0,
  302. sum: 20,
  303. taskType: {
  304. simpleQuery: true,
  305. taskName: keyword,
  306. statisticalHosId: this.getHosId,
  307. },
  308. };
  309. this.isLoading = true;
  310. this.mainService.getFetchDataList("simple/data", "taskType", postData).subscribe(result => {
  311. this.isLoading = false;
  312. if(result.status == 200){
  313. this.taskTypeList = result.list || [];
  314. }else{
  315. this.taskTypeList = [];
  316. }
  317. });
  318. }
  319. openChangeTaskType(flag){
  320. flag && this.setIsSelecting(false);
  321. flag && this.getTaskTypeList();
  322. }
  323. // =================科室===================
  324. // 科室搜索
  325. changeRepairDeptInp(e) {
  326. this.searchTimer(this.getRepairDeptList, e);
  327. }
  328. // 获取科室列表
  329. deptList:any[] = [];
  330. getRepairDeptList(keyword?){
  331. let postData: any = {
  332. idx: 0,
  333. sum: 20,
  334. department: {
  335. statisticalHosId: this.getHosId,
  336. dept: keyword,
  337. searchType: 1,
  338. },
  339. };
  340. this.isLoading = true;
  341. this.mainService.getFetchDataList("simple/data", "department", postData).subscribe(result => {
  342. this.isLoading = false;
  343. if(result.status == 200){
  344. this.deptList = result.list || [];
  345. }else{
  346. this.deptList = [];
  347. }
  348. });
  349. }
  350. openChangeRepairDept(flag){
  351. flag && this.setIsSelecting(false);
  352. flag && this.getRepairDeptList();
  353. }
  354. // =================来源===================
  355. // 获取来源列表
  356. sourceList:any[] = [];
  357. getSourceDataList(keyword?){
  358. let postData:any = {
  359. idx: 0,
  360. sum: 9999,
  361. hosId: this.getHosId,
  362. };
  363. this.isLoading = true;
  364. this.mainService
  365. .postCustom("itsm/report", "sourceTransOrder", postData)
  366. .subscribe((result) => {
  367. this.isLoading = false;
  368. this.sourceList = result.dataList;
  369. });
  370. }
  371. // =================评价===================
  372. // 获取评价列表
  373. evaluateList:any[] = [];
  374. getWorkHourEvaluateList(){
  375. this.isLoading = true;
  376. this.mainService
  377. .getDictionary("list", "workorderEvaluation")
  378. .subscribe((data) => {
  379. this.isLoading = false;
  380. this.evaluateList = data;
  381. });
  382. }
  383. // =================执行人===================
  384. // 执行人搜索
  385. changeExecuteUserInp(e) {
  386. this.searchTimer(this.getExecuteUserList, e);
  387. }
  388. // 获取执行人列表
  389. executeUserList:any[] = [];
  390. getExecuteUserList(keyword?){
  391. let postData = {
  392. user: {
  393. name: keyword,
  394. hospital: { id: this.getHosId },
  395. usertype: { id: 106 }, //配送人员
  396. },
  397. idx: 0,
  398. sum: 20,
  399. };
  400. this.isLoading = true;
  401. this.mainService
  402. .getFetchDataList("data", "user", postData)
  403. .subscribe((data) => {
  404. this.isLoading = false;
  405. if(data.status == 200){
  406. this.executeUserList = data.list || [];
  407. }else{
  408. this.executeUserList = [];
  409. }
  410. });
  411. }
  412. openChangeExecuteUser(flag){
  413. flag && this.setIsSelecting(false);
  414. flag && this.getExecuteUserList();
  415. }
  416. // =================时段===================
  417. // 获取时段列表
  418. timeFrameList:any[] = [];
  419. getTimeFrameList(){
  420. for(let i=0; i<24; i++){
  421. this.timeFrameList.push({
  422. name: i,
  423. id: i
  424. })
  425. }
  426. }
  427. }