XuGongTeJi_flutter/lib/page/stockOut/stock_out_empty.dart

199 lines
6.6 KiB
Dart
Raw Normal View History

2025-02-20 13:48:18 +08:00
import 'package:flutter/material.dart';
import '/common/colorCom.dart';
import 'package:wms_app/utils/dialogUtils.dart';
2025-02-22 15:56:40 +08:00
import 'package:wms_app/api_client/stock_out.dart';
import 'dart:convert';
2025-02-20 13:48:18 +08:00
class StockOutEmpty extends StatefulWidget {
const StockOutEmpty({super.key});
@override
State<StockOutEmpty> createState() => _CallEmptyCartPageState();
}
class _CallEmptyCartPageState extends State<StockOutEmpty> {
2025-02-22 15:56:40 +08:00
int vehicle_0 = 0, vehicle_1 = 1;
String status_0 = "不可用", status_1 = "不可用";
@override
void initState() {
super.initState();
_fetchData();
}
Future<void> _fetchData() async {
await StockOutApi.getVehicleIsEmpty(vehicle_0).then((response) {
if (response["code"] != 200) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showWarningMessage(thisContext, "警告", "服务器请求失败",
btnLabel: "我知道了");
}
return;
}
final data = Map<String, dynamic>.from(jsonDecode(response["data"]));
if (data["code"] == 200) {
// 请求成功
if (data["data"]["isEmpty"] == 1 && data["data"]["isLock"] == 0) {
status_0 = "可用";
return;
}
}
return;
}).catchError((err) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showErrorMessage(
thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}",
btnLabel: "我知道了");
}
return;
});
await StockOutApi.getVehicleIsEmpty(vehicle_1).then((response) {
if (response["code"] != 200) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showWarningMessage(thisContext, "警告", "服务器请求失败",
btnLabel: "我知道了");
}
return;
}
final data = Map<String, dynamic>.from(jsonDecode(response["data"]));
if (data["code"] == 200) {
// 请求成功
if (data["data"]["isEmpty"] == 1 && data["data"]["isLock"] == 0) {
status_1 = "可用";
return;
}
}
return;
}).catchError((err) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showErrorMessage(
thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}",
btnLabel: "我知道了");
}
return;
});
}
2025-02-20 13:48:18 +08:00
String selectedOption = "1";
String status = "可用";
bool isLoading = false;
void callEmptyCart() {
2025-02-22 15:56:40 +08:00
if ((selectedOption == "1" && status_0 == "不可用") ||
(selectedOption == "2" && status_1 == "不可用")) {
2025-02-20 13:48:18 +08:00
DialogUtils.showWarningMessage(context, "警告", "选中的空托不可用",
btnLabel: "我知道了");
} else {
2025-02-22 15:56:40 +08:00
StockOutApi.addStockOut().then((response) {
if (response["code"] != 200) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showWarningMessage(thisContext, "警告", "服务器请求失败",
btnLabel: "我知道了");
}
return;
}
final data = Map<String, dynamic>.from(jsonDecode(response["data"]));
if (data["code"] == 200) {
DialogUtils.showSuccessMessage(context, "成功", "空托已呼叫",
btnLabel: "我知道了");
return;
}
}).catchError((err) {
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showErrorMessage(
thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}",
btnLabel: "我知道了");
}
return;
});
2025-02-20 13:48:18 +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),
),
),
2025-02-22 15:56:40 +08:00
body: FutureBuilder<void>(
future: _fetchData(), // 使用FutureBuilder来等待_fetchData的完成
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator()); // 显示加载中
} else if (snapshot.hasError) {
return Center(
child: Text("请求失败: ${snapshot.error.toString()}"),
);
} else {
return Center(
child: Padding(
padding: const EdgeInsets.only(top: 5, left: 10, right: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Expanded(
child: DropdownButton<String>(
value: selectedOption,
isExpanded: true,
items: [
DropdownMenuItem(
value: "1",
child: Text("1 - $status_0"),
),
DropdownMenuItem(
value: "2",
child: Text("2 - $status_1"),
),
],
onChanged: (value) {
setState(() {
selectedOption = value!;
});
},
),
2025-02-20 13:48:18 +08:00
),
2025-02-22 15:56:40 +08:00
Padding(
padding: const EdgeInsets.only(left: 10),
child: ElevatedButton(
onPressed: isLoading ? null : callEmptyCart,
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
ColorCommon.colorScheme),
),
child: Text("出库",
style: TextStyle(color: Colors.white)),
),
2025-02-20 13:48:18 +08:00
),
],
),
2025-02-22 15:56:40 +08:00
],
2025-02-20 13:48:18 +08:00
),
2025-02-22 15:56:40 +08:00
),
);
}
},
2025-02-20 13:48:18 +08:00
),
);
}
}