add.component.ts 9.3 KB

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