application-for-housing.component.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import { NgxSpinnerService } from 'ngx-spinner';
  2. import { ActivatedRoute, Params, Router } from '@angular/router';
  3. import { Component, OnInit, ViewChild } from '@angular/core';
  4. import { NgForm } from '@angular/forms';
  5. import { ToastrService } from 'ngx-toastr';
  6. import { Location, formatDate } from '@angular/common';
  7. import { UserService } from 'src/app/shared/user.service';
  8. import { DashboardService } from 'src/app/shared/dashboard.service';
  9. import { HttpClient } from '@angular/common/http';
  10. import { AuthServiceService } from 'src/app/shared/auth-service.service';
  11. @Component({
  12. selector: 'app-application-for-housing',
  13. templateUrl: './application-for-housing.component.html',
  14. styleUrls: ['./application-for-housing.component.css']
  15. })
  16. export class ApplicationForHousingComponent implements OnInit {
  17. departmentUserLoginId: any;
  18. constructor(
  19. private route: ActivatedRoute,
  20. private http: HttpClient,
  21. private toastr: ToastrService,
  22. private dashBoardSer: DashboardService,
  23. private spiner: NgxSpinnerService,
  24. private location: Location,
  25. public authService: AuthServiceService,
  26. private userService: UserService,
  27. private router: Router
  28. ) { }
  29. subLocationList = [];
  30. checkSaveClick: boolean = false;
  31. bindingDateSplitStart;
  32. checked : boolean = false;
  33. pageId: number;
  34. uploaded: boolean = false;
  35. disabledVal: boolean = true;
  36. serviceId: number;
  37. userId: number = 0;
  38. search: any;
  39. reportVal:boolean = false;
  40. saveTherequist: boolean = false;
  41. whosend = '';
  42. applyForOther : boolean = false;
  43. showdetails : boolean = false;
  44. showSearch: boolean = false;
  45. send: boolean = true;
  46. searchValue = null;
  47. applyForm = {
  48. employee_id: null,
  49. files:[]
  50. };
  51. dataForm = {
  52. id_number: '',
  53. name : '',
  54. phoneNum: '',
  55. functional_number:'',
  56. email:''
  57. };
  58. files = [{
  59. title : null,
  60. file: null,
  61. file_type: null,
  62. nameFile: null,
  63. }];
  64. ngOnInit() {
  65. //init the values of permision boolean
  66. this.authService.showAddBtn = false;
  67. this.authService.showDeleteBtn = false;
  68. this.authService.showEditBtn = false;
  69. //show / hide notification search in header
  70. this.authService.notificationLogin = true;
  71. this.authService.showSearchHeader = false;
  72. this.authService.showHeaderLogin = false;
  73. this.authService.showHeaderDashBoard = true;
  74. this.authService.showDashboardHeader = true;
  75. this.authService.internalHeader = false;
  76. this.route.params.subscribe(
  77. (parmas: Params) => {
  78. this.pageId = +parmas['reportId'];
  79. localStorage.setItem('pageIdActive', parmas['reportId']);
  80. this.whosend = parmas['comefrom'];
  81. }
  82. );
  83. this.route.parent.params.subscribe(
  84. (params:Params) => {
  85. this.serviceId = params['serviceID'];
  86. this.userId = params['userID'];
  87. }
  88. );
  89. if(this.whosend == 'new'){
  90. this.http.get(this.authService.pathApi + '/profile').subscribe(
  91. res => {
  92. this.dataForm.id_number = res['user'].identity_number;
  93. this.dataForm.name = res['user'].name;
  94. this.dataForm.phoneNum = res['user'].phone;
  95. this.applyForm.employee_id = res['user'].id;
  96. console.log(this.applyForm.employee_id);
  97. this.dataForm.functional_number = res['user'].functional_number;
  98. this.dataForm.email = res['user'].email;
  99. console.log('dsf',res)
  100. this.showdetails = true;
  101. this.applyForOther = false;
  102. this.send = false;
  103. },
  104. (error) => {console.log(error)},
  105. );
  106. }else{
  107. this.showSearch = true;
  108. }
  109. if(this.whosend == 'new'){
  110. this.http.get(this.authService.pathApi + '/get_employee_request_status/' + this.userId).subscribe(
  111. res => {
  112. console.log('ser' , res);
  113. const status = res['status']
  114. if(status == 'employee free to make new request'){
  115. this.location.back();
  116. this.toastr.warning('لديك طلب بالفعل');
  117. console.log("Fuck");
  118. }else if(status == 'employee free to make new request'){
  119. console.log('Done');
  120. }
  121. },
  122. err => {
  123. console.log(err);
  124. }
  125. );
  126. }
  127. }
  128. plusImage() {
  129. this.files.push({
  130. title: null,
  131. file: null,
  132. file_type: null,
  133. nameFile: null,
  134. });
  135. console.log('files after plus ', this.files);
  136. }
  137. //delete row from table
  138. onDeleteRow(index:number) {
  139. this.files.splice(index , 1);
  140. console.log('files after delete ',this.files);
  141. }
  142. //change file
  143. onFileChanges(event, index:number) {
  144. console.log(event);
  145. console.log(index);
  146. this.uploaded = true;
  147. this.files[index].nameFile = event[0].name.substring(0,20) + '....';
  148. this.files[index].file = event[0].base64;
  149. this.files[index].file_type = event[0].type.split('/')[1];
  150. console.log(this.files);
  151. console.log('files after change ',this.files);
  152. }
  153. SearchOnUser(){
  154. const key = this.searchValue
  155. console.log(key);
  156. console.log('here');
  157. this.http.get(this.authService.pathApi + '/find_user/' + key ).subscribe(
  158. res => {
  159. console.log('user',res);
  160. if(res['user'] == null){
  161. this.showdetails = false;
  162. }else{
  163. this.dataForm.id_number = res['user'].identity_number;
  164. this.dataForm.name = res['user'].name;
  165. this.dataForm.phoneNum = res['user'].phone;
  166. this.applyForm.employee_id = res['user'].id;
  167. this.dataForm.functional_number = res['user'].functional_number;
  168. this.dataForm.email = res['user'].email;
  169. this.applyForOther = true;
  170. this.showdetails = true;
  171. this.http.get(this.authService.pathApi + '/get_employee_request_status/' + this.applyForm.employee_id).subscribe(
  172. res => {
  173. console.log('ser' , res);
  174. const status = res['status']
  175. if(status == 'employee free to make new request'){
  176. this.toastr.warning('لديه طلب بالفعل');
  177. this.applyForOther = false;
  178. this.showdetails = false;
  179. }
  180. },
  181. err => {
  182. console.log(err);
  183. }
  184. );
  185. }
  186. },
  187. err => {
  188. console.log(err);
  189. this.showdetails = false;
  190. }
  191. );
  192. // }
  193. }
  194. onSubmitted(){
  195. for (let i = 0; i < this.files.length; i++) {
  196. if(this.files[i].file_type){
  197. this.files[i].file_type = this.files[i].file_type.toLowerCase();
  198. }
  199. if(!this.files[i].file){
  200. this.files.splice(i , 1);
  201. }
  202. else if(!this.files[i].title){
  203. this.toastr.warning('ادخل عنوان الملف رقم ' + (i+1) );
  204. return 0;
  205. } else {
  206. delete this.files[i].nameFile;
  207. this.applyForm.files.push(this.files[i]);
  208. }
  209. }
  210. console.log(this.applyForm);
  211. this.http.post(this.authService.pathApi + '/add_housing_request' , this.applyForm )
  212. .subscribe(
  213. res => {
  214. console.log(res);
  215. this.toastr.success('تم حفظ الطلب ');
  216. // this.router.navigate(['/service/' + this.userId + '/' + this.serviceId + '/followCommunicationList/58']);
  217. this.location.back();
  218. },
  219. err => {
  220. console.log(err)
  221. this.toastr.error('حدث خطأ في الاتصال ');
  222. }
  223. );
  224. }
  225. }