Files
Hushian/Presentation/HushianWebApp/Pages/FromUserSide/ZUserPanel.razor

285 lines
9.2 KiB
Plaintext
Raw Normal View History

2025-07-12 21:33:44 +03:30
@using Common.Dtos.Company
@using Common.Dtos.Conversation
@using Common.Dtos.Group
2025-07-11 20:37:28 +03:30
@using HushianWebApp.Components.UserPanel
@using HushianWebApp.Service
@using HushianWebApp.Services
@inject IJSRuntime JSRuntime
@inject CompanyService companyService
@inject GroupService groupService
@inject ILocalStorageService localStorageService;
@inject AuthService authService;
@inject BaseController baseController;
@inject ConversationService conversationService
@layout UserPanelLayout
2025-07-29 22:21:38 +03:30
@page "/ZUserPanel/{CompanyID:int}"
@page "/ZUserPanel/{CompanyID:int}/{ConversationID:int?}"
2025-07-11 20:37:28 +03:30
<div class="card shadow chat-box-expanded">
<div class="card-header bg-success text-white d-flex justify-content-between align-items-center">
<span>
<strong>@CompanyName / @groups.FirstOrDefault(f => f.ID == SelectedGroup)?.Name / @SelectedConversation?.ExperFullName</strong><br />
<Badge Color="BadgeColor.Danger"
2025-07-26 16:52:59 +03:30
Position="Position.Absolute"
Placement="BadgePlacement.TopRight"
IndicatorType="BadgeIndicatorType.RoundedPill"
VisuallyHiddenText="status"></Badge>
2025-07-11 20:37:28 +03:30
<small>پاسخگویی سوالات شما هستیم</small>
</span>
2025-07-26 22:15:48 +03:30
@if (ConversationID.HasValue)
{
<button class="btn-close btn-close-white" @onclick="CloseChat"></button>
}
2025-07-11 20:37:28 +03:30
</div>
<div class="card-body" style="max-height: 500px; overflow-y: auto; background-color: #f9f9f9;">
2025-07-27 16:04:28 +03:30
@if (!IsFisrLoding)
2025-07-11 20:37:28 +03:30
{
2025-07-27 16:04:28 +03:30
@if (!IsLogin)
{
<LoginComponent OnMultipleOfThree="EventCallback.Factory.Create(this, Login)" />
}
@if (IsLogin)
2025-07-11 20:37:28 +03:30
{
2025-07-27 16:04:28 +03:30
@if (SelectedConversation == null)
{
<button class="btn btn-outline-secondary btn-sm mt-2"
@onclick="()=> {SelectedGroup=0; StateHasChanged();}" style="margin-left:5px;margin-bottom:5px">
شرکت @CompanyName (@CountQueueCompany)
</button>
@GCContent
@if (Conversations.Count > 0)
{
@ConversationsContent
}
2025-07-11 20:37:28 +03:30
2025-07-27 16:04:28 +03:30
}
else
2025-07-11 20:37:28 +03:30
{
2025-07-27 16:04:28 +03:30
<ChatBoxComponent SelectedConversationItems="SelectedConversationItems" />
2025-07-11 20:37:28 +03:30
}
2025-07-27 16:04:28 +03:30
2025-07-11 20:37:28 +03:30
}
2025-07-27 16:04:28 +03:30
}
else
{
<div class="d-flex justify-content-center">
<Spinner Class="me-3" Type="SpinnerType.Dots" Color="SpinnerColor.Primary" Visible="@IsFisrLoding" />
2025-07-11 20:37:28 +03:30
2025-07-27 16:04:28 +03:30
</div>
2025-07-11 20:37:28 +03:30
}
</div>
2025-07-27 16:04:28 +03:30
@if (IsLogin && (@* Conversations.Count == 0 && *@ SelectedConversation == null) || (@* Conversations.Count > 0 && *@ SelectedConversation != null && (SelectedConversation.status != Common.Enums.ConversationStatus.Finished)))
2025-07-11 20:37:28 +03:30
{
<div class="card-header text-white d-flex justify-content-between align-items-center">
<input type="text" class="form-control" @bind-value="InputMessage" placeholder="پیام خود را بنویسید..." style="margin-left:10px" />
<Button Color="ButtonColor.Dark" Outline="true"><Icon Name="IconName.AppIndicator" @onclick="OnClickSendMssage" /> </Button>
</div>
}
</div>
<style>
.chat-box-expanded {
2025-07-26 16:52:59 +03:30
position: fixed;
bottom: 50%;
right: 50%;
transform: translate(50%, 50%);
width: 90vw;
height: 80%;
z-index: 1051;
transition: all 0.3s ease;
2025-07-11 20:37:28 +03:30
}
</style>
@code {
#region Parameter
[Parameter] public int CompanyID { get; set; }
[Parameter] public int? ConversationID { get; set; }
#endregion
#region Fild
2025-07-12 21:33:44 +03:30
public Read_ConversationDto? SelectedConversation { get; set; } = null;
public List<Read_ConversationDto> Conversations { get; set; } = new();
public List<Read_ConversationResponseDto>? SelectedConversationItems { get; set; } = null;
2025-07-11 20:37:28 +03:30
public RenderFragment GCContent { get; set; }
public RenderFragment ConversationsContent { get; set; }
2025-07-12 21:33:44 +03:30
List<Read_GroupDto> groups = new List<Read_GroupDto>();
public ReadANDUpdate_CompanyDto company { get; set; } = new();
2025-07-11 20:37:28 +03:30
int CountQueueCompany = 0;
public string CompanyName { get; set; } = "هوشیان";
public bool IsLogin { get; set; } = false;
2025-07-27 16:04:28 +03:30
public bool IsFisrLoding { get; set; } = true;
2025-07-11 20:37:28 +03:30
public int? SelectedGroup { get; set; }
public string InputMessage { get; set; }
public bool Sending { get; set; } = false;
2025-08-07 22:41:22 +03:30
2025-07-11 20:37:28 +03:30
#endregion
}
@functions {
protected override async Task OnParametersSetAsync()
{
2025-07-26 22:15:48 +03:30
// if (ConversationID.HasValue && ConversationID > 0 && Conversations.Count > 0)
// await SelectedConv(ConversationID.Value);
2025-07-11 20:37:28 +03:30
await base.OnParametersSetAsync();
}
protected override async Task OnInitializedAsync()
{
2025-07-27 16:04:28 +03:30
IsFisrLoding = true;
2025-07-11 20:37:28 +03:30
await CheckOnline();
2025-07-27 16:04:28 +03:30
IsFisrLoding = false;
2025-07-11 20:37:28 +03:30
await base.OnInitializedAsync();
}
async Task CheckOnline()
{
2025-07-26 15:11:07 +03:30
var token = await localStorageService.GetItem<string>("U/key");
2025-07-11 20:37:28 +03:30
if (string.IsNullOrEmpty(token))
{
IsLogin = false;
}
else
{
await baseController.RemoveToken();
await baseController.SetToken(token);
if (!await authService.IsOnline())
{
await baseController.RemoveToken();
IsLogin = false;
}
else
{
IsLogin = true;
await Login();
}
}
}
async Task CallBackSelectedGroup(int ID)
{
SelectedGroup = ID;
StateHasChanged();
}
async Task Login()
{
// اینجا منطق ورود کاربر را پیاده‌سازی کنید
IsLogin = true;
var _company = await companyService.GetCompany(CompanyID);
if (_company == null)
{
// not Founf Company
}
else
{
if (!_company.Available)
{
// not Available Company
}
else
{
2025-07-12 21:33:44 +03:30
CompanyName = _company.FullName;
2025-07-11 20:37:28 +03:30
company = _company;
var _groups = await groupService.GetGroupsCompany(CompanyID);
if (_groups != null)
{
CountQueueCompany = await conversationService.GetCountQueueCompany(CompanyID);
groups = _groups;
GCContent =@<GCComponent groups="groups"
CompanyID=CompanyID
OnMultipleOfThree="EventCallback.Factory.Create<int>(this, CallBackSelectedGroup)" />
;
2025-07-26 16:52:59 +03:30
2025-07-11 20:37:28 +03:30
}
else
{
// ex Groups Company
}
2025-07-26 16:52:59 +03:30
Conversations = await conversationService.MyConversationUserSide(CompanyID);
if (Conversations.Count > 0)
ConversationsContent =@<ConversionHistoryComponent Conversations="Conversations"
2025-07-27 16:04:28 +03:30
OnMultipleOfThree="EventCallback.Factory.Create<int>(this, SelectedConv)" />
;
2025-07-26 22:15:48 +03:30
if (ConversationID.HasValue && ConversationID > 0 && Conversations.Count > 0)
await SelectedConv(ConversationID.Value);
2025-07-11 20:37:28 +03:30
}
}
StateHasChanged();
}
async Task SelectedConv(int ID)
{
if (Conversations.Any(f => f.ID == ID))
{
SelectedConversation = Conversations.FirstOrDefault(f => f.ID == ID);
SelectedConversationItems = await conversationService.GetConversationItems(ID);
SelectedGroup = SelectedConversation.GroupID;
2025-07-26 22:15:48 +03:30
ConversationID = ID;
2025-07-11 20:37:28 +03:30
StateHasChanged();
}
}
private void CloseChat()
{
// می‌توان اینجا حالت مخفی‌سازی کامپوننت را تنظیم کرد
2025-07-26 22:15:48 +03:30
SelectedConversation = null;
SelectedConversationItems = null;
SelectedGroup = null;
ConversationID = null;
StateHasChanged();
2025-07-11 20:37:28 +03:30
}
private void GoBack()
{
// برگشت به منوی قبلی یا وضعیت قبلی
}
async Task OnClickSendMssage()
{
2025-07-26 22:15:48 +03:30
2025-07-27 16:04:28 +03:30
if (string.IsNullOrEmpty(InputMessage)) return;
2025-07-11 20:37:28 +03:30
Sending = true;
if (SelectedConversation != null)
{
2025-07-12 21:33:44 +03:30
var item = new ADD_ConversationResponseDto()
2025-07-11 20:37:28 +03:30
{
ConversationID = SelectedConversation.ID,
2025-07-12 21:33:44 +03:30
Text = InputMessage
2025-07-11 20:37:28 +03:30
};
2025-07-27 16:04:28 +03:30
var inputconv= await conversationService.ADDConversationItem(SelectedConversation.ID, InputMessage, Common.Enums.ConversationType.UE);
if (inputconv!=null) SelectedConversationItems.Add(inputconv);
2025-07-11 20:37:28 +03:30
}
else
{
2025-07-12 21:33:44 +03:30
var Item = new ADD_ConversationDto()
2025-07-11 20:37:28 +03:30
{
CompanyID = CompanyID,
GroupID = SelectedGroup,
Question = InputMessage
};
2025-07-27 16:04:28 +03:30
var convNEW= await conversationService.NewConversationFromCurrentUser(Item);
if (convNEW !=null)
2025-07-26 16:52:59 +03:30
{
2025-07-27 16:04:28 +03:30
Conversations.Add(convNEW);
await SelectedConv(convNEW.ID);
2025-07-26 16:52:59 +03:30
}
2025-07-11 20:37:28 +03:30
}
2025-07-26 16:52:59 +03:30
InputMessage = string.Empty;
2025-07-11 20:37:28 +03:30
Sending = false;
}
}