#
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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/common/main_card.dart';
import 'package:zy_wms_pda/common/pagination.dart';
 
import '../../../common/pagination.dart';
import '../../../widgets/buttons/custom_elevated_button.dart';
import '../common/order_pick_card.dart';
import '../common/select_box.dart';
 
class OrderListPage extends StatefulWidget {
  const OrderListPage({super.key});
 
  @override
  State<OrderListPage> createState() => _OrderListPageState();
}
 
class _OrderListPageState extends State<OrderListPage> {
  ScrollController _scrollController = ScrollController();
  // TextEditingController _pageController = TextEditingController();
 
  String? _selectedValue; // 存储选中的值
  String? _selectedOrderNo = null; // 存储选中的订单编号
  final List<String> _options = ['选项1', '选项2', '选项3'];
  int _currentPage = 2; // 当前页码
  int _totalPages = 5; // 假设总页数为 5// 下拉框选项
  int _total = 0;
  var items = []; // 订单列表数据
  List<String> _selectedOrderIds = []; // 用于存储选中的订单编号的列表
 
  @override
  void initState() {
    super.initState();
    _getOrders(1);
    _selectedOrderNo = null;
  }
 
  void _getOrders(curr, {limit = 20}) async {
    var detlsPage = await ApiService.orderDetlsPage(curr, limit: limit);
    print(detlsPage);
    setState(() {
      _currentPage = detlsPage['data']['current'];
      // _pageController.text = _currentPage.toString();
      _totalPages = detlsPage['data']['pages'];
      _total = detlsPage['data']['total'];
      items = detlsPage['data']['records'];
      items.forEach((item) {
        item['count'] = item['anfme'] - item['qty'];
        item['isSelected'] = false;
      });
      _scrollController.jumpTo(0);
    });
  }
  void _updateSelect(int id,bool value) {
    setState(() {
      items.forEach((item) {
        if (item['id'] == id) {
          item['isSelected'] = value;
          print(item['isSelected']);
        }
      });
    });
  }
 
  void _selectAll(bool value) {
    setState(() {
      items.forEach((item) {
        if (value) {
          item['isSelected'] = true;
        } else {
          item['isSelected'] = false;
        }
      });
    });
  }
 
  void _pick() {
    var pickList = [];
    items.forEach((item) {
      if (item['count'] != 0 && item['isSelected']) {
        pickList.add(item);
      }
    });
    Get.back(result: pickList);
  }
  @override
  Widget build(BuildContext context) {
 
    return Scaffold(
      appBar: AppBar(title: const Text('Order List')),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          children: [
            SearchBarx(),
            SizedBox(height: 2), // 添加一些间隔,以增强层次感
            PageList(_selectedOrderIds, items, _scrollController,_updateSelect),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
              decoration: BoxDecoration(
                color: Colors.white,
                boxShadow: [
                  BoxShadow(
                    color: Colors.grey.withOpacity(0.5),
                    spreadRadius: 2,
                    blurRadius: 5,
                    offset: Offset(0, 3), // changes position of shadow 3
                  ),
                ],
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Checkbox(
                    value: _selectedOrderNo == '456', // 检查当前订单是否被选中
                    onChanged: (bool? value) {
                      setState(() {
                        if (_selectedOrderNo == '456') {
                          _selectAll(false);
                          _selectedOrderNo = null; // 取消选中状态
                        } else {
                          _selectAll(true);
                          _selectedOrderNo = '456'; // 否则选中当前订单
                        }
                      });
                    },
                  ),
                  Text('当前页全选'),
                  const Spacer(),
                  CEBtn(
                      title: '提取',
                      type: Type.primary,
                      btnSize: BtnSize.large,
                      onPressed: _pick)
                ],
              ),
            ),
            Pagination(
              onValueChanged: (value) {
                print(value);
                setState(() {
                  _currentPage = value;
                });
                _getOrders(value);
              },
              total: _total,
              currentPage: _currentPage,
              totalPages: _totalPages,
            ),
          ],
        ),
      ),
    );
  }
}
 
Widget SearchBarx() {
  return Container(
    padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
    decoration: BoxDecoration(
      color: Colors.white,
      boxShadow: [
        BoxShadow(
          color: Colors.grey.withOpacity(0.5),
          spreadRadius: 2,
          blurRadius: 5,
          offset: const Offset(3, 0),
        ),
      ],
    ),
    child: Row(
      children: [
        SelectBox(),
        SizedBox(width: 4),
        Expanded(
          child: Container(
            padding: const EdgeInsets.symmetric(horizontal: 4),
            decoration: BoxDecoration(
              color: Colors.grey[200],
              borderRadius: BorderRadius.circular(15),
            ),
            child: TextField(
              decoration: InputDecoration(
                hintText: 'Search',
                border: InputBorder.none,
              ),
            ),
          ),
        ),
        IconButton(
          icon: const Icon(Icons.subject_outlined),
          onPressed: () {},
        ),
      ],
    ),
  );
}
 
Widget PageList(selectedOrderNos,items, _scrollController,_updateSelect) {
  return Expanded(
    child: ListView.builder(
      controller: _scrollController,
      itemCount: items.length,
      itemBuilder: (context, index) {
        // 定义边距
        double topPadding = index == 0 ? 8 : 4; // 第一个项目没有上边距
        double bottomPadding = index == 19 ? 8 : 4; // 最后一个项目没有下边距
        var item = items[index];
        return Padding(
          padding: EdgeInsets.only(top: topPadding, bottom: bottomPadding),
          child: OrderPickCard(
            id: item['id'].toString(),
            orderNo: item['orderNo'],
            orderStatus: 'orderStatus',
            matnr: item['matnr'],
            threeCode: item['threeCode'],
            anfme: item['anfme'].toString(),
            maktx: item['maktx'],
            qty: item['qty'].toString(),
            count: item['count'].toString(),
            createdTime: item["createTime\$"],
            onValueChanged: (value) {
              item['count'] = value;
            },
            onSelected: (value) {
              _updateSelect(item['id'], value);
              print("选中了订单:$value");
            },
            isSelected: item['isSelected'],
          ), // 这里调用你的 ListItem 组件
        );
      },
    ),
  );
}