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-25 16:00:50 +08:00
|
|
|
import 'package:logger/logger.dart';
|
|
|
|
|
|
|
|
|
|
var logger = Logger(
|
|
|
|
|
printer: PrettyPrinter(),
|
|
|
|
|
);
|
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-25 16:00:50 +08:00
|
|
|
int availableVehiclesNum = 0; // 可用空托盘的数量
|
|
|
|
|
bool isDataLoaded = false; // 用于标记数据是否已经加载过
|
|
|
|
|
String goodsId = "0"; // 商品ID
|
|
|
|
|
int selectedQuantity = 1; // 用户选择的空托盘数量
|
2025-02-22 15:56:40 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2025-02-25 16:00:50 +08:00
|
|
|
_fetchAvailableVehicles(); // 获取所有可用空托盘的数量
|
2025-02-22 15:56:40 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-25 16:00:50 +08:00
|
|
|
Future<void> _fetchAvailableVehicles() async {
|
|
|
|
|
// 只有在数据未加载过时才重新发起请求
|
|
|
|
|
if (isDataLoaded) return;
|
|
|
|
|
|
|
|
|
|
await StockOutApi.getAvailVehicleList().then((response) {
|
2025-02-22 15:56:40 +08:00
|
|
|
if (response["code"] != 200) {
|
|
|
|
|
var thisContext = context;
|
|
|
|
|
if (thisContext.mounted) {
|
|
|
|
|
DialogUtils.showWarningMessage(thisContext, "警告", "服务器请求失败",
|
|
|
|
|
btnLabel: "我知道了");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-25 16:00:50 +08:00
|
|
|
logger.e("yuqili response ${response}");
|
|
|
|
|
final data = List<dynamic>.from(jsonDecode(response["data"]));
|
|
|
|
|
logger.e("yuqili data ${data}");
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
availableVehiclesNum = data.length;
|
|
|
|
|
isDataLoaded = true; // 数据加载完毕,设置标志位
|
|
|
|
|
});
|
2025-02-22 15:56:40 +08:00
|
|
|
}).catchError((err) {
|
|
|
|
|
var thisContext = context;
|
|
|
|
|
if (thisContext.mounted) {
|
|
|
|
|
DialogUtils.showErrorMessage(
|
|
|
|
|
thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}",
|
|
|
|
|
btnLabel: "我知道了");
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-02-25 16:00:50 +08:00
|
|
|
}
|
2025-02-22 15:56:40 +08:00
|
|
|
|
2025-02-25 16:00:50 +08:00
|
|
|
void callEmptyCart(int quantity) {
|
|
|
|
|
// 业务逻辑,调用出库接口等
|
|
|
|
|
StockOutApi.addStockOut(goodsId, quantity, "空托盘出库").then((response) {
|
2025-02-22 15:56:40 +08:00
|
|
|
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) {
|
2025-02-25 16:00:50 +08:00
|
|
|
DialogUtils.showSuccessMessage(context, "成功", "空托已呼叫",
|
|
|
|
|
btnLabel: "我知道了");
|
|
|
|
|
return;
|
2025-02-22 15:56:40 +08:00
|
|
|
}
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
var thisContext = context;
|
|
|
|
|
if (thisContext.mounted) {
|
|
|
|
|
DialogUtils.showErrorMessage(
|
|
|
|
|
thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}",
|
|
|
|
|
btnLabel: "我知道了");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
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>(
|
2025-02-25 16:00:50 +08:00
|
|
|
future: _fetchAvailableVehicles(), // 使用FutureBuilder来等待获取所有车辆信息
|
2025-02-22 15:56:40 +08:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
|
|
|
return Center(child: CircularProgressIndicator()); // 显示加载中
|
|
|
|
|
} else if (snapshot.hasError) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: Text("请求失败: ${snapshot.error.toString()}"),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2025-02-25 16:00:50 +08:00
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
// 添加一个文本来提示用户选择空托数量
|
|
|
|
|
Text("呼叫空托数量: ", style: TextStyle(fontSize: 16)),
|
|
|
|
|
// 下拉框
|
|
|
|
|
DropdownButton<int>(
|
|
|
|
|
value: selectedQuantity,
|
|
|
|
|
items: List.generate(availableVehiclesNum, (index) {
|
|
|
|
|
return DropdownMenuItem<int>(
|
|
|
|
|
value: index + 1,
|
|
|
|
|
child: Text("${index + 1}"),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
selectedQuantity = value!;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
hint: Text("选择空托盘数量"),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(width: 20), // 添加一些空间
|
|
|
|
|
// 出库按钮
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () => callEmptyCart(selectedQuantity),
|
|
|
|
|
style: ButtonStyle(
|
|
|
|
|
backgroundColor: MaterialStateProperty.all(
|
|
|
|
|
ColorCommon.colorScheme),
|
2025-02-20 13:48:18 +08:00
|
|
|
),
|
2025-02-25 16:00:50 +08:00
|
|
|
child: Text("出库", style: TextStyle(color: Colors.white)),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-02-22 15:56:40 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-02-20 13:48:18 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|