138 lines
4.7 KiB
Plaintext
138 lines
4.7 KiB
Plaintext
@page "/currency/create"
|
|
@page "/currency/edit/{id:long}"
|
|
@page "/{locale}/currency/create"
|
|
@page "/{locale}/currency/edit/{id:long}"
|
|
|
|
@inject ILogger<CurrencyEdit> Logger
|
|
@attribute [Authorize]
|
|
|
|
<PageContainer Title="@(Id > 0 ? "编辑货币信息" : "新增货币信息")">
|
|
<Breadcrumb>
|
|
<Breadcrumb>
|
|
<BreadcrumbItem Href="/">管理后台</BreadcrumbItem>
|
|
<BreadcrumbItem Href="/admin/list">系统功能</BreadcrumbItem>
|
|
<BreadcrumbItem>货币管理</BreadcrumbItem>
|
|
</Breadcrumb>
|
|
</Breadcrumb>
|
|
<ChildContent>
|
|
|
|
<Spin Spinning="pageLoading">
|
|
<Card Title="货币信息">
|
|
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="14" OnFinish="OnFormFinishAsync">
|
|
<FormItem Label="名称" Required>
|
|
<Input @bind-Value="@context.Name" Placeholder="货币名称" />
|
|
</FormItem>
|
|
<FormItem Label="货币代码">
|
|
<Input @bind-Value="@context.CurrencyCode" Placeholder="货币代码" />
|
|
</FormItem>
|
|
<FormItem Label="汇率">
|
|
<Input @bind-Value="@context.Rate" Placeholder="汇率" />
|
|
</FormItem>
|
|
<FormItem Label="展示本地">
|
|
<SimpleSelect @bind-Value="@context.DisplayLocale" Placeholder="语言文化">
|
|
<SelectOptions>
|
|
@foreach (var item in LanguageCultures)
|
|
{
|
|
<SimpleSelectOption Value="@item.Key" Label="@($"{item.Value} - {item.Key}")"></SimpleSelectOption>
|
|
}
|
|
</SelectOptions>
|
|
</SimpleSelect>
|
|
</FormItem>
|
|
<FormItem Label="自定义格式">
|
|
<Input @bind-Value="@context.CustomFormatting" Placeholder="自定义格式" />
|
|
</FormItem>
|
|
<FormItem Label="显示排序">
|
|
<Input @bind-Value="@context.DisplayOrder" Placeholder="显示排序" />
|
|
</FormItem>
|
|
<FormItem Label="状态">
|
|
<Checkbox Checked="@context.Enabled">启用</Checkbox>
|
|
</FormItem>
|
|
<FormItem WrapperCol="new ColLayoutParam { Span = 24, Offset = 5 }">
|
|
<Button Type="@ButtonType.Primary" HtmlType="submit" Loading="saving">
|
|
提交保存
|
|
</Button>
|
|
</FormItem>
|
|
</Form>
|
|
</Card>
|
|
</Spin>
|
|
</ChildContent>
|
|
</PageContainer>
|
|
@code {
|
|
[Parameter]
|
|
public string Locale { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public long Id { get; set; }
|
|
|
|
[SupplyParameterFromForm]
|
|
CurrencyModel model { get; set; } = new();
|
|
Form<CurrencyModel> editform = null!;
|
|
Dictionary<string, string> LanguageCultures = LanguageCulture.Descriptions.ToDictionary();
|
|
bool pageLoading = false;
|
|
bool saving = false;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
base.OnInitialized();
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
if (Id > 0)
|
|
{
|
|
LoadData();
|
|
}
|
|
base.OnParametersSet();
|
|
}
|
|
|
|
async void LoadData()
|
|
{
|
|
pageLoading = true;
|
|
var url = $"/api/currency/{Id}";
|
|
var apiResult = await HttpService.Get<ApiResult<Currency>>(url);
|
|
if (apiResult.Success)
|
|
{
|
|
if (apiResult.Data == null)
|
|
{
|
|
Navigation.NavigateTo($"/currency/create");
|
|
}
|
|
else
|
|
{
|
|
model = apiResult.Data.Adapt<CurrencyModel>();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Navigation.NavigateTo($"/currency/create");
|
|
}
|
|
|
|
pageLoading = false;
|
|
StateHasChanged();
|
|
}
|
|
|
|
async void OnFormFinishAsync()
|
|
{
|
|
if (editform.Validate())
|
|
{
|
|
saving = true;
|
|
var url = $"api/currency/save";
|
|
var result = new ApiResult<string>();
|
|
result = await HttpService.Post<ApiResult<string>>(url, model);
|
|
|
|
|
|
if (result.Code == (int)ResultCode.Success)
|
|
{
|
|
saving = false;
|
|
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
|
|
Navigation.NavigateTo($"/currency/list");
|
|
}
|
|
else
|
|
{
|
|
saving = false;
|
|
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|