h-selfdelivery-admin-panel-p/src/app/pages/clients/clients.component.ts

167 lines
4.6 KiB
TypeScript

import { Component, OnInit } from "@angular/core";
import { JsonrpcService, RpcService } from "src/app/services/jsonrpc.service";
import { MessageService } from "primeng/api";
import { Client } from "src/app/interface/data";
import { ConfirmationService } from 'primeng/api';
@Component({
selector: 'app-clents',
templateUrl: './clients.component.html',
styleUrls: ['./clients.component.scss']
})
export class ClientsComponent implements OnInit {
public clients: Client[] = [];
public new_cl = true;
public choose = this.jsonRpcService.ClientChoose;
public create = false;
public chooseName!: string;
public myAudio = new Audio();
constructor(
private jsonRpcService: JsonrpcService,
private messageService: MessageService,
private confirmationService: ConfirmationService
) { }
ngOnInit(): void {
this.getClients();
}
async getClients() {
this.create = false;
this.new_cl = true;
await this.jsonRpcService.rpc2({
method: 'getClients',
params: {
"name": ""
}
}, RpcService.authService, false)
.subscribe({
next: (result) => {
let data = result.result;
this.clients = data;
document.getElementsByTagName('thead')[0].style.display = 'table';
document.getElementsByTagName('thead')[0].style.width = '100%';
document.getElementsByTagName('thead')[0].style.tableLayout = 'fixed';
document.getElementsByTagName('tbody')[0].style.display = 'block';
document.getElementsByTagName('tbody')[0].style.maxHeight = 'calc(100vh - 290px)';
document.getElementsByTagName('tbody')[0].style.overflowY = 'scroll';
},
error: (err) => {
console.log('ERROR: ', err)
this.messageService.add({
severity: 'error',
summary: 'Произошла ошибка!',
})
}
});
this.chooseName = this.jsonRpcService.ClientChooseName;
}
changeClient1(id: any, name: any) {
this.new_cl = false;
setTimeout(() => document.getElementsByTagName("input")[0].value = name, 100);
this.jsonRpcService.changeId = id
}
changeClient() {
let name_n = document.getElementsByTagName("input")[0].value
this.jsonRpcService.rpc2({
method: 'updateClient',
params: {
"client_id": this.jsonRpcService.changeId,
"name": name_n
}
}, RpcService.authService, false)
.subscribe({
next: (result) => {
let data = result.result;
/*this.clients = data;*/
},
error: (err) => {
console.log('ERROR: ', err)
this.messageService.add({
severity: 'error',
summary: 'Произошла ошибка!',
})
}
});
this.new_cl = true;
this.jsonRpcService.changeId = "";
this.getClients();
}
deleteClient(id: any) {
this.jsonRpcService.rpc2({
method: 'deleteClient',
params: {
"client_id": id
}
}, RpcService.authService, false)
.subscribe({
next: (result) => {
let data = result.result;
/*this.clients = data;*/
},
error: (err) => {
console.log('ERROR: ', err)
this.messageService.add({
severity: 'error',
summary: 'Произошла ошибка!',
})
}
});
setTimeout(() => this.getClients(), 100);
}
chooseClient(id: any, name: any) {
this.jsonRpcService.ClientChooseName = name;
this.jsonRpcService.ClientChoose = id;
this.choose = this.jsonRpcService.ClientChoose;
this.chooseName = this.jsonRpcService.ClientChooseName;
}
createCient() {
this.new_cl = false;
this.create = true;
}
createClient2() {
let name = document.getElementsByTagName("input")[0].value
this.jsonRpcService.rpc2({
method: 'createClient',
params: {
"name": name
}
}, RpcService.authService, false)
.subscribe({
next: (result) => {
let data = result.result;
/*this.clients = data;*/
},
error: (err) => {
console.log('ERROR: ', err)
this.messageService.add({
severity: 'error',
summary: 'Произошла ошибка!',
})
}
});
setTimeout(() => this.getClients(), 100);
}
confirm(id: any) {
this.confirmationService.confirm({
message: 'Вы действительно хотите удалить элемент?',
accept: () => {
this.deleteClient(id)
}
});
}
}