Files
psp_panel/src/app/domains/pos/layouts/layout.component.ts
T

144 lines
3.9 KiB
TypeScript
Raw Normal View History

2026-03-29 18:07:10 +03:30
import { AuthService } from '@/core';
import { NativeBridgeService } from '@/core/services';
import { ToastService } from '@/core/services/toast.service';
import { LayoutService } from '@/layout/service/layout.service';
2026-03-18 13:35:57 +03:30
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
import {
AfterViewInit,
Component,
TemplateRef,
ViewChild,
computed,
inject,
signal,
} from '@angular/core';
2026-03-18 13:35:57 +03:30
import { RouterOutlet } from '@angular/router';
import { MenuItem } from 'primeng/api';
import { Button, ButtonDirective } from 'primeng/button';
import { Card } from 'primeng/card';
import { Menu } from 'primeng/menu';
2026-03-29 18:07:10 +03:30
import images from 'src/assets/images';
import { PosInfoStore, PosProfileStore } from '../store';
import { PosChooseCardsComponent } from './choose-pos.component';
import { PosMainMenuSidebarComponent } from './mainMenuSidebar/main-menu-sidebar.component';
2026-03-18 13:35:57 +03:30
@Component({
selector: 'pos-layout',
templateUrl: './layout.component.html',
imports: [
PageLoadingComponent,
RouterOutlet,
ButtonDirective,
Card,
PosChooseCardsComponent,
Button,
PosMainMenuSidebarComponent,
Menu,
],
2026-03-18 13:35:57 +03:30
})
export class PosLayoutComponent implements AfterViewInit {
2026-03-18 13:35:57 +03:30
constructor() {}
private readonly nativeBridgeService = inject(NativeBridgeService);
private readonly toastService = inject(ToastService);
@ViewChild('topbarStart', { static: true }) topbarStart!: TemplateRef<any>;
@ViewChild('topbarCenter', { static: true }) topbarCenter!: TemplateRef<any>;
@ViewChild('topbarEnd', { static: true }) topbarEnd!: TemplateRef<any>;
2026-03-18 13:35:57 +03:30
2026-04-23 01:22:44 +03:30
private readonly posProfileStore = inject(PosProfileStore);
private readonly posInfoStore = inject(PosInfoStore);
2026-03-29 18:07:10 +03:30
private readonly authService = inject(AuthService);
private readonly layoutService = inject(LayoutService);
mainMenuVisible = signal(false);
2026-03-18 13:35:57 +03:30
2026-04-23 01:22:44 +03:30
readonly posProfileLoading = computed(() => this.posProfileStore.loading());
readonly posProfile = computed(() => this.posProfileStore.entity());
readonly posProfileError = computed(() => this.posProfileStore.error());
readonly posInfoLoading = computed(() => this.posInfoStore.loading());
readonly posInfo = computed(() => this.posInfoStore.entity());
readonly posInfoError = computed(() => this.posInfoStore.error());
readonly loading = computed(() => this.posProfileLoading());
readonly error = computed(() => this.posProfileError());
2026-03-29 18:07:10 +03:30
logout = () => {
this.authService.logout();
};
profileMenuItems: MenuItem[] = [
{
label: 'راهنمای سامانه',
icon: 'pi pi-question-circle',
disabled: true,
},
{
label: 'خروج',
icon: 'pi pi-sign-out',
command: this.logout,
},
];
2026-03-29 18:07:10 +03:30
placeholderLogo = images.placeholders.logo;
now = new Date();
2026-03-18 13:35:57 +03:30
getData() {
this.posProfileStore.getData().subscribe({
next: () => {
this.posInfoStore.getData().subscribe();
},
});
2026-03-18 13:35:57 +03:30
}
toggleMenu() {
this.mainMenuVisible.update((v) => !v);
}
onChoosePos() {
this.getData();
}
doPay() {
// this.nativeBridgeService.pay({
// amount: 10_000,
// id: '1',
// });
this.nativeBridgeService.print({
title: 'salam',
items: [
{
label: 'مجموع قیمت',
value: '10_000',
},
],
});
// @ts-ignore
// window.NativeBridge.pay(12312, 'test');
}
2026-03-18 13:35:57 +03:30
ngOnInit() {
this.layoutService.changeIsFullPage(true);
2026-03-18 13:35:57 +03:30
this.getData();
}
ngAfterViewInit() {
this.layoutService.setTopbarStartSlot(this.topbarStart);
this.layoutService.setTopbarCenterSlot(this.topbarCenter);
this.layoutService.setTopbarEndSlot(this.topbarEnd);
}
ngOnDestroy() {
this.layoutService.changeIsFullPage(false);
this.layoutService.setTopbarStartSlot(null);
this.layoutService.setTopbarCenterSlot(null);
this.layoutService.setTopbarEndSlot(null);
}
refresh() {
window.location.reload();
}
2026-03-18 13:35:57 +03:30
}