244 lines
7.8 KiB
Plaintext
244 lines
7.8 KiB
Plaintext
@using Hushian.Application.Dtos
|
|
@using Hushian.Application.Dtos.Company
|
|
@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
|
|
@page "/UserPanel/{CompanyID:int}"
|
|
@page "/UserPanel/{CompanyID:int}/{ConversationID:int?}"
|
|
|
|
<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"
|
|
Position="Position.Absolute"
|
|
Placement="BadgePlacement.TopRight"
|
|
IndicatorType="BadgeIndicatorType.RoundedPill"
|
|
VisuallyHiddenText="status"></Badge>
|
|
<small>پاسخگویی سوالات شما هستیم</small>
|
|
</span>
|
|
<button class="btn-close btn-close-white" @onclick="CloseChat"></button>
|
|
</div>
|
|
<div class="card-body" style="max-height: 500px; overflow-y: auto; background-color: #f9f9f9;">
|
|
|
|
@if (!IsLogin)
|
|
{
|
|
<LoginComponent OnMultipleOfThree="EventCallback.Factory.Create(this, Login)" />
|
|
}
|
|
@if (IsLogin)
|
|
{
|
|
@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
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
<ChatBoxComponent Conversations="Conversations" SelectedConversationItems="SelectedConversationItems" />
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
</div>
|
|
@if (IsLogin && (Conversations.Count == 0 && SelectedConversation == null) || (Conversations.Count > 0 && SelectedConversation != null && SelectedConversation.status == Hushian.Enums.ConversationStatus.InProgress))
|
|
{
|
|
<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 {
|
|
position: fixed;
|
|
bottom: 50%;
|
|
right: 50%;
|
|
transform: translate(50%, 50%);
|
|
width: 90vw;
|
|
height: 80%;
|
|
z-index: 1051;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
</style>
|
|
@code {
|
|
#region Parameter
|
|
[Parameter] public int CompanyID { get; set; }
|
|
[Parameter] public int? ConversationID { get; set; }
|
|
#endregion
|
|
#region Fild
|
|
public ConversationDto? SelectedConversation { get; set; } = null;
|
|
public List<ConversationDto> Conversations { get; set; } = new();
|
|
public List<ConversationItemDto>? SelectedConversationItems { get; set; } = null;
|
|
public RenderFragment GCContent { get; set; }
|
|
public RenderFragment ConversationsContent { get; set; }
|
|
List<GroupDto> groups = new List<GroupDto>();
|
|
public CompanyDto company { get; set; } = new();
|
|
int CountQueueCompany = 0;
|
|
public string CompanyName { get; set; } = "هوشیان";
|
|
public bool IsLogin { get; set; } = false;
|
|
public int? SelectedGroup { get; set; }
|
|
public string InputMessage { get; set; }
|
|
public bool Sending { get; set; } = false;
|
|
#endregion
|
|
}
|
|
@functions {
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (ConversationID.HasValue && ConversationID > 0 && Conversations.Count > 0)
|
|
await SelectedConv(ConversationID.Value);
|
|
|
|
await base.OnParametersSetAsync();
|
|
}
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await CheckOnline();
|
|
await base.OnInitializedAsync();
|
|
}
|
|
async Task CheckOnline()
|
|
{
|
|
var token = await localStorageService.GetItem<string>("key");
|
|
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
|
|
{
|
|
CompanyName = _company.Fullname;
|
|
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)" />
|
|
;
|
|
Conversations = await conversationService.MyConversationUserSide(CompanyID);
|
|
if (Conversations.Count > 0)
|
|
ConversationsContent =@<ConversionHistoryComponent Conversations="Conversations"
|
|
OnMultipleOfThree="EventCallback.Factory.Create<int>(this, SelectedConv)" />
|
|
;
|
|
}
|
|
else
|
|
{
|
|
// ex Groups Company
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
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;
|
|
StateHasChanged();
|
|
}
|
|
|
|
}
|
|
private void CloseChat()
|
|
{
|
|
// میتوان اینجا حالت مخفیسازی کامپوننت را تنظیم کرد
|
|
}
|
|
private void GoBack()
|
|
{
|
|
// برگشت به منوی قبلی یا وضعیت قبلی
|
|
}
|
|
async Task OnClickSendMssage()
|
|
{
|
|
Sending = true;
|
|
if (SelectedConversation != null)
|
|
{
|
|
var item = new ADDConversationItemDto()
|
|
{
|
|
ConversationID = SelectedConversation.ID,
|
|
text = InputMessage
|
|
};
|
|
}
|
|
else
|
|
{
|
|
var Item = new ADDConversationDto()
|
|
{
|
|
CompanyID = CompanyID,
|
|
GroupID = SelectedGroup,
|
|
Question = InputMessage
|
|
};
|
|
}
|
|
Sending = false;
|
|
}
|
|
}
|
|
|
|
|
|
|