XuGongTeJi_flutter/lib/page/stockIn/stack_in_ebs.dart

415 lines
16 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/stock_in.dart';
import 'package:wms_app/utils/stringUtils.dart';
import '/common/colorCom.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'package:wms_app/utils/dialogUtils.dart';
class StockInWheelEBS extends StatefulWidget {
const StockInWheelEBS({super.key});
2025-02-23 20:39:20 +08:00
2025-02-19 18:52:05 +08:00
@override
State<StockInWheelEBS> createState() => _StockInWheelEBSPageState();
}
/// EBS码盘入库
class _StockInWheelEBSPageState extends State<StockInWheelEBS> {
final _vehicleTextController = TextEditingController(); // 载具号输入框
final _goodsCodeController = TextEditingController(); // 条码输入框
List<dynamic> packageData = []; // 已经码盘的数据
int packageDataId = 0; // 已经码盘的数据的序号
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2025-02-23 20:39:20 +08:00
iconTheme: const IconThemeData(color: Colors.white),
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: const Icon(Icons.arrow_back)),
2025-02-19 18:52:05 +08:00
centerTitle: true,
backgroundColor: ColorCommon.colorScheme,
title: const Text(
"EBS码盘入库",
style: TextStyle(color: Colors.white),
),
),
body: Center(
2025-02-23 20:39:20 +08:00
child: Padding(
padding: const EdgeInsets.only(top: 5, left: 10, right: 10),
2025-02-19 18:52:05 +08:00
child: ListView(
2025-02-23 20:39:20 +08:00
children: [
BrnTextInputFormItem(
controller: _vehicleTextController,
title: "载具号:",
hint: "请扫描或输入",
isRequire: true,
2025-02-19 18:52:05 +08:00
),
2025-02-23 20:39:20 +08:00
BrnTextInputFormItem(
controller: _goodsCodeController,
title: "条码:",
hint: "请扫描物料二维码",
isRequire: true,
),
Padding(
padding: const EdgeInsets.only(top: 5),
child: ElevatedButton(
onPressed: resolveCode,
style: ButtonStyle(
backgroundColor:
WidgetStateProperty.all(ColorCommon.colorScheme),
),
child: const Text("添加物料",
style: TextStyle(color: Colors.white)))),
Padding(
padding: const EdgeInsets.only(top: 0),
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,
width: MediaQuery.of(context).size.width,
backgroundColor: Colors.transparent,
columns: [
TDTableCol(
title: '*',
colKey: 'action',
width: 45,
align: TDTableColAlign.center,
cellBuilder: (BuildContext context) {
return const SizedBox(
child: Icon(TDIcons.delete,
color: Colors.redAccent, size: 10),
);
},
),
TDTableCol(
title: '序号',
colKey: 'id',
align: TDTableColAlign.center,
width: 80),
TDTableCol(
title: '采购单号',
colKey: 'segment1',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '物料号',
colKey: 'itemId',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '批次号',
colKey: 'batch',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '数量',
colKey: 'quantity',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '重量',
colKey: 'weight',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '生产日期',
colKey: 'productData',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '送货单号',
colKey: 'sendOrderId',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '物料描述',
colKey: 'goodsName',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '单位',
colKey: 'unit',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '订单头主键',
colKey: 'poHeaderId',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '订单行主键',
colKey: 'poLineId',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
TDTableCol(
title: '发运行主键',
colKey: 'lineLocationId',
align: TDTableColAlign.center,
ellipsis: true,
ellipsisTitle: true,
width: 100),
],
data: packageData,
onCellTap: (index, dynamic, cell) {
clickLine(index, dynamic, cell);
}),
),
],
2025-02-19 18:52:05 +08:00
)),
),
);
}
/// 行数据点击事件
void clickLine(index, dynamic, cell) {
2025-02-23 20:39:20 +08:00
if (cell.colKey == "action") {
// 点击删除
2025-02-19 18:52:05 +08:00
delete(dynamic);
return;
}
2025-02-23 20:39:20 +08:00
if (cell.colKey == "quantity") {
// 点击数量
2025-02-19 18:52:05 +08:00
modifyNumber(index, dynamic);
return;
}
showDetails(index, dynamic);
}
/// 解析条码
void resolveCode() {
String code = _goodsCodeController.text;
2025-02-23 20:39:20 +08:00
if (StringUtils.isEmpty(code)) {
2025-02-19 18:52:05 +08:00
DialogUtils.showWarningMessage(context, "警告", "条码文本框内无数据,请先扫描或者输入数据");
return;
}
List<String> codeData = code.split(",");
2025-02-23 20:39:20 +08:00
if (codeData.length != 6 && codeData.length != 8) {
2025-02-19 18:52:05 +08:00
DialogUtils.showWarningMessage(context, "警告", "条码格式错误");
return;
}
// 请求获取详细数据,发送订单号和物料号
String sendOrderId = "";
2025-02-23 20:39:20 +08:00
if (codeData.length == 7) {
2025-02-19 18:52:05 +08:00
sendOrderId = codeData[6];
}
String orderId = codeData[0];
String goodsId = codeData[1];
BrnLoadingDialog.show(context, content: "正在请求服务器数据");
2025-02-23 20:39:20 +08:00
StockInApi.getGoodsCanUse(orderId, goodsId).then((response) {
if (response["code"] != 200) {
2025-02-19 18:52:05 +08:00
var thisContext = context;
2025-02-23 20:39:20 +08:00
if (thisContext.mounted) {
DialogUtils.showWarningMessage(thisContext, "警告", "服务器请求失败",
btnLabel: "我知道了");
2025-02-19 18:52:05 +08:00
}
return;
}
final data = Map<String, dynamic>.from(jsonDecode(response["data"]));
2025-02-23 20:39:20 +08:00
if (data["code"] == 200) {
2025-02-19 18:52:05 +08:00
final item = data["data"] as dynamic;
setState(() {
2025-02-23 20:39:20 +08:00
packageDataId++;
2025-02-19 18:52:05 +08:00
packageData.add({
"id": packageDataId.toString(),
"segment1": codeData[0],
"itemId": codeData[1],
"batch": codeData[2],
"quantity": codeData[3],
"weight": codeData[4],
"productData": codeData[5],
"sendOrderId": sendOrderId, // 送货单号
"goodsName": item["itemDesc"].toString(),
"unit": item["purUomCode"].toString(),
"poHeaderId": item["poHeaderId"].toString(),
"poLineId": item["poLineId"].toString(),
"lineLocationId": item["lineLocationId"].toString(),
});
_goodsCodeController.clear();
});
return;
}
var thisContext = context;
2025-02-23 20:39:20 +08:00
if (thisContext.mounted) {
DialogUtils.showWarningMessage(
thisContext, "数据异常", "服务器返回错误:${data["message"]} ",
btnLabel: "我知道了");
2025-02-19 18:52:05 +08:00
}
return;
2025-02-23 20:39:20 +08:00
}).catchError((err) {
2025-02-19 18:52:05 +08:00
var thisContext = context;
2025-02-23 20:39:20 +08:00
if (thisContext.mounted) {
DialogUtils.showErrorMessage(
thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()} ",
btnLabel: "我知道了");
2025-02-19 18:52:05 +08:00
}
return;
2025-02-23 20:39:20 +08:00
}).whenComplete(() {
2025-02-19 18:52:05 +08:00
var thisContext = context;
2025-02-23 20:39:20 +08:00
if (thisContext.mounted) {
2025-02-19 18:52:05 +08:00
BrnLoadingDialog.dismiss(thisContext);
}
});
}
/// 删除已经码盘的物料
void delete(dynamic) {
setState(() {
2025-02-23 20:39:20 +08:00
packageData.removeWhere((r) {
2025-02-19 18:52:05 +08:00
return r["id"] == dynamic["id"];
});
});
2025-02-23 20:39:20 +08:00
if (packageData.isEmpty) {
2025-02-19 18:52:05 +08:00
packageDataId = 0;
}
}
/// 修改数量
void modifyNumber(index, dynamic) {
2025-02-23 20:39:20 +08:00
DialogUtils.showInputMessage(context, "请输入要修改的数量", message: "仅支持数字",
confirm: (value) {
if (!StringUtils.isNumber(value)) {
2025-02-19 18:52:05 +08:00
DialogUtils.showWarningMessage(context, "警告", "该文本框仅支持数字");
return;
}
2025-02-23 20:39:20 +08:00
setState(() {
packageData.where((w) => w["id"] == dynamic["id"]).first["quantity"] =
value;
2025-02-19 18:52:05 +08:00
});
});
}
/// 显示详细信息
void showDetails(index, tableRow) {
List<dynamic> message = [];
2025-02-23 20:39:20 +08:00
message.add({"label": "序号:", "msg": tableRow["id"].toString()});
message.add({"label": "采购单号:", "msg": tableRow["segment1"].toString()});
message.add({"label": "物料号:", "msg": tableRow["itemId"].toString()});
message.add({"label": "批次号:", "msg": tableRow["batch"].toString()});
message.add({"label": "数量:", "msg": tableRow["quantity"].toString()});
message.add({"label": "重量:", "msg": tableRow["weight"].toString()});
message.add({"label": "生产日期:", "msg": tableRow["productData"].toString()});
message.add({"label": "送货单号:", "msg": tableRow["sendOrderId"].toString()});
message.add({"label": "物料描述:", "msg": tableRow["goodsName"].toString()});
message.add({"label": "单位:", "msg": tableRow["unit"].toString()});
message.add({"label": "订单头主键:", "msg": tableRow["poHeaderId"].toString()});
message.add({"label": "订单行主键:", "msg": tableRow["poLineId"].toString()});
message
.add({"label": "发运行主键:", "msg": tableRow["lineLocationId"].toString()});
2025-02-19 18:52:05 +08:00
DialogUtils.showMessageList(context, "数据详情", message, btnLabel: "我知道了");
}
/// 码盘完成
void wheelComplete() {
2025-02-23 20:39:20 +08:00
if (packageData.isEmpty) {
2025-02-19 18:52:05 +08:00
DialogUtils.showWarningMessage(context, "警告", "您的码盘数据为空", btnLabel: "确定");
return;
}
String vehicleNo = _vehicleTextController.text;
2025-02-23 20:39:20 +08:00
if (StringUtils.isEmpty(vehicleNo)) {
DialogUtils.showWarningMessage(context, "警告", "请先扫描载具号",
btnLabel: "返回填写");
2025-02-19 18:52:05 +08:00
return;
}
int dataCount = packageData.length;
2025-02-23 20:39:20 +08:00
DialogUtils.showConfirmMessage(
context, "码盘完成", "载具:$vehicleNo 码盘 $dataCount 条数据,是否继续?",
confirmBtn: "继续", confirm: () {
2025-02-19 18:52:05 +08:00
int taskType = 1; // 1 表示进库2 表示进站台
BrnLoadingDialog.show(context, content: "正在请求入库");
2025-02-23 20:39:20 +08:00
StockInApi.stockInComplete(packageData).then((response) {
2025-02-19 18:52:05 +08:00
if (response["code"] != 200) {
var thisContext = context;
if (thisContext.mounted) {
2025-02-23 20:39:20 +08:00
DialogUtils.showWarningMessage(thisContext, "警告", "服务器请求失败",
btnLabel: "我知道了");
2025-02-19 18:52:05 +08:00
}
return;
}
final data = Map<String, dynamic>.from(jsonDecode(response["data"]));
if (data["code"] == 200) {
// 请求成功
setState(() {
_vehicleTextController.clear();
packageData = [];
});
var thisContext = context;
if (thisContext.mounted) {
2025-02-23 20:39:20 +08:00
DialogUtils.showSuccessMessage(thisContext, "码盘成功", "",
btnLabel: "我知道了");
2025-02-19 18:52:05 +08:00
}
return;
}
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showWarningMessage(
thisContext, "警告", "服务器返回失败:${data["message"]}",
btnLabel: "我知道了");
}
return;
}).catchError((err) {
var thisContext = context;
if (thisContext.mounted) {
2025-02-23 20:39:20 +08:00
DialogUtils.showErrorMessage(
thisContext, "请求发生错误", "请求服务器发生错误:${err.toString()}",
btnLabel: "我知道了");
2025-02-19 18:52:05 +08:00
}
return;
}).whenComplete(() {
var thisContext = context;
if (thisContext.mounted) {
BrnLoadingDialog.dismiss(thisContext);
}
});
});
}
2025-02-23 20:39:20 +08:00
}