phone-search-more.component.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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-phone-search-more',
  10. templateUrl: './phone-search-more.component.html',
  11. styleUrls: ['./phone-search-more.component.less']
  12. })
  13. export class PhoneSearchMoreComponent 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. ngOnInit() {
  29. this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
  30. let fun = v[0];
  31. fun.call(this, v[1]);
  32. });
  33. this.initForm();
  34. this.getSourceList();
  35. }
  36. // 隐藏模态框
  37. hideModal() {
  38. this.cancelEvent.emit()
  39. }
  40. // 初始化form表单
  41. initForm() {
  42. this.groupList = this.fieldConfig.fields.groupDTO ? [this.fieldConfig.fields.groupDTO] : [];
  43. this.userList = this.fieldConfig.fields.userDTO ? [this.fieldConfig.fields.userDTO] : [];
  44. this.statisticsTypeList = this.fieldConfig.fields.statisticsTypeDTO ? [this.fieldConfig.fields.statisticsTypeDTO] : [];
  45. this.buildingList = this.fieldConfig.fields.buildingDTO ? [this.fieldConfig.fields.buildingDTO] : [];
  46. this.taskTypeList = this.fieldConfig.fields.taskTypeDTO ? [this.fieldConfig.fields.taskTypeDTO] : [];
  47. this.deptList = this.fieldConfig.fields.deptDTO ? [this.fieldConfig.fields.deptDTO] : [];
  48. this.validateForm = this.fb.group({
  49. groupId: [this.fieldConfig.fields.groupId || null],
  50. userId: [this.fieldConfig.fields.userId === undefined ? null : this.fieldConfig.fields.userId],
  51. statisticsTypeId: [this.fieldConfig.fields.statisticsTypeId || null],
  52. buildingId: [this.fieldConfig.fields.buildingId || null],
  53. taskTypeId: [this.fieldConfig.fields.taskTypeDTO ? this.fieldConfig.fields.taskTypeDTO.id : null],
  54. deptId: [this.fieldConfig.fields.deptDTO ? this.fieldConfig.fields.deptDTO.id : null],
  55. });
  56. }
  57. // 表单提交
  58. submitForm(): void {
  59. for (const i in this.validateForm.controls) {
  60. this.validateForm.controls[i].markAsDirty({ onlySelf: true });
  61. this.validateForm.controls[i].updateValueAndValidity();
  62. }
  63. if (this.validateForm.invalid) return;
  64. let fields:any = {}
  65. if(this.fieldConfig.config.groupAndUser){
  66. fields.groupId = this.validateForm.value.groupId;
  67. fields.groupDTO = this.groupList.find(item => item.id == this.validateForm.value.groupId);
  68. fields.userId = this.validateForm.value.userId;
  69. fields.userDTO = this.userList.find(item => item.id == this.validateForm.value.userId);
  70. }
  71. if(this.fieldConfig.config.statisticsType){
  72. fields.statisticsTypeId = this.validateForm.value.statisticsTypeId;
  73. fields.statisticsTypeDTO = this.statisticsTypeList.find(item => item.id == this.validateForm.value.statisticsTypeId);
  74. }
  75. if(this.fieldConfig.config.building){
  76. fields.buildingId = this.validateForm.value.buildingId;
  77. fields.buildingDTO = this.buildingList.find(item => item.id == this.validateForm.value.buildingId);
  78. }
  79. if(this.fieldConfig.config.taskType){
  80. fields.taskTypeId = this.validateForm.value.taskTypeId;
  81. fields.taskTypeDTO = this.taskTypeList.find(item => item.id == this.validateForm.value.taskTypeId);
  82. }
  83. if(this.fieldConfig.config.dept){
  84. fields.deptId = this.validateForm.value.deptId;
  85. fields.deptDTO = this.deptList.find(item => item.id == this.validateForm.value.deptId);
  86. }
  87. this.submitEvent.emit(fields);
  88. this.hideModal();
  89. }
  90. get getHosId(){
  91. return this.parentDutyId || this.dutyId || this.hosId;
  92. }
  93. // 防抖
  94. isLoading = false;
  95. isSelecting:boolean = false; // 是否在选中状态
  96. searchTimer(fun, e) {
  97. if (this.isSelecting) {
  98. this.isSelecting = false; // 重置标志
  99. return; // 跳过处理
  100. }
  101. this.isLoading = true;
  102. this.searchTimerSubject.next([fun, e]);
  103. }
  104. // 设置标志
  105. setIsSelecting(flag){
  106. this.isSelecting = flag; // 设置标志
  107. }
  108. // =================分组===================
  109. // 分组搜索
  110. changeGroupInp(e) {
  111. this.searchTimer(this.getGroupList, e);
  112. }
  113. // 获取分组列表
  114. groupList:any[] = [];
  115. getGroupList(keyword?){
  116. let postData: any = {
  117. idx: 0,
  118. sum: 20,
  119. group2: {
  120. statisticalHosId: this.getHosId,
  121. groupName: keyword,
  122. type: 1,
  123. },
  124. };
  125. this.isLoading = true;
  126. this.mainService.getFetchDataList("simple/data", "group2", postData).subscribe(result => {
  127. this.isLoading = false;
  128. if(result.status == 200){
  129. this.groupList = result.list || [];
  130. }else{
  131. this.groupList = [];
  132. }
  133. });
  134. }
  135. openChangeGroup(flag){
  136. flag && this.setIsSelecting(false);
  137. flag && this.getGroupList();
  138. }
  139. changeGroup(id){
  140. this.setIsSelecting(true);
  141. this.userList = [];
  142. this.validateForm.controls.userId.setValue(null);
  143. this.getUserList();
  144. }
  145. // =================人员===================
  146. // 人员搜索
  147. changeUserInp(e) {
  148. this.searchTimer(this.getUserList, e);
  149. }
  150. // 获取人员列表
  151. userList:any[] = [];
  152. getUserList(keyword = ''){
  153. if(!this.validateForm.value.groupId){
  154. this.isLoading = false;
  155. this.userList = [];
  156. return;
  157. }
  158. let postData: any = {
  159. idx: 0,
  160. sum: 20,
  161. user: {
  162. name: keyword,
  163. simpleQuery: true,
  164. groupdata: { id: this.validateForm.value.groupId },
  165. },
  166. };
  167. this.isLoading = true;
  168. this.mainService.getFetchDataList("simple/data", "user", postData).subscribe(result => {
  169. this.isLoading = false;
  170. if(result.status == 200){
  171. this.userList = result.list || [];
  172. }else{
  173. this.userList = [];
  174. }
  175. });
  176. }
  177. openChangeUser(flag){
  178. flag && this.setIsSelecting(false);
  179. flag && this.getUserList();
  180. }
  181. // =================统计分类===================
  182. // 获取统计分类列表
  183. statisticsTypeList:any[] = [];
  184. getSourceList(){
  185. this.mainService.getDictionary("list", "statistics_date_type").subscribe(result => {
  186. this.statisticsTypeList = result;
  187. });
  188. }
  189. // =================楼栋===================
  190. // 楼栋搜索
  191. changeBuildingInp(e) {
  192. this.searchTimer(this.getBuildingList, e);
  193. }
  194. // 获取楼栋列表
  195. buildingList:any[] = [];
  196. getBuildingList(keyword?){
  197. let postData: any = {
  198. idx: 0,
  199. sum: 20,
  200. building: {
  201. simpleQuery: true,
  202. buildingName: keyword,
  203. statisticalHosId:this.getHosId,
  204. },
  205. };
  206. this.isLoading = true;
  207. this.mainService.getFetchDataList("simple/data", "building", postData).subscribe(result => {
  208. this.isLoading = false;
  209. if(result.status == 200){
  210. this.buildingList = result.list || [];
  211. }else{
  212. this.buildingList = [];
  213. }
  214. });
  215. }
  216. openChangeBuilding(flag){
  217. flag && this.setIsSelecting(false);
  218. flag && this.getBuildingList();
  219. }
  220. // =================任务类型===================
  221. // 任务类型搜索
  222. changeTaskTypeInp(e) {
  223. this.searchTimer(this.getTaskTypeList, e);
  224. }
  225. // 获取任务类型列表
  226. taskTypeList:any[] = [];
  227. getTaskTypeList(keyword?){
  228. let postData: any = {
  229. idx: 0,
  230. sum: 20,
  231. taskType: {
  232. simpleQuery: true,
  233. taskName: keyword,
  234. statisticalHosId: this.getHosId,
  235. },
  236. };
  237. this.isLoading = true;
  238. this.mainService.getFetchDataList("simple/data", "taskType", postData).subscribe(result => {
  239. this.isLoading = false;
  240. if(result.status == 200){
  241. this.taskTypeList = result.list || [];
  242. }else{
  243. this.taskTypeList = [];
  244. }
  245. });
  246. }
  247. openChangeTaskType(flag){
  248. flag && this.setIsSelecting(false);
  249. flag && this.getTaskTypeList();
  250. }
  251. // =================科室===================
  252. // 科室搜索
  253. changeRepairDeptInp(e) {
  254. this.searchTimer(this.getRepairDeptList, e);
  255. }
  256. // 获取科室列表
  257. deptList:any[] = [];
  258. getRepairDeptList(keyword?){
  259. let postData: any = {
  260. idx: 0,
  261. sum: 20,
  262. department: {
  263. statisticalHosId: this.getHosId,
  264. dept: keyword,
  265. searchType: 1,
  266. },
  267. };
  268. this.isLoading = true;
  269. this.mainService.getFetchDataList("simple/data", "department", postData).subscribe(result => {
  270. this.isLoading = false;
  271. if(result.status == 200){
  272. this.deptList = result.list || [];
  273. }else{
  274. this.deptList = [];
  275. }
  276. });
  277. }
  278. openChangeRepairDept(flag){
  279. flag && this.setIsSelecting(false);
  280. flag && this.getRepairDeptList();
  281. }
  282. }