u
This commit is contained in:
@@ -1,41 +1,62 @@
|
||||
<div class="org-chart-container">
|
||||
<div class="org-tree">
|
||||
<div class="org-node root-node" id="root-node">
|
||||
<div class="node-card">
|
||||
<div class="node-avatar">
|
||||
<MudAvatar Size="Size.Large">
|
||||
<MudImage ObjectFit="ObjectFit.Cover"
|
||||
ObjectPosition="ObjectPosition.Center"
|
||||
Src="images/avatar1.jpg" />
|
||||
</MudAvatar>
|
||||
@if (_currentUser?.Children?.Any() == true)
|
||||
{
|
||||
<button class="expand-btn" @onclick="ToggleExpand" data-user-id="@_currentUser.Id">
|
||||
<MudIcon Icon="@(_isExpanded ? Icons.Material.Filled.Remove : Icons.Material.Filled.Add)" Size="Size.Small" />
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<div class="node-info">
|
||||
<div class="node-name">@(_currentUser?.FirstName) @(_currentUser?.LastName)</div>
|
||||
<div class="node-amounts">
|
||||
<div class="personal-amount">
|
||||
<span class="label">خرید شخصی:</span>
|
||||
<span class="amount">@(_currentUser?.PersonalPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
|
||||
</div>
|
||||
<div class="team-amount">
|
||||
<span class="label">خرید تیمی:</span>
|
||||
<span class="amount">@(_currentUser?.TeamPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
|
||||
@if (_currentUser != null)
|
||||
{
|
||||
<div class="org-chart-container">
|
||||
<div class="org-tree">
|
||||
<div class="org-node root-node" id="root-node">
|
||||
<div class="node-card">
|
||||
<div class="node-avatar">
|
||||
@if (!string.IsNullOrWhiteSpace(_currentUser.Avatar))
|
||||
{
|
||||
<MudAvatar Size="Size.Large">
|
||||
<MudImage ObjectFit="ObjectFit.Cover"
|
||||
ObjectPosition="ObjectPosition.Center"
|
||||
Src="@_currentUser.Avatar" />
|
||||
</MudAvatar>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudAvatar Size="Size.Large" Color="Color.Primary" Variant="Variant.Outlined">
|
||||
@(string.IsNullOrWhiteSpace(_currentUser.FirstName) ? "N" : _currentUser.FirstName.Substring(0, 1))
|
||||
</MudAvatar>
|
||||
}
|
||||
|
||||
@if (_currentUser?.Children?.Any() == true)
|
||||
{
|
||||
<button class="expand-btn" @onclick="ToggleExpand" data-user-id="@_currentUser.Id">
|
||||
<MudIcon Icon="@(_isExpanded ? Icons.Material.Filled.Remove : Icons.Material.Filled.Add)" Size="Size.Small" />
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<div class="node-info">
|
||||
@if (!string.IsNullOrWhiteSpace(_currentUser.FirstName) || !string.IsNullOrWhiteSpace(_currentUser.LastName))
|
||||
{
|
||||
<div class="node-name">@_currentUser.FirstName @_currentUser.LastName</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="node-name">@_currentUser.Mobile</div>
|
||||
}
|
||||
<div class="node-amounts">
|
||||
<div class="personal-amount">
|
||||
<span class="label">خرید شخصی:</span>
|
||||
<span class="amount">@(_currentUser?.PersonalPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
|
||||
</div>
|
||||
<div class="team-amount">
|
||||
<span class="label">خرید تیمی:</span>
|
||||
<span class="amount">@(_currentUser?.TeamPurchase?.ToThousands().ToCurrencyUnitIRT() ?? "0 تومان")</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (_isExpanded && _currentUser?.Children?.Any() == true)
|
||||
{
|
||||
<CascadingValue Value="this">
|
||||
<OrganizationChartLevel Nodes="_currentUser.Children" Level="1" />
|
||||
</CascadingValue>
|
||||
}
|
||||
@if (_isExpanded && _currentUser?.Children?.Any() == true)
|
||||
{
|
||||
<CascadingValue Value="this">
|
||||
<OrganizationChartLevel Nodes="_currentUser.Children" Level="1" />
|
||||
</CascadingValue>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using static FrontOffice.Main.Pages.Profile.Components.OrganizationChartLevel;
|
||||
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using static FrontOffice.Main.Pages.Profile.Components.OrganizationChartLevel;
|
||||
|
||||
namespace FrontOffice.Main.Pages.Profile.Components;
|
||||
public partial class OrganizationChart
|
||||
@@ -6,112 +9,82 @@ public partial class OrganizationChart
|
||||
private UserNode? _currentUser;
|
||||
private bool _isExpanded;
|
||||
|
||||
[Inject] private UserContract.UserContractClient UserContract { get; set; } = default!;
|
||||
private GetUserResponse _userProfile = new();
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadCurrentUser();
|
||||
}
|
||||
|
||||
private async Task LoadUserProfile()
|
||||
{
|
||||
try
|
||||
{
|
||||
_userProfile = await UserContract.GetUserAsync(request: new());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Handle the case when user is not authenticated or API fails
|
||||
_userProfile = new GetUserResponse();
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
private async Task LoadCurrentUser()
|
||||
{
|
||||
await LoadUserProfile();
|
||||
|
||||
|
||||
// Mock data - replace with actual API call
|
||||
_currentUser = new UserNode
|
||||
{
|
||||
Id = 1,
|
||||
FirstName = "علی",
|
||||
LastName = "رضایی",
|
||||
Avatar = "images/avatar1.jpg",
|
||||
PersonalPurchase = 2500000,
|
||||
TeamPurchase = 15000000,
|
||||
Children = new List<UserNode>
|
||||
{
|
||||
new UserNode
|
||||
{
|
||||
Id = 2,
|
||||
FirstName = "مریم",
|
||||
LastName = "احمدی",
|
||||
Avatar = "images/avatar2.jpg",
|
||||
PersonalPurchase = 1800000,
|
||||
TeamPurchase = 8500000,
|
||||
Children = new List<UserNode>
|
||||
{
|
||||
new UserNode
|
||||
{
|
||||
Id = 5,
|
||||
FirstName = "سارا",
|
||||
LastName = "کریمی",
|
||||
PersonalPurchase = 1200000,
|
||||
TeamPurchase = 3200000,
|
||||
Children = new List<UserNode>
|
||||
{
|
||||
new UserNode
|
||||
{
|
||||
Id = 8,
|
||||
FirstName = "نازنین",
|
||||
LastName = "رضایی",
|
||||
PersonalPurchase = 950000,
|
||||
TeamPurchase = 2100000
|
||||
},
|
||||
new UserNode
|
||||
{
|
||||
Id = 8,
|
||||
FirstName = "فرزاد",
|
||||
LastName = "رضایی",
|
||||
PersonalPurchase = 950000,
|
||||
TeamPurchase = 2100000
|
||||
}
|
||||
}
|
||||
},
|
||||
new UserNode
|
||||
{
|
||||
Id = 6,
|
||||
FirstName = "امیر",
|
||||
LastName = "حسینی",
|
||||
PersonalPurchase = 950000,
|
||||
TeamPurchase = 1800000
|
||||
}
|
||||
}
|
||||
},
|
||||
new UserNode
|
||||
{
|
||||
Id = 3,
|
||||
FirstName = "حسن",
|
||||
LastName = "کریمی",
|
||||
Avatar = "images/avatar3.jpg",
|
||||
PersonalPurchase = 2200000,
|
||||
TeamPurchase = 9200000,
|
||||
Children = new List<UserNode>
|
||||
{
|
||||
new UserNode
|
||||
{
|
||||
Id = 7,
|
||||
FirstName = "فاطمه",
|
||||
LastName = "رضایی",
|
||||
PersonalPurchase = 1350000,
|
||||
TeamPurchase = 4100000
|
||||
},
|
||||
new UserNode
|
||||
{
|
||||
Id = 7,
|
||||
FirstName = "آرش",
|
||||
LastName = "رضایی",
|
||||
PersonalPurchase = 1350000,
|
||||
TeamPurchase = 4100000
|
||||
}
|
||||
}
|
||||
},
|
||||
new UserNode
|
||||
{
|
||||
Id = 4,
|
||||
FirstName = "زهرا",
|
||||
LastName = "محمدی",
|
||||
Avatar = "images/avatar4.jpg",
|
||||
PersonalPurchase = 1950000,
|
||||
TeamPurchase = 7800000
|
||||
}
|
||||
}
|
||||
Id = _userProfile.Id,
|
||||
FirstName = _userProfile.FirstName,
|
||||
LastName = _userProfile.LastName,
|
||||
Mobile = _userProfile.Mobile,
|
||||
Avatar = _userProfile.AvatarPath,
|
||||
PersonalPurchase = 0,
|
||||
TeamPurchase = 0,
|
||||
Children = await GetUserChildren(userId: _userProfile.Id)
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<List<UserNode>?> GetUserChildren(long userId)
|
||||
{
|
||||
Console.WriteLine("OK0");
|
||||
if (userId != 0)
|
||||
{
|
||||
Console.WriteLine("OK1");
|
||||
var children = await UserContract.GetAllUserByFilterAsync(request: new()
|
||||
{
|
||||
Filter = new()
|
||||
{
|
||||
ParentId = userId,
|
||||
}
|
||||
});
|
||||
if (children?.Models?.Any() == true)
|
||||
{
|
||||
Console.WriteLine("OK2");
|
||||
var result = new List<UserNode>();
|
||||
foreach (var item in children.Models)
|
||||
{
|
||||
var node = new UserNode
|
||||
{
|
||||
Id = item.Id,
|
||||
FirstName = item.FirstName,
|
||||
LastName = item.LastName,
|
||||
Mobile = item.Mobile,
|
||||
Avatar = item.AvatarPath,
|
||||
ReferralCode = item.ReferralCode,
|
||||
PersonalPurchase = 0,
|
||||
TeamPurchase = 0,
|
||||
Children = await GetUserChildren(userId: item.Id)
|
||||
};
|
||||
result.Add(node);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private void ToggleExpand()
|
||||
{
|
||||
_isExpanded = !_isExpanded;
|
||||
|
||||
@@ -6,11 +6,22 @@
|
||||
<div class="node-connector"></div>
|
||||
<div class="node-card">
|
||||
<div class="node-avatar">
|
||||
<MudAvatar Size="@GetAvatarSize(Level)">
|
||||
<MudImage ObjectFit="ObjectFit.Cover"
|
||||
ObjectPosition="ObjectPosition.Center"
|
||||
Src="@(string.IsNullOrEmpty(node.Avatar) ? "images/avatar1.jpg" : node.Avatar)" />
|
||||
</MudAvatar>
|
||||
@if (!string.IsNullOrWhiteSpace(node.Avatar))
|
||||
{
|
||||
<MudAvatar Size="@GetAvatarSize(Level)">
|
||||
<MudImage ObjectFit="ObjectFit.Cover"
|
||||
ObjectPosition="ObjectPosition.Center"
|
||||
Src="@node.Avatar" />
|
||||
</MudAvatar>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudAvatar Size="@GetAvatarSize(Level)"
|
||||
Color="Color.Primary"
|
||||
Variant="Variant.Outlined">
|
||||
@(string.IsNullOrWhiteSpace(node.FirstName) ? "N" : node.FirstName.Substring(0, 1))
|
||||
</MudAvatar>
|
||||
}
|
||||
@if (node.Children?.Any() == true)
|
||||
{
|
||||
<button class="expand-btn" @onclick="() => ToggleNodeExpand(node.Id)" data-user-id="@node.Id">
|
||||
@@ -19,7 +30,14 @@
|
||||
}
|
||||
</div>
|
||||
<div class="node-info">
|
||||
<div class="node-name">@node.FirstName @node.LastName</div>
|
||||
@if (!string.IsNullOrWhiteSpace(node.FirstName) || !string.IsNullOrWhiteSpace(node.LastName))
|
||||
{
|
||||
<div class="node-name">@node.FirstName @node.LastName</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="node-name">@node.Mobile</div>
|
||||
}
|
||||
<div class="node-amounts">
|
||||
<div class="personal-amount">
|
||||
<span class="label">خرید شخصی:</span>
|
||||
|
||||
@@ -40,6 +40,8 @@ public partial class OrganizationChartLevel
|
||||
public long Id { get; set; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string? Mobile { get; set; }
|
||||
public string? ReferralCode { get; set; }
|
||||
public string? Avatar { get; set; }
|
||||
public long? PersonalPurchase { get; set; }
|
||||
public long? TeamPurchase { get; set; }
|
||||
|
||||
@@ -136,7 +136,7 @@ public partial class Index
|
||||
|
||||
private async Task ShareReferralCode()
|
||||
{
|
||||
var shareText = $"کد دعوت من در فرصت: {_userProfile.ReferralCode}\nبرای عضویت از این لینک استفاده کنید: {Navigation.BaseUri}?ref={_userProfile.ReferralCode}";
|
||||
var shareText = $"کد دعوت من در فرصت: {_userProfile.ReferralCode}\nبرای عضویت از این لینک استفاده کنید:";
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user