individual_culling_page.dart 5.7 KB

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