wms_app_jingwangchengpin/lib/page/stockIn/stack_in_ebs.dart
2025-01-08 15:45:00 +08:00

329 lines
13 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:convert';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:wms_app/apiclient/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});
@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(
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(
"EBS码盘入库",
style: TextStyle(color: Colors.white),
),
),
body: Center(
child: Padding(padding: const EdgeInsets.only(top: 5, left: 10, right: 10),
child: ListView(
children: [
BrnTextInputFormItem(
controller: _vehicleTextController,
title: "载具号:", hint: "请扫描或输入",
isRequire: true,
),
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);
}),
),
],
)),
),
);
}
/// 行数据点击事件
void clickLine(index, dynamic, cell) {
if(cell.colKey == "action") { // 点击删除
delete(dynamic);
return;
}
if(cell.colKey == "quantity") { // 点击数量
modifyNumber(index, dynamic);
return;
}
showDetails(index, dynamic);
}
/// 解析条码
void resolveCode() {
String code = _goodsCodeController.text;
if(StringUtils.isEmpty(code)) {
DialogUtils.showWarningMessage(context, "警告", "条码文本框内无数据,请先扫描或者输入数据");
return;
}
List<String> codeData = code.split(",");
if(codeData.length != 6 && codeData.length != 8) {
DialogUtils.showWarningMessage(context, "警告", "条码格式错误");
return;
}
// 请求获取详细数据,发送订单号和物料号
String sendOrderId = "";
if(codeData.length == 7) {
sendOrderId = codeData[6];
}
String orderId = codeData[0];
String goodsId = codeData[1];
BrnLoadingDialog.show(context, content: "正在请求服务器数据");
StockIn.getGoodsCanUse(orderId, goodsId).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 item = data["data"] as dynamic;
setState(() {
packageDataId ++;
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;
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 delete(dynamic) {
setState(() {
packageData.removeWhere((r){
return r["id"] == dynamic["id"];
});
});
if(packageData.isEmpty) {
packageDataId = 0;
}
}
/// 修改数量
void modifyNumber(index, dynamic) {
DialogUtils.showInputMessage(context, "请输入要修改的数量", message: "仅支持数字", confirm: (value) {
if(!StringUtils.isNumber(value)) {
DialogUtils.showWarningMessage(context, "警告", "该文本框仅支持数字");
return;
}
setState((){
packageData.where((w)=>w["id"] == dynamic["id"]).first["quantity"] = value;
});
});
}
/// 显示详细信息
void showDetails(index, tableRow) {
List<dynamic> message = [];
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()});
DialogUtils.showMessageList(context, "数据详情", message, btnLabel: "我知道了");
}
/// 码盘完成
void wheelComplete() {
if(packageData.isEmpty){
DialogUtils.showWarningMessage(context, "警告", "您的码盘数据为空", btnLabel: "确定");
return;
}
String vehicleNo = _vehicleTextController.text;
if(StringUtils.isEmpty(vehicleNo)) {
DialogUtils.showWarningMessage(context, "警告", "请先扫描载具号", btnLabel: "返回填写");
return;
}
int dataCount = packageData.length;
DialogUtils.showConfirmMessage(context, "码盘完成", "载具:$vehicleNo 码盘 $dataCount 条数据,是否继续?", confirmBtn: "继续", confirm: ()
{
int taskType = 1; // 1 表示进库2 表示进站台
BrnLoadingDialog.show(context, content: "正在请求入库");
StockIn.stockInComplete({
"vehicleNo": vehicleNo,
"inArea": taskType.toString(),
"storageArea" : "",
"goods": packageData
}).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) {
// 请求成功
setState(() {
_vehicleTextController.clear();
packageData = [];
});
var thisContext = context;
if (thisContext.mounted) {
DialogUtils.showSuccessMessage(
thisContext, "码盘成功", "", btnLabel: "我知道了");
}
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);
}
});
});
}
}