| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- import 'package:chicken_farm/apis/index.dart';
- import 'package:flutter/material.dart';
- import 'package:chicken_farm/components/vb_app_bar.dart';
- import 'package:chicken_farm/components/vb_dict_select.dart';
- import 'package:chicken_farm/core/utils/toast.dart';
- import 'package:chicken_farm/components/vb_rfid_field.dart';
- class IndividualCullingPage extends StatefulWidget {
- const IndividualCullingPage({super.key});
- @override
- State<IndividualCullingPage> createState() => _IndividualCullingPageState();
- }
- class _IndividualCullingPageState extends State<IndividualCullingPage> {
- String? _rfid;
- String? _cullReason;
- String? _disposalMethod;
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: const VberAppBar(title: '个体淘汰', showLeftButton: true),
- body: Padding(
- padding: const EdgeInsets.all(16.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- // 电子编号区域
- _buildRfidSection(),
- const SizedBox(height: 20),
- // 淘汰原因
- _buildCullReasonSection(),
- const SizedBox(height: 20),
- // 处置方式
- _buildDisposalMethodSection(),
- const SizedBox(height: 30),
- // 提交按钮
- SizedBox(
- width: double.infinity,
- child: ElevatedButton(
- onPressed:
- _rfid != null &&
- _cullReason != null &&
- _disposalMethod != null
- ? _handleSubmit
- : null,
- style: ElevatedButton.styleFrom(
- backgroundColor:
- _rfid != null &&
- _cullReason != null &&
- _disposalMethod != null
- ? Colors.blue
- : Colors.grey,
- foregroundColor: Colors.white,
- ),
- child: const Text('提交'),
- ),
- ),
- ],
- ),
- ),
- );
- }
- Widget _buildRfidSection() {
- return VberRfidField(
- rfid: _rfid,
- onRfidScanned: (rfid) {
- setState(() {
- _rfid = rfid;
- });
- ToastUtil.success('电子编号识别成功');
- },
- label: '电子编号',
- placeholder: '未识别',
- );
- }
- Widget _buildCullReasonSection() {
- 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: VberDictSelect(
- dictType: 'chicken_cull_reason',
- value: _cullReason,
- onChanged: (value) {
- setState(() {
- _cullReason = value;
- });
- },
- hint: '请选择淘汰原因',
- hideUnderline: true,
- ),
- ),
- ],
- );
- }
- Widget _buildDisposalMethodSection() {
- 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: VberDictSelect(
- dictType: 'chicken_disposal_method',
- value: _disposalMethod,
- onChanged: (value) {
- setState(() {
- _disposalMethod = value;
- });
- },
- hint: '请选择处置方式',
- hideUnderline: true,
- ),
- ),
- ],
- );
- }
- // 提交数据
- void _handleSubmit() {
- final data = {
- "rfid": _rfid,
- "cull_reason": _cullReason,
- "disposal_method": _disposalMethod,
- };
- apis.breeding.submitApi
- .cull(data)
- .then((_) {
- if (mounted) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(
- content: Text('淘汰提交成功'),
- backgroundColor: Colors.green,
- ),
- );
- // 提交后重置表单
- setState(() {
- _rfid = null;
- _cullReason = null;
- _disposalMethod = null;
- });
- }
- })
- .catchError((err) {
- ToastUtil.error('淘汰提交失败');
- if (mounted && err != null) {
- String errorMessage = err.toString();
- if (err is Exception) {
- errorMessage = err.toString();
- }
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(errorMessage),
- backgroundColor: Colors.red,
- ),
- );
- }
- });
- }
- }
|