TaskBarView.java
8.21 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package com.huaheng.mobilewms.view;
import android.content.Context;
import android.content.DialogInterface;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AlertDialog;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.huaheng.mobilewms.R;
import com.huaheng.mobilewms.bean.TaskDetail;
import com.huaheng.mobilewms.https.HttpInterface;
import com.huaheng.mobilewms.https.Subscribers.ProgressSubscriber;
import com.huaheng.mobilewms.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.mobilewms.util.WMSUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class TaskBarView extends ConstraintLayout {
//备货入按钮
@BindView((R.id.btBeihuo))
Button bt_beihuo;
//二次分拣按钮
@BindView(R.id.btSecond)
Button bt_second;
@BindView(R.id.btSelectAll)
Button bt_selectAll;
List<TaskShipItemView> list;
//记录用户输入的容器编号
String containerCodeInput = "";
public TaskBarView(Context context){
super(context);
LayoutInflater.from(context).inflate(R.layout.task_bar_view, this);
ButterKnife.bind(this);
}
@OnClick(R.id.btSelectAll)
public void selectAll(){
boolean all = true;
//all: 检查是否已经全选,已经完全的除外
for(TaskShipItemView v : list){
if(!v.isItemSelected() && !v.isDone()){
all = false;
}
}
//全选或全不选
for(TaskShipItemView v : list){
v.select(!all);
}
}
/**打开对话框**/
public void openDialog(String title, DialogInterface.OnClickListener listener){
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(title);
// 通过LayoutInflater来加载一个xml的布局文件作为一个View对象
View view = LayoutInflater.from(getContext()).inflate(R.layout.task_ship_dialog, null);
// 设置我们自己定义的布局文件作为弹出框的Content
builder.setView(view);
final EditText etContainerCode = (EditText)view.findViewById(R.id.containerCode);
final EditText etQty = (EditText)view.findViewById(R.id.qty);
final TextView lbQty = (TextView)view.findViewById(R.id.lbQty);
etContainerCode.setText(containerCodeInput);
if(isBatch()){
etQty.setVisibility(View.GONE);
lbQty.setVisibility(View.GONE);
}else{
String qty = WMSUtils.cleanFloatZero(getSelectTaskDetail().getFreeQty().toString());
etQty.setText(qty);
}
builder.setPositiveButton("确定", listener);
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
//响应回车事件
etContainerCode.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (null != keyEvent && KeyEvent.KEYCODE_ENTER == keyEvent.getKeyCode()) {
switch (keyEvent.getAction()) {
case KeyEvent.ACTION_UP:
etQty.requestFocus();
containerCodeInput = textView.getText().toString();
return true;
default:
return true;
}
}
return false;
}
});
}
@OnClick(R.id.btBeihuo)
public void transfer(){
if(selectNothing()){
Toast.makeText(getContext(), "请先选择!", Toast.LENGTH_LONG).show();
return;
}
openDialog("备货入", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText qty = (EditText)((AlertDialog)dialog).findViewById(R.id.qty);
EditText container = (EditText)((AlertDialog)dialog).findViewById(R.id.containerCode);
// Toast.makeText(getContext(), qty.getText().toString() + "\n" + container.getText().toString(), Toast.LENGTH_SHORT).show();
BigDecimal srcQty = getSelectTaskDetail().getQty();
BigDecimal selectQty = WMSUtils.newBigDecimal(qty.getText().toString());
BigDecimal freeQty = getSelectTaskDetail().getFreeQty();
if( freeQty.compareTo(selectQty)<0){
Toast.makeText(getContext(), "数量不能超过:" + srcQty, Toast.LENGTH_SHORT).show();
containerCodeInput = container.getText().toString();
transfer();
return;
}
transfer(getSelectTaskDetail(), container.getText().toString(),qty.getText().toString());
containerCodeInput = "";
}
});
}
@OnClick(R.id.btSecond)
public void secondSorting(){
if(selectNothing()){
Toast.makeText(getContext(), "请先选择!", Toast.LENGTH_LONG).show();
return;
}
openDialog("二次分拣", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText qty = (EditText)((AlertDialog)dialog).findViewById(R.id.qty);
EditText container = (EditText)((AlertDialog)dialog).findViewById(R.id.containerCode);
Toast.makeText(getContext(), qty.getText().toString() + "\n" + container.getText().toString(), Toast.LENGTH_LONG).show();
}
});
}
public void setList(List<TaskShipItemView> list){
this.list = list;
}
/**
* 获取被选中的任务明细列表
* @return
*/
public List<TaskDetail> getSelectTaskDetailList(){
List list = new ArrayList();
for(TaskShipItemView v : this.list){
if(v.isItemSelected()){
list.add(v.getTaskDetal());
}
}
return list;
}
/**取当前被选中的taskDetail**/
public TaskDetail getSelectTaskDetail(){
return getSelectTaskDetailList().get(0);
}
/**是不是批量**/
public boolean isBatch(){
return getSelectTaskDetailList().size() > 1;
}
/***检查是否还未选择**/
public boolean selectNothing(){
return getSelectTaskDetailList().size() == 0;
}
/**
/**备货入**/
private void transfer(TaskDetail detail, String containerCode, String qty) {
HttpInterface.getInsstance().taskTtransfer(new ProgressSubscriber<String>(getContext(), transfersListener), detail.getId(), containerCode, qty);
}
//
// /**批量备货入**/
// private void transfers(String taskHeadId) {
// HttpInterface.getInsstance().transfers(new ProgressSubscriber<String>(getContext(), transfersListener), taskHeadId);
// }
//
// /**二次分拣**/
// private void secondSorting(String taskHeadId, String container) {
// HttpInterface.getInsstance().secondSorting(new ProgressSubscriber<String>(getContext(), secondSortingListener), container);
// }
//
// /**批量二次分拣**/
// private void secondSortings(String taskHeadId) {
// HttpInterface.getInsstance().secondSortings(new ProgressSubscriber<String>(getContext(), secondSortingListener), taskHeadId);
// }
SubscriberOnNextListener secondSortingListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String str) {
}
@Override
public void onError(String str) {
}
};
SubscriberOnNextListener transfersListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String str) {
}
@Override
public void onError(String str) {
}
};
}