94 lines
2.4 KiB
Plaintext
94 lines
2.4 KiB
Plaintext
@inherits BaseForm
|
|
@using Entities.Entities.Static
|
|
@inject HttpClient http
|
|
|
|
|
|
|
|
@if (IsLoading)
|
|
{
|
|
<Loadingspinner />
|
|
}
|
|
else
|
|
{
|
|
<div class="form-floating mb-3">
|
|
<select class="form-select" id="province" @oninput="ProvinceChange" aria-label="Floating label select example">
|
|
<option value="0">همه</option>
|
|
@foreach (var p in Provinces)
|
|
{
|
|
<option value="@p.Id">@p.ProvinceName</option>
|
|
}
|
|
</select>
|
|
<label for="province">استان</label>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-floating mb-3">
|
|
<SimpleBlazorMultiselect.SimpleMultiselect DefaultText="شهر" Class="font-medium" Options="(SelectProvinceId == 0 )? Cities : Cities.Where(c => c.ProvinceId == SelectProvinceId).ToList()" IsMultiSelect="false" TItem="City" StringSelector="b => b.CityName" CanFilter="true" @bind-SelectedOptions="selectCity" >
|
|
<SelectedOptionsRenderer Context="options">
|
|
@foreach (var item in options)
|
|
{
|
|
<span class="badge bg-primary font-medium"
|
|
style="padding: 6px; margin-right: 10px;">
|
|
@item.CityName
|
|
</span>
|
|
}
|
|
</SelectedOptionsRenderer>
|
|
</SimpleBlazorMultiselect.SimpleMultiselect>
|
|
</div>
|
|
|
|
}
|
|
|
|
@code {
|
|
[Parameter]
|
|
public List<Province> Provinces { get; set; } = new();
|
|
|
|
[Parameter]
|
|
public List<City> Cities { get; set; } = new();
|
|
|
|
[Parameter]
|
|
public City? Value { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<City> ValueChanged { get; set; }
|
|
|
|
|
|
private int SelectProvinceId = 0;
|
|
|
|
private HashSet<City> _selectCity = new();
|
|
private HashSet<City> selectCity { get { return _selectCity; } set { _selectCity = value; Value = value.FirstOrDefault(); ValueChanged.InvokeAsync(Value); } }
|
|
|
|
|
|
|
|
|
|
protected override async Task LoadDataAsync()
|
|
{
|
|
if (Provinces.Count() == 0)
|
|
{
|
|
Provinces = await http.GetTable<Province>();
|
|
}
|
|
if (Cities.Count() == 0)
|
|
{
|
|
Cities = await http.GetTable<City>();
|
|
}
|
|
if(Value != null)
|
|
{
|
|
selectCity.Add(Value);
|
|
}
|
|
await base.LoadDataAsync();
|
|
}
|
|
|
|
private void ProvinceChange(ChangeEventArgs e)
|
|
{
|
|
SelectProvinceId = int.Parse(e!.Value!.ToString()!);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|