add.component.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import { Component, OnInit } from '@angular/core';
  2. import { NzModalRef, NzMessageService, NzNotificationService, NzDrawerRef } from 'ng-zorro-antd';
  3. import { _HttpClient, SettingsService } from '@delon/theme';
  4. import { InvoiceManagePurchase } from 'app/entity/invoice-management/invoice-manage-purchase';
  5. import { FormBuilder, Validators, FormGroup } from '@angular/forms';
  6. import { DatePipe } from '@angular/common';
  7. import { ProjectManageArchives } from 'app/entity/project-manage-archives/project-manage-archives';
  8. import { ProjectManageArchivesService } from 'app/services/project-manage-archives/project-manage-archives.service';
  9. import { BaseArchivesCollectionLine } from 'app/entity/basedata/base-archives-collection-line';
  10. import { BaseArchivesCollectionLineService } from 'app/services/basedata/base-archives-collection-line.service';
  11. import { InvoiceManagePurchaseService } from 'app/services/invoice-management/invoice-manage-purchase.service';
  12. import { I18NService } from '@core';
  13. @Component({
  14. selector: 'app-invoice-management-invoice-manage-purchase-add',
  15. templateUrl: './add.component.html',
  16. styles: [
  17. `
  18. .base {
  19. position: absolute;
  20. bottom: 0px;
  21. width: 100%;
  22. border-top: 1px solid rgb(232, 232, 232);
  23. padding: 6px 16px;
  24. text-align: right;
  25. left: 0px;
  26. background: #fff;
  27. z-index: 99;
  28. }
  29. `,
  30. ],
  31. })
  32. export class InvoiceManagementInvoiceManagePurchaseAddComponent implements OnInit {
  33. constructor(
  34. private fb: FormBuilder,
  35. private settingsService: SettingsService,
  36. private datePipe: DatePipe,
  37. private projectManageArchivesService: ProjectManageArchivesService,
  38. private baseArchivesCollectionLineService:BaseArchivesCollectionLineService,
  39. private nzNotificationService:NzNotificationService,
  40. private drawerRef:NzDrawerRef,
  41. private invoiceManagePurchaseService:InvoiceManagePurchaseService,
  42. private i18NService:I18NService
  43. ) {}
  44. ngOnInit(): void {
  45. //初始化表单
  46. this.validateForm = this.fb.group({
  47. proArchivesId: [null, [Validators.required]],
  48. });
  49. //项目下拉数据
  50. this.isLoadingSave = true;
  51. this.getProList().then(()=>{
  52. this.isLoadingSave = false;
  53. });
  54. }
  55. validateForm!: FormGroup;
  56. invoiceManagePurchase: InvoiceManagePurchase = {
  57. currentUser: this.settingsService.user.realname,
  58. createTime: this.datePipe.transform(new Date(), 'yyyy-MM-dd HH:mm:ss'),
  59. }; //对象
  60. isLoadingSave = false;
  61. proList = []; //项目下拉数据
  62. itemDataList=[];//明细表格数据集合
  63. coArchivesList=[];//条线档案数据集合
  64. /**
  65. * 获取项目下拉数据
  66. */
  67. getProList() {
  68. return new Promise(resolve => {
  69. let projectManageArchives = new ProjectManageArchives();
  70. projectManageArchives.pageSize = 20000;
  71. projectManageArchives.pkOrg = sessionStorage.getItem('pkOrg');
  72. this.projectManageArchivesService.getList(projectManageArchives).then(response => {
  73. if (response.result.records) {
  74. this.proList = response.result.records;
  75. }
  76. resolve();
  77. });
  78. });
  79. }
  80. /**
  81. * 获取条线下拉数据
  82. */
  83. // getCoArchivesList(){
  84. // return new Promise(resolve => {
  85. // let baseArchivesCollectionLine = new BaseArchivesCollectionLine();
  86. // baseArchivesCollectionLine.pageSize = 20000;
  87. // baseArchivesCollectionLine.pkOrg = sessionStorage.getItem('pkOrg');
  88. // this.baseArchivesCollectionLineService.getList(baseArchivesCollectionLine).then(response => {
  89. // if (response.result.records) {
  90. // this.coArchivesList = response.result.records;
  91. // }
  92. // resolve();
  93. // });
  94. // });
  95. // }
  96. /**
  97. * 项目下拉选择事件
  98. * 获取条线下拉数据
  99. */
  100. proChange(event) {
  101. if (event) {
  102. //根据id获取项目档案数据
  103. this.projectManageArchivesService.getListById(event).then(response => {
  104. if (response.success) {
  105. let project = JSON.parse(JSON.stringify(response.result)); //项目档案对象
  106. this.invoiceManagePurchase.proCode = project.proCode; //项目档案编码
  107. this.invoiceManagePurchase.proName = project.proName; //项目档案名称
  108. //获取首付款条线
  109. this.getLineList();
  110. }
  111. });
  112. }
  113. }
  114. //获取条线下拉数据
  115. getLineList(){
  116. //查询条件
  117. let projectManageArchives={proArchivesId:this.invoiceManagePurchase.proArchivesId,planType:"1"};
  118. this.projectManageArchivesService.getLineList(projectManageArchives).then((response)=>{
  119. if(response.success){
  120. this.coArchivesList=response.result
  121. }
  122. })
  123. }
  124. /**
  125. * 条线下拉选择事件
  126. * 获取名称和里程碑下拉数据
  127. */
  128. coArchivesChange(data){
  129. if(data.coArchivesId){
  130. //获取条线名称
  131. this.coArchivesList.forEach(element => {
  132. if(data.coArchivesId===element.id){
  133. data.coArchivesName=element.planName;
  134. }
  135. });
  136. //获取里程碑下拉数据
  137. let where={businessId:data.coArchivesId};
  138. this.projectManageArchivesService.getMileNameById(where).then((response)=>{
  139. if(response.success){
  140. data.proBusinessList=response.result;
  141. //一般用于选择完里程碑又反过来选条线 则重新获取金额
  142. if(data.proBusinessId){
  143. this.proBusinessChange(data);
  144. }
  145. }
  146. })
  147. }
  148. }
  149. /**
  150. * 里程碑选择事件
  151. * 获取名称和金额
  152. */
  153. uncoPrice=0;//未收票金额
  154. proBusinessChange(data){
  155. if(data.proBusinessId){
  156. data.proBusinessList.forEach(element => {
  157. if(element.mileId===data.proBusinessId){
  158. data.proArchivesMilestone=element.mileName;//名称
  159. data.price=element.price;//金额
  160. }
  161. });
  162. //查询条件
  163. let where={coArchivesId:data.coArchivesId,proBusinessId:data.proBusinessId}
  164. //获取未开票金额
  165. this.invoiceManagePurchaseService.getChildrenList(where).then((response)=>{
  166. if(response.success){
  167. if(response.result.uncoPrice){
  168. data.uncoPrice=response.result.uncoPrice;//未收票金额
  169. data.uncoPriceMax=Number(response.result.uncoPrice);//未收票金额
  170. }else{
  171. data.uncoPrice=JSON.parse(JSON.stringify(data.price));//未收票金额
  172. data.uncoPriceMax=Number(JSON.parse(JSON.stringify(data.price)));//未收票金额
  173. }
  174. }
  175. })
  176. }
  177. }
  178. /**
  179. * 收票输入事件
  180. */
  181. coPriceKeyUp(data){
  182. if(data.coPrice){
  183. //未开票金额减已开票金额
  184. data.uncoPrice=data.uncoPriceMax-Number(data.coPrice);
  185. }
  186. }
  187. /**
  188. * 获取里程碑下拉数据
  189. */
  190. proBusinessList=[];//里程碑下拉数据
  191. // getBusinessList(){
  192. // //查询条件:项目档案id、计划类型
  193. // let business={businessId:this.invoiceManagePurchase.proArchivesId,planType:"1"}
  194. // this.projectManageArchivesService.getMileNameById(business).then((response)=>{
  195. // if(response.success){
  196. // this.proBusinessList=response.result;
  197. // }
  198. // })
  199. // }
  200. /**
  201. * 增行按钮
  202. */
  203. sort = 0;
  204. addRow() {
  205. this.itemDataList = [
  206. ...this.itemDataList,
  207. {
  208. price:"",
  209. uncoPrice:"",
  210. coPrice:"",
  211. sort: this.sort
  212. },
  213. ];
  214. this.sort++;
  215. }
  216. /**
  217. * 删除行
  218. */
  219. deleteRow(sort) {
  220. this.itemDataList = this.itemDataList.filter(d => d.sort !== sort);
  221. }
  222. //金额格式化
  223. formatterDollar = (value: number) => {
  224. if(value){
  225. return `$ ${value}`;
  226. }else{
  227. return `$ `;
  228. }
  229. };
  230. parserDollar = (value: string) => value.replace('$ ', '');
  231. /**
  232. * 提交保存按钮
  233. */
  234. submitForm(): any {
  235. return new Promise(resolve => {
  236. for (const i in this.validateForm.controls) {
  237. this.validateForm.controls[i].markAsDirty();
  238. this.validateForm.controls[i].updateValueAndValidity();
  239. }
  240. let valid = this.validateForm.valid;
  241. if(valid){
  242. this.isLoadingSave=true;
  243. this.invoiceManagePurchase.type="1";//采购
  244. this.invoiceManagePurchase.pkOrg=sessionStorage.getItem("pkOrg");
  245. //子表保存数据处理
  246. if(this.itemDataList&&this.itemDataList.length>0){
  247. }else{
  248. //是否填写明细数据
  249. this.nzNotificationService.warning("填写明细数据","");
  250. this.isLoadingSave=false;
  251. return;
  252. }
  253. this.invoiceManagePurchase.detailList=this.itemDataList;
  254. this.invoiceManagePurchaseService.add(this.invoiceManagePurchase).then((response)=>{
  255. if (response.success) {
  256. //保存成功
  257. this.isLoadingSave = false;
  258. this.nzNotificationService.success(this.i18NService.fanyi('save.ok'), '');
  259. this.drawerRef.close(true);
  260. resolve();
  261. } else {
  262. //保存失败
  263. this.isLoadingSave = false;
  264. this.nzNotificationService.error(this.i18NService.fanyi('save.not'), '');
  265. }
  266. })
  267. }
  268. });
  269. }
  270. close() {
  271. this.drawerRef.close();
  272. }
  273. }