individual_culling_page.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import 'package:chicken_farm/apis/index.dart';
  2. import 'package:chicken_farm/core/utils/datetime_util.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:chicken_farm/components/vb_app_bar.dart';
  5. import 'package:chicken_farm/components/vb_dict_select.dart';
  6. import 'package:chicken_farm/core/utils/toast.dart';
  7. import 'package:chicken_farm/components/vb_electronic_id_field.dart';
  8. class IndividualCullingPage extends StatefulWidget {
  9. const IndividualCullingPage({super.key});
  10. @override
  11. State<IndividualCullingPage> createState() => _IndividualCullingPageState();
  12. }
  13. class _IndividualCullingPageState extends State<IndividualCullingPage> {
  14. String? _electronicId;
  15. String? _cullReason;
  16. String? _disposalMethod;
  17. @override
  18. Widget build(BuildContext context) {
  19. return Scaffold(
  20. appBar: const VberAppBar(title: '个体淘汰', showLeftButton: true),
  21. body: SingleChildScrollView(
  22. padding: const EdgeInsets.all(16.0),
  23. child: Column(
  24. crossAxisAlignment: CrossAxisAlignment.start,
  25. children: [
  26. // 电子编号区域
  27. _buildElectronicIdSection(),
  28. const SizedBox(height: 20),
  29. // 淘汰原因
  30. _buildCullReasonSection(),
  31. const SizedBox(height: 20),
  32. // 处置方式
  33. _buildDisposalMethodSection(),
  34. const SizedBox(height: 30),
  35. // 提交按钮
  36. SizedBox(
  37. width: double.infinity,
  38. child: ElevatedButton(
  39. onPressed:
  40. _electronicId != null &&
  41. _cullReason != null &&
  42. _disposalMethod != null
  43. ? _handleSubmit
  44. : null,
  45. style: ElevatedButton.styleFrom(
  46. backgroundColor:
  47. _electronicId != null &&
  48. _cullReason != null &&
  49. _disposalMethod != null
  50. ? Colors.blue
  51. : Colors.grey,
  52. foregroundColor: Colors.white,
  53. ),
  54. child: const Text('提交'),
  55. ),
  56. ),
  57. ],
  58. ),
  59. ),
  60. );
  61. }
  62. Widget _buildElectronicIdSection() {
  63. return VberElectronicIdsField(
  64. electronicId: _electronicId,
  65. onIdScanned: (id) {
  66. if (id == _electronicId) {
  67. ScaffoldMessenger.of(context).showSnackBar(
  68. const SnackBar(
  69. content: Text('电子编号未改变'),
  70. backgroundColor: Colors.orange,
  71. ),
  72. );
  73. } else {
  74. setState(() {
  75. _electronicId = id;
  76. });
  77. // ToastUtil.success('电子编号识别成功');
  78. ScaffoldMessenger.of(context).showSnackBar(
  79. const SnackBar(
  80. content: Text('成功识别新的电子编号'),
  81. backgroundColor: Colors.green,
  82. ),
  83. );
  84. }
  85. },
  86. label: '电子编号',
  87. placeholder: '未识别',
  88. );
  89. }
  90. Widget _buildCullReasonSection() {
  91. return Column(
  92. crossAxisAlignment: CrossAxisAlignment.start,
  93. children: [
  94. const Text('淘汰原因', style: TextStyle(fontWeight: FontWeight.bold)),
  95. const SizedBox(height: 10),
  96. Container(
  97. padding: const EdgeInsets.fromLTRB(16, 2, 16, 2),
  98. decoration: BoxDecoration(
  99. border: Border.all(color: Colors.grey),
  100. borderRadius: BorderRadius.circular(8),
  101. ),
  102. child: VberDictSelect(
  103. dictType: 'chicken_cull_reason',
  104. value: _cullReason,
  105. onChanged: (value) {
  106. setState(() {
  107. _cullReason = value;
  108. });
  109. },
  110. hint: '请选择淘汰原因',
  111. hideUnderline: true,
  112. ),
  113. ),
  114. ],
  115. );
  116. }
  117. Widget _buildDisposalMethodSection() {
  118. return Column(
  119. crossAxisAlignment: CrossAxisAlignment.start,
  120. children: [
  121. const Text('处置方式', style: TextStyle(fontWeight: FontWeight.bold)),
  122. const SizedBox(height: 10),
  123. Container(
  124. padding: const EdgeInsets.fromLTRB(16, 2, 16, 2),
  125. decoration: BoxDecoration(
  126. border: Border.all(color: Colors.grey),
  127. borderRadius: BorderRadius.circular(8),
  128. ),
  129. child: VberDictSelect(
  130. dictType: 'chicken_disposal_method',
  131. value: _disposalMethod,
  132. onChanged: (value) {
  133. setState(() {
  134. _disposalMethod = value;
  135. });
  136. },
  137. hint: '请选择处置方式',
  138. hideUnderline: true,
  139. ),
  140. ),
  141. ],
  142. );
  143. }
  144. // 提交数据
  145. void _handleSubmit() {
  146. final data = {
  147. "electronicId": _electronicId,
  148. "cullReason": _cullReason,
  149. "disposalMethod": _disposalMethod,
  150. 'date': DateTimeUtil.format(DateTime.now()),
  151. };
  152. apis.breeding.submitApi.cull(data).then((res) {
  153. if (res.success) {
  154. ToastUtil.success(res.message.isNotEmpty ? res.message : '淘汰提交成功');
  155. if (mounted) {
  156. // 提交后重置表单
  157. setState(() {
  158. _electronicId = null;
  159. // _cullReason = null;
  160. // _disposalMethod = null;
  161. });
  162. }
  163. } else {
  164. ToastUtil.errorAlert(res.message.isNotEmpty ? res.message : '淘汰提交失败');
  165. }
  166. });
  167. }
  168. }