|
|
@@ -1,3 +1,4 @@
|
|
|
+import 'package:chicken_farm/core/config/app_config.dart';
|
|
|
import 'package:chicken_farm/core/utils/logger.dart';
|
|
|
import 'package:chicken_farm/apis/index.dart';
|
|
|
import 'package:chicken_farm/components/vb_rfid_field.dart';
|
|
|
@@ -19,8 +20,8 @@ class BatchCreatePage extends StatefulWidget {
|
|
|
|
|
|
class _BatchCreatePageState extends State<BatchCreatePage> {
|
|
|
final List<String> _rfids = [];
|
|
|
- String? _selectedBatchNum;
|
|
|
- String? _selectedFamilyId;
|
|
|
+ String? _batchNum;
|
|
|
+ String? _familyId;
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
@@ -32,10 +33,10 @@ class _BatchCreatePageState extends State<BatchCreatePage> {
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
children: [
|
|
|
// 批次选择
|
|
|
- _buildBatchSearchSelect(),
|
|
|
+ _buildBatchInput(),
|
|
|
const SizedBox(height: 10),
|
|
|
// 家系号选择
|
|
|
- _buildFamilySearchSelect(),
|
|
|
+ _buildFamilyInput(),
|
|
|
const SizedBox(height: 20),
|
|
|
// 电子编号区域
|
|
|
_buildRfidSection(),
|
|
|
@@ -45,16 +46,14 @@ class _BatchCreatePageState extends State<BatchCreatePage> {
|
|
|
width: double.infinity,
|
|
|
child: ElevatedButton(
|
|
|
onPressed:
|
|
|
- _rfids.isNotEmpty &&
|
|
|
- _selectedBatchNum != null &&
|
|
|
- _selectedFamilyId != null
|
|
|
+ _rfids.isNotEmpty && _batchNum != null && _familyId != null
|
|
|
? _handleSubmit
|
|
|
: null,
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
backgroundColor:
|
|
|
_rfids.isNotEmpty &&
|
|
|
- _selectedBatchNum != null &&
|
|
|
- _selectedFamilyId != null
|
|
|
+ _batchNum != null &&
|
|
|
+ _familyId != null
|
|
|
? Colors.blue
|
|
|
: Colors.grey,
|
|
|
foregroundColor: Colors.white,
|
|
|
@@ -119,6 +118,74 @@ class _BatchCreatePageState extends State<BatchCreatePage> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ Widget _buildBatchInput() {
|
|
|
+ if (AppConfig.isOffline) {
|
|
|
+ // 离线模式下使用文本输入框
|
|
|
+ return Column(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ const Text('批次号', style: TextStyle(fontWeight: FontWeight.bold)),
|
|
|
+ const SizedBox(height: 10),
|
|
|
+ Container(
|
|
|
+ padding: const EdgeInsets.fromLTRB(16, 2, 16, 2),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ border: Border.all(color: Colors.grey),
|
|
|
+ borderRadius: BorderRadius.circular(8),
|
|
|
+ ),
|
|
|
+ child: TextField(
|
|
|
+ decoration: const InputDecoration(
|
|
|
+ hintText: '请输入批次号',
|
|
|
+ border: InputBorder.none,
|
|
|
+ ),
|
|
|
+ onChanged: (value) {
|
|
|
+ setState(() {
|
|
|
+ _batchNum = value.isNotEmpty ? value : null;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ // 在线模式下使用原来的搜索选择器
|
|
|
+ return _buildBatchSearchSelect();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget _buildFamilyInput() {
|
|
|
+ if (AppConfig.isOffline) {
|
|
|
+ // 离线模式下使用文本输入框
|
|
|
+ return Column(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ const Text('家系号', style: TextStyle(fontWeight: FontWeight.bold)),
|
|
|
+ const SizedBox(height: 10),
|
|
|
+ Container(
|
|
|
+ padding: const EdgeInsets.fromLTRB(16, 2, 16, 2),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ border: Border.all(color: Colors.grey),
|
|
|
+ borderRadius: BorderRadius.circular(8),
|
|
|
+ ),
|
|
|
+ child: TextField(
|
|
|
+ decoration: const InputDecoration(
|
|
|
+ hintText: '请输入家系号',
|
|
|
+ border: InputBorder.none,
|
|
|
+ ),
|
|
|
+ onChanged: (value) {
|
|
|
+ setState(() {
|
|
|
+ _familyId = value.isNotEmpty ? value : null;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ // 在线模式下使用原来的搜索选择器
|
|
|
+ return _buildFamilySearchSelect();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Widget _buildBatchSearchSelect() {
|
|
|
return Column(
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
@@ -145,13 +212,13 @@ class _BatchCreatePageState extends State<BatchCreatePage> {
|
|
|
extra: data,
|
|
|
);
|
|
|
},
|
|
|
- value: _selectedBatchNum,
|
|
|
+ value: _batchNum,
|
|
|
hint: '批次号',
|
|
|
onChanged: (String? value) {
|
|
|
setState(() {
|
|
|
- _selectedBatchNum = value;
|
|
|
+ _batchNum = value;
|
|
|
// 当切换批次时,重置后续选项和数据
|
|
|
- _selectedFamilyId = null;
|
|
|
+ _familyId = null;
|
|
|
});
|
|
|
|
|
|
// // 获取翅号数据
|
|
|
@@ -193,11 +260,11 @@ class _BatchCreatePageState extends State<BatchCreatePage> {
|
|
|
extra: data,
|
|
|
);
|
|
|
},
|
|
|
- value: _selectedFamilyId,
|
|
|
+ value: _familyId,
|
|
|
hint: '家系号',
|
|
|
onChanged: (String? value) {
|
|
|
setState(() {
|
|
|
- _selectedFamilyId = value;
|
|
|
+ _familyId = value;
|
|
|
});
|
|
|
},
|
|
|
hideUnderline: true,
|
|
|
@@ -262,11 +329,7 @@ class _BatchCreatePageState extends State<BatchCreatePage> {
|
|
|
// 提交数据
|
|
|
void _handleSubmit() {
|
|
|
final data = _rfids.map((rfid) {
|
|
|
- return {
|
|
|
- 'rfid': rfid,
|
|
|
- 'batchNum': _selectedBatchNum,
|
|
|
- 'familyId': _selectedFamilyId,
|
|
|
- };
|
|
|
+ return {'rfid': rfid, 'batchNum': _batchNum, 'familyId': _familyId};
|
|
|
}).toList();
|
|
|
apis.breeding.submitApi
|
|
|
.create(data)
|