feat: 商品详情页、XLS导入修复、分页选择器、导出功能
后端: - 新增 product_images 表,支持每商品最多5张图(服务端压缩至1200px/JPEG85%) - products 表新增 public_id(UUID)、description 字段 - 新增商品详情接口、二维码接口、公开商品接口(无鉴权) - 修复 XLS 导入:OLE2 magic bytes 检测 + 临时文件解析,兼容 extrame/xls - 修复商品/名称/系列/规格三张表导入数据为0(LastCol()=0 bug) - 所有导入接口返回 total/imported/skipped 统计 - config 新增 StorageConfig,支持 STORAGE_* 环境变量覆盖 - 种子数据修复:products 补 public_id、新增 product_images TRUNCATE、schema.sql 表名修正 前端: - 商品详情页:图片上传/删除、描述内联编辑、二维码弹窗、公开链接复制 - 公开商品页:无鉴权路由 /product/:public_id,Flutter Web SPA - 商品详情列表(批次追踪)商品名超链接跳转详情页 - 导航「商品管理」改名「商品详情」 - 所有列表表格新增每页条数选择(10/20/50/100) - 表格列头内嵌筛选(FilterableColumnHeader) - 导出 Excel 功能(入库/出库/库存/财务/批次/往来单位) - 网络恢复自动刷新 + 离线缓存展示 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../models/inventory.dart';
|
||||
import '../../providers/inventory_provider.dart';
|
||||
import '../../widgets/data_table_card.dart';
|
||||
import '../../widgets/multi_select_dropdown.dart' show ColDef, ColumnToggleButton, FilterableColumnHeader;
|
||||
import '../../providers/connectivity_provider.dart';
|
||||
import '../../core/utils/export_util.dart';
|
||||
|
||||
class BatchTrackingScreen extends ConsumerStatefulWidget {
|
||||
const BatchTrackingScreen({super.key});
|
||||
@@ -17,6 +19,7 @@ class BatchTrackingScreen extends ConsumerStatefulWidget {
|
||||
|
||||
class _BatchTrackingScreenState extends ConsumerState<BatchTrackingScreen> {
|
||||
int _page = 1;
|
||||
int _pageSize = 20;
|
||||
int _total = 0;
|
||||
late Future<List<ProductTrackingRecord>> _future;
|
||||
List<ProductTrackingRecord> _records = [];
|
||||
@@ -49,7 +52,7 @@ class _BatchTrackingScreenState extends ConsumerState<BatchTrackingScreen> {
|
||||
void _fetch() {
|
||||
_future = ref
|
||||
.read(inventoryRepositoryProvider)
|
||||
.listProducts(page: _page, pageSize: 20)
|
||||
.listProducts(page: _page, pageSize: _pageSize)
|
||||
.then((r) {
|
||||
_total = r.total;
|
||||
_records = r.data;
|
||||
@@ -189,15 +192,44 @@ class _BatchTrackingScreenState extends ConsumerState<BatchTrackingScreen> {
|
||||
return DataTableCard(
|
||||
totalCount: _total,
|
||||
page: _page,
|
||||
pageSize: _pageSize,
|
||||
onPageChanged: (p) => setState(() {
|
||||
_page = p;
|
||||
_fetch();
|
||||
}),
|
||||
onPageSizeChanged: (s) => setState(() {
|
||||
_pageSize = s;
|
||||
_page = 1;
|
||||
_fetch();
|
||||
}),
|
||||
toolbar: Row(
|
||||
children: [
|
||||
const Text('已审核入库商品(含库存与销售状态)',
|
||||
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary)),
|
||||
const Spacer(),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => exportExcel(
|
||||
filename: '商品管理',
|
||||
headers: ['商品名称', '商品编码', '规格', '批次号', '入库单号', '供应商', '仓库', '入库日期', '数量', '单价', '状态', '买家'],
|
||||
rows: records.map((r) => [
|
||||
r.productName ?? '',
|
||||
r.productCode ?? '',
|
||||
r.productSpec ?? '',
|
||||
r.batchNo ?? '',
|
||||
r.orderNo ?? '',
|
||||
r.supplierName ?? '',
|
||||
r.warehouseName ?? '',
|
||||
r.orderDate?.substring(0, 10) ?? '',
|
||||
r.quantity.toInt(),
|
||||
r.unitPrice,
|
||||
r.isSoldOut ? '已卖出' : '在售',
|
||||
r.buyerName ?? '',
|
||||
]).toList(),
|
||||
),
|
||||
icon: const Icon(Icons.download, size: 16),
|
||||
label: const Text('导出'),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh, size: 18),
|
||||
onPressed: () => setState(() {
|
||||
@@ -224,21 +256,30 @@ class _BatchTrackingScreenState extends ConsumerState<BatchTrackingScreen> {
|
||||
(r.batchNo != null && r.batchNo!.isNotEmpty) ? r.batchNo! : null;
|
||||
switch (key) {
|
||||
case 'product':
|
||||
return DataCell(Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(r.productName ?? '-',
|
||||
style: const TextStyle(
|
||||
fontSize: 13, fontWeight: FontWeight.w500)),
|
||||
if (r.productCode != null)
|
||||
Text(r.productCode!,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: AppTheme.textSecondary,
|
||||
fontFamily: 'monospace')),
|
||||
],
|
||||
));
|
||||
return DataCell(
|
||||
GestureDetector(
|
||||
onTap: () => context.push('/products/${r.productId}'),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(r.productName ?? '-',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppTheme.primary,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationColor: AppTheme.primary)),
|
||||
if (r.productCode != null)
|
||||
Text(r.productCode!,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: AppTheme.textSecondary,
|
||||
fontFamily: 'monospace')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
case 'spec':
|
||||
return DataCell(Text(r.productSpec ?? '-',
|
||||
style: const TextStyle(fontSize: 12)));
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../../providers/inventory_provider.dart';
|
||||
import '../../widgets/data_table_card.dart';
|
||||
import '../../widgets/multi_select_dropdown.dart' show FilterableColumnHeader;
|
||||
import '../../widgets/page_scaffold.dart';
|
||||
import '../../core/utils/export_util.dart';
|
||||
|
||||
class InventoryListScreen extends ConsumerStatefulWidget {
|
||||
const InventoryListScreen({super.key});
|
||||
@@ -128,10 +129,13 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: DataTableCard(
|
||||
totalCount: filteredItems.length,
|
||||
totalCount: result.total,
|
||||
page: result.page,
|
||||
pageSize: result.pageSize,
|
||||
onPageChanged: (p) =>
|
||||
ref.read(inventoryListProvider.notifier).setPage(p),
|
||||
onPageSizeChanged: (s) =>
|
||||
ref.read(inventoryListProvider.notifier).setPageSize(s),
|
||||
toolbar: Row(
|
||||
children: [
|
||||
OutlinedButton.icon(
|
||||
@@ -139,6 +143,32 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
|
||||
icon: const Icon(Icons.fact_check, size: 16),
|
||||
label: const Text('发起盘点'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => exportExcel(
|
||||
filename: '库存查询',
|
||||
headers: ['商品编码', '商品名称', '品牌', '规格', '仓库', '库存', '安全库存', '状态'],
|
||||
rows: filteredItems.map((item) {
|
||||
final status = item.quantity == 0
|
||||
? '缺货'
|
||||
: (item.minStock != null && item.quantity < item.minStock!)
|
||||
? '库存不足'
|
||||
: '正常';
|
||||
return [
|
||||
item.productCode ?? '',
|
||||
item.productName ?? '',
|
||||
item.productBrand ?? '',
|
||||
item.productSpec ?? '',
|
||||
item.warehouseName ?? '',
|
||||
item.quantity.toInt(),
|
||||
item.minStock ?? '',
|
||||
status,
|
||||
];
|
||||
}).toList(),
|
||||
),
|
||||
icon: const Icon(Icons.download, size: 16),
|
||||
label: const Text('导出'),
|
||||
),
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
width: 200,
|
||||
@@ -284,6 +314,24 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
|
||||
style: const TextStyle(
|
||||
fontSize: 13, color: AppTheme.accent),
|
||||
),
|
||||
const Spacer(),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => exportExcel(
|
||||
filename: '库存预警',
|
||||
headers: ['商品编码', '商品名称', '仓库', '当前库存', '安全库存', '缺口', '状态'],
|
||||
rows: warnings.map((item) => [
|
||||
item.productCode ?? '',
|
||||
item.productName ?? '',
|
||||
item.warehouseName ?? '',
|
||||
item.quantity.toInt(),
|
||||
item.minStock ?? 0,
|
||||
item.minStock! - item.quantity.toInt(),
|
||||
item.quantity == 0 ? '缺货' : '库存不足',
|
||||
]).toList(),
|
||||
),
|
||||
icon: const Icon(Icons.download, size: 16),
|
||||
label: const Text('导出'),
|
||||
),
|
||||
],
|
||||
),
|
||||
columns: const [
|
||||
@@ -377,15 +425,37 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
|
||||
return DataTableCard(
|
||||
totalCount: result.total,
|
||||
page: result.page,
|
||||
pageSize: result.pageSize,
|
||||
onPageChanged: (p) =>
|
||||
ref.read(inventoryLogProvider.notifier).setPage(p),
|
||||
toolbar: const Row(
|
||||
onPageSizeChanged: (s) =>
|
||||
ref.read(inventoryLogProvider.notifier).setPageSize(s),
|
||||
toolbar: Row(
|
||||
children: [
|
||||
Icon(Icons.history, color: AppTheme.primary, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text('库存流水记录',
|
||||
const Icon(Icons.history, color: AppTheme.primary, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
const Text('库存流水记录',
|
||||
style: TextStyle(
|
||||
fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
const Spacer(),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => exportExcel(
|
||||
filename: '库存流水',
|
||||
headers: ['商品名称', '仓库', '方向', '数量', '变前', '变后', '来源', '时间'],
|
||||
rows: logs.map((log) => [
|
||||
log.productName ?? '',
|
||||
log.warehouseName ?? '',
|
||||
log.direction == 'in' ? '入库' : '出库',
|
||||
log.quantity.toInt(),
|
||||
log.qtyBefore?.toInt() ?? 0,
|
||||
log.qtyAfter?.toInt() ?? 0,
|
||||
log.refType ?? '',
|
||||
log.createdAt?.substring(0, 19) ?? '',
|
||||
]).toList(),
|
||||
),
|
||||
icon: const Icon(Icons.download, size: 16),
|
||||
label: const Text('导出'),
|
||||
),
|
||||
],
|
||||
),
|
||||
columns: const [
|
||||
|
||||
Reference in New Issue
Block a user