complex good module
This commit is contained in:
+17
@@ -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>
|
||||
+55
@@ -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);
|
||||
}
|
||||
}
|
||||
+25
@@ -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()"
|
||||
/>
|
||||
+42
@@ -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);
|
||||
}
|
||||
}
|
||||
+8
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
@@ -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"
|
||||
|
||||
+3
@@ -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(),
|
||||
),
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user