Vendor app Client: Maiora
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

126 líneas
3.5 KiB

  1. import { Component, OnInit, Input } from '@angular/core';
  2. import { OrderService } from '../services/order.service';
  3. import * as moment from 'moment';
  4. @Component({
  5. selector: 'app-orders',
  6. templateUrl: './orders.component.html',
  7. styleUrls: ['./orders.component.scss']
  8. })
  9. export class OrdersComponent implements OnInit {
  10. showRejectionPopup: boolean = false;
  11. orderList: any = [];
  12. tempOrderList: any = [];
  13. orderStatus: any = [];
  14. searchTerm: string = '';
  15. showFilter: boolean = false;
  16. filterOption: {
  17. orderStatus: string,
  18. orderstatus_id: number
  19. } = {
  20. orderStatus: 'All',
  21. orderstatus_id: 0
  22. };
  23. @Input() params: any;
  24. constructor(
  25. private orderService: OrderService
  26. ) { }
  27. ngOnInit() {
  28. if (this.params) {
  29. try {
  30. switch(this.params.filterType) {
  31. case 'pending': this.filterOption = {
  32. orderStatus: 'Pending',
  33. orderstatus_id: 6
  34. }; break;
  35. case 'delivered': this.filterOption = {
  36. orderStatus: 'Delivered',
  37. orderstatus_id: 3
  38. }; break;
  39. case 'confirmed': this.filterOption = {
  40. orderStatus: 'Accepted',
  41. orderstatus_id: 1
  42. }; break;
  43. default: this.filterOption = {
  44. orderStatus: 'All',
  45. orderstatus_id: 0
  46. }; break;
  47. }
  48. } catch {
  49. this.filterOption = {
  50. orderStatus: 'All',
  51. orderstatus_id: 0
  52. };
  53. }
  54. }
  55. this.orderService.getOrders().then((data) => {
  56. this.orderList = data;
  57. this.orderList = this.orderList.filter((order) => {
  58. return order.orderstatus;
  59. });
  60. this.tempOrderList = this.orderList.filter((order) => {
  61. return order.orderstatus;
  62. });
  63. }, () => {
  64. alert("Error getting the orders");
  65. });
  66. this.orderService.getallOrderStatus().then((data: any) => {
  67. this.orderStatus = data;
  68. this.orderStatus.push({
  69. orderStatus: 'All',
  70. orderstatus_id: 0
  71. });
  72. }, () => {
  73. alert("Error getting the order statuses");
  74. });
  75. }
  76. getFormattedDate(date: any, format: string) {
  77. return moment(date).format(format);
  78. }
  79. getFixedDecimalPoints(price: string | number) {
  80. return Number(price).toFixed(2);
  81. }
  82. getOrderStatus(id: string | number) {
  83. return this.orderStatus.find((status: any) => {
  84. return id === status.orderstatus_id
  85. });
  86. }
  87. updateOrder(order) {
  88. this.orderService.updateOrder(order).then((data) => {
  89. console.log(data);
  90. }, (err) => {
  91. console.log(err)
  92. alert("Failed to update order");
  93. })
  94. }
  95. getFilteredOrders(id: number, orders?: any) {
  96. if (id > 0) {
  97. return this.tempOrderList.filter((order) => {
  98. return order.orderstatus.orderstatus_id === id;
  99. });
  100. } else {
  101. return this.tempOrderList;
  102. }
  103. }
  104. searchOrders() {
  105. this.tempOrderList = this.orderList.filter((order: any) => {
  106. return order.orders_id.toString().toLowerCase().includes(this.searchTerm.toLowerCase());
  107. });
  108. }
  109. }