|
|
|
@@ -11,7 +11,6 @@ import '../../models/stock_in.dart';
|
|
|
|
|
import '../../core/config/app_constants.dart';
|
|
|
|
|
import '../../providers/partner_provider.dart';
|
|
|
|
|
import '../../providers/product_option_provider.dart';
|
|
|
|
|
import '../../providers/product_provider.dart';
|
|
|
|
|
import '../../providers/inventory_provider.dart';
|
|
|
|
|
import '../../providers/stock_in_provider.dart';
|
|
|
|
|
import '../../providers/warehouse_provider.dart';
|
|
|
|
@@ -306,58 +305,22 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
|
|
|
|
|
|
|
|
|
|
setState(() => _submitting = true);
|
|
|
|
|
|
|
|
|
|
// Resolve product IDs for items where productId is null
|
|
|
|
|
// 入库每行 = 一个特有产品:明细只带 名称/系列/规格(字典文本) + 批次/生产日期,
|
|
|
|
|
// 由后端为每行新建独立产品(序列号),前端不再 findOrCreate 复用。
|
|
|
|
|
final nameOpts = ref.read(productNameListProvider).valueOrNull ?? [];
|
|
|
|
|
final seriesOpts = ref.read(productSeriesListProvider).valueOrNull ?? [];
|
|
|
|
|
final specOpts = ref.read(productSpecListProvider).valueOrNull ?? [];
|
|
|
|
|
String optName(List<dynamic> opts, int? id) =>
|
|
|
|
|
opts.where((o) => o.id == id).firstOrNull?.name as String? ?? '';
|
|
|
|
|
|
|
|
|
|
for (final item in _items) {
|
|
|
|
|
if (item.productId == null) {
|
|
|
|
|
final name = nameOpts
|
|
|
|
|
.where((o) => o.id == item.selectedNameId)
|
|
|
|
|
.firstOrNull
|
|
|
|
|
?.name ??
|
|
|
|
|
'';
|
|
|
|
|
final series = seriesOpts
|
|
|
|
|
.where((o) => o.id == item.selectedSeriesId)
|
|
|
|
|
.firstOrNull
|
|
|
|
|
?.name ??
|
|
|
|
|
'';
|
|
|
|
|
final spec = specOpts
|
|
|
|
|
.where((o) => o.id == item.selectedSpecId)
|
|
|
|
|
.firstOrNull
|
|
|
|
|
?.name ??
|
|
|
|
|
'';
|
|
|
|
|
if (name.isEmpty) {
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
const SnackBar(
|
|
|
|
|
content: Text('请选择商品名称'), backgroundColor: AppTheme.danger),
|
|
|
|
|
);
|
|
|
|
|
setState(() => _submitting = false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
final product =
|
|
|
|
|
await ref.read(productRepositoryProvider).findOrCreate(
|
|
|
|
|
name: name,
|
|
|
|
|
series: series,
|
|
|
|
|
spec: spec,
|
|
|
|
|
originId: item.selectedOriginId,
|
|
|
|
|
shelfLifeId: item.selectedShelfLifeId,
|
|
|
|
|
storageId: item.selectedStorageId,
|
|
|
|
|
descriptionDocId: item.selectedDescriptionDocId,
|
|
|
|
|
);
|
|
|
|
|
item.productId = product.id;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (mounted) {
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(
|
|
|
|
|
content: Text('商品查找失败:$e'), backgroundColor: AppTheme.danger),
|
|
|
|
|
);
|
|
|
|
|
setState(() => _submitting = false);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (optName(nameOpts, item.selectedNameId).isEmpty) {
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
const SnackBar(
|
|
|
|
|
content: Text('请选择商品名称'), backgroundColor: AppTheme.danger),
|
|
|
|
|
);
|
|
|
|
|
setState(() => _submitting = false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -367,7 +330,9 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
|
|
|
|
|
final batchNo = item.batchNoCtrl.text.trim();
|
|
|
|
|
final productionDate = item.productionDateCtrl.text.trim();
|
|
|
|
|
return {
|
|
|
|
|
'product_id': item.productId ?? 0,
|
|
|
|
|
'product_name': optName(nameOpts, item.selectedNameId),
|
|
|
|
|
'series': optName(seriesOpts, item.selectedSeriesId),
|
|
|
|
|
'spec': optName(specOpts, item.selectedSpecId),
|
|
|
|
|
'quantity': qty,
|
|
|
|
|
'unit_price': price,
|
|
|
|
|
'total_price': qty * price,
|
|
|
|
|