321 lines
13 KiB
Dart
321 lines
13 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 StockInWheel extends StatefulWidget {
|
|||
|
|
const StockInWheel({super.key});
|
|||
|
|
@override
|
|||
|
|
State<StockInWheel> createState() => _StockInWheelPageState();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 手动码盘入库
|
|||
|
|
class _StockInWheelPageState extends State<StockInWheel> {
|
|||
|
|
|
|||
|
|
final _vehicleTextController = TextEditingController(); // 载具号输入框
|
|||
|
|
final _boxNoTextController = TextEditingController(); // 箱号输入框
|
|||
|
|
List<dynamic> tableData = []; // 表格数据类型
|
|||
|
|
int tableIndex = 0; // 序号
|
|||
|
|
|
|||
|
|
@override
|
|||
|
|
void initState() {
|
|||
|
|
super.initState();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@override
|
|||
|
|
Widget build(BuildContext context) {
|
|||
|
|
return Scaffold(
|
|||
|
|
appBar: AppBar(
|
|||
|
|
iconTheme: const IconThemeData(
|
|||
|
|
color: Colors.white
|
|||
|
|
),
|
|||
|
|
leading: IconButton(onPressed: () {
|
|||
|
|
if(tableData.isNotEmpty) {
|
|||
|
|
DialogUtils.showConfirmMessage(context, "退出确认", "您还有未提交的码盘数据,如果退出本页面将全部丢失", confirmBtn: "继续退出", confirm: (){
|
|||
|
|
Navigator.of(context).pop();
|
|||
|
|
});
|
|||
|
|
} else {
|
|||
|
|
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(padding: const EdgeInsets.only(
|
|||
|
|
top: 10,
|
|||
|
|
left: 10,
|
|||
|
|
right: 10,
|
|||
|
|
), child: ListView(
|
|||
|
|
children: [
|
|||
|
|
TextField(
|
|||
|
|
decoration: const InputDecoration(
|
|||
|
|
labelText: "载具号:",
|
|||
|
|
),
|
|||
|
|
controller: _vehicleTextController,
|
|||
|
|
),
|
|||
|
|
TextField(
|
|||
|
|
decoration: const InputDecoration(
|
|||
|
|
labelText: "箱号:",
|
|||
|
|
),
|
|||
|
|
controller: _boxNoTextController,
|
|||
|
|
),
|
|||
|
|
Padding(padding: const EdgeInsets.only(
|
|||
|
|
top: 20
|
|||
|
|
), child: ElevatedButton(
|
|||
|
|
onPressed: addGoods,
|
|||
|
|
style: ButtonStyle(
|
|||
|
|
backgroundColor: WidgetStateProperty.all(ColorCommon.colorScheme),
|
|||
|
|
),
|
|||
|
|
child: const Text(
|
|||
|
|
"添加物料",
|
|||
|
|
style: TextStyle(
|
|||
|
|
color: Colors.white
|
|||
|
|
))
|
|||
|
|
)),
|
|||
|
|
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
|
|||
|
|
))
|
|||
|
|
)),
|
|||
|
|
const Padding(padding: EdgeInsets.only(
|
|||
|
|
top: 10,
|
|||
|
|
bottom: 10
|
|||
|
|
), child: Text("当前已经添加的物料:"),
|
|||
|
|
),
|
|||
|
|
Container(
|
|||
|
|
decoration: BoxDecoration(
|
|||
|
|
border: Border.all(color: const Color(0x4D0C0C05), width: 0.3),// border
|
|||
|
|
borderRadius: BorderRadius.circular((5)), // 圆角
|
|||
|
|
),
|
|||
|
|
child: TDTable(
|
|||
|
|
bordered: true,
|
|||
|
|
height: 300,
|
|||
|
|
width: MediaQuery.of(context).size.width,
|
|||
|
|
backgroundColor: Colors.transparent,
|
|||
|
|
columns: [
|
|||
|
|
TDTableCol(title: '序号', colKey: 'id', align: TDTableColAlign.center, width: 80),
|
|||
|
|
TDTableCol(title: '载具号', colKey: 'vehicleNo', align: TDTableColAlign.center, ellipsis: true, width: 80),
|
|||
|
|
TDTableCol(title: '箱号', colKey: 'boxNo', align: TDTableColAlign.center, ellipsis: true, width: 80),
|
|||
|
|
TDTableCol(title: '包装数量', colKey: 'goodsNum', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
|||
|
|
TDTableCol(title: '产品编码', colKey: 'goodsId', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
|||
|
|
TDTableCol(title: '每包数量', colKey: 'numPerBox', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
|||
|
|
TDTableCol(title: '包数量', colKey: 'picketNum', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
|||
|
|
TDTableCol(title: '零包数量', colKey: 'otherNum', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
|||
|
|
TDTableCol(title: '销售订单', colKey: 'saleOrderNo', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
|||
|
|
TDTableCol(title: '包装层级', colKey: 'packetLevel', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
|||
|
|
TDTableCol(title: '周期', colKey: 'cycle', align: TDTableColAlign.center, ellipsis: true, width: 80),
|
|||
|
|
TDTableCol(title: '客户销售订单', colKey: 'customSaleOrderNo', align: TDTableColAlign.center, ellipsis: true, width: 110),
|
|||
|
|
TDTableCol(title: '子库', colKey: 'minorWarehouseId', align: TDTableColAlign.center, ellipsis: true, width: 80),
|
|||
|
|
TDTableCol(title: '产品描述', colKey: 'goodsDesc', align: TDTableColAlign.center, ellipsis: true, width: 100),
|
|||
|
|
TDTableCol(
|
|||
|
|
title: '*',
|
|||
|
|
colKey: 'action',
|
|||
|
|
width: 45,
|
|||
|
|
align: TDTableColAlign.center,
|
|||
|
|
cellBuilder: (BuildContext context) {
|
|||
|
|
return const SizedBox(
|
|||
|
|
child: Icon(TDIcons.delete, color: Colors.redAccent, size: 10),
|
|||
|
|
);
|
|||
|
|
},
|
|||
|
|
)
|
|||
|
|
],
|
|||
|
|
data: tableData,
|
|||
|
|
onCellTap: (index, dynamic, cell) {
|
|||
|
|
if(cell.colKey == "action") {
|
|||
|
|
removeGoods(index, dynamic);
|
|||
|
|
} else {
|
|||
|
|
showDetails(index, dynamic);
|
|||
|
|
}
|
|||
|
|
}),
|
|||
|
|
)
|
|||
|
|
],
|
|||
|
|
)),
|
|||
|
|
),
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 添加物料
|
|||
|
|
void addGoods() {
|
|||
|
|
String vehicleNo = _vehicleTextController.text.trim();
|
|||
|
|
String boxNo = _boxNoTextController.text.trim();
|
|||
|
|
if(vehicleNo.isEmpty || boxNo.isEmpty){
|
|||
|
|
DialogUtils.showWarningMessage(context, "警告", "有必填项未填", btnLabel: "我知道了");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if(tableData.isNotEmpty) {
|
|||
|
|
String lastVehicleNo = tableData.first["vehicleNo"];
|
|||
|
|
if(lastVehicleNo != vehicleNo) {
|
|||
|
|
DialogUtils.showWarningMessage(context, "警告", "本次码盘的载具号和之前不一致 \r\n请先清空之前码盘的数据", btnLabel: "我知道了");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
BrnLoadingDialog.show(context, content: "正在拉取数据");
|
|||
|
|
// 请求服务器获取数据
|
|||
|
|
WmsApiClient.getGoodsDetail(boxNo).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 goodsDetails = data["data"];
|
|||
|
|
setState(() {
|
|||
|
|
tableIndex ++;
|
|||
|
|
tableData.add({
|
|||
|
|
'id': (tableIndex).toString(),
|
|||
|
|
'vehicleNo': vehicleNo,
|
|||
|
|
'boxNo': goodsDetails["boxNo"],
|
|||
|
|
'goodsNum': goodsDetails["goodsNum"].toString(),
|
|||
|
|
'goodsId': goodsDetails["goodsId"],
|
|||
|
|
'numPerBox': goodsDetails["numPerBox"].toString(),
|
|||
|
|
'picketNum': goodsDetails["picketNum"].toString(),
|
|||
|
|
'otherNum': goodsDetails["otherNum"].toString(),
|
|||
|
|
'saleOrderNo': goodsDetails["saleOrderNo"],
|
|||
|
|
'packetLevel': goodsDetails["packetLevel"],
|
|||
|
|
'cycle': goodsDetails["cycle"],
|
|||
|
|
'customSaleOrderNo': goodsDetails["customSaleOrderNo"],
|
|||
|
|
'minorWarehouseId': goodsDetails["minorWarehouseId"],
|
|||
|
|
'goodsDesc': goodsDetails["goodsDesc"]
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
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 removeGoods(index, dynamic) {
|
|||
|
|
setState(() {
|
|||
|
|
tableData.removeWhere((r){
|
|||
|
|
return r["id"] == dynamic["id"];
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
if(tableData.isEmpty){
|
|||
|
|
tableIndex = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 显示详细信息
|
|||
|
|
void showDetails(index, dynamic) {
|
|||
|
|
String goodsDetails = "";
|
|||
|
|
goodsDetails += "序号:${dynamic["id"]??""}\r\n";
|
|||
|
|
goodsDetails += "载具号:${dynamic["vehicleNo"]??""}\r\n";
|
|||
|
|
goodsDetails += "箱号:${dynamic["boxNo"]??""}\r\n";
|
|||
|
|
goodsDetails += "包装数量:${dynamic["goodsNum"]??""}\r\n";
|
|||
|
|
goodsDetails += "产品编码:${dynamic["goodsId"]??""}\r\n";
|
|||
|
|
goodsDetails += "每包数量:${dynamic["numPerBox"]??""}\r\n";
|
|||
|
|
goodsDetails += "包数量:${dynamic["picketNum"]??""}\r\n";
|
|||
|
|
goodsDetails += "零包数量:${dynamic["otherNum"]??""}\r\n";
|
|||
|
|
goodsDetails += "销售订单:${dynamic["saleOrderNo"]??""}\r\n";
|
|||
|
|
goodsDetails += "包装层级:${dynamic["packetLevel"]??""}\r\n";
|
|||
|
|
goodsDetails += "周期:${dynamic["cycle"]??""}\r\n";
|
|||
|
|
goodsDetails += "客户销售订单:${dynamic["customSaleOrderNo"]??""}\r\n";
|
|||
|
|
goodsDetails += "子库:${dynamic["minorWarehouseId"]??""}\r\n";
|
|||
|
|
goodsDetails += "产品描述:${dynamic["goodsDesc"]??""}";
|
|||
|
|
DialogUtils.showMessage(context, "详情", goodsDetails, btnLabel: "我知道了");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 码盘完成
|
|||
|
|
void wheelComplete() {
|
|||
|
|
if(tableData.isEmpty) {
|
|||
|
|
DialogUtils.showWarningMessage(context, "警告", "您还没有码盘的数据", btnLabel: "返回填写");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
DialogUtils.showSingleSelectDialog(context, "请输入入库位置", ["库内","站台"], onSubmitClick: (selectedIndex, value){
|
|||
|
|
int taskType = selectedIndex == 0 ? 1 : 2; // 1 表示进库,2 表示进站台
|
|||
|
|
List<dynamic> bindingGoods = [];
|
|||
|
|
dynamic requestData = {"vehicleNo" : tableData.first["vehicleNo"], "taskType" : taskType, "bindingGoods" : bindingGoods };
|
|||
|
|
for (var item in tableData) {
|
|||
|
|
bindingGoods.add({
|
|||
|
|
"boxNo": item["boxNo"],
|
|||
|
|
"numPerBox": item["numPerBox"],
|
|||
|
|
"goodsNum": item["goodsNum"],
|
|||
|
|
"picketNum": item["picketNum"],
|
|||
|
|
"otherNum": item["otherNum"],
|
|||
|
|
"goodsId": item["goodsId"],
|
|||
|
|
"saleOrderNo": item["saleOrderNo"],
|
|||
|
|
"packetLevel": item["packetLevel"],
|
|||
|
|
"cycle": item["cycle"],
|
|||
|
|
"customSaleOrderNo": item["customSaleOrderNo"],
|
|||
|
|
"minorWarehouseId": item["minorWarehouseId"],
|
|||
|
|
"goodsDesc": item["goodsDesc"],
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
BrnLoadingDialog.show(context, content: "正在请求");
|
|||
|
|
WmsApiClient.bindingVehicleIn(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: "我知道了");
|
|||
|
|
_vehicleTextController.text = "";
|
|||
|
|
_boxNoTextController.text = "";
|
|||
|
|
setState(() {
|
|||
|
|
tableData = [];
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|