292 lines
12 KiB
Dart
292 lines
12 KiB
Dart
import 'dart:convert';
|
||
|
||
import 'package:bruno/bruno.dart';
|
||
import 'package:flutter/material.dart';
|
||
import '/common/colorCom.dart';
|
||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||
import 'package:wms_app/utils/DialogUtils.dart';
|
||
import 'package:wms_app/apiclient/WmsApiClient.dart';
|
||
|
||
class StockInWheelEBS extends StatefulWidget {
|
||
const StockInWheelEBS({super.key});
|
||
@override
|
||
State<StockInWheelEBS> createState() => _StockInWheelEBSPageState();
|
||
}
|
||
|
||
/// EBS码盘入库
|
||
class _StockInWheelEBSPageState extends State<StockInWheelEBS> {
|
||
|
||
final _vehicleTextController = TextEditingController(); // 载具号输入框
|
||
List<dynamic> tableData = []; // 表格数据类型
|
||
int tableIndex = 0; // 序号
|
||
int selectCount = 0; // 已选择的数量
|
||
String inArea = "立体库"; // 入库位置
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
}
|
||
|
||
@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)),
|
||
actions: [
|
||
IconButton(onPressed: () {
|
||
getTableData(); // 刷新表格按钮
|
||
}, icon: const Icon(Icons.refresh))
|
||
],
|
||
centerTitle: true,
|
||
backgroundColor: ColorCommon.colorScheme,
|
||
title: const Text(
|
||
"EBS成品入库",
|
||
style: TextStyle(
|
||
color: Colors.white
|
||
),
|
||
),
|
||
),
|
||
body: Center(
|
||
child: Padding(padding: const EdgeInsets.only(
|
||
top: 10,
|
||
left: 10,
|
||
right: 10,
|
||
), child: ListView(
|
||
children: [
|
||
BrnTextInputFormItem(
|
||
controller: _vehicleTextController,
|
||
title: "载具号:", hint: "请扫描或输入"
|
||
),
|
||
BrnRadioInputFormItem(
|
||
title: "选择目的地:",
|
||
options: [inArea, "装箱线"],
|
||
value: inArea,
|
||
onChanged: (oldValue, newValue) {
|
||
inArea = newValue ?? "立体库";
|
||
},
|
||
),
|
||
Padding(padding: const EdgeInsets.only(
|
||
top: 5
|
||
), child: ElevatedButton(
|
||
onPressed: wheelComplete,
|
||
style: ButtonStyle(
|
||
backgroundColor: WidgetStateProperty.all(ColorCommon.colorScheme),
|
||
),
|
||
child: const Text(
|
||
"码盘完成",
|
||
style: TextStyle(
|
||
color: Colors.white
|
||
))
|
||
)),
|
||
Padding(padding: const EdgeInsets.only(
|
||
top: 10,
|
||
bottom: 10
|
||
), child: Text("已经载入的入库单(已选择:$selectCount):"),
|
||
),
|
||
Container(
|
||
decoration: BoxDecoration(
|
||
border: Border.all(color: const Color(0x4D0C0C05), width: 0.3),// border
|
||
borderRadius: BorderRadius.circular((5)), // 圆角
|
||
),
|
||
child: TDTable(
|
||
bordered: true,
|
||
width: MediaQuery.of(context).size.width,
|
||
backgroundColor: Colors.transparent,
|
||
columns: [
|
||
TDTableCol(title: '*', colKey: 'action', width: 45, align: TDTableColAlign.center),
|
||
TDTableCol(title: '序号', colKey: 'id', align: TDTableColAlign.center, width: 80),
|
||
TDTableCol(title: '物料ID', colKey: 'itemId', align: TDTableColAlign.center, ellipsis: true, width: 80),
|
||
TDTableCol(title: '物料编码', colKey: 'itemCode', align: TDTableColAlign.center, ellipsis: true, width: 80),
|
||
TDTableCol(title: '数量', colKey: 'quantity', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
||
TDTableCol(title: '已接收数量', colKey: 'quantityReceives', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
||
TDTableCol(title: '物料描述', colKey: 'itemDesc', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
||
TDTableCol(title: '订单头主键', colKey: 'poHeaderId', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
||
TDTableCol(title: '订单行主键', colKey: 'poLineId', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
||
TDTableCol(title: '发运行主键', colKey: 'lineLocationId', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
||
TDTableCol(title: '收货组织代码', colKey: 'shipToOrganization', align: TDTableColAlign.center, ellipsis: true, width: 110),
|
||
TDTableCol(title: '采购单位', colKey: 'purUomCode', align: TDTableColAlign.center, ellipsis: true, width: 80),
|
||
TDTableCol(title: '库存单位', colKey: 'invUomCode', align: TDTableColAlign.center, ellipsis: true, width: 110),
|
||
TDTableCol(title: '发运行号', colKey: 'shipmentNum', align: TDTableColAlign.center, ellipsis: true, width: 80),
|
||
TDTableCol(title: '分配ID', colKey: 'poDistributionId', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
||
],
|
||
data: tableData,
|
||
onCellTap: (index, dynamic, cell) {
|
||
if(cell.colKey == "action") {
|
||
setState(() {
|
||
final action = dynamic["action"];
|
||
dynamic["action"] = action == "✓" ? "" : "✓";
|
||
selectCount = tableData.where((w) => w["action"] == "✓").length;
|
||
});
|
||
} else {
|
||
showDetails(index, dynamic);
|
||
}
|
||
}),
|
||
)
|
||
],
|
||
)),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 获取入库单数据
|
||
void getTableData() {
|
||
BrnLoadingDialog.show(context, content: "正在拉取数据", barrierDismissible: false);
|
||
setState(() {
|
||
tableData = [];
|
||
tableIndex = 0;
|
||
});
|
||
WmsApiClient.getCuxData().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) {
|
||
// 服务器返回成功
|
||
final cuxData = data["data"] as List<dynamic>;
|
||
setState(() {
|
||
for (var item in cuxData) {
|
||
tableIndex ++;
|
||
tableData.add({
|
||
'id': (tableIndex).toString(),
|
||
'itemId': item["itemId"].toString(),
|
||
'itemCode': item["itemCode"],
|
||
'quantity': item["quantity"].toString(),
|
||
'quantityReceives': item["quantityReceives"].toString(),
|
||
'itemDesc': item["itemDesc"],
|
||
'poHeaderId': item["poHeaderId"].toString(),
|
||
'poLineId': item["poLineId"].toString(),
|
||
'lineLocationId': item["lineLocationId"].toString(),
|
||
'shipToOrganization': item["shipToOrganization"],
|
||
'purUomCode': item["purUomCode"],
|
||
'invUomCode': item["invUomCode"],
|
||
'shipmentNum': item["shipmentNum"].toString(),
|
||
'poDistributionId': item["poDistributionId"].toString(),
|
||
});
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
// 服务器返回失败
|
||
var thisContext = context;
|
||
if(thisContext.mounted) {
|
||
DialogUtils.showWarningMessage(thisContext, "警告", "服务器返回失败:${data["message"]}", btnLabel: "我知道了");
|
||
}
|
||
return;
|
||
}).catchError((err){
|
||
var thisContext = context;
|
||
if(thisContext.mounted) {
|
||
DialogUtils.showErrorMessage(thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}", btnLabel: "我知道了");
|
||
}
|
||
return;
|
||
}).whenComplete((){
|
||
var thisContext = context;
|
||
if(thisContext.mounted) {
|
||
BrnLoadingDialog.dismiss(thisContext);
|
||
}
|
||
});
|
||
}
|
||
|
||
/// 显示详细信息
|
||
void showDetails(index, dynamic) {
|
||
String goodsDetails = "";
|
||
goodsDetails += "序号:${dynamic["id"]??""}\r\n";
|
||
goodsDetails += "物料ID:${dynamic["itemId"]??""}\r\n";
|
||
goodsDetails += "物料编码:${dynamic["itemCode"]??""}\r\n";
|
||
goodsDetails += "数量:${dynamic["quantity"]??""}\r\n";
|
||
goodsDetails += "已接收数量:${dynamic["quantityReceives"]??""}\r\n";
|
||
goodsDetails += "物料描述:${dynamic["itemDesc"]??""}\r\n";
|
||
goodsDetails += "订单头主键:${dynamic["poHeaderId"]??""}\r\n";
|
||
goodsDetails += "订单行主键:${dynamic["poLineId"]??""}\r\n";
|
||
goodsDetails += "发运行主键:${dynamic["lineLocationId"]??""}\r\n";
|
||
goodsDetails += "收货组织代码:${dynamic["shipToOrganization"]??""}\r\n";
|
||
goodsDetails += "采购单位:${dynamic["purUomCode"]??""}\r\n";
|
||
goodsDetails += "库存单位:${dynamic["invUomCode"]??""}\r\n";
|
||
goodsDetails += "发运行号:${dynamic["shipmentNum"]??""}\r\n";
|
||
goodsDetails += "分配ID:${dynamic["poDistributionId"]??""}";
|
||
DialogUtils.showMessage(context, "详情", goodsDetails, btnLabel: "我知道了");
|
||
}
|
||
|
||
/// 码盘完成
|
||
void wheelComplete() {
|
||
if(tableData.isEmpty) {
|
||
DialogUtils.showWarningMessage(context, "警告", "您当前没有待入库的入库单", btnLabel: "确定");
|
||
return;
|
||
}
|
||
String vehicleNo = _vehicleTextController.text;
|
||
if(vehicleNo == "") {
|
||
DialogUtils.showWarningMessage(context, "警告", "请先扫描载具号", btnLabel: "返回填写");
|
||
return;
|
||
}
|
||
List<dynamic> selectData = tableData.where((w) => w["action"] == "✓").toList();
|
||
if(selectCount < 1) {
|
||
DialogUtils.showWarningMessage(context, "警告", "您还没有选择入库单", btnLabel: "返回选择");
|
||
return;
|
||
}
|
||
DialogUtils.showConfirmMessage(context, "完成确认?", "当前选择了 $selectCount 条入库单,是否继续?", confirmBtn: "继续", confirm: () {
|
||
int taskType = inArea == "立体库" ? 1 : 2; // 1 表示进库,2 表示进站台
|
||
List<dynamic> bindingGoods = [];
|
||
dynamic requestData = {"vehicleNo" : vehicleNo, "taskType" : taskType, "bindingGoods" : bindingGoods };
|
||
for (var item in selectData) {
|
||
bindingGoods.add({
|
||
"boxNo": item["itemId"],
|
||
"numPerBox": item["quantityReceives"],
|
||
"goodsNum": item["quantity"],
|
||
"picketNum": item["quantity"],
|
||
"otherNum": item["quantity"],
|
||
"goodsId": item["itemCode"],
|
||
"saleOrderNo": item["lineLocationId"],
|
||
"packetLevel": "",
|
||
"cycle": "",
|
||
"customSaleOrderNo": item["shipToOrganization"],
|
||
"minorWarehouseId": item["poDistributionId"],
|
||
"goodsDesc": item["itemDesc"],
|
||
"poHeaderId":item["poHeaderId"],
|
||
"poLineId":item["poLineId"],
|
||
"lineLocationId":item["lineLocationId"],
|
||
});
|
||
}
|
||
BrnLoadingDialog.show(context, content: "正在请求入库");
|
||
WmsApiClient.bindingVehicleInEbs(requestData).then((response){
|
||
final data = Map<String, dynamic>.from(jsonDecode(response["data"]));
|
||
if(data["code"] == 200) {
|
||
// 请求成功
|
||
var thisContext = context;
|
||
if(thisContext.mounted) {
|
||
DialogUtils.showSuccessMessage(thisContext, "成功", "", btnLabel: "我知道了");
|
||
getTableData(); // 刷新信息
|
||
setState(() {
|
||
_vehicleTextController.text = "";
|
||
});
|
||
}
|
||
return;
|
||
}
|
||
var thisContext = context;
|
||
if(thisContext.mounted) {
|
||
DialogUtils.showWarningMessage(thisContext, "警告", "服务器返回失败:${data["message"]}", btnLabel: "我知道了");
|
||
}
|
||
return;
|
||
}).catchError((err){
|
||
var thisContext = context;
|
||
if(thisContext.mounted) {
|
||
DialogUtils.showErrorMessage(thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()} \r\n ${jsonEncode(requestData)}", btnLabel: "我知道了");
|
||
}
|
||
return;
|
||
}).whenComplete((){
|
||
var thisContext = context;
|
||
if(thisContext.mounted) {
|
||
BrnLoadingDialog.dismiss(thisContext);
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
} |