MessageOperationDialog.java
14.3 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
package com.naji.xiaotao.tangshi.ui;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.naji.xiaotao.R;
import com.naji.xiaotao.common.dialog.RightDialog;
import com.naji.xiaotao.cookbook.ui.CookBookMainActivity;
import com.naji.xiaotao.http.RetrofitClient;
import com.naji.xiaotao.order.ui.OrderActivity;
import com.naji.xiaotao.order.ui.OrderAffirmActivity;
import com.naji.xiaotao.order.ui.OrderRetireActivity;
import com.naji.xiaotao.receipt.entity.ReceiptEntity;
import com.naji.xiaotao.receipt.service.ReceipApiService;
import com.naji.xiaotao.receipt.ui.ReceiptActivity;
import com.naji.xiaotao.tangshi.adapter.MessageAdapter;
import com.naji.xiaotao.message.entity.Message;
import com.naji.xiaotao.tangshi.entity.PrintEntity;
import com.naji.xiaotao.tangshi.service.TangshiApiService;
import com.naji.xiaotao.util.DialogUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.http.BaseResponse;
import me.goldze.mvvmhabit.http.ResponseThrowable;
import me.goldze.mvvmhabit.utils.MaterialDialogUtils;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;
public class MessageOperationDialog extends DialogFragment implements View.OnClickListener,MessageAdapter.onOperationClickListener {
private RecyclerView mRecyclerview;
private List<Message> mDatas=new ArrayList<>();
private MessageAdapter mAdapter;
private String pid;//票据id
private Context mContext;
private String orderid;
private String tableid;
private String tablename;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext=getContext();
mDatas=getArguments().getParcelableArrayList("message");
orderid=getArguments().getString("orderid");
tableid=getArguments().getString("tableid");
tablename=getArguments().getString("tablename");
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
getDialog().setCanceledOnTouchOutside(true);
View view=inflater.inflate(R.layout.dialog_message_operation,container);
((TextView)view.findViewById(R.id.tablename)).setText(tablename);
if(mDatas.size()<=0){
view.findViewById(R.id.layout_message).setVisibility(View.GONE);
}else{
view.findViewById(R.id.layout_message).setVisibility(View.VISIBLE);
}
mRecyclerview=view.findViewById(R.id.recyclerview);
mRecyclerview.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false));
mAdapter=new MessageAdapter(mContext,mDatas,null,getArguments().getBoolean("isWaitingSure",false));
mAdapter.setOnOperationClickListener(this);
mRecyclerview.setAdapter(mAdapter);
initListener(view);
return view;
}
private void initListener(View view){
view.findViewById(R.id.close).setOnClickListener(this);
view.findViewById(R.id.zhuantai).setOnClickListener(this);
view.findViewById(R.id.tuicai).setOnClickListener(this);
view.findViewById(R.id.qingtai).setOnClickListener(this);
view.findViewById(R.id.bingtai).setOnClickListener(this);
view.findViewById(R.id.yujiedan).setOnClickListener(this);
view.findViewById(R.id.kedan).setOnClickListener(this);
view.findViewById(R.id.jiacai).setOnClickListener(this);
view.findViewById(R.id.cuicai).setOnClickListener(this);
view.findViewById(R.id.shoukuan).setOnClickListener(this);
view.findViewById(R.id.detail).setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.close://关闭
break;
case R.id.zhuantai://转台
Intent intent4=new Intent(mContext, TableListActivity.class);
intent4.putExtra("orderid",orderid);
intent4.putExtra("tableid",tableid);
startActivity(intent4);
break;
case R.id.tuicai://退菜
Intent intent=new Intent(mContext, OrderRetireActivity.class);
intent.putExtra("orderid",orderid);
startActivity(intent);
break;
case R.id.qingtai://清台
QingtaiDialog dialog=new QingtaiDialog();
Bundle bundle=new Bundle();
bundle.putString("tableid",tableid);
dialog.setArguments(bundle);
dialog.show(((AppCompatActivity)mContext).getSupportFragmentManager(),"qingtaiFragmnetDislog");
break;
case R.id.bingtai://并菜
break;
case R.id.yujiedan://预结单
getSellerTeamplageById();
break;
case R.id.kedan://开发票
getInvoiceByOrderId();
break;
case R.id.jiacai://加菜
Intent intent3=new Intent(mContext, CookBookMainActivity.class);
intent3.putExtra("orderid",orderid);
intent3.putExtra("fromSource","1");//加菜
startActivity(intent3);
break;
case R.id.cuicai://催菜
break;
case R.id.shoukuan://收款
case R.id.detail://订单详情
Intent intent2=new Intent(mContext, OrderActivity.class);
intent2.putExtra("orderid",orderid);
startActivity(intent2);
break;
}
dismiss();
}
//获取订单发票信息;
private void getInvoiceByOrderId(){
RetrofitClient.getInstance().create(ReceipApiService.class)
.getReceiptDetail(orderid)
.compose(RxUtils.schedulersTransformer())
.compose(RxUtils.exceptionTransformer())
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable disposable) throws Exception {
}
})
.subscribe(new Consumer<BaseResponse<List<ReceiptEntity>>>() {
@Override
public void accept(BaseResponse<List<ReceiptEntity>> listBaseResponse) throws Exception {
if(listBaseResponse.getRet()==200){
if(listBaseResponse.getData()!=null&&listBaseResponse.getData().size()>0){
Intent intent=new Intent(mContext,ReceiptActivity.class);
Bundle bundle=new Bundle();
bundle.putString("orderid",orderid);
intent.putExtras(bundle);
mContext.startActivity(intent);
}else{
ToastUtils.showShort("该桌顾客暂未提交发票信息");
}
}else{
ToastUtils.showShort(listBaseResponse.getMsg());
}
}
}, new Consumer<ResponseThrowable>() {
@Override
public void accept(ResponseThrowable responseThrowable) throws Exception {
responseThrowable.printStackTrace();
ToastUtils.showShort(responseThrowable.msg);
}
});
}
//获取商家票据信息
private void getSellerTeamplageById(){
Map<String,String> params=new HashMap<>();
params.put("sellerid",SPUtils.getInstance("user_info").getString("sellerid"));
RetrofitClient.getInstance().create(TangshiApiService.class)
.getSellerTeamplageById(params)
.compose(RxUtils.schedulersTransformer())
.compose(RxUtils.exceptionTransformer())
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable disposable) throws Exception {
DialogUtil.showDialog(mContext);
}
})
.subscribe(new Consumer<BaseResponse<List<List<PrintEntity>>>>() {
@Override
public void accept(BaseResponse<List<List<PrintEntity>>> listBaseResponse) throws Exception {
if(listBaseResponse.getRet()==200){
for(PrintEntity entity:listBaseResponse.getData().get(0)){
if(entity.getName().equals("预结单")){
pid=entity.getId();
printOrderOnly();
break;
}
}
if(TextUtils.isEmpty(pid)){
DialogUtil.dismissDialog();
MaterialDialogUtils.showBasicDialogNoCancel(mContext,"提示","此商家没有配置打印预结单").show();
}
}else{
DialogUtil.dismissDialog();
ToastUtils.showShort(listBaseResponse.getMsg());
}
}
}, new Consumer<ResponseThrowable>() {
@Override
public void accept(ResponseThrowable responseThrowable) throws Exception {
DialogUtil.dismissDialog();
responseThrowable.printStackTrace();
ToastUtils.showShort(responseThrowable.msg);
}
});
}
//打印预结单
private void printOrderOnly(){
Map<String,String> params=new HashMap<>();
params.put("sellerid", SPUtils.getInstance("user_info").getString("sellerid"));
params.put("orderid",orderid);
params.put("pid",pid);
RetrofitClient.getInstance().create(TangshiApiService.class)
.printOrderOnly(params)
.compose(RxUtils.schedulersTransformer())
.compose(RxUtils.exceptionTransformer())
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable disposable) throws Exception {
}
})
.subscribe(new Consumer<BaseResponse<List<List<String>>>>() {
@Override
public void accept(BaseResponse<List<List<String>>> listBaseResponse) throws Exception {
DialogUtil.dismissDialog();
if(listBaseResponse.getRet()==200){
final RightDialog dialog=new RightDialog();
Bundle bundle=new Bundle();
bundle.putString("msg","打印成功");
dialog.setArguments(bundle);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
dialog.dismiss();
}
}, 1000);
dialog.show(((AppCompatActivity)mContext).getSupportFragmentManager(),"rightDialog");
}else if(listBaseResponse.getRet()==394){
MaterialDialogUtils.showBasicDialogNoCancel(mContext,"提示","打印机未配置,票据和菜品将无法打印,\n请联系管理员处理").show();
}else{
ToastUtils.showShort(listBaseResponse.getMsg());
}
}
}, new Consumer<ResponseThrowable>() {
@Override
public void accept(ResponseThrowable responseThrowable) throws Exception {
DialogUtil.dismissDialog();
responseThrowable.printStackTrace();
ToastUtils.showShort(responseThrowable.msg);
}
});
}
@Override
public void onStart() {
super.onStart();
// 设置宽度为屏宽, 靠近屏幕底部。
Window window = getDialog().getWindow();WindowManager.LayoutParams lp = window.getAttributes();
lp.gravity = Gravity.BOTTOM; // 紧贴底部
lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 宽度持平
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
@Override
public void onOperationClick(int type, String message_id) {
switch (type){
case 1://呼叫服务
break;
case 2://加减菜,审核
Intent intent=new Intent(mContext,OrderAffirmActivity.class);
intent.putExtra("orderid",orderid);
startActivity(intent);
break;
case 3://开发票
Intent intent1=new Intent(mContext, ReceiptActivity.class);
Bundle bundle=new Bundle();
bundle.putString("orderid",orderid);
intent1.putExtras(bundle);
startActivity(intent1);
break;
}
dismiss();
}
}