feat(client): 商品详情页展示所有字段,补全分类/库存预警/备注/自定义字段/描述文档

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-09 22:50:47 +08:00
parent 0ec609255c
commit afa1a0bcd2
2 changed files with 65 additions and 2 deletions
+11 -1
View File
@@ -18,10 +18,14 @@ class Product {
final String? remark;
final Map<String, dynamic>? customFields;
final List<ProductImage> images;
// 产地/保质期/储存方式名称(Detail 接口 Preload 后填充)
// 产地/保质期/储存方式/分类名称(Detail 接口 Preload 后填充)
final String? originName;
final String? shelfLifeName;
final String? storageName;
final String? categoryName;
// 描述文档(关联的字典记录)
final String? descriptionDocTitle;
final String? descriptionDocContent;
const Product({
required this.id,
@@ -44,6 +48,9 @@ class Product {
this.originName,
this.shelfLifeName,
this.storageName,
this.categoryName,
this.descriptionDocTitle,
this.descriptionDocContent,
});
factory Product.fromJson(Map<String, dynamic> json) => Product(
@@ -78,6 +85,9 @@ class Product {
originName: (json['origin'] as Map<String, dynamic>?)?['name'] as String?,
shelfLifeName: (json['shelf_life'] as Map<String, dynamic>?)?['name'] as String?,
storageName: (json['storage'] as Map<String, dynamic>?)?['name'] as String?,
categoryName: (json['category'] as Map<String, dynamic>?)?['name'] as String?,
descriptionDocTitle: (json['description_doc'] as Map<String, dynamic>?)?['title'] as String?,
descriptionDocContent: (json['description_doc'] as Map<String, dynamic>?)?['content'] as String?,
);
Map<String, dynamic> toJson() => {
@@ -202,6 +202,10 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
categoryId: p.categoryId, brand: p.brand, purchasePrice: p.purchasePrice,
salePrice: p.salePrice, minStock: p.minStock, description: p.description,
remark: p.remark, customFields: p.customFields, images: images,
originName: p.originName, shelfLifeName: p.shelfLifeName,
storageName: p.storageName, categoryName: p.categoryName,
descriptionDocTitle: p.descriptionDocTitle,
descriptionDocContent: p.descriptionDocContent,
);
});
}
@@ -275,6 +279,10 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
],
const SizedBox(height: 20),
_buildDescSection(),
if (p.descriptionDocTitle?.isNotEmpty ?? false) ...[
const SizedBox(height: 20),
_buildDescriptionDocSection(p),
],
const SizedBox(height: 20),
_buildPublicLinkSection(p),
],
@@ -353,7 +361,11 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
SizedBox(width: 200, child: row('规格', p.spec?.isEmpty ?? true ? '-' : p.spec!)),
SizedBox(width: 200, child: row('品牌', p.brand?.isEmpty ?? true ? '-' : p.brand!)),
SizedBox(width: 200, child: row('单位', p.unit.isEmpty ? '-' : p.unit)),
SizedBox(width: 200, child: row('进价', p.purchasePrice != null ? '¥${p.purchasePrice!.toStringAsFixed(2)}' : '-')),
if (p.categoryName?.isNotEmpty ?? false)
SizedBox(width: 200, child: row('分类', p.categoryName!)),
SizedBox(width: 200, child: row('进价', p.purchasePrice != null && p.purchasePrice! > 0 ? '¥${p.purchasePrice!.toStringAsFixed(2)}' : '-')),
if (p.minStock != null && p.minStock! > 0)
SizedBox(width: 200, child: row('库存预警', '${p.minStock}')),
if (p.originName?.isNotEmpty ?? false)
SizedBox(width: 200, child: row('产地', p.originName!)),
if (p.shelfLifeName?.isNotEmpty ?? false)
@@ -362,6 +374,47 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
SizedBox(width: 200, child: row('储存方式', p.storageName!)),
if (p.barcode?.isNotEmpty ?? false)
SizedBox(width: 200, child: row('条码', p.barcode!)),
if (p.remark?.isNotEmpty ?? false)
SizedBox(width: 400, child: row('备注', p.remark!)),
...?_buildCustomFieldRows(p, row),
],
),
),
);
}
List<Widget>? _buildCustomFieldRows(
Product p, Widget Function(String, String) row) {
final fields = p.customFields;
if (fields == null || fields.isEmpty) return null;
return fields.entries
.where((e) => e.value != null && e.value.toString().isNotEmpty)
.map((e) =>
SizedBox(width: 200, child: row(e.key, e.value.toString())))
.toList();
}
Widget _buildDescriptionDocSection(Product p) {
return Card(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(color: AppTheme.border, width: 0.5),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(p.descriptionDocTitle!,
style: const TextStyle(
fontSize: 14, fontWeight: FontWeight.w600)),
if (p.descriptionDocContent?.isNotEmpty ?? false) ...[
const SizedBox(height: 10),
Text(p.descriptionDocContent!,
style: const TextStyle(
fontSize: 13, color: AppTheme.textSecondary, height: 1.6)),
],
],
),
),