InboundMaterialViewModel.cs
5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using IndustrialControl.Services;
using System.Threading.Tasks;
namespace IndustrialControl.ViewModels
{
public partial class InboundMaterialViewModel : ObservableObject
{
private readonly IWarehouseDataService _warehouseSvc;
public ObservableCollection<string> AvailableBins { get; set; } = new ObservableCollection<string>
{
"CK1_A201",
"CK1_A202",
"CK1_A203",
"CK1_A204"
};
public InboundMaterialViewModel(IWarehouseDataService warehouseSvc)
{
_warehouseSvc = warehouseSvc;
// 初始化命令
ShowPendingCommand = new RelayCommand(() => SwitchTab(true));
ShowScannedCommand = new RelayCommand(() => SwitchTab(false));
ConfirmCommand = new AsyncRelayCommand(ConfirmInboundAsync);
// 默认显示待入库明细
IsPendingVisible = true;
IsScannedVisible = false;
// 测试数据(上线可去掉)
PendingList = new ObservableCollection<PendingItem>
{
new PendingItem { Name="物料1", Spec="XXX", PendingQty=100, Bin="CK1_A201", ScannedQty=80 },
new PendingItem { Name="物料2", Spec="YYY", PendingQty=50, Bin="CK1_A202", ScannedQty=0 }
};
ScannedList = new ObservableCollection<OutScannedItem>
{
new OutScannedItem { IsSelected=false, Barcode="FSC2025060300001", Name="物料1", Spec="XXX", Bin="CK1_A201", Qty=1 },
new OutScannedItem { IsSelected=false, Barcode="FSC2025060300002", Name="物料1", Spec="XXX", Bin="请选择", Qty=1 }
};
}
// 基础信息
[ObservableProperty] private string orderNo;
[ObservableProperty] private string linkedDeliveryNo;
[ObservableProperty] private string linkedPurchaseNo;
[ObservableProperty] private string supplier;
// Tab 显示控制
[ObservableProperty] private bool isPendingVisible;
[ObservableProperty] private bool isScannedVisible;
// Tab 按钮颜色
[ObservableProperty] private string pendingTabColor = "#E6F2FF";
[ObservableProperty] private string scannedTabColor = "White";
[ObservableProperty] private string pendingTextColor = "#007BFF";
[ObservableProperty] private string scannedTextColor = "#333333";
// 列表数据
public ObservableCollection<PendingItem> PendingList { get; set; }
public ObservableCollection<OutScannedItem> ScannedList { get; set; }
// 命令
public IRelayCommand ShowPendingCommand { get; }
public IRelayCommand ShowScannedCommand { get; }
public IAsyncRelayCommand ConfirmCommand { get; }
/// <summary>
/// 切换 Tab
/// </summary>
private void SwitchTab(bool showPending)
{
IsPendingVisible = showPending;
IsScannedVisible = !showPending;
if (showPending)
{
PendingTabColor = "#E6F2FF";
ScannedTabColor = "White";
PendingTextColor = "#007BFF";
ScannedTextColor = "#333333";
}
else
{
PendingTabColor = "White";
ScannedTabColor = "#E6F2FF";
PendingTextColor = "#333333";
ScannedTextColor = "#007BFF";
}
}
/// <summary>
/// 清空扫描记录
/// </summary>
public void ClearScan()
{
ScannedList.Clear();
}
/// <summary>
/// 清空所有数据
/// </summary>
public void ClearAll()
{
OrderNo = string.Empty;
LinkedDeliveryNo = string.Empty;
LinkedPurchaseNo = string.Empty;
Supplier = string.Empty;
PendingList.Clear();
ScannedList.Clear();
}
/// <summary>
/// 扫描通过逻辑
/// </summary>
public void PassSelectedScan()
{
foreach (var item in ScannedList)
{
if (item.IsSelected)
{
// 这里可以做业务处理,比如更新状态
}
}
}
/// <summary>
/// 取消扫描逻辑
/// </summary>
public void CancelSelectedScan()
{
for (int i = ScannedList.Count - 1; i >= 0; i--)
{
if (ScannedList[i].IsSelected)
{
ScannedList.RemoveAt(i);
}
}
}
/// <summary>
/// 确认入库逻辑
/// </summary>
public async Task<bool> ConfirmInboundAsync()
{
if (string.IsNullOrWhiteSpace(OrderNo))
return false;
var result = await _warehouseSvc.ConfirmInboundAsync(OrderNo,
ScannedList.Select(x => new ScanItem(0, x.Barcode, x.Bin, x.Qty)));
return result.Succeeded;
}
}
// 待入库明细模型
public class PendingItem
{
public string Name { get; set; }
public string Spec { get; set; }
public int PendingQty { get; set; }
public string Bin { get; set; }
public int ScannedQty { get; set; }
}
// 扫描明细模型
public class OutScannedItem
{
public bool IsSelected { get; set; }
public string Barcode { get; set; }
public string Name { get; set; }
public string Spec { get; set; }
public string Bin { get; set; }
public int Qty { get; set; }
}
}