import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:get/get.dart';
|
|
import '../../../common/bottom_bar.dart';
|
import '../../../common/detl_edit_page.dart';
|
import '../../../widgets/buttons/custom_elevated_button.dart';
|
import '../common/order_edit_card.dart';
|
import '../common/order_page_config.dart';
|
|
class MatDetlsEditPage extends StatefulWidget {
|
final List<Map<String, dynamic>>? data;
|
|
const MatDetlsEditPage({super.key, this.data});
|
|
@override
|
State<MatDetlsEditPage> createState() => _MatDetlsEditPageState();
|
}
|
|
class _MatDetlsEditPageState extends State<MatDetlsEditPage> {
|
var items = []; // 订单列表数据
|
/// 重置按钮
|
///
|
|
@override
|
void initState() {
|
super.initState();
|
items = widget.data!;
|
}
|
|
void _reset() {
|
setState(() {});
|
}
|
|
void _addItem() {
|
Get.toNamed('/order_list_page')?.then((result) => {
|
setState(() {
|
result.forEach((item) {
|
addItem(item);
|
});
|
})
|
});
|
}
|
|
void addItem(item) {
|
var fieldsToMatch = ['matnr', 'orderNo'];
|
for (var existingItem in items) {
|
bool isMatch =
|
fieldsToMatch.every((field) => existingItem[field] == item[field]);
|
|
if (isMatch) {
|
var val = existingItem['count'];
|
var newVal = item['count'];
|
if ((val is int && newVal is int) ||
|
(val is double && newVal is double)) {
|
existingItem['count'] = val + newVal;
|
}
|
return;
|
}
|
}
|
items.add(item);
|
}
|
|
void _editItem(item, index) async {
|
var result = await Get.to(() => DetlEditPage(
|
data: item,
|
config: orderPageConfig,
|
maxCount: item['anfme'] - item['qty']));
|
print(result);
|
if (result != null) {
|
setState(() {
|
items[index] = result;
|
});
|
}
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
appBar: AppBar(title: const Text('物料明细编辑')),
|
body: Center(
|
child: ListView.builder(
|
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: OrderEditCard(
|
orderNo: item['orderNo'],
|
matnr: item['matnr'],
|
maktx: item['maktx'],
|
count: item['count'],
|
edit: () => _editItem(item, index),
|
),
|
);
|
},
|
),
|
),
|
bottomNavigationBar: BottomBar(
|
children: [
|
CEBtn(
|
title: '重置',
|
type: Type.cancel,
|
btnSize: BtnSize.large,
|
onPressed: _reset),
|
CEBtn(
|
title: '添加',
|
type: Type.primary,
|
btnSize: BtnSize.large,
|
onPressed: _addItem),
|
CEBtn(
|
title: '完成',
|
type: Type.second,
|
btnSize: BtnSize.large,
|
onPressed: () {
|
Get.back(result: items);
|
}),
|
],
|
),
|
);
|
}
|
}
|