|
|
|
package com.naji.xiaotao.cart.vm;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.databinding.ObservableArrayList;
|
|
|
|
import android.databinding.ObservableBoolean;
|
|
|
|
import android.databinding.ObservableField;
|
|
|
|
import android.databinding.ObservableInt;
|
|
|
|
import android.databinding.ObservableList;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.afollestad.materialdialogs.DialogAction;
|
|
|
|
import com.afollestad.materialdialogs.MaterialDialog;
|
|
|
|
import com.naji.xiaotao.BR;
|
|
|
|
import com.naji.xiaotao.R;
|
|
|
|
import com.naji.xiaotao.cart.entity.CartCookbook;
|
|
|
|
import com.naji.xiaotao.cart.entity.CartCookbookDetail;
|
|
|
|
import com.naji.xiaotao.cart.entity.CartEntity;
|
|
|
|
import com.naji.xiaotao.cart.entity.ClearOutter;
|
|
|
|
import com.naji.xiaotao.cart.entity.OrderEntity;
|
|
|
|
import com.naji.xiaotao.cart.entity.RemarkEntity;
|
|
|
|
import com.naji.xiaotao.cart.entity.RemarkItemEntity;
|
|
|
|
import com.naji.xiaotao.cart.service.CartApiService;
|
|
|
|
import com.naji.xiaotao.cart.ui.CartActivity;
|
|
|
|
import com.naji.xiaotao.cart.ui.ClearDialogFragment;
|
|
|
|
import com.naji.xiaotao.cart.ui.RemarkActivity;
|
|
|
|
import com.naji.xiaotao.common.dialog.RightDialog;
|
|
|
|
import com.naji.xiaotao.cookbook.bean.OuterEntity;
|
|
|
|
import com.naji.xiaotao.cookbook.ui.CookBookMainActivity;
|
|
|
|
import com.naji.xiaotao.http.RetrofitClient;
|
|
|
|
import com.naji.xiaotao.login.entity.SellerConfig;
|
|
|
|
import com.naji.xiaotao.login.service.LoginApiService;
|
|
|
|
import com.naji.xiaotao.order.ui.OrderActivity;
|
|
|
|
import com.naji.xiaotao.order.vm.OrderItemViewModel;
|
|
|
|
import com.naji.xiaotao.tangshi.ui.TangShiActivity;
|
|
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
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.base.BaseViewModel;
|
|
|
|
import me.goldze.mvvmhabit.base.TitleViewModel;
|
|
|
|
import me.goldze.mvvmhabit.binding.command.BindingAction;
|
|
|
|
import me.goldze.mvvmhabit.binding.command.BindingCommand;
|
|
|
|
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
|
|
|
|
import me.goldze.mvvmhabit.bus.Messenger;
|
|
|
|
import me.goldze.mvvmhabit.bus.RxBus;
|
|
|
|
import me.goldze.mvvmhabit.bus.RxSubscriptions;
|
|
|
|
import me.goldze.mvvmhabit.http.BaseResponse;
|
|
|
|
import me.goldze.mvvmhabit.http.ResponseThrowable;
|
|
|
|
import me.goldze.mvvmhabit.utils.KLog;
|
|
|
|
import me.goldze.mvvmhabit.utils.MaterialDialogUtils;
|
|
|
|
import me.goldze.mvvmhabit.utils.RxUtils;
|
|
|
|
import me.goldze.mvvmhabit.utils.SPUtils;
|
|
|
|
import me.goldze.mvvmhabit.utils.ToastUtils;
|
|
|
|
import me.tatarka.bindingcollectionadapter2.ItemBinding;
|
|
|
|
import me.tatarka.bindingcollectionadapter2.OnItemBind;
|
|
|
|
|
|
|
|
public class CartViewModel extends BaseViewModel{
|
|
|
|
|
|
|
|
public static final String TOKEN_DELETE_ITEM="token_delete_item";//删减一个菜品item
|
|
|
|
|
|
|
|
public ObservableField<String> no=new ObservableField<>();//单号
|
|
|
|
public ObservableField<String> pnum=new ObservableField<>();//当前用餐人数
|
|
|
|
public ObservableField<String> tableid=new ObservableField<>();//台号
|
|
|
|
public ObservableInt tableVisibility=new ObservableInt(View.GONE);//是否显示台号
|
|
|
|
public ObservableField<String> remark=new ObservableField<>();//备注
|
|
|
|
public ObservableField<String> title=new ObservableField<>();//list标题
|
|
|
|
|
|
|
|
private String orderid;//订单id
|
|
|
|
|
|
|
|
public OrderEntity orderEntity;
|
|
|
|
|
|
|
|
private ArrayList<CartCookbook> cLists=new ArrayList<>();
|
|
|
|
|
|
|
|
private OnRequestFocusListener onRequestFocusListener;
|
|
|
|
|
|
|
|
|
|
|
|
private Disposable mSubscription;//订阅者
|
|
|
|
|
|
|
|
public TitleViewModel titleViewModel;
|
|
|
|
|
|
|
|
private float countPrice;//订单金额
|
|
|
|
private int countTotal;//订单人数
|
|
|
|
|
|
|
|
public String isSetMealFee;//是否设置餐位费
|
|
|
|
private String meelFee;//餐位费
|
|
|
|
|
|
|
|
private float ortherMoney=0.00f;//餐位费
|
|
|
|
|
|
|
|
private String fromSource;//加菜
|
|
|
|
private boolean isFast;//是否快餐
|
|
|
|
private boolean isWaitingSure;//待确认
|
|
|
|
|
|
|
|
public CartViewModel(Context context,String orderid,OnRequestFocusListener onRequestFocusListener,String fromSource,boolean isFast,boolean isWaitingSure){
|
|
|
|
super(context);
|
|
|
|
this.orderid=orderid;
|
|
|
|
this.onRequestFocusListener=onRequestFocusListener;
|
|
|
|
this.titleViewModel=new TitleViewModel(context,"购物车");
|
|
|
|
this.fromSource=fromSource;
|
|
|
|
this.isFast=isFast;
|
|
|
|
this.isWaitingSure=isWaitingSure;
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnRequestFocusListener{
|
|
|
|
//人数输入框获取焦点
|
|
|
|
void onPnumRequestFocus();
|
|
|
|
//备注获取焦点
|
|
|
|
void onRemardRequestFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
getOrderDetail();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerRxBus() {
|
|
|
|
super.registerRxBus();
|
|
|
|
//监听总的菜品数量和价格变化
|
|
|
|
mSubscription=RxBus.getDefault().toObservable(String.class).subscribe(new Consumer<String>() {
|
|
|
|
@Override
|
|
|
|
public void accept(String s) throws Exception {
|
|
|
|
if(s.contains("¥")){
|
|
|
|
countPrice=Float.parseFloat(s.substring(s.indexOf("¥")+1));
|
|
|
|
String all= new DecimalFormat("##0.00").format(countPrice+ortherMoney);
|
|
|
|
title.set(s.substring(0,s.indexOf("¥")+1)+all);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
RxSubscriptions.add(mSubscription);
|
|
|
|
//监听删除掉一个菜品Item
|
|
|
|
Messenger.getDefault().register(context, TOKEN_DELETE_ITEM, CartItemViewModel.class, new BindingConsumer<CartItemViewModel>() {
|
|
|
|
@Override
|
|
|
|
public void call(CartItemViewModel cartItemViewModel) {
|
|
|
|
observableList.remove(cartItemViewModel);
|
|
|
|
int titleIndex=Integer.parseInt(cartItemViewModel.entity.getTag());
|
|
|
|
KLog.d("titleIndex",titleIndex);
|
|
|
|
KLog.d("size",observableList.size());
|
|
|
|
int size=observableList.get(titleIndex).entity.getSize();
|
|
|
|
observableList.get(titleIndex).title.set(cartItemViewModel.entity.getClass_name()+"("+(size-1)+")");
|
|
|
|
observableList.get(titleIndex).entity.setSize(--size);
|
|
|
|
KLog.d("titleIndex:"+titleIndex+"size:"+size);
|
|
|
|
if(size==0){//只剩标题,删除标题
|
|
|
|
observableList.remove(titleIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeRxBus() {
|
|
|
|
super.removeRxBus();
|
|
|
|
RxSubscriptions.remove(mSubscription);
|
|
|
|
Messenger.getDefault().unregister(context,TOKEN_DELETE_ITEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ObservableList<CartItemViewModel> observableList=new ObservableArrayList<>();
|
|
|
|
public OnItemBind<CartItemViewModel> onItemBind=new OnItemBind<CartItemViewModel>() {
|
|
|
|
@Override
|
|
|
|
public void onItemBind(ItemBinding itemBinding, int position, CartItemViewModel item) {
|
|
|
|
itemBinding.set(BR.viewModel,item.entity.isTitle()? R.layout.cart_item_title:R.layout.cart_item_content);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//修改就餐人数
|
|
|
|
public BindingCommand onPnumClick=new BindingCommand(new BindingAction() {
|
|
|
|
@Override
|
|
|
|
public void call() {
|
|
|
|
if(onRequestFocusListener!=null){
|
|
|
|
onRequestFocusListener.onPnumRequestFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//修改备注
|
|
|
|
public BindingCommand onRemarkClick=new BindingCommand(new BindingAction() {
|
|
|
|
@Override
|
|
|
|
public void call() {
|
|
|
|
Bundle bundle=new Bundle();
|
|
|
|
bundle.putString("orderid",orderid);
|
|
|
|
bundle.putString("remarkid",orderEntity.getRemarkid());
|
|
|
|
bundle.putString("remark",orderEntity.getRemark());
|
|
|
|
startActivity(RemarkActivity.class,bundle);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//获取订单详情
|
|
|
|
private void getOrderDetail(){
|
|
|
|
HashMap<String,String> params=new HashMap<>();
|
|
|
|
params.put("orderid",orderid);
|
|
|
|
if(isWaitingSure){
|
|
|
|
params.put("status","2");//2 待确认菜品
|
|
|
|
}else{
|
|
|
|
params.put("status","0");//0 购物车中菜品 1 已下单菜品
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RetrofitClient.getInstance().create(CartApiService.class)
|
|
|
|
.getOrderById(params)
|
|
|
|
.compose(RxUtils.schedulersTransformer())
|
|
|
|
.compose(RxUtils.exceptionTransformer())
|
|
|
|
.doOnSubscribe(new Consumer<Disposable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(Disposable disposable) throws Exception {
|
|
|
|
showDialog();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.subscribe(new Consumer<BaseResponse<List<CartEntity>>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void accept(BaseResponse<List<CartEntity>> listBaseResponse) throws Exception {
|
|
|
|
dismissDialog();
|
|
|
|
if(listBaseResponse.getRet()==200){
|
|
|
|
orderEntity=listBaseResponse.getData().get(0).getOrder().get(0);
|
|
|
|
no.set("单号:"+orderEntity.getRow_num());
|
|
|
|
pnum.set(orderEntity.getPnum());
|
|
|
|
tableid.set("台号:"+orderEntity.getTablename());
|
|
|
|
if(orderEntity.getTablename().equals("快餐")){
|
|
|
|
tableVisibility.set(View.GONE);
|
|
|
|
}else{
|
|
|
|
tableVisibility.set(View.VISIBLE);
|
|
|
|
}
|
|
|
|
StringBuilder builder=new StringBuilder();
|
|
|
|
if(orderEntity.getRemarkList()!=null&&orderEntity.getRemarkList().size()>0){
|
|
|
|
for(RemarkItemEntity itemEntity:orderEntity.getRemarkList()){
|
|
|
|
builder.append(itemEntity.getRemark()+",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!TextUtils.isEmpty(orderEntity.getRemark())){
|
|
|
|
builder.append(orderEntity.getRemark()+",");
|
|
|
|
}
|
|
|
|
if(builder.length()>0){
|
|
|
|
remark.set(builder.toString().substring(0,builder.toString().length()-1));
|
|
|
|
}else{
|
|
|
|
remark.set("");
|
|
|
|
}
|
|
|
|
countTotal=listBaseResponse.getData().get(0).getCountTotal();
|
|
|
|
countPrice=listBaseResponse.getData().get(0).getCountPirce();
|
|
|
|
cLists.clear();
|
|
|
|
cLists.addAll(listBaseResponse.getData().get(0).getCookbooklist());
|
|
|
|
getSellerConfig();
|
|
|
|
}else{
|
|
|
|
ToastUtils.showShort(listBaseResponse.getMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, new Consumer<ResponseThrowable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(ResponseThrowable throwable) throws Exception {
|
|
|
|
dismissDialog();
|
|
|
|
ToastUtils.showShort(throwable.msg);
|
|
|
|
throwable.printStackTrace();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取商家配置
|
|
|
|
private void getSellerConfig(){
|
|
|
|
Map<String,String> params=new HashMap<>();
|
|
|
|
params.put("sellerid",SPUtils.getInstance("user_info").getString("sellerid"));
|
|
|
|
params.put("type","1");//1堂食配置 2外卖配置
|
|
|
|
RetrofitClient.getInstance().create(LoginApiService.class)
|
|
|
|
.getSellerConfig(params)
|
|
|
|
.compose(RxUtils.schedulersTransformer())
|
|
|
|
.compose(RxUtils.exceptionTransformer())
|
|
|
|
.doOnSubscribe(new Consumer<Disposable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(Disposable disposable) throws Exception {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.subscribe(new Consumer<BaseResponse<List<SellerConfig>>>() {
|
|
|
|
@Override
|
|
|
|
public void accept(BaseResponse<List<SellerConfig>> listBaseResponse) throws Exception {
|
|
|
|
if(listBaseResponse.getRet()==200){
|
|
|
|
KLog.d("sssssssssssss");
|
|
|
|
isSetMealFee=listBaseResponse.getData().get(0).getIs_set_meal_fee();
|
|
|
|
meelFee=listBaseResponse.getData().get(0).getMeal_fee();
|
|
|
|
if(isSetMealFee.equals("1")){
|
|
|
|
ortherMoney=Float.parseFloat(meelFee)*Integer.parseInt(orderEntity.getPnum());
|
|
|
|
}
|
|
|
|
String all= new DecimalFormat("##0.00").format(countPrice+ortherMoney);
|
|
|
|
title.set("已点"+countTotal+"个菜,共计¥"+all);
|
|
|
|
initCookbookList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}, new Consumer<ResponseThrowable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(ResponseThrowable responseThrowable) throws Exception {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initCookbookList(){
|
|
|
|
observableList.clear();
|
|
|
|
int tag=0;
|
|
|
|
for(int i=0;i<cLists.size();i++){
|
|
|
|
CartCookbookDetail head=new CartCookbookDetail();
|
|
|
|
head.setTitle(true);
|
|
|
|
head.setClass_name(cLists.get(i).getClass_name());
|
|
|
|
head.setTitleName(cLists.get(i).getClass_name()+"("+cLists.get(i).getList().size()+")");
|
|
|
|
head.setTag(String.valueOf(i));
|
|
|
|
head.setSize(cLists.get(i).getList().size());
|
|
|
|
observableList.add(new CartItemViewModel(context,head,orderid,fromSource));
|
|
|
|
int titleIndex=tag;
|
|
|
|
for(int j=0;j<cLists.get(i).getList().size();j++){
|
|
|
|
tag++;
|
|
|
|
CartCookbookDetail content=cLists.get(i).getList().get(j);
|
|
|
|
content.setTitleName(cLists.get(i).getClass_name()+"("+cLists.get(i).getList().size()+")");
|
|
|
|
content.setTag(String.valueOf(titleIndex));
|
|
|
|
observableList.add(new CartItemViewModel(context,content,orderid,fromSource));
|
|
|
|
}
|
|
|
|
tag++;
|
|
|
|
}
|
|
|
|
if(isSetMealFee.equals("1")){
|
|
|
|
CartCookbookDetail head=new CartCookbookDetail();
|
|
|
|
head.setTitle(true);
|
|
|
|
head.setClass_name("其它");
|
|
|
|
head.setTitleName("其它");
|
|
|
|
observableList.add(new CartItemViewModel(context,head,orderid,fromSource));
|
|
|
|
CartCookbookDetail content=new CartCookbookDetail();
|
|
|
|
content.setTitleName("其它");
|
|
|
|
content.setName("餐位费");
|
|
|
|
content.setPrice(meelFee);
|
|
|
|
content.setUnit("位");
|
|
|
|
content.setCount(orderEntity.getPnum());
|
|
|
|
observableList.add(new CartItemViewModel(context,content,orderid,fromSource));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//修改人数
|
|
|
|
public BindingCommand textChangeCommand=new BindingCommand(new BindingConsumer<String>() {
|
|
|
|
@Override
|
|
|
|
public void call(String s) {
|
|
|
|
if(!TextUtils.isEmpty(s)){
|
|
|
|
int pnum=Integer.parseInt(s);
|
|
|
|
if(isSetMealFee!=null&&isSetMealFee.equals("1")){
|
|
|
|
ortherMoney=Float.parseFloat(meelFee)* pnum;
|
|
|
|
String titleText=title.get().toString();
|
|
|
|
KLog.d("titleText:"+titleText);
|
|
|
|
String all= new DecimalFormat("##0.00").format(countPrice+ortherMoney);
|
|
|
|
title.set(titleText.substring(0,titleText.indexOf("¥")+1)+all);
|
|
|
|
KLog.d(countPrice);
|
|
|
|
KLog.d(ortherMoney);
|
|
|
|
KLog.d("title:"+(titleText.substring(0,titleText.indexOf("¥")+1)));
|
|
|
|
RxBus.getDefault().post(pnum);
|
|
|
|
}
|
|
|
|
setOrderById(pnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//继续点菜
|
|
|
|
public BindingCommand onContinueClickCommand=new BindingCommand(new BindingAction() {
|
|
|
|
@Override
|
|
|
|
public void call() {
|
|
|
|
Intent intent=new Intent(context,CookBookMainActivity.class);
|
|
|
|
intent.putExtra("orderid",orderid);
|
|
|
|
intent.putExtra("isFast",isFast);
|
|
|
|
intent.putExtra("fromSource",fromSource);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//点击确认下单按钮
|
|
|
|
public BindingCommand onSureClickCommand=new BindingCommand(new BindingAction() {
|
|
|
|
@Override
|
|
|
|
public void call() {
|
|
|
|
setClearNum();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//修改订单人数备注
|
|
|
|
private void setOrderById(int pnum){
|
|
|
|
Map<String,String> params=new HashMap<>();
|
|
|
|
params.put("orderid",orderid);
|
|
|
|
params.put("pnum",pnum+"");
|
|
|
|
RetrofitClient.getInstance().create(CartApiService.class)
|
|
|
|
.setOrderById(params)
|
|
|
|
.compose(RxUtils.schedulersTransformer())
|
|
|
|
.compose(RxUtils.exceptionTransformer())
|
|
|
|
.doOnSubscribe(new Consumer<Disposable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(Disposable disposable) throws Exception {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.subscribe(new Consumer<BaseResponse<List<String>>>() {
|
|
|
|
@Override
|
|
|
|
public void accept(BaseResponse<List<String>> listBaseResponse) throws Exception {
|
|
|
|
|
|
|
|
if(listBaseResponse.getRet()==200){
|
|
|
|
|
|
|
|
}else{
|
|
|
|
ToastUtils.showShort(listBaseResponse.getMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, new Consumer<ResponseThrowable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(ResponseThrowable responseThrowable) throws Exception {
|
|
|
|
responseThrowable.printStackTrace();
|
|
|
|
ToastUtils.showShort(responseThrowable.msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//下单时检测菜品是否充足
|
|
|
|
private void setClearNum(){
|
|
|
|
if(TextUtils.isEmpty(pnum.get())){
|
|
|
|
ToastUtils.showShort("请输入用餐人数");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Map<String,String> params=new HashMap<>();
|
|
|
|
params.put("orderid",orderEntity.getId());
|
|
|
|
if(TextUtils.isEmpty(fromSource)){
|
|
|
|
params.put("type","1");//下单1、加菜2
|
|
|
|
}else{
|
|
|
|
params.put("type","2");//下单1、加菜2
|
|
|
|
}
|
|
|
|
|
|
|
|
params.put("identity","2");//1 顾客 2 服务员
|
|
|
|
RetrofitClient.getInstance().create(CartApiService.class)
|
|
|
|
.setClearNum(params)
|
|
|
|
.compose(RxUtils.schedulersTransformer())
|
|
|
|
.compose(RxUtils.exceptionTransformer())
|
|
|
|
.doOnSubscribe(new Consumer<Disposable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(Disposable disposable) throws Exception {
|
|
|
|
showDialog();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.subscribe(new Consumer<BaseResponse<List<ClearOutter>>>() {
|
|
|
|
@Override
|
|
|
|
public void accept(BaseResponse<List<ClearOutter>> listBaseResponse) throws Exception {
|
|
|
|
if(listBaseResponse.getRet()==200){
|
|
|
|
if(listBaseResponse.getData().size()==0){//没有仓储不足菜品直接下单
|
|
|
|
placeOrder();
|
|
|
|
}else{
|
|
|
|
dismissDialog();
|
|
|
|
ClearDialogFragment dialog=new ClearDialogFragment();
|
|
|
|
Bundle bundle=new Bundle();
|
|
|
|
bundle.putParcelable("clearOuter",listBaseResponse.getData().get(0));
|
|
|
|
bundle.putString("orderid",orderid);
|
|
|
|
bundle.putString("fromSource",fromSource);
|
|
|
|
bundle.putBoolean("isFast",isFast);
|
|
|
|
dialog.setArguments(bundle);
|
|
|
|
dialog.show(((CartActivity)context).getSupportFragmentManager(),"clearFragment");
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
dismissDialog();
|
|
|
|
ToastUtils.showShort(listBaseResponse.getMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, new Consumer<ResponseThrowable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(ResponseThrowable responseThrowable) throws Exception {
|
|
|
|
dismissDialog();
|
|
|
|
responseThrowable.printStackTrace();
|
|
|
|
ToastUtils.showShort(responseThrowable.msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//下单接口
|
|
|
|
private void placeOrder(){
|
|
|
|
Map<String,String> params=new HashMap<>();
|
|
|
|
params.put("sellerid",orderEntity.getSellerid());
|
|
|
|
params.put("orderid",orderEntity.getId());
|
|
|
|
if(TextUtils.isEmpty(fromSource)){
|
|
|
|
params.put("type","1");//下单1、加菜2
|
|
|
|
}else{
|
|
|
|
params.put("type","2");//下单1、加菜2
|
|
|
|
}
|
|
|
|
params.put("identity","2");//1 顾客 2 服务员
|
|
|
|
RetrofitClient.getInstance().create(CartApiService.class)
|
|
|
|
.placeOrder(params)
|
|
|
|
.compose(RxUtils.schedulersTransformer())
|
|
|
|
.compose(RxUtils.exceptionTransformer())
|
|
|
|
.doOnSubscribe(new Consumer<Disposable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(Disposable disposable) throws Exception {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.subscribe(new Consumer<BaseResponse<List<String>>>() {
|
|
|
|
@Override
|
|
|
|
public void accept(BaseResponse<List<String>> listBaseResponse) throws Exception {
|
|
|
|
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();
|
|
|
|
if(isFast){//快速点餐直接跳到订单详情
|
|
|
|
Intent intent=new Intent(context, OrderActivity.class);
|
|
|
|
intent.putExtra("orderid",orderid);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}else{
|
|
|
|
startActivity(TangShiActivity.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},1000);
|
|
|
|
dialog.show(((AppCompatActivity)context).getSupportFragmentManager(),"rightDialog");
|
|
|
|
}else{
|
|
|
|
ToastUtils.showShort(listBaseResponse.getMsg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, new Consumer<ResponseThrowable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(ResponseThrowable responseThrowable) throws Exception {
|
|
|
|
dismissDialog();
|
|
|
|
responseThrowable.printStackTrace();
|
|
|
|
ToastUtils.showShort(responseThrowable.msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|