complex good module

This commit is contained in:
2026-03-16 20:59:28 +03:30
parent 739aef67a3
commit f2766e2d7d
17 changed files with 375 additions and 0 deletions
@@ -0,0 +1,17 @@
<p-dialog [header]="preparedTitle" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
<app-input label="عنوان" [control]="form.controls.name" name="name" />
<app-input label="شناسه عمومی" [control]="form.controls.sku" name="sku" />
<catalog-guild-goodCategories-select
[guildId]="guildId"
label="دسته‌بندی"
[control]="form.controls.category_id"
name="category_id"
/>
<app-enum-select type="unitType" [control]="form.controls.unit_type" />
<app-enum-select type="goodPricingModel" [control]="form.controls.pricing_model" />
<app-input label="توضیحات" [control]="form.controls.description" name="description" />
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</p-dialog>
@@ -0,0 +1,55 @@
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { Dialog } from 'primeng/dialog';
import { EnumSelectComponent } from '@/shared/apiEnum/select.component';
import { CatalogGuildGoodCategoriesSelectComponent } from '@/shared/catalog/guildGoodCategories';
import { IConsumerComplexGoodRequest, IConsumerComplexGoodResponse } from '../../models/goods_io';
import { GuildGoodsService } from '../../services/goods.service';
@Component({
selector: 'consumer-complex-good-form',
templateUrl: './form.component.html',
imports: [
ReactiveFormsModule,
Dialog,
InputComponent,
FormFooterActionsComponent,
EnumSelectComponent,
CatalogGuildGoodCategoriesSelectComponent,
],
})
export class ConsumerComplexGoodFormComponent extends AbstractFormDialog<
IConsumerComplexGoodRequest,
IConsumerComplexGoodResponse
> {
@Input({ required: true }) businessId!: string;
@Input({ required: true }) complexId!: string;
@Input({ required: true }) guildId!: string;
@Input() categoryId?: string;
private service = inject(GuildGoodsService);
form = this.fb.group({
name: [this.initialValues?.name || '', [Validators.required]],
sku: [this.initialValues?.sku || '', [Validators.required]],
unit_type: [this.initialValues?.unit_type || '', [Validators.required]],
pricing_model: [this.initialValues?.pricing_model || '', [Validators.required]],
category_id: [this.initialValues?.category.id || '', [Validators.required]],
description: [this.initialValues?.description || ''],
});
get preparedTitle() {
return `${this.editMode ? 'ویرایش' : 'ایجاد'} کالا`;
}
override submitForm(payload: IConsumerComplexGoodRequest) {
if (this.editMode) {
return this.service.update(this.businessId, this.complexId, this.categoryId!, payload);
}
return this.service.create(this.businessId, this.complexId, payload);
}
}
@@ -0,0 +1,25 @@
<app-page-data-list
pageTitle="مدیریت کالاها"
[addNewCtaLabel]="'افزودن کالای جدید'"
[columns]="columns"
[showAdd]="true"
emptyPlaceholderTitle="کالایی یافت نشد"
emptyPlaceholderDescription="برای افزودن کالای جدید، روی دکمهٔ بالا کلیک کنید."
[items]="items()"
[loading]="loading()"
[showAdd]="true"
[showEdit]="true"
[fullHeight]="fullHeight"
(onEdit)="onEditClick($event)"
(onAdd)="openAddForm()"
/>
<consumer-complex-good-form
[businessId]="businessId"
[complexId]="complexId"
[guildId]="guildId"
[(visible)]="visibleForm"
[initialValues]="selectedItemForEdit() || undefined"
[categoryId]="selectedItemForEdit()?.id"
[editMode]="editMode()"
(onSubmit)="refresh()"
/>
@@ -0,0 +1,42 @@
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
import {
IColumn,
PageDataListComponent,
} from '@/shared/components/pageDataList/page-data-list.component';
import { Component, inject, Input } from '@angular/core';
import { IConsumerComplexGoodResponse } from '../../models/goods_io';
import { GuildGoodsService } from '../../services/goods.service';
import { ConsumerComplexGoodFormComponent } from './form.component';
@Component({
selector: 'consumer-complex-goods-list',
templateUrl: './list.component.html',
imports: [PageDataListComponent, ConsumerComplexGoodFormComponent],
})
export class ConsumerComplexGoodsListComponent extends AbstractList<IConsumerComplexGoodResponse> {
@Input({ required: true }) businessId!: string;
@Input({ required: true }) complexId!: string;
@Input({ required: true }) guildId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه' },
{ field: 'name', header: 'عنوان' },
{ field: 'sku', header: 'شناسه‌ی عمومی' },
{ field: 'category', header: 'دسته‌بندی', type: 'nested', nestedPath: 'category.name' },
{
field: 'created_at',
header: 'تاریخ ایجاد',
type: 'date',
},
];
service = inject(GuildGoodsService);
override setColumns(): void {
this.columns = this.header;
}
override getDataRequest() {
return this.service.getAll(this.businessId, this.complexId);
}
}
@@ -0,0 +1,8 @@
const baseUrl = (businessId: string, complexId: string) =>
`/api/v1/consumer/business_activities/${businessId}/complexes/${complexId}/goods`;
export const CONSUMER_COMPLEX_GOODS_API_ROUTES = {
list: (businessId: string, complexId: string) => `${baseUrl(businessId, complexId)}`,
single: (businessId: string, complexId: string, id: string) =>
`${baseUrl(businessId, complexId)}/${id}`,
};
@@ -0,0 +1,48 @@
import { NamedRoutes } from '@/core';
import { Routes } from '@angular/router';
export type TGoodsRouteNames = 'goods';
const baseUrl = (businessId: string, complexId: string) =>
`/consumer/business_activities/${businessId}/complexes/${complexId}/goods`;
export const consumerComplexGoodsNamedRoutes: NamedRoutes<TGoodsRouteNames> = {
goods: {
path: 'goods',
loadComponent: () =>
import('../../views/goods/list.component').then((m) => m.ConsumerComplexGoodsComponent),
// @ts-ignore
meta: {
title: 'کالاها',
pagePath: (businessId: string, complexId: string) => baseUrl(businessId, complexId),
},
},
// good: {
// path: 'goods/:goodId',
// loadComponent: () =>
// import('../../views/goods/single.component').then((m) => m.SuperAdminUserPosComponent),
// // @ts-ignore
// meta: {
// title: 'پایانه‌ی فروش',
// pagePath: (businessId: string, complexId: string, goodId: string) =>
// `${baseUrl(businessId, complexId)}/${goodId}`,
// },
// },
};
export const CONSUMER_COMPLEX_GOODS_ROUTES: Routes = [
consumerComplexGoodsNamedRoutes.goods,
// {
// path: consumerComplexGoodsNamedRoutes.good.path,
// loadComponent: () =>
// import('../../components/goods/layout.component').then(
// (m) => m.SuperAdminConsumerPosLayoutComponent,
// ),
// children: [
// {
// path: '',
// loadComponent: consumerComplexGoodsNamedRoutes.good.loadComponent,
// },
// ],
// },
];
@@ -0,0 +1,23 @@
import ISummary from '@/core/models';
export interface IConsumerComplexGoodRawResponse {
id: string;
name: string;
sku: string;
category: ISummary;
unit_type: string;
pricing_model: string;
description?: string;
created_at: string;
updated_at: string;
}
export interface IConsumerComplexGoodResponse extends IConsumerComplexGoodRawResponse {}
export interface IConsumerComplexGoodRequest {
name: string;
sku: string;
category_id: string;
unit_type: string;
pricing_model: string;
description?: string;
}
@@ -0,0 +1,58 @@
import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { CONSUMER_COMPLEX_GOODS_API_ROUTES } from '../constants/apiRoutes/complexGoods';
import {
IConsumerComplexGoodRawResponse,
IConsumerComplexGoodRequest,
IConsumerComplexGoodResponse,
} from '../models/goods_io';
@Injectable({ providedIn: 'root' })
export class GuildGoodsService {
constructor(private http: HttpClient) {}
private apiRoutes = CONSUMER_COMPLEX_GOODS_API_ROUTES;
getAll(
businessId: string,
complexId: string,
): Observable<IPaginatedResponse<IConsumerComplexGoodResponse>> {
return this.http.get<IPaginatedResponse<IConsumerComplexGoodRawResponse>>(
this.apiRoutes.list(businessId, complexId),
);
}
getSingle(
businessId: string,
complexId: string,
id: string,
): Observable<IConsumerComplexGoodResponse> {
return this.http.get<IConsumerComplexGoodRawResponse>(
this.apiRoutes.single(businessId, complexId, id),
);
}
create(
businessId: string,
complexId: string,
data: IConsumerComplexGoodRequest,
): Observable<IConsumerComplexGoodResponse> {
return this.http.post<IConsumerComplexGoodResponse>(
this.apiRoutes.list(businessId, complexId),
data,
);
}
update(
businessId: string,
complexId: string,
id: string,
data: IConsumerComplexGoodRequest,
): Observable<IConsumerComplexGoodResponse> {
return this.http.patch<IConsumerComplexGoodResponse>(
this.apiRoutes.single(businessId, complexId, id),
data,
);
}
}
@@ -10,6 +10,7 @@
</app-card-data>
<consumer-poses-list [businessId]="businessId()" [complexId]="complexId()" />
<consumer-complex-goods-list [businessId]="businessId()" [complexId]="complexId()" [guildId]="business()!.guild.id" />
<consumer-complex-form
[(visible)]="editMode"
@@ -4,6 +4,7 @@ import pageParamsUtils from '@/utils/page-params.utils';
import { Component, computed, effect, inject, signal } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ConsumerComplexFormComponent } from '../../components/complexes/form.component';
import { ConsumerComplexGoodsListComponent } from '../../components/goods/list.component';
import { ConsumerPosesComponent } from '../../components/poses/list.component';
import { BusinessActivityStore } from '../../store/businessActivity.store';
import { ConsumerComplexStore } from '../../store/complex.store';
@@ -16,6 +17,7 @@ import { ConsumerComplexStore } from '../../store/complex.store';
KeyValueComponent,
ConsumerComplexFormComponent,
ConsumerPosesComponent,
ConsumerComplexGoodsListComponent,
],
})
export class ConsumerComplexComponent {
@@ -33,6 +35,7 @@ export class ConsumerComplexComponent {
readonly loading = computed(() => this.store.loading());
readonly complex = computed(() => this.store.entity());
readonly business = computed(() => this.businessStore.entity());
constructor() {
effect(() => {
@@ -0,0 +1 @@
<consumer-complex-goods-list [businessId]="businessId()" [complexId]="complexId()" />
@@ -0,0 +1,44 @@
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
import { BreadcrumbService } from '@/core/services';
import pageParamsUtils from '@/utils/page-params.utils';
import { Component, computed, inject, signal } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ConsumerComplexGoodsListComponent } from '../../components/goods/list.component';
import { consumerComplexGoodsNamedRoutes } from '../../constants/routes/goods';
import { BusinessActivityStore } from '../../store/businessActivity.store';
import { ConsumerComplexStore } from '../../store/complex.store';
@Component({
selector: 'consumer-complex-goods',
templateUrl: './list.component.html',
imports: [ConsumerComplexGoodsListComponent],
})
export class ConsumerComplexGoodsComponent {
private readonly route = inject(ActivatedRoute);
private readonly breadcrumbService = inject(BreadcrumbService);
private readonly businessStore = inject(BusinessActivityStore);
private readonly complexStore = inject(ConsumerComplexStore);
pageParams = computed(() => pageParamsUtils(this.route));
businessId = signal<string>(this.pageParams()['businessActivityId']);
complexId = signal<string>(this.pageParams()['complexId']);
ngOnInit() {
this.setBreadcrumb();
}
setBreadcrumb() {
this.breadcrumbService.setItems([
...this.businessStore.breadcrumbItems(),
...this.complexStore.breadcrumbItems(),
{
title: consumerComplexGoodsNamedRoutes.goods.meta.title,
routerLink: consumerComplexGoodsNamedRoutes.goods.meta.pagePath!(
this.businessId(),
this.complexId(),
),
},
]);
}
}
+1
View File
@@ -2,6 +2,7 @@ const baseUrl = '/api/v1/catalog';
export const CATALOG_API_ROUTES = {
guilds: () => `${baseUrl}/guilds`,
guildGoodCategories: (guildId: string) => `${baseUrl}/guilds/${guildId}/good_categories`,
providers: () => `${baseUrl}/providers`,
devices: () => `${baseUrl}/devices`,
deviceBrands: () => `${baseUrl}/device_brands`,
@@ -0,0 +1,13 @@
<uikit-field [label]="label" [control]="control" [showLabel]="showLabel" [showErrors]="showErrors">
<p-select
[loading]="loading()"
[options]="items()"
optionLabel="name"
[optionValue]="selectOptionValue"
placeholder="انتخاب دسته‌بندی"
[formControl]="control"
[showClear]="showClear"
[filter]="true"
appendTo="body"
/>
</uikit-field>
@@ -0,0 +1,31 @@
import { IListingResponse } from '@/core/models/service.model';
import ISummary from '@/core/models/summary';
import { AbstractSelectComponent } from '@/shared/abstractClasses';
import { UikitFieldComponent } from '@/uikit';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { Select } from 'primeng/select';
import { CatalogsService } from '../../service';
@Component({
selector: 'catalog-guild-goodCategories-select',
templateUrl: './select.component.html',
imports: [UikitFieldComponent, Select, ReactiveFormsModule],
})
export class CatalogGuildGoodCategoriesSelectComponent extends AbstractSelectComponent<
ISummary,
IListingResponse<ISummary>
> {
@Input({ required: true }) guildId!: string;
@Input() override showClear: boolean = false;
@Input() label: string = '';
private readonly service = inject(CatalogsService);
ngOnInit() {
this.getData();
}
getDataService() {
return this.service.getGuildGoodCategories(this.guildId);
}
}
@@ -0,0 +1 @@
export * from './components/select.component';
+4
View File
@@ -15,6 +15,10 @@ export class CatalogsService {
return this.http.get<IListingResponse<ISummary>>(this.apiRoutes.guilds());
}
getGuildGoodCategories(guildId: string): Observable<IListingResponse<ISummary>> {
return this.http.get<IListingResponse<ISummary>>(this.apiRoutes.guildGoodCategories(guildId));
}
getProviders(): Observable<IListingResponse<ISummary>> {
return this.http.get<IListingResponse<ISummary>>(this.apiRoutes.providers());
}