#
whycq
2025-03-03 6a90c5bde0facc8330ce4c7c7d89292717b7ac65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:zy_wms_pda/api/api_service.dart';
import 'package:zy_wms_pda/pages/inbound/mat_detls_page.dart';
 
import '../../common/bottom_bar.dart';
import '../../common/empty_count.dart';
import '../../widgets/buttons/custom_elevated_button.dart';
import 'mat_card.dart';
 
class InboundPage extends StatefulWidget {
  const InboundPage({super.key});
 
  @override
  State<InboundPage> createState() => _InboundPageState();
}
 
class _InboundPageState extends State<InboundPage> {
  /// 输入框焦点
  FocusNode barcodeFocus = FocusNode();
  TextEditingController _barCodeController = TextEditingController();
 
  late List<Map<String, dynamic>> items = [];
  int maxLen = 8;
 
  void _reset() {
    setState(() {
      items = [];
    });
  }
 
  @override
  Widget build(BuildContext context) {
 
    return Scaffold(
      appBar: AppBar(
        title: Text('组托'),
      ),
      body: Padding(
        padding: EdgeInsets.all(16),
        child: ListView(
          children: [
            Container(
              padding: EdgeInsets.all(8),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(10)),
              child: Column(
                children: [
                  TextField(
                    controller: _barCodeController,
                    focusNode: barcodeFocus,
                    onTapOutside: (e) => {barcodeFocus.unfocus()},
                    decoration: InputDecoration(labelText: '托盘码',counterText: '${_barCodeController.text.length}/$maxLen'),
                    onChanged: (text) {
                      setState(() {
                        if (text.length > maxLen) {
                          _barCodeController.clear(); // 清空文本
                        } else {
                          _barCodeController.text = text;
                        }
                      });
                    },
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.all(8),
              margin: EdgeInsets.only(left: 0, top: 8, right: 0, bottom: 8),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(10)),
              // child: Text('物料明细', style: TextStyle(fontSize: 18)),
              child: Row(
                // direction: Axis.horizontal,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('物料明细', style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold,fontFamily: 'PingFang SC')),
                  CEBtn(title: '编辑', type: Type.second, onPressed: () async {
                    var result = await Get.to(() => MatDetlsPage(data: items));
                    if (result!= null) {
                      setState(() {
                        items = result;
                      });
                    }
                  }),
                ],
              ),
            ),
            ListItems(items),
          ],
        ),
      ),
      bottomNavigationBar: BottomBar(
        children: [
          CEBtn(title: '重置', type: Type.cancel, onPressed: _reset),
          CEBtn(title: '组托', type: Type.second, onPressed: () {
            var result = ApiService.mobileComb(_barCodeController.text,items);
            print('result:$result');
          }),
        ],
      ),
    );
  }
}
 
/// 物料列表
Widget ListItems(List<Map<String, dynamic>> items) {
  return Container(
    child: Column(
      children: items.isEmpty
          ? [
        EmptyCount()
      ]
          : List.generate(items.length, (index) {
        var item = items[index];
        return MatCard(
          item: item,
          isEdit: false,
        );
      }),
    ),
  );
}