wms_app_jingwangbancai/lib/page/pick/pick.dart

268 lines
9.4 KiB
Dart

import 'dart:convert';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'package:wms_app/utils/stringUtils.dart';
import '../../apiclient/pickApi.dart';
import '../../utils/dialogUtils.dart';
import '/common/colorCom.dart';
class Pick extends StatefulWidget {
const Pick({super.key});
@override
State<Pick> createState() => _PickPageState();
}
class _PickPageState extends State<Pick> {
final _vehicleNoTextController = TextEditingController(); // 查询输入框
List<dynamic> tableData = [];
int dataCount = 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(
"出库拣货",
style: TextStyle(
color: Colors.white
)),
),
body: Center(
child: Padding(padding: const EdgeInsets.only(
left: 10,
right: 10,
top: 5
), child: ListView(
children: [
BrnTextInputFormItem(
controller: _vehicleNoTextController,
title: "载具号:", hint: "请扫描或输入需要拣货的载具号",
isRequire: true,
),
Padding(padding: const EdgeInsets.only(
top: 5
), child: ElevatedButton(
onPressed: search,
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(ColorCommon.colorScheme),
),
child: const Text(
"查询拣货任务",
style: TextStyle(
color: Colors.white
))
)),
Padding(padding: const EdgeInsets.only(
), child: ElevatedButton(
onPressed: pickComplete,
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: 'id', align: TDTableColAlign.center, width: 60),
TDTableCol(title: '载具号', colKey: 'vehicleNo', align: TDTableColAlign.center, ellipsis: true, width: 150),
TDTableCol(title: '物料号', colKey: 'goodsId', align: TDTableColAlign.center, ellipsis: true, width: 100),
TDTableCol(title: '需要拣货数', colKey: 'needNum', align: TDTableColAlign.center, ellipsis: true, width: 100),
TDTableCol(title: '实际拣货数', colKey: 'pickNum', align: TDTableColAlign.center, ellipsis: true, width: 100),
TDTableCol(title: '物料名称', colKey: 'goodsName', align: TDTableColAlign.center, ellipsis: true, width: 100),
],
data: tableData,
onCellTap: (index, dynamic, cell) {
clickLine(index, dynamic, cell);
}),
)
],
)
)),
);
}
/// 查询拣货数
void search() {
String vehicleNo = _vehicleNoTextController.text;
if(StringUtils.isEmpty(vehicleNo)) {
DialogUtils.showWarningMessage(context, "警告", "请先扫描或者输入载具号", btnLabel: "确定");
return;
}
setState(() {
tableData = [];
});
dataCount = 0;
BrnLoadingDialog.show(context, content: "正在查询...");
PickApi.getPickTask(vehicleNo).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 returnData = data["data"] as List<dynamic>;
// 请求成功
setState(() {
for(var pickTask in returnData) {
dataCount ++;
tableData.add({
"id" : dataCount.toString(),
"vehicleNo": pickTask["vehicleNo"].toString(),
"goodsId": pickTask["goodsId"].toString(),
"needNum": pickTask["pickingNum"].toString(),
"pickNum": pickTask["pickingNum"].toString(),
"goodsName": pickTask["goodsName"].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 clickLine(index, dynamic, cell) {
if(cell.colKey == "pickNum") { // 点击数量
showPickForm(index, dynamic);
return;
}
showDetails(index, dynamic);
}
/// 点击行展示数据详情
void showDetails(index, tableRow) {
List<dynamic> message = [];
message.add({"label":"序号:", "msg":tableRow["id"].toString()});
message.add({"label":"载具号:", "msg":tableRow["vehicleNo"].toString()});
message.add({"label":"物料号:", "msg":tableRow["goodsId"].toString()});
message.add({"label":"需要拣货数:", "msg":tableRow["needNum"].toString()});
message.add({"label":"实际拣货数:", "msg":tableRow["pickNum"].toString()});
message.add({"label":"物料名称:", "msg":tableRow["goodsName"].toString()});
DialogUtils.showMessageList(context, "数据详情", message, btnLabel: "我知道了");
}
/// 展示拣货的弹窗
void showPickForm(index, dynamic) {
DialogUtils.showInputMessage(context, "请输入要拣货数量", message: "仅支持数字", confirm: (value) {
if(!StringUtils.isNumber(value)) {
DialogUtils.showWarningMessage(context, "警告", "该文本框仅支持数字");
return;
}
setState((){
tableData.where((w)=>w["id"] == dynamic["id"]).first["pickNum"] = value;
});
});
}
/// 拣货完成
void pickComplete() {
if(tableData.isEmpty) {
DialogUtils.showWarningMessage(context, "警告", "没有拣货数据", btnLabel: "确定");
return;
}
List<dynamic> data = [];
for(var pickData in tableData) {
data.add({
"vehicleNo": pickData["vehicleNo"].toString(),
"goodsId": pickData["goodsId"].toString(),
"pickingNum": pickData["pickNum"].toString()
});
}
BrnLoadingDialog.show(context, content: "请稍后...");
PickApi.pickComplete(data).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(() {
_vehicleNoTextController.clear();
tableData = [];
});
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);
}
});
}
}