wms_app_jingwangbancai/lib/page/stockIn/stock_in_normal.dart

280 lines
10 KiB
Dart
Raw Normal View History

2024-12-29 13:05:26 +08:00
import 'dart:convert';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
2025-01-07 08:03:43 +08:00
import 'package:wms_app/apiclient/stock_in.dart';
import '../../common/colorCom.dart';
import '../../utils/dialogUtils.dart';
import '../../utils/stringUtils.dart';
class StockInNormal extends StatefulWidget {
const StockInNormal({super.key});
2024-12-29 13:05:26 +08:00
@override
2025-01-07 08:03:43 +08:00
State<StockInNormal> createState() => _StockInNormalState();
2024-12-29 13:05:26 +08:00
}
2025-01-07 08:03:43 +08:00
/// 通用普通码盘界面
class _StockInNormalState extends State<StockInNormal> {
2024-12-29 13:05:26 +08:00
final _vehicleTextController = TextEditingController(); // 载具号输入框
2025-01-07 08:03:43 +08:00
final _goodsCodeController = TextEditingController(text: "5312452695,30601000080,24B7251524,1,0.481,20241128"); // 条码输入框
2024-12-29 13:05:26 +08:00
List<dynamic> packageData = []; // 已经码盘的数据
int packageDataId = 0; // 已经码盘的数据的序号
@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(
2025-01-07 08:03:43 +08:00
"单机码盘入库",
2024-12-29 13:05:26 +08:00
style: TextStyle(
color: Colors.white
),
),
),
body: Center(
2025-01-07 08:03:43 +08:00
child: Padding(padding: const EdgeInsets.only(top: 5, left: 10, right: 10),
child: ListView(
2024-12-29 13:05:26 +08:00
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(
2025-01-07 08:03:43 +08:00
onPressed: wheelComplete,
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(ColorCommon.colorScheme),
),
child: const Text(
"码盘完成",
style: TextStyle(
color: Colors.white
))
2024-12-29 13:05:26 +08:00
)),
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),
2025-01-07 08:03:43 +08:00
//TDTableCol(title: '有效日期', colKey: 'deadLineData', align: TDTableColAlign.center, ellipsis: true, ellipsisTitle: true, width: 100)
2024-12-29 13:05:26 +08:00
],
data: packageData,
onCellTap: (index, dynamic, cell) {
clickLine(index, dynamic, cell);
}),
),
],
)),
),
);
}
/// 解析条码
void resolveCode() {
String code = _goodsCodeController.text;
if(StringUtils.isEmpty(code)) {
DialogUtils.showWarningMessage(context, "警告", "条码文本框内无数据,请先扫描或者输入数据");
return;
}
List<String> codeData = code.split(",");
2025-01-07 08:03:43 +08:00
if(codeData.length != 6) {
2024-12-29 13:05:26 +08:00
DialogUtils.showWarningMessage(context, "警告", "条码格式错误");
return;
}
setState(() {
2025-01-07 08:03:43 +08:00
packageDataId ++;
packageData.add({
"id": packageDataId.toString(),
"segment1": codeData[0],
"itemId": codeData[1],
"batch": codeData[2],
"quantity": codeData[3],
"weight": codeData[4],
"productData": codeData[5]
2024-12-29 13:05:26 +08:00
});
2025-01-07 08:03:43 +08:00
_goodsCodeController.clear();
2024-12-29 13:05:26 +08:00
});
2025-01-07 08:03:43 +08:00
return;
2024-12-29 13:05:26 +08:00
}
/// 码盘完成
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: "正在请求入库");
2025-01-07 08:03:43 +08:00
StockIn.stockInComplete({
2024-12-29 13:05:26 +08:00
"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);
}
});
});
}
2025-01-07 08:03:43 +08:00
/// 行数据点击事件
void clickLine(index, dynamic, cell) {
if(cell.colKey == "action") { // 点击删除
delete(dynamic);
return;
}
if(cell.colKey == "quantity") { // 点击数量
modifyNumber(index, dynamic);
return;
}
showDetails(index, dynamic);
}
/// 删除已经码盘的物料
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()});
DialogUtils.showMessageList(context, "数据详情", message, btnLabel: "我知道了");
}
2024-12-29 13:05:26 +08:00
}