essential-information.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. import { Component, OnInit, Output, EventEmitter } from '@angular/core';
  2. import { NzModalRef, NzMessageService } from 'ng-zorro-antd';
  3. import { _HttpClient } from '@delon/theme';
  4. import { Validators, FormGroup, FormBuilder } from '@angular/forms';
  5. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  6. import { BaseArchivesProjectApproval } from 'app/entity/basedata/base-archives-project-approval';
  7. import { BaseArchivesProjectApprovalService } from 'app/services/basedata/base-archives-project-approval.service';
  8. import { Customer } from 'app/entity/basedata/customer';
  9. import { CustomerService } from 'app/services/basedata/customer.service';
  10. import { PersonnelService } from 'app/services/basedata/personnel.service';
  11. import { recursiveQuery } from '@shared/utils/yuan copy';
  12. @Component({
  13. selector: 'app-project-manage-archives-add-essential-information',
  14. templateUrl: './essential-information.component.html',
  15. })
  16. export class ProjectManageArchivesAddEssentialInformationComponent implements OnInit {
  17. constructor(
  18. private fb: FormBuilder,
  19. private baseArchivesProjectApprovalService: BaseArchivesProjectApprovalService,
  20. private customerService: CustomerService,
  21. private personnelService: PersonnelService,
  22. ) {}
  23. ngOnInit(): void {
  24. //初始化表单
  25. this.validateForm = this.fb.group({
  26. proId: [null, [Validators.required]],
  27. cusId: [null, [Validators.required]],
  28. totalPrice: [null, [Validators.required]],
  29. saleManagerId: [null],
  30. saleManIds: [null],
  31. impManagerId: [null],
  32. impConsultantIds: [null],
  33. deManagerId: [null],
  34. deEngineerIds: [null],
  35. seManagerId: [null],
  36. seEngineerIds: [null],
  37. milestoneId: [null, [Validators.required]]
  38. });
  39. this.getProList();
  40. this.getCusList();
  41. this.getPersonnelList();
  42. }
  43. validateForm!: FormGroup;
  44. projectManageArchivesa: ProjectManageArchives = {
  45. totalPrice: 0,
  46. impConsultantList:[],
  47. deEngineerList:[],
  48. seEngineerList:[]
  49. }; //项目档案主表对象
  50. proList: any = []; //项目立项档案数据集合
  51. cusList = []; //客户档案数据集合
  52. //金额格式化
  53. formatterDollar = (value: number) => {
  54. if(value){
  55. return `$ ${value}`;
  56. }else{
  57. return `$ `;
  58. }
  59. };
  60. parserDollar = (value: string) => value.replace('$ ', '');
  61. saleManIds = []; //业务员id绑定
  62. personnelList = []; //人员下拉数据
  63. impConsultantIds = []; //实施顾问下拉选择绑定
  64. deEngineerIds = []; //开发工程师下拉选择绑定
  65. seEngineerIds = []; //服务工程师下拉选择绑定
  66. milestoneList = []; //里程碑类型下拉数据
  67. /**
  68. * 查询项目立项
  69. */
  70. getProList() {
  71. return new Promise(resolve => {
  72. let baseArchivesProjectApproval = new BaseArchivesProjectApproval();
  73. baseArchivesProjectApproval.pkOrg = sessionStorage.getItem('pkOrg');
  74. this.baseArchivesProjectApprovalService.getTreeList(baseArchivesProjectApproval).then(response => {
  75. this.proList = response.result;
  76. resolve();
  77. });
  78. });
  79. }
  80. /**
  81. * 里程碑类型选择事件
  82. */
  83. //回写里程碑类型到其他页签查询明细
  84. @Output() milestone = new EventEmitter<{}>();
  85. milestoneChange(event) {
  86. if (event) {
  87. this.milestoneList.forEach(element => {
  88. if (element.value === event) {
  89. this.projectManageArchivesa.milestoneType = element.text;
  90. }
  91. });
  92. this.milestone.emit(this.projectManageArchivesa);
  93. }
  94. }
  95. /**
  96. * 项目立项选择事件
  97. * @param event 立项id
  98. */
  99. proChange(event) {
  100. this.getChild(this.proList, event);
  101. }
  102. //递归查找项目名称
  103. getChild(list, event) {
  104. list.forEach(element => {
  105. if (event === element.id) {
  106. this.projectManageArchivesa.proCode = element.code;
  107. this.projectManageArchivesa.proName = element.title;
  108. } else {
  109. //如果没找到则进入子集查找
  110. if (element.children && element.children.length > 0) {
  111. this.getChild(element.children, event);
  112. }
  113. }
  114. });
  115. }
  116. /**
  117. * 客户档案数据
  118. */
  119. getCusList() {
  120. return new Promise(resolve => {
  121. let customer = new Customer();
  122. customer.pkOrg = sessionStorage.getItem('pkOrg');
  123. customer.pageSize = 20000;
  124. this.customerService.getCustomer1(customer).then(response => {
  125. this.cusList = response.result.records;
  126. resolve();
  127. });
  128. });
  129. }
  130. /**
  131. * 客户档案选择事件
  132. */
  133. cusChange(event) {
  134. this.cusList.forEach(element => {
  135. if (event === element.id) {
  136. this.projectManageArchivesa.cusCode = element.code;
  137. this.projectManageArchivesa.cusName = element.name;
  138. }
  139. });
  140. this.getProjectManageArchivesa();
  141. }
  142. /**
  143. * 人员下拉查询
  144. */
  145. saleManagerList = []; //销售经理下拉数据
  146. impManagerList = []; //实施经理下拉数据
  147. deManagerList = []; //开发项目经理数据
  148. seManagerList = []; //服务项目经理数据
  149. getPersonnelList() {
  150. // return new Promise(resolve => {
  151. // this.personnelService.queryApprover(sessionStorage.getItem('pkOrg')).then(response => {
  152. // this.personnelList = JSON.parse(JSON.stringify(response.result));
  153. // this.saleManagerList = JSON.parse(JSON.stringify(response.result));
  154. // this.impManagerList = JSON.parse(JSON.stringify(response.result));
  155. // this.deManagerList = JSON.parse(JSON.stringify(response.result));
  156. // this.seManagerList = JSON.parse(JSON.stringify(response.result));
  157. // recursiveQuery(this.personnelList);
  158. // recursiveQuery(this.saleManagerList);
  159. // recursiveQuery(this.impManagerList);
  160. // recursiveQuery(this.deManagerList);
  161. // recursiveQuery(this.seManagerList);
  162. // resolve();
  163. // });
  164. // });
  165. }
  166. /**
  167. * 经理选择触发事件
  168. * @param event 经理id
  169. * @param type 经理类型
  170. */
  171. managerChange(event, type) {
  172. if (event) {
  173. this.saleManagerList.forEach(pkOrg => {
  174. pkOrg.children.forEach(depart => {
  175. depart.children.forEach(personnel => {
  176. if (personnel.key === event) {
  177. if (type === '1') {
  178. //销售经理名称
  179. this.projectManageArchivesa.saleManager = personnel.name;
  180. } else if (type === '2') {
  181. //实施项目经理名称
  182. this.projectManageArchivesa.impManager = personnel.name;
  183. } else if (type === '3') {
  184. //开发项目经理名称
  185. this.projectManageArchivesa.deManager = personnel.name;
  186. } else if (type === '4') {
  187. //服务经理名称
  188. this.projectManageArchivesa.seManager = personnel.name;
  189. }
  190. }
  191. });
  192. });
  193. });
  194. this.getProjectManageArchivesa(type);
  195. }
  196. }
  197. /**
  198. * 人员多选触发事件
  199. * @param event 人员id
  200. * @param type 经理类型
  201. */
  202. personnelChange(event, type) {
  203. if (event) {
  204. let names = '';
  205. let ids = '';
  206. let sort = 0;
  207. //根据下拉数据获取名称
  208. event.forEach(element => {
  209. this.saleManagerList.forEach(pkOrg => {
  210. pkOrg.children.forEach(depart => {
  211. depart.children.forEach(personnel => {
  212. if (personnel.key === element) {
  213. if (names === '') {
  214. names = personnel.name;
  215. ids = personnel.key;
  216. } else {
  217. names = names + '、' + personnel.name;
  218. ids = ids + '、' + personnel.key;
  219. }
  220. sort++;
  221. }
  222. });
  223. });
  224. });
  225. });
  226. //有数据则正常赋值
  227. if (sort > 0) {
  228. if (type === '1') {
  229. //业务员
  230. this.projectManageArchivesa.saleManId = ids;
  231. this.projectManageArchivesa.saleMan = names;
  232. } else if (type === '2') {
  233. //实施顾问
  234. this.projectManageArchivesa.impConsultantId = ids;
  235. this.projectManageArchivesa.impConsultant = names;
  236. } else if (type === '3') {
  237. //开发工程师
  238. this.projectManageArchivesa.deEngineerId = ids;
  239. this.projectManageArchivesa.deEngineer = names;
  240. } else if (type === '4') {
  241. //服务工程师
  242. this.projectManageArchivesa.seEngineerId = ids;
  243. this.projectManageArchivesa.seEngineer = names;
  244. }
  245. } else {
  246. //没数据则清空
  247. if (type === '1') {
  248. //业务员
  249. this.projectManageArchivesa.saleManId = '';
  250. this.projectManageArchivesa.saleMan = '';
  251. } else if (type === '2') {
  252. //实施顾问
  253. this.projectManageArchivesa.impConsultantId = '';
  254. this.projectManageArchivesa.impConsultant = '';
  255. } else if (type === '3') {
  256. //开发工程师
  257. this.projectManageArchivesa.deEngineerId = '';
  258. this.projectManageArchivesa.deEngineer = '';
  259. } else if (type === '4') {
  260. //服务工程师
  261. this.projectManageArchivesa.seEngineerId = '';
  262. this.projectManageArchivesa.seEngineer = '';
  263. }
  264. }
  265. this.getProjectManageArchivesa(type);
  266. }
  267. }
  268. // //人员选择信息回写到其他页签的执行人
  269. // @Output() personnelIds = new EventEmitter<{}>();
  270. // getPersonnelIds(type){
  271. // //参数人员ids,类型(2实施、3开发、4服务)
  272. // let personnelIds=[];
  273. // if(type==='2'){//实施
  274. // personnelIds.push(this.projectManageArchivesa.impManagerId);//实施经理
  275. // Array.prototype.push.apply(personnelIds, this.impConsultantIds);//实施顾问
  276. // }
  277. // if(type==='3'){//开发
  278. // personnelIds.push(this.projectManageArchivesa.deManagerId);//开发经理
  279. // Array.prototype.push.apply(personnelIds, this.deEngineerIds);//开发工程师
  280. // }
  281. // if(type==='4'){//服务
  282. // personnelIds.push(this.projectManageArchivesa.seManagerId);//服务经理
  283. // Array.prototype.push.apply(personnelIds, this.seEngineerIds);//服务工程师
  284. // }
  285. // let per={personnelIds:personnelIds,type:type}
  286. // this.personnelIds.emit(per);
  287. // }
  288. //基本信息回写到其他页签
  289. @Output() projectManageArchivesaEntiy = new EventEmitter<{}>();
  290. getProjectManageArchivesa(type?:any) {
  291. //获取人员id传到其他页签
  292. if(type){
  293. if(type==='2'){//实施
  294. this.projectManageArchivesa.impConsultantList=[];
  295. if(this.projectManageArchivesa.impManagerId){
  296. this.projectManageArchivesa.impConsultantList.push(this.projectManageArchivesa.impManagerId);//实施经理
  297. }
  298. if(this.impConsultantIds&&this.impConsultantIds.length>0){
  299. Array.prototype.push.apply(this.projectManageArchivesa.impConsultantList, this.impConsultantIds);//实施顾问
  300. }
  301. }
  302. if(type==='3'){//开发
  303. this.projectManageArchivesa.deEngineerList=[]
  304. if(this.projectManageArchivesa.deManagerId){
  305. this.projectManageArchivesa.deEngineerList.push(this.projectManageArchivesa.deManagerId);//开发经理
  306. }
  307. if(this.deEngineerIds&&this.deEngineerIds.length>0){
  308. Array.prototype.push.apply(this.projectManageArchivesa.deEngineerList, this.deEngineerIds);//开发工程师
  309. }
  310. }
  311. if(type==='4'){//服务
  312. this.projectManageArchivesa.seEngineerList=[];
  313. if(this.projectManageArchivesa.seManagerId){
  314. this.projectManageArchivesa.seEngineerList.push(this.projectManageArchivesa.seManagerId);//服务经理
  315. }
  316. if(this.seEngineerIds&&this.seEngineerIds.length>0){
  317. Array.prototype.push.apply(this.projectManageArchivesa.seEngineerList, this.seEngineerIds);//服务工程师
  318. }
  319. }
  320. }
  321. this.projectManageArchivesaEntiy.emit(this.projectManageArchivesa);
  322. }
  323. submitForm() {
  324. for (const i in this.validateForm.controls) {
  325. this.validateForm.controls[i].markAsDirty();
  326. this.validateForm.controls[i].updateValueAndValidity();
  327. }
  328. let valid = this.validateForm.valid;
  329. return valid;
  330. }
  331. }