h-selfdelivery-admin-panel-p/src/app/pages/orders/orders.component.ts
Luba Kaysina 4296ee3755 сделала нотификацию
добавила функционал на вкладки зоны, подразделения, терминалы, клиенты
2022-06-10 16:31:48 +04:00

207 lines
5.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Component, OnInit, Renderer2, ElementRef, Input } from "@angular/core";
import { TableModule } from 'primeng/table';
import { JsonrpcService, RpcService } from "src/app/services/jsonrpc.service";
import { MessageService } from "primeng/api";
import { Order, Products, Delivery_address, Notification } from "src/app/interface/data";
import { ClientsComponent } from "../clients/clients.component";
/*import { SwPush, NewsletterService } from '@angular/service-worker*/
@Component({
selector: 'app-orders',
templateUrl: './orders.component.html',
styleUrls: ['./orders.component.scss'],
providers: [ClientsComponent]
})
export class OrdersComponent implements OnInit {
public orders: Array<Order> = [];
public order: Array<Order> = [];
public view: boolean = true;
public chooseName!: string;
public lastOrderUpdateTime: string = "";
public choose = this.jsonRpcService.ClientChoose;
public notification: Array<Notification> = [];
public map_new = new Map();
public map_new_fin = new Map();
public map_due = new Map();
public myAudioP = new Audio();
public myAudioA = new Audio();
public statuses = [
"К готовке",
"Готовится",
"Готово",
"Отменен",
"Можно забирать",
"У курьера",
"Доставлен",
"Не подтвержден",
"Требует согласия",
"Требуется оплата",
"Оплата просрочена",
"Новый",
"Выдан",
"Нужен возврат"
];
constructor(
private jsonRpcService: JsonrpcService,
private messageService: MessageService,
private clientsComponent: ClientsComponent,
) {
}
async ngOnInit() {
if (this.choose) {
this.getOrders();
setTimeout(() => this.notif(), 700);
setInterval(() => this.getOrders(), 60000);
this.chooseName = this.jsonRpcService.ClientChooseName;
}
}
notif() {
for (let i = 0; i < this.orders.length; i++) {
this.map_new.set(this.orders[i].id, true)
this.map_new_fin.set(this.orders[i].id, true)
}
}
async getOrders() {
this.myAudioP.src = "../../../assets/myAudio.mp3";
this.myAudioA.src = "../../../assets/myAudio2.mp3";
if (this.view == true) {
await this.jsonRpcService.rpc2({
method: 'getOrders',
params: {
"client_id": this.choose, "order_status": [
"readyToStart",
"inProgress",
"complete",
"cancel",
"readyToPickup",
"onWay",
"delivered",
"unconfirmed",
"requiresConsent",
"requiresPayment",
"paymentOverdue",
"newOrder",
"issued",
"needReturnPayment"
]
}
}, RpcService.authService, false)
.subscribe({
next: (result) => {
let data = result.result;
this.color(data);
this.orders = data;
this.lastOrderUpdateTime = Date().toString();
},
error: (err) => {
console.log('ERROR: ', err)
this.messageService.add({
severity: 'error',
summary: 'Произошла ошибка!',
})
}
}
);
}
setTimeout (() => this.notif2(), 700)
}
notif2() {
for (let i = 0; i < this.orders.length; i++) {
if (this.map_new.has(this.orders[i].id) == false) {
this.map_new.set(this.orders[i].id, true);
}
if (this.map_new_fin.has(this.orders[i].id) == false && this.map_new.has(this.orders[i].id) == true) {
this.myAudioP.load();
this.myAudioP.play();
this.map_new_fin.set(this.orders[i].id, true);
}
var date1 = new Date();
var date2 = new Date(this.orders[i].due_datetime);
if ((date2.getTime() - date1.getTime() < 1000 * 3600) && (this.orders[i].status_h == 'К готовке') && (this.map_due.has(this.orders[i].id) == false) && (date2.getTime() - date1.getTime() > 1000 * 1080)) {
this.myAudioA.load();
this.myAudioA.play();
this.map_due.set(this.orders[i].id, true);
}
}
}
async vievOrder(id: any) {
await this.jsonRpcService.rpc2({
method: 'getOrders',
params: { "client_id": this.choose, "order_id": id }
}, RpcService.authService, false)
.subscribe({
next: (result) => {
let data = result.result
this.order = data
},
error: (err) => {
console.log('ERROR: ', err)
this.messageService.add({
severity: 'error',
summary: 'Произошла ошибка!',
})
}
}
);
this.view = false
}
listOrders() {
this.view = true;
this.getOrders();
}
color(targetData: any) {
for (let i = 0; i < targetData.length; i++) {
var item = targetData[i];
var date1 = new Date();
var date2 = new Date(item.due_datetime);
if ((date2.getTime() - date1.getTime() < 1000 * 3600) && (item.status_h == 'К готовке') && (date2.getTime() - date1.getTime() >= 0)) {
item.item_style = 'orange'
};
if ((item.status_h == 'К готовке') && (date2.getTime() - date1.getTime() < 0)) {
item.item_style = 'red'
};
if (item.status_h == 'Готово') {
item.item_style = 'green'
};
if ((item.status_h == 'Отменен') || (item.status_h == 'Оплата просрочена')) {
item.item_style = 'grey'
};
if ((date2.getTime() - date1.getTime() >= 1000 * 3600) && (item.status_h == 'К готовке')) {
item.item_style = 'yellow'
};
if (item.status_h == 'Готовится') {
item.item_style = 'blue'
};
if (item.status_h == 'Выдан') {
item.item_style = 'lilac'
};
}
}
}