添加项目文件。

This commit is contained in:
2025-12-02 13:10:10 +08:00
parent 93a2382a16
commit 289aa4cbe7
400 changed files with 91177 additions and 0 deletions

View File

@@ -0,0 +1,137 @@
@page "/product/category/edit"
@page "/product/category/edit/{Id:long?}"
@inject ILogger<CategoryEdit> Logger
@* @attribute [Authorize] *@
<PageTitle>分类编辑</PageTitle>
<Title Level="4">分类信息</Title>
<Spin Spinning="pageLoading">
<Card Title="" Class="hideborder"
Style="margin-top: 24px;"
BodyStyle="padding: 0 32px 40px 32px">
<Form @ref="editform" Model="@model" LabelColSpan="5" WrapperColSpan="19" OnFinish="OnFormFinishAsync">
@* @if (languages.Count > 1 && Id > 0)
{
<Tabs ActiveKey="@context.Language" OnTabClick="OnLanguageTabChange">
<TabPane Key="0">
<TabTemplate>
<span>标准</span>
</TabTemplate>
</TabPane>
@foreach (var item in languages)
{
<TabPane Key="@item.Id.ToString()">
<TabTemplate>
<span>@item.Name @item.Id.ToString()</span>
</TabTemplate>
</TabPane>
}
</Tabs>
}
<FormItem Label="上级菜单">
<SimpleSelect DefaultValue="" Style="width:300px;" @bind-Value="@context.ParentId">
<SelectOptions>
<SimpleSelectOption Value="0" Label="无上级"></SimpleSelectOption>
@foreach (var item in categories)
{
<SimpleSelectOption Value="@item.Id.ToString()" Label="@item.Name"></SimpleSelectOption>
}
</SelectOptions>
</SimpleSelect>
</FormItem>
<FormItem Label="分类名称" Required>
<Input @bind-Value="@context.Name" Placeholder="分类名称" />
</FormItem>
<FormItem Label="URL缩略名" Required>
<Input @bind-Value="@context.Slug" Placeholder="URL缩略名" />
</FormItem>
<FormItem Label="图标">
<Button OnClick="HandleSetIcon">
@if (string.IsNullOrEmpty(formModel.Image))
{
<span>选择图标</span>
}
else
{
<span>已选图标:</span>
}
</Button> <Button Size="@ButtonSize.Large" Type="@ButtonType.Text" Icon="@formModel.Image"></Button>
</FormItem> *@
<FormItem Label="Meta描述">
<Input @bind-Value="@context.MetaDescription" Placeholder="Meta描述" />
</FormItem>
<FormItem Label="Meta关键词">
<Input @bind-Value="@context.MetaKeywords" Placeholder="Meta关键词" />
</FormItem>
<FormItem Label="显示排序">
<Input @bind-Value="@context.DisplayOrder" Placeholder="显示排序" />
</FormItem>
<FormItem Label="状态">
<Checkbox @bind-Checked="@context.Enabled">启用</Checkbox>
</FormItem>
<FormItem WrapperCol="new ColLayoutParam { Span = 24, Offset = 5 }">
<Button Type="@ButtonType.Primary" HtmlType="submit">
提交保存
</Button>
</FormItem>
</Form>
</Card>
</Spin>
@code {
[SupplyParameterFromQuery]
int? Lang { get; set; }
[Parameter]
public long? Id { get; set; }
[SupplyParameterFromForm]
CategoryModel model { get; set; } = new();
Form<CategoryModel> editform = null!;
bool pageLoading = true;
List<CategoryItem> Categories = new();
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override async Task OnParametersSetAsync()
{
pageLoading = true;
// await LoadCategories();
// if (Id > 0)
// {
// await LoadData();
// await SearchAttribute(string.Empty);
// }
// else
// {
// editCategory = true;
// CategoryPath = string.Empty;
// }
// if (Categories.Any())
// {
// BindCategory();
// }
pageLoading = false;
base.OnParametersSet();
}
async Task LoadCategories()
{
var url = $"/api/category/items";
var apiResult = await HttpService.Get<ApiResult<List<CategoryItem>>>(url);
if (apiResult.Success)
{
Categories = apiResult.Data ?? new();
}
}
async void OnFormFinishAsync()
{
}
}

View File

@@ -0,0 +1,336 @@
@page "/category/list"
@inject ILogger<CategoryList> Logger
@attribute [Authorize]
<PageTitle>分类管理</PageTitle>
<Title Level="4">菜单管理</Title>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Class="mt-3">
<Table DataSource="categories" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
菜单列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c=>c.Name" Title="名称">
<AntDesign.Text>@GetName(context)</AntDesign.Text>
</PropertyColumn>
<PropertyColumn Property="c=>c.Slug" Title="缩略名" Width="80px" Align="ColumnAlign.Center">
</PropertyColumn>
<PropertyColumn Property="c=>c.DisplayOrder" Title="排序" Width="100px" />
<PropertyColumn Property="c=>c.Enabled" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Enabled)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CreateTime" Title="时间" Width="190px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="160px">
<Space>
@if (context.IsLast)
{
<SpaceItem>
<a Href="@($"/attribute/list?categoryid={context.Id}")">属性</a>
</SpaceItem>
<SpaceItem>
<a Href="@($"/specification/list?categoryid={context.Id}")">规格</a>
</SpaceItem>
}
<SpaceItem>
<Dropdown Trigger="@(new Trigger[] { Trigger.Click })">
<Overlay>
<Menu>
<MenuItem>
<a @onclick="(e)=>OnEditClick(context)"> <Icon Type="@IconType.Outline.Edit" /> 编辑</a>
</MenuItem>
<MenuDivider />
<MenuItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a> <Icon Type="@IconType.Outline.Delete" /> 删除</a>
</Popconfirm>
</MenuItem>
</Menu>
</Overlay>
<ChildContent>
<a class="ant-dropdown-link" @onclick:preventDefault>
<Icon Type="@IconType.Outline.Menu" />
</a>
</ChildContent>
</Dropdown>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='("设置菜单")' OnClose="_=>CloseDrawer()">
<Form LabelColSpan="5" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="名称">
<Input @bind-Value="model.Name" For="(()=>model.Name)" />
</FormItem>
<FormItem Label="缩略名">
<Input @bind-Value="model.Slug" For="(()=>model.Slug)" />
</FormItem>
<FormItem Label="上级分类">
<Select @bind-Value="@model.ParentId" TItemValue="long" TItem="string" Placeholder="请选择上级分类">
<SelectOptions>
<SelectOption Value="0L" Label="无" />
@foreach (var item in categories)
{
<SelectOption Value="@item.Id" Label="@GetName(item)" />
}
</SelectOptions>
</Select>
</FormItem>
<FormItem Label="排序">
<Input @bind-Value="model.DisplayOrder" For="(()=>model.DisplayOrder)" />
</FormItem>
<FormItem Label="状态">
<Checkbox @bind-Value="model.Enabled" For="(()=>model.Enabled)">启用</Checkbox>
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromForm]
CategorySearch search { get; set; } = new();
Form<CategorySearch> searchForm = null!;
[SupplyParameterFromForm]
CategoryModel model { get; set; } = new();
Form<CategoryModel> editform = null!;
List<CategoryItem> categories = new();
bool drawerVisible;
protected override void OnParametersSet()
{
loadQueryString();
LoadList();
base.OnParametersSet();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
}
private async void LoadList()
{
var url = "/api/category/list";
var apiResult = await HttpService.Get<ApiResult<List<CategoryItem>>>(url);
if (apiResult.Success)
{
if (apiResult.Data != null)
{
categories = apiResult.Data;
StateHasChanged();
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
void OnSearchReset()
{
search = new();
searchForm?.Reset();
OnSearchFinish();
}
private void OnReset()
{
search = new();
LoadList();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/category/list?page={page}");
}
else
{
Navigation.NavigateTo($"/category/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/category/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/category/list?{queryString}");
}
}
LoadList();
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/category/delete/{id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
void OnEditClick(CategoryItem item)
{
this.model = item.Adapt<CategoryModel>();
drawerVisible = true;
}
async Task OnFormFinish()
{
if (editform.Validate())
{
var result = new ApiResult<string>();
var data = model.Adapt<CategoryModel>();
if (model.Id > 0)
{
var url = $"api/category/edit";
result = await HttpService.Post<ApiResult<string>>(url, data);
}
else
{
var url = $"api/category/add";
result = await HttpService.Post<ApiResult<string>>(url, data);
}
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
private string GetPath(string path)
{
var array = path.Split(",").ToList();
var pathText = string.Empty;
foreach (var item in array)
{
var name = categories.Where(p => p.Id == item.ToLong()).Select(p => p.Name).SingleOrDefault();
if (string.IsNullOrEmpty(pathText))
{
pathText = name;
}
else
{
pathText = $"{pathText}>{name}";
}
}
return pathText;
}
private string GetName(CategoryItem menu)
{
string name = string.Empty;
if (menu.Depth > 0)
{
var symbol = " ";
for (var i = 0; i < menu.Depth; i++)
{
symbol = $"{symbol}{symbol}";
}
name = $"{symbol}├ {menu.Name}";
}
else
{
name = menu.Name;
}
return name;
}
void OnCreateClick()
{
model = new CategoryModel();
drawerVisible = true;
}
void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
}

View File

@@ -0,0 +1,5 @@
<h3>GoodsList</h3>
@code {
}

View File

@@ -0,0 +1,290 @@
@page "/attribute/predefined/list/{AttributeId:long}"
@inject ILogger<PredefinedAttributeList> Logger
@attribute [Authorize]
<PageTitle>产品属性管理</PageTitle>
<Title Level="4">属性列表</Title>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Value" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
@productAttribute.Name 属性预设值列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c=>c.Value" Title="名称"></PropertyColumn>
<PropertyColumn Property="c=>c.DisplayOrder" Title="排序" Width="150px" Align="ColumnAlign.Center" />
<PropertyColumn Property="c=>c.Status" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Status == 1)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CreateTime" Title="时间" Width="200px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="180px">
<Space>
<SpaceItem>
<a @onclick="(e)=>OnEditClick(context)">编辑</a>
</SpaceItem>
<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='($"设置{productAttribute.Name}属性预设值")' OnClose="_=>CloseDrawer()">
<Form LabelColSpan="4" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="名称">
<Input @bind-Value="model.Value" For="(()=>model.Value)" />
</FormItem>
<FormItem Label="排序">
<Input @bind-Value="model.DisplayOrder" For="(()=>model.DisplayOrder)" />
</FormItem>
<FormItem Label="状态">
<RadioGroup @bind-Value="@model.Status" ButtonStyle="RadioButtonStyle.Solid">
<Radio RadioButton Value="1">启用</Radio>
<Radio RadioButton Value="2">禁用</Radio>
</RadioGroup>
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[Parameter]
public long AttributeId { get; set; }
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
ProductAttributeOptionSearch search { get; set; } = new();
Form<ProductAttributeOptionSearch> searchForm = null!;
[SupplyParameterFromForm]
ProductAttributeOptionModel model { get; set; } = new();
Form<ProductAttributeOptionModel> editform = null!;
ProductAttribute productAttribute = new();
PagingList<ProductAttributeOption> PagingList = new();
bool loading { get; set; } = true;
bool searchExpand { get; set; } = false;
bool drawerVisible;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
loadQueryString();
LoadList();
LoadAttribute();
base.OnParametersSet();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Value = query.GetQueryString("Value");
}
private async void LoadAttribute()
{
var url = $"/api/productattribute/{AttributeId}";
var apiResult = await HttpService.Get<ApiResult<ProductAttribute>>(url);
if (apiResult.Success)
{
if (apiResult.Data != null)
{
productAttribute = apiResult.Data;
}
}
}
private async void LoadList()
{
loading = true;
var url = "/api/productattributeoption/search";
var apiResult = await HttpService.GetPagingList<ProductAttributeOption>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnSearchReset()
{
search = new();
LoadList();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/attribute/predefined/list/{AttributeId}?page={page}");
}
else
{
Navigation.NavigateTo($"/attribute/predefined/list/{AttributeId}");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/attribute/predefined/list/{AttributeId}?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/attribute/predefined/list/{AttributeId}?{queryString}");
}
}
}
void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/productattributeoption/delete/{model.Id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
async Task OnFormFinish()
{
if (editform.Validate())
{
var result = new ApiResult<string>();
if (model.Id > 0)
{
var url = $"api/productattributeoption/edit";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/productattributeoption/add";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
void OnEditClick(ProductAttributeOption option)
{
this.model = option.Adapt<ProductAttributeOptionModel>();
drawerVisible = true;
}
void OnCreateClick()
{
model = new();
drawerVisible = true;
}
private void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
}

View File

@@ -0,0 +1,325 @@
@page "/specification/predefined/list/{SpecificationId:long}"
@inject ILogger<PredefinedSpecificationList> Logger
@attribute [Authorize]
<PageTitle>产品规格管理</PageTitle>
<Title Level="4">属性列表</Title>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Value" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
@specificationAttribute.Name 属性列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c=>c.Value" Title="名称"></PropertyColumn>
<PropertyColumn Property="c=>c.DisplayOrder" Title="排序" Width="150px" Align="ColumnAlign.Center" />
<PropertyColumn Property="c=>c.Status" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Status == 1)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CreateTime" Title="时间" Width="200px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="180px">
<Space>
<SpaceItem>
<a @onclick="(e)=>OnEditClick(context)">编辑</a>
</SpaceItem>
<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='($"设置{specificationAttribute.Name}规格预设值")' OnClose="_=>CloseDrawer()">
<Form LabelColSpan="4" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="名称">
<Input @bind-Value="model.Value" For="(()=>model.Value)" />
</FormItem>
<FormItem Label="排序">
<Input @bind-Value="model.DisplayOrder" For="(()=>model.DisplayOrder)" />
</FormItem>
<FormItem Label="状态">
<RadioGroup @bind-Value="@model.Status" ButtonStyle="RadioButtonStyle.Solid">
<Radio RadioButton Value="1">启用</Radio>
<Radio RadioButton Value="2">禁用</Radio>
</RadioGroup>
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[Parameter]
public long SpecificationId { get; set; }
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
SpecificationAttributeOptionSearch search { get; set; } = new();
Form<SpecificationAttributeOptionSearch> searchForm = null!;
[SupplyParameterFromForm]
SpecificationAttributeOptionModel model { get; set; } = new();
Form<SpecificationAttributeOptionModel> editform = null!;
SpecificationAttribute specificationAttribute = new();
PagingList<SpecificationAttributeOption> PagingList = new();
bool loading { get; set; } = true;
bool searchExpand { get; set; } = false;
private bool drawerVisible;
SpecificationAttributeOptionModelValidator validator = new();
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
loadQueryString();
LoadList();
LoadSpecification();
base.OnParametersSet();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Value = query.GetQueryString("Value");
}
private async void LoadList()
{
loading = true;
var url = "/api/specificationattributeoption/search";
var apiResult = await HttpService.GetPagingList<SpecificationAttributeOption>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
private async void LoadSpecification()
{
var url = $"/api/specificationattribute/{SpecificationId}";
var apiResult = await HttpService.Get<ApiResult<SpecificationAttribute>>(url);
if (apiResult.Success)
{
if (apiResult.Data != null)
{
specificationAttribute = apiResult.Data;
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnSearchReset()
{
search = new();
LoadList();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/specification/predefined/list/{SpecificationId}?page={page}");
}
else
{
Navigation.NavigateTo($"/specification/predefined/list/{SpecificationId}");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/specification/predefined/list/{SpecificationId}?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/specification/predefined/list/{SpecificationId}?{queryString}");
}
}
// LoadList();
}
void OnPageChanged(PaginationEventArgs args)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
Navigation.NavigateTo($"/attribute/list?page={args.Page}");
}
else
{
Navigation.NavigateTo($"/attribute/list?page={Page}&{queryString}");
}
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/specificationattributeoption/delete/{model.Id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
async Task OnFormFinish()
{
model.SpecificationId = SpecificationId;
if (editform.Validate())
{
var result = new ApiResult<string>();
if (model.Id > 0)
{
var url = $"api/specificationattributeoption/edit";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/specificationattributeoption/add";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
private void OnPageChanged(int args)
{
OnSearch(args);
}
private bool _editDrawerOpen;
private void OpenDrawer()
{
model = new();
_editDrawerOpen = true;
}
void OnEditClick(SpecificationAttributeOption item)
{
this.model = item.Adapt<SpecificationAttributeOptionModel>();
drawerVisible = true;
}
void OnDrawerOverlayClick(bool state)
{
if (!state)
{
model = new();
_editDrawerOpen = state;
}
}
void OnCreateClick()
{
drawerVisible = true;
}
void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
}

View File

@@ -0,0 +1,339 @@
@page "/attribute/list"
@rendermode InteractiveAuto
@inject ILogger<ProductAttributeList> Logger
@inject HttpService HttpService
@attribute [Authorize]
<PageTitle>产品属性管理</PageTitle>
<Title Level="4">属性列表</Title>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
属性列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c=>c.Name" Title="名称"></PropertyColumn>
<PropertyColumn Property="c=>c.ControlType" Title="控件">
@if (context.ControlType == 1)
{
<Tag Color="TagColor.Green">选项</Tag>
}
else
{
<Tag>文本框</Tag>
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CategoryName" Title="分类"></PropertyColumn>
<PropertyColumn Property="c=>c.WeightIsRequired" Title="重量" Width="100px">
@if (context.WeightIsRequired)
{
<Tag>必填</Tag>
}
</PropertyColumn>
<PropertyColumn Property="c=>c.IsRequired" Title="默认" Width="100px">
@if (context.IsRequired)
{
<Tag>必选</Tag>
}
</PropertyColumn>
<PropertyColumn Property="c=>c.DisplayOrder" Title="排序" Width="150px" Align="ColumnAlign.Center" />
<PropertyColumn Property="c=>c.Status" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Status == 1)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CreateTime" Title="时间" Width="200px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="180px">
<Space>
<SpaceItem>
<a @onclick="(e)=>OnViewPredefinedListClick(context.Id)">预设值</a>
</SpaceItem>
<SpaceItem>
<a @onclick="(e)=>OnEditClick(context)">编辑</a>
</SpaceItem>
<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='("设置菜单")' OnClose="_=>CloseDrawer()">
<Form LabelColSpan="4" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="名称">
<Input @bind-Value="model.Name" For="(()=>model.Name)" />
</FormItem>
<FormItem Label="控件">
<RadioGroup @bind-Value="@model.ControlType" ButtonStyle="RadioButtonStyle.Solid">
<Radio RadioButton Value="0">默认(文本)</Radio>
<Radio RadioButton Value="1">选项</Radio>
</RadioGroup>
</FormItem>
<FormItem Label="重量">
<Checkbox @bind-Value="model.WeightIsRequired">必填</Checkbox>
</FormItem>
<FormItem Label="默认">
<Checkbox @bind-Value="model.IsRequired">默认属性</Checkbox>
</FormItem>
<FormItem Label="状态">
<RadioGroup @bind-Value="@model.Status" ButtonStyle="RadioButtonStyle.Solid">
<Radio RadioButton Value="1">启用</Radio>
<Radio RadioButton Value="2">禁用</Radio>
</RadioGroup>
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery]
long CategoryId { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
ProductAttributeSearch search { get; set; } = new();
Form<ProductAttributeSearch> searchForm = null!;
[SupplyParameterFromForm]
ProductAttributeModel model { get; set; } = new();
Form<ProductAttributeModel> editform = null!;
PagingList<ProductAttributeItemModel> PagingList = new();
bool loading { get; set; } = true;
bool searchExpand { get; set; } = false;
private bool drawerVisible;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
loadQueryString();
LoadList();
model.CategoryId = CategoryId;
base.OnParametersSet();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
search.CategoryId = CategoryId;
}
private async void LoadList()
{
loading = true;
var url = "/api/productattribute/search";
var apiResult = await HttpService.GetPagingList<ProductAttributeItemModel>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnSearchReset()
{
search = new();
LoadList();
}
private void OnReset()
{
search = new();
LoadList();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/attribute/list?page={page}");
}
else
{
Navigation.NavigateTo($"/attribute/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/attribute/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/attribute/list?{queryString}");
}
}
}
void OnPageChanged(PaginationEventArgs args)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
Navigation.NavigateTo($"/attribute/list?page={args.Page}");
}
else
{
Navigation.NavigateTo($"/attribute/list?page={Page}&{queryString}");
}
}
void OnEditClick(ProductAttribute productAttribute)
{
this.model = productAttribute.Adapt<ProductAttributeModel>();
drawerVisible = true;
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/productattribute/delete/{id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
async Task OnFormFinish()
{
Console.WriteLine("run on from finish ");
if (CategoryId > 0)
{
model.CategoryId = CategoryId;
}
if (editform.Validate())
{
var result = new ApiResult<string>();
if (model.Id > 0)
{
var url = $"api/productattribute/edit";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/productattribute/add";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
private void OnPageChanged(int args)
{
OnSearch(args);
}
void OnCreateClick()
{
drawerVisible = true;
}
void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
void OnViewPredefinedListClick(long id)
{
Navigation.NavigateTo($"/attribute/Predefined/list/{id}");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,425 @@
@page "/product/list"
@inject ILogger<ProductList> Logger
@attribute [Authorize]
<PageTitle>产品管理</PageTitle>
<Title Level="4">产品列表</Title>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Title" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
产品列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c=>c.Title" Title="名称">
<div>@context.Title</div>
<Text Copyable Type="TextElementType.Secondary" CopyConfig="CopyHint">@context.Id</Text>
</PropertyColumn>
<PropertyColumn Property="c=>c.StockQuantity" Title="库存" Width="150px" Align="ColumnAlign.Center" />
<PropertyColumn Property="c=>c.DisplayOrder" Title="排序" Width="150px" Align="ColumnAlign.Center" />
<PropertyColumn Property="c=>c.Status" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Status == 1)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CreateTime" Title="时间" Width="200px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="180px">
<Space>
<SpaceItem>
<a @onclick="(e)=>OnClickAddStock(context)">入库</a>
</SpaceItem>
<SpaceItem>
<a @onclick="(e)=>OnEditClick(context.Id)">编辑</a>
</SpaceItem>
<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='("设置库存")' OnClose="_=>CloseDrawer()">
<Form LabelColSpan="5" @ref="@stockForm" Model="@stockModel" OnFinish="OnStockFormFinish">
<FluentValidationValidator />
<FormItem Label="产品名称">
@stockModel.Title
</FormItem>
@if (!stockModel.AddAttribute)
{
@foreach (var item in stockModel.ProductStockAttributes)
{
<FormItem Label="@item.Name">
<Select @bind-Value="@item.AttributeValue.OptionId" TItemValue="long" TItem="long">
<SelectOptions>
@foreach (var value in item.ProductAttributeValues)
{
<SelectOption Value="@value.Id" Label="@GetAttributeValue(value)" />
}
</SelectOptions>
</Select>
</FormItem>
}
}
<FormItem Label="规格">
<Checkbox @bind-Value="@stockModel.AddAttribute" Disabled=false>
设置新规格
</Checkbox>
</FormItem>
@if (stockModel.AddAttribute)
{
@foreach (var item in stockModel.ProductStockAttributes)
{
<FormItem Label="@item.Name">
<Input @bind-Value="@item.AttributeValue.Name" Placeholder="请输入规格" Style="width:160px;"></Input>
@if (item.WeightIsRequired)
{
<AntDesign.Input Type="InputType.Text" @bind-Value="@item.AttributeValue.Weight" Placeholder="重量" WrapperStyle="width:80px">
<Suffix>@GetWeightUnit(item.WeightUnit)</Suffix>
</AntDesign.Input>
}
</FormItem>
}
}
<FormItem Label="SKU编码">
<Input @bind-Value="stockModel.ProductAttributeCombination.SkuNumber" For="(()=>stockModel.ProductAttributeCombination.SkuNumber)" />
</FormItem>
<FormItem Label="存放仓库">
<AutoComplete TOption="SelectItem" Placeholder="输入或选择仓储" @bind-Value="@stockModel.WarehouseId"
OnInput="(e) => OnWarehouseInput(e)"
Options="warehouseSelectItems">
<OptionTemplate Context="option">
<AutoCompleteOption Value="@option.Value.Id" Label="@option.Value.Name">
</AutoCompleteOption>
</OptionTemplate>
</AutoComplete>
</FormItem>
<FormItem Label="新增库存">
<Input Type="InputType.Number" @bind-Value="stockModel.AddStockQuantity" For="(()=>stockModel.AddStockQuantity)" />
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
ProductSearch search { get; set; } = new();
Form<ProductSearch> searchForm = null!;
PagingList<Product> PagingList = new();
bool loading { get; set; } = true;
bool searchExpand { get; set; } = false;
[SupplyParameterFromForm]
ProductAddStockModel stockModel { get; set; } = new();
Form<ProductAddStockModel> stockForm = null!;
bool drawerVisible;
string WarehouseName = string.Empty;
List<SelectItem> warehouseSelectItems = new();
public TypographyCopyableConfig CopyHint { get; set; } = null!;
protected override void OnInitialized()
{
CopyHint = new() { OnCopy = () => MessageService.Success("复制成功") };
base.OnInitialized();
}
protected override void OnParametersSet()
{
loadQueryString();
LoadList();
base.OnParametersSet();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Title = query.GetQueryString("Title");
search.CategoryId = query.GetQueryString("CategoryId");
var data = query.GetQueryString("RangeTime");
if (!string.IsNullOrEmpty(data))
{
var rangetime = data.Split("-");
if (rangetime != null && rangetime.Length > 0)
{
searchExpand = true;
search.RangeTime[0] = rangetime[0].NumberToDateTime();
search.RangeTime[1] = rangetime[1].NumberToDateTime();
StateHasChanged();
}
}
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
MessageService.Info("正在查询数据...");
OnSearch(Page.Value);
}
private void OnSearchReset()
{
search = new();
LoadList();
}
private async void LoadList()
{
loading = true;
var url = "/api/product/search";
var apiResult = await HttpService.GetPagingList<Product>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
private void OnReset()
{
search = new();
LoadList();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/product/list?page={page}");
}
else
{
Navigation.NavigateTo($"/product/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/product/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/product/list?{queryString}");
}
}
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/product/delete/{id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
void OnCreateClick()
{
Navigation.NavigateTo($"/product/create");
}
void OnEditClick(long id)
{
Navigation.NavigateTo($"/product/edit/{id}");
}
async Task OnClickAddStock(Product product)
{
drawerVisible = true;
stockModel = product.Adapt<ProductAddStockModel>();
stockModel.ProductId = product.Id;
var url = $"/api/product/attributes/{product.Id}";
var apiResult = await HttpService.Post<ApiResult<List<ProductStockAttributeModel>>>(url, new());
if (apiResult.Success)
{
stockModel.ProductStockAttributes = apiResult.Data ?? new();
}
WarehouseSearch warehouseSearch = new()
{
CorporationId = product.CorporationId
};
url = $"/api/warehouse/select";
var selectResult = await HttpService.Post<ApiResult<List<SelectItem>>>(url, warehouseSearch);
if (selectResult.Success)
{
warehouseSelectItems = selectResult.Data ?? new();
}
}
async void OnWarehouseInput(ChangeEventArgs e)
{
WarehouseSearch warehouseSearch = new()
{
CorporationId = stockModel.CorporationId,
Name = e.Value?.ToString()
};
var url = $"/api/warehouse/select";
var selectResult = await HttpService.Post<ApiResult<List<SelectItem>>>(url, warehouseSearch);
if (selectResult.Success)
{
warehouseSelectItems = selectResult.Data ?? new();
}
}
Func<object, object, bool> CompareWith = (a, b) =>
{
if (a is SelectItem o1 && b is SelectItem o2)
{
return o1.Name == o2.Name;
}
else
{
return false;
}
};
void CloseDrawer()
{
drawerVisible = false;
stockForm.Reset();
}
async Task OnStockFormFinish()
{
if (stockForm.Validate())
{
var result = new ApiResult<string>();
Console.WriteLine(stockModel.ToJson());
var url = $"api/product/stock/add";
result = await HttpService.Post<ApiResult<string>>(url, stockModel);
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
string GetAttributeValue(ProductAttributeValueModel value)
{
if (value.Weight > 0)
{
return $"{value.Name}{value.Weight.RemoveTrailingZeros()}{GetWeightUnit(value.WeightUnit)}";
}
else
{
return value.Name;
}
}
string GetWeightUnit(int weightUnit)
{
switch (weightUnit)
{
case 1:
return $"mg";
case 3:
return $"kg";
case 4:
return $"t";
case 5:
return $"lb";
case 6:
return $"oz";
default:
return $"g";
}
}
}

View File

@@ -0,0 +1,258 @@
@page "/product/stock/list"
@inject ILogger<ProductStockList> Logger
@attribute [Authorize]
<PageTitle>产品库存列表</PageTitle>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
产品库存列表
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c=>c.Title" Title="名称"></PropertyColumn>
<ActionColumn Title="规格">
@foreach (var item in context.Sku)
{
<AntDesign.Text>
@item.ValueName
@if (item.Weight > 0)
{
<AntDesign.Text>@($"{item.Weight}{@GetWeightUnit(item.WeightUnit)}")</AntDesign.Text>
}
</AntDesign.Text>
}
</ActionColumn>
<PropertyColumn Property="c=>c.Weight" Title="重量" Width="150px" Align="ColumnAlign.Center">
@context.Weight.RemoveTrailingZeros()
</PropertyColumn>
<PropertyColumn Property="c=>c.StockQuantity" Title="库存" Width="80px" Align="ColumnAlign.Center">
</PropertyColumn>
<PropertyColumn Property="c=>c.UpdateTime" Title="更新时间" Width="200px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="180px">
<Space>
<SpaceItem>
<a @onclick="(e)=>OnClickAddStock(context)">入库</a>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='("规格库存入库")' OnClose="_=>CloseDrawer()">
<Form LabelColSpan="4" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="产品标题">
@model.Title
</FormItem>
<FormItem Label="规格">
@if (model.Sku != null)
{
@foreach (var item in model.Sku)
{
<GridRow>
<GridCol>@item.AttributeName</GridCol>
<GridCol>
@item.ValueName
@if (item.Weight > 0)
{
<AntDesign.Text>@($"{item.Weight}{@GetWeightUnit(item.WeightUnit)}")</AntDesign.Text>
}
</GridCol>
</GridRow>
}
}
</FormItem>
<FormItem Label="新增库存">
<Input @bind-Value="@model.AddStockQuantity"></Input>
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
ProductStockUnitSearch search { get; set; } = new();
Form<ProductStockUnitSearch> searchForm = null!;
PagingList<ProductStockUnitModel> PagingList = new();
[SupplyParameterFromForm]
ProductStockModel model { get; set; } = new();
Form<ProductStockModel> editform = null!;
bool loading { get; set; } = true;
bool searchExpand { get; set; } = false;
private bool drawerVisible;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
loadQueryString();
LoadList();
base.OnParametersSet();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Key = query.GetQueryString("Key");
search.Type = query.GetQueryString("Type").ToInt();
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnSearchReset()
{
search = new();
LoadList();
}
private async void LoadList()
{
loading = true;
var url = "/api/product/stock/search";
var apiResult = await HttpService.GetPagingList<ProductStockUnitModel>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
private void OnReset()
{
search = new();
LoadList();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/product/stock/list?page={page}");
}
else
{
Navigation.NavigateTo($"/product/stock/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/product/stock/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/product/stock/list?{queryString}");
}
}
}
void OnPageChanged(PaginationEventArgs args)
{
OnSearch(args.Page);
}
string PriceFormat(decimal value)
{
return value.ToString("G");
}
void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
void OnClickAddStock(ProductStockUnitModel item)
{
model = item.Adapt<ProductStockModel>();
drawerVisible = true;
}
async Task OnFormFinish()
{
if (editform.Validate())
{
var result = new ApiResult<string>();
var url = $"api/product/skustock/add";
result = await HttpService.Post<ApiResult<string>>(url, model);
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
string GetWeightUnit(int weightUnit)
{
switch (weightUnit)
{
case 1:
return $"mg";
case 3:
return $"kg";
case 4:
return $"t";
case 5:
return $"lb";
case 6:
return $"oz";
default:
return $"g";
}
}
}

View File

@@ -0,0 +1,319 @@
@page "/specification/list"
@inject ILogger<SpecificationList> Logger
@attribute [Authorize]
<PageTitle>产品规格管理</PageTitle>
<Title Level="4">属性列表</Title>
<Card>
<Form @ref="searchForm" Model="search" Layout="FormLayout.Inline" Class="search-form" OnFinish="OnSearchFinish">
<Row Justify="RowJustify.Start" Gutter="16">
<Col>
<FormItem Label="名称">
<Input @bind-Value="search.Name" Placeholder="名称" AllowClear />
</FormItem>
</Col>
<Col>
<div class="ant-form-item" style="width:200px;display:flex;">
<Button Type="ButtonType.Primary" HtmlType="submit">查询</Button>
<Button Style="margin: 0 8px;" OnClick="OnSearchReset">重置</Button>
</div>
</Col>
</Row>
</Form>
</Card>
<Card Class="mt-3">
<Table DataSource="PagingList.Items" PageSize="100" HidePagination="true" Resizable>
<TitleTemplate>
<Flex Justify="FlexJustify.SpaceBetween">
属性列表
<div>
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
</div>
</Flex>
</TitleTemplate>
<ColumnDefinitions>
<PropertyColumn Property="c=>c.Name" Title="名称"></PropertyColumn>
<PropertyColumn Property="c=>c.ControlType" Title="控件">
@if (context.ControlType == 1)
{
<Tag Color="TagColor.Green">选项</Tag>
}
else
{
<Tag>文本框</Tag>
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CategoryName" Title="分类"></PropertyColumn>
<PropertyColumn Property="c=>c.DisplayOrder" Title="排序" Width="150px" Align="ColumnAlign.Center" />
<PropertyColumn Property="c=>c.Status" Title="状态" Width="80px" Align="ColumnAlign.Center">
@if (context.Status == 1)
{
<AntDesign.Text Type="TextElementType.Success"><Icon Type="check" Theme=" IconThemeType.Outline" Width="1.3em" Height="1.3em" /></AntDesign.Text>
}
else
{
<Icon Type="close" Theme="IconThemeType.Outline" Width="1.3em" Height="1.3em" />
}
</PropertyColumn>
<PropertyColumn Property="c=>c.CreateTime" Title="时间" Width="200px" />
<ActionColumn Title="操作" Align="ColumnAlign.Right" Width="180px">
<Space>
<SpaceItem>
<a @onclick="(e)=>OnViewPredefinedListClick(context.Id)">预设值</a>
</SpaceItem>
<SpaceItem>
<a @onclick="(e)=>OnEditClick(context)">编辑</a>
</SpaceItem>
<SpaceItem>
<Popconfirm Placement="@Placement.Left" Title="@("删除这条数据无法恢复,您确定要删除吗?")"
OnConfirm="@(e=>HandleDeleteConfirmAsync(e,context.Id))"
OkText="确定"
CancelText="取消">
<a>删除</a>
</Popconfirm>
</SpaceItem>
</Space>
</ActionColumn>
</ColumnDefinitions>
</Table>
<br />
<Row Justify="RowJustify.End">
<Pagination Current="PagingList.Index" Total="PagingList.Count" PageSize="PagingList.Size" ShowSizeChanger="false" OnChange="OnPageChanged"></Pagination>
</Row>
</Card>
<Drawer Closable="true" Width="520" Visible="drawerVisible" Title='("设置规格属性")' OnClose="_=>CloseDrawer()">
<Form LabelColSpan="4" @ref="@editform" Model="@model" OnFinish="OnFormFinish">
<FluentValidationValidator />
<FormItem Label="名称">
<Input @bind-Value="model.Name" For="(()=>model.Name)" />
</FormItem>
<FormItem Label="控件">
<RadioGroup @bind-Value="@model.ControlType" ButtonStyle="RadioButtonStyle.Solid">
<Radio RadioButton Value="0">默认(文本)</Radio>
<Radio RadioButton Value="1">选项</Radio>
</RadioGroup>
</FormItem>
<FormItem Label="状态">
<RadioGroup @bind-Value="@model.Status" ButtonStyle="RadioButtonStyle.Solid">
<Radio RadioButton Value="1">启用</Radio>
<Radio RadioButton Value="2">禁用</Radio>
</RadioGroup>
</FormItem>
<FormItem WrapperColOffset="4">
<Button Type="ButtonType.Primary" HtmlType="submit" Style="width: 100%;">保存</Button>
</FormItem>
</Form>
</Drawer>
@code {
[SupplyParameterFromQuery]
int? Page { get; set; }
[SupplyParameterFromQuery]
long CategoryId { get; set; }
[SupplyParameterFromQuery(Name = "size")]
int? PageSize { get; set; }
[SupplyParameterFromForm]
SpecificationAttributeSearch search { get; set; } = new();
Form<SpecificationAttributeSearch> searchForm = null!;
[SupplyParameterFromForm]
SpecificationAttributeModel model { get; set; } = new();
Form<SpecificationAttributeModel> editform = null!;
PagingList<SpecificationAttributeItemModel> PagingList = new();
bool loading { get; set; } = true;
bool searchExpand { get; set; } = false;
private bool drawerVisible;
protected override void OnInitialized()
{
base.OnInitialized();
}
protected override void OnParametersSet()
{
loadQueryString();
LoadList();
base.OnParametersSet();
}
void loadQueryString()
{
var uri = new Uri(Navigation.Uri);
var query = uri.Query;
search.Name = query.GetQueryString("Name");
search.CategoryId = CategoryId;
}
private async void LoadList()
{
loading = true;
var url = "/api/specificationattribute/search";
var apiResult = await HttpService.GetPagingList<SpecificationAttributeItemModel>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
if (apiResult.Success)
{
if (apiResult.Data != null)
{
PagingList = apiResult.Data;
}
}
loading = false;
StateHasChanged();
}
void OnSearchFinish()
{
Page = Page.GetValueOrDefault(1) - 1;
OnSearch(Page.Value);
}
private void OnSearchReset()
{
search = new();
LoadList();
}
private void OnReset()
{
search = new();
LoadList();
}
private void OnSearch(int page)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
if (page > 1)
{
Navigation.NavigateTo($"/specification/list?page={page}");
}
else
{
Navigation.NavigateTo($"/specification/list");
}
}
else
{
if (page > 1)
{
Navigation.NavigateTo($"/specification/list?page={page}&{queryString}");
}
else
{
Navigation.NavigateTo($"/specification/list?{queryString}");
}
}
}
void OnEditClick(SpecificationAttribute attribute)
{
this.model = attribute.Adapt<SpecificationAttributeModel>();
drawerVisible = true;
}
async Task HandleDeleteConfirmAsync(MouseEventArgs e, long id)
{
var url = $"/api/specificationattribute/delete/{model.Id}";
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
if (apiResult.Success)
{
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "操作提示", Content = $"数据删除失败.{apiResult.Message}" });
}
}
async Task OnFormFinish()
{
if (CategoryId > 0)
{
model.CategoryId = CategoryId;
}
if (editform.Validate())
{
var result = new ApiResult<string>();
if (model.Id > 0)
{
var url = $"api/specificationattribute/edit";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
else
{
var url = $"api/specificationattribute/add";
result = await HttpService.Post<ApiResult<string>>(url, model);
}
if (result.Code == (int)ResultCode.Success)
{
CloseDrawer();
LoadList();
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
}
else
{
await ModalService.ErrorAsync(new ConfirmOptions() { Title = "服务异常", Content = result.Message });
}
}
}
void OnPageChanged(PaginationEventArgs args)
{
var queryString = search.BuildQueryString();
if (string.IsNullOrEmpty(queryString))
{
Navigation.NavigateTo($"/specification/list?page={args.Page}");
}
else
{
Navigation.NavigateTo($"/specification/list?page={Page}&{queryString}");
}
}
void OnCreateClick()
{
drawerVisible = true;
}
void CloseDrawer()
{
drawerVisible = false;
editform.Reset();
}
void OnViewPredefinedListClick(long id)
{
Navigation.NavigateTo($"/specification/Predefined/list/{id}");
}
}