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 组件
|
);
|
},
|
),
|
);
|
}
|