XuGongTeJi_flutter/lib/page/stockIn/stock_in_empty.dart

148 lines
4.2 KiB
Dart
Raw Normal View History

2025-02-19 18:52:05 +08:00
import 'dart:convert';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:wms_app/api_client/dto/empty_Vehicle_in_request.dart';
import 'package:wms_app/api_client/stock_in.dart';
2025-02-25 16:00:50 +08:00
import 'package:wms_app/page/stockIn/stock_in_buy.dart';
import '../../model/bo/stock_in_data_xugong.dart';
2025-02-19 18:52:05 +08:00
import '/common/colorCom.dart';
import 'package:wms_app/utils/dialogUtils.dart';
class StockInEmpty extends StatefulWidget {
const StockInEmpty({super.key});
2025-02-25 16:00:50 +08:00
2025-02-19 18:52:05 +08:00
@override
State<StockInEmpty> createState() => _StockInEmptyPageState();
}
/// 空托入库界面
class _StockInEmptyPageState extends State<StockInEmpty> {
2025-02-25 16:50:15 +08:00
final _vehicleTextController = TextEditingController();
2025-02-19 18:52:05 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
iconTheme: const IconThemeData(color: Colors.white),
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: const Icon(Icons.arrow_back)),
centerTitle: true,
backgroundColor: ColorCommon.colorScheme,
title: const Text(
"空料箱入库",
style: TextStyle(color: Colors.white),
),
),
body: Center(
child: Padding(
2025-02-25 16:00:50 +08:00
padding: const EdgeInsets.only(top: 5, left: 10, right: 10),
child: ListView(
children: [
BrnTextInputFormItem(
controller: _vehicleTextController,
title: "料箱号:",
hint: "需要入库的料箱号",
isRequire: true,
),
Padding(
padding: const EdgeInsets.only(top: 5),
child: ElevatedButton(
onPressed: emptyIn,
style: ButtonStyle(
backgroundColor:
WidgetStateProperty.all(ColorCommon.colorScheme),
),
child: const Text("空载具入库",
style: TextStyle(color: Colors.white))))
],
)),
2025-02-19 18:52:05 +08:00
),
);
}
void emptyIn() {
String vehicleNo = _vehicleTextController.text.trim();
2025-02-25 16:00:50 +08:00
if (vehicleNo.isEmpty) {
2025-02-19 18:52:05 +08:00
DialogUtils.showWarningMessage(context, "请先填写容器号", "", btnLabel: "返回填写");
return;
}
2025-02-25 16:00:50 +08:00
2025-02-19 18:52:05 +08:00
BrnLoadingDialog.show(context,
content: "请稍后...", barrierDismissible: false);
2025-02-25 16:50:15 +08:00
_emptyVehicleIn(vehicleNo).then((isCreateInTaskSuccess) {
2025-02-25 16:00:50 +08:00
_dismissLoading();
if (isCreateInTaskSuccess) {
_showSuccessDialog("空托入库成功");
_clearData();
} else {
_showWarningDialog("创建入库任务失败");
2025-02-19 18:52:05 +08:00
}
2025-02-25 16:00:50 +08:00
}).catchError((err) {
_dismissLoading();
_handleError(err);
});
}
// 调用 emptyVehicleIn 接口
Future<bool> _emptyVehicleIn(String vehicleNo) async {
try {
var response = await StockInApi.emptyVehicleIn(vehicleNo);
if (response["code"] != 200) {
_showWarningDialog("服务器请求失败");
return false;
2025-02-19 18:52:05 +08:00
}
2025-02-25 16:00:50 +08:00
return true;
} catch (err) {
_handleError(err);
return false;
}
}
// 显示错误提示
void _handleError(dynamic err) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showErrorMessage(
thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}",
btnLabel: "我知道了");
}
}
// 显示成功提示
void _showSuccessDialog(String message) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showSuccessMessage(thisContext, message, "",
btnLabel: "我知道了");
}
}
// 显示警告提示
void _showWarningDialog(String message) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showWarningMessage(thisContext, "警告", message,
btnLabel: "我知道了");
}
}
// 清除数据
void _clearData() {
setState(() {
_vehicleTextController.clear();
2025-02-19 18:52:05 +08:00
});
}
2025-02-25 16:00:50 +08:00
// 隐藏加载对话框
void _dismissLoading() {
var thisContext = context;
if (thisContext.mounted) {
BrnLoadingDialog.dismiss(thisContext);
}
}
2025-02-19 18:52:05 +08:00
}