contract.page.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Component, OnInit } from '@angular/core';
  2. import { UserData } from '../../providers/user-data';
  3. import { Storage } from '@ionic/storage'
  4. import { Router } from '@angular/router';
  5. @Component({
  6. selector: 'app-contract',
  7. templateUrl: './contract.page.html',
  8. styleUrls: ['./contract.page.scss'],
  9. })
  10. export class ContractPage implements OnInit {
  11. contractInfo={
  12. sscContractdateGt: '',
  13. sscContractdateLt: '',
  14. sscState: '',
  15. sscCreator: '',
  16. sscCode: ''
  17. }
  18. constructor(public userData: UserData,
  19. private router: Router,
  20. private storage: Storage,) { }
  21. ngOnInit() {
  22. }
  23. search() {
  24. this.storage.set('contractForm', this.getSerchForm())
  25. this.router.navigateByUrl('/contract-table');
  26. }
  27. getSerchForm() {
  28. let queryForm = {
  29. query: {
  30. bool: {
  31. must: [],
  32. must_not: [],
  33. should: []
  34. }
  35. },
  36. from: 0,
  37. size: 10,
  38. sort: [{sscContractdate: {order: "desc"}}],
  39. aggs: {}
  40. };
  41. if (this.contractInfo.sscCode) {
  42. let prefix = {}
  43. prefix['sscCode.keyword'] = this.contractInfo.sscCode.toUpperCase()
  44. queryForm.query.bool.must.push({
  45. prefix: prefix
  46. })
  47. }
  48. if (this.contractInfo.sscContractdateGt || this.contractInfo.sscContractdateLt) {
  49. let range = {
  50. sscContractdate: {}
  51. }
  52. if (this.contractInfo.sscContractdateGt) {
  53. range.sscContractdate['gt'] = new Date(this.contractInfo.sscContractdateGt).getTime()
  54. }
  55. if (this.contractInfo.sscContractdateLt) {
  56. range.sscContractdate['lt'] = new Date(this.contractInfo.sscContractdateLt).getTime()
  57. }
  58. queryForm.query.bool.must.push({
  59. range: range
  60. })
  61. }
  62. if (this.contractInfo.sscCreator) {
  63. let prefix = {}
  64. prefix['sscCreator.keyword'] = this.contractInfo.sscCreator
  65. queryForm.query.bool.must.push({
  66. prefix: prefix
  67. })
  68. }
  69. return queryForm
  70. }
  71. }