Commit 044908ec by 张建升

菜品食材綁定 代码同步

parent adb702b0
......@@ -24,7 +24,6 @@ public class DishDetailBean {
private boolean deletes;// 非必须 删除 false 未删除 true 删除
private String foodBasicUnit;// string 非必须 食材基本单位
private List<DeputyUnitBean> foodUnits;
private boolean show=true;
public DishDetailBean(PurchaseFoodBean foodBean , DishNode dishNode ) {
// this.id = foodBean.get; ///此时的 id 一定是null deletes必是f
......@@ -41,6 +40,5 @@ public class DishDetailBean {
this.foodNo = foodBean.getFoodNo();
this.type = 0;
this.foodUnits = foodBean.getFoodUnits();
this.show = true;
}
}
......@@ -97,7 +97,6 @@ public class DishesPresenter extends BasePresenter<DishesContract.Model, DishesC
public void onError(@NotNull Throwable t) {
super.onError(t);
mRootView.loadDishGroupFail();
LogUtil.e("ZJS"," onError ");
}
});
}
......@@ -121,15 +120,22 @@ public class DishesPresenter extends BasePresenter<DishesContract.Model, DishesC
@Override
public void onNext(DishDetailResultBean dishDetailBean) {//數據處理
if (dishDetailBean.isSuccess()) {
LogUtil.e("ZJS"," dishDetailBean"+dishDetailBean.toString());
dishNode.setDetailBean(dishDetailBean);
mRootView.loadDishesInfo(dishNode,dishDetailBean);
} else if (TextUtil.isNotEmptyOrNullOrUndefined(dishDetailBean.getErrMsg())) {
mRootView.showMessage(dishDetailBean.getErrMsg());
mRootView.loadDishesFail();
} else {
mRootView.loadDishesFail();
mRootView.showMessage(AppConstant.GET_INFO_ERROR);
}
}
@Override
public void onError(@NotNull Throwable t) {
super.onError(t);
mRootView.loadDishesFail();
}
});
}
......@@ -147,7 +153,6 @@ public class DishesPresenter extends BasePresenter<DishesContract.Model, DishesC
@Override
public void onNext(BaseResult bindResult) {//數據處理
if (bindResult.isSuccess()) {
LogUtil.e("ZJS"," 菜品食材綁定成功 bindResult"+bindResult.toString());
DishDetailResultBean dishDetailResultBean=new DishDetailResultBean();
dishDetailResultBean.setData(dishDetailBeans);
dishNode.setDetailBean(dishDetailResultBean);
......
package com.gingersoft.supply_chain.mvp.ui.adapter.dishes;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gingersoft.gsa.cloud.common.utils.CollectionUtils;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils;
import com.gingersoft.supply_chain.R;
import com.gingersoft.supply_chain.mvp.bean.DeputyUnitBean;
import com.gingersoft.supply_chain.mvp.bean.DishDetailBean;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -19,7 +22,8 @@ import java.util.List;
*/
public class DishDetailAdapter extends BaseQuickAdapter<DishDetailBean, BaseViewHolder> {
public DishDetailAdapter(Context context, List<DishDetailBean> foods) {
private List<DishDetailBean> dels=new ArrayList<>();
public DishDetailAdapter( List<DishDetailBean> foods) {
super(R.layout.item_dishes_foods,foods);
addChildClickViewIds(R.id.tv_dishes_unit,R.id.tv_dishes_del);
}
......@@ -29,20 +33,54 @@ public class DishDetailAdapter extends BaseQuickAdapter<DishDetailBean, BaseView
protected void convert(@NotNull BaseViewHolder viewHolder, DishDetailBean item) {
viewHolder.setText(R.id.tv_dishes_name, item.getFoodName());//食材名字
viewHolder.setText(R.id.tv_dishes_unit, item.getBasicUnitName());//配置的單位
if (item.isShow()) {
// viewHolder.itemView.setVisibility(View.VISIBLE);
// viewHolder.setTextColor(R.id.tv_dishes_name, ArmsUtils.getColor(context, R.color.color_18));
} else {
// viewHolder.itemView.setVisibility(View.GONE);
// viewHolder.setTextColor(R.id.tv_dishes_name, ArmsUtils.getColor(context, R.color.switcher_off_color));
}
final EditText count=viewHolder.getView(R.id.et_dishes_count);
count.setTag(item);
count.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
// viewHolder.setText(R.id.tv_dishes_unit, item.getUnitName());
List<DeputyUnitBean> deputyUnitBeans= item.getFoodUnits();//副單位
if (CollectionUtils.isNullOrEmpty(deputyUnitBeans)) {
// addChildClickViewIds(R.id.tv_dishes_unit); consumeQuantity
@Override
public void afterTextChanged(Editable s) {
DishDetailBean tag= (DishDetailBean) count.getTag();
if (TextUtil.isEmptyOrNullOrUndefined(s)) {
ToastUtils.show(getContext(),"數量不能為空");
count.setText(String.valueOf(tag.getConsumeQuantity()));
count.setSelection(count.getText().toString().length());
}else {
tag.setConsumeQuantity(Integer.parseInt(s.toString()));
}
}
});
count.setText(String.valueOf(item.getConsumeQuantity()));//消耗數量
}
public void addDel(DishDetailBean del){
dels.add(del);
}
public List<DishDetailBean> getDels() {
return dels;
}
public void removeDel(DishDetailBean remove){
for (int i = 0; i < dels.size(); i++) {
DishDetailBean del=dels.get(i);
if (remove.getPurchaseFoodId()==del.getPurchaseFoodId()) {
dels.remove(del);
}
}
viewHolder.setText(R.id.tv_dishes_count, String.valueOf(item.getConsumeQuantity()));//消耗數量
}
public void clearDel(){
dels.clear();
}
}
......@@ -38,8 +38,6 @@ public class DishProvider extends BaseNodeProvider {
@Override
public void onClick(@NotNull BaseViewHolder helper, @NotNull View view, BaseNode data, int position) {
DishNode entity = (DishNode) data;
LogUtil.e("zjs"," onClick entity.isExpanded()="+entity.toString());
if (entity.isExpanded()) {
getAdapter().collapse(position);
} else {
......
......@@ -95,7 +95,7 @@ public class DishesGroupProvider extends BaseNodeProvider {
DishesGroupNode groupNode= (DishesGroupNode)data;
List<DishNode> dishNodes= groupNode.getDishNodes();
LogUtil.e("zjs","父菜单点击 onClick position ="+position+" getFoodName"+groupNode.getFoodName()+" groupNode="+groupNode.isExpanded());
// LogUtil.e("zjs","父菜单点击 onClick position ="+position+" getFoodName"+groupNode.getFoodName()+" groupNode="+groupNode.isExpanded());
if (CollectionUtils.isNotNullOrEmpty(dishNodes)) {
if (groupNode.getPos()==0) {
groupNode.setPos(1);
......
......@@ -12,7 +12,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.gingersoft.gsa.cloud.common.utils.CollectionUtils;
import com.gingersoft.gsa.cloud.common.utils.log.LogUtil;
import com.gingersoft.gsa.cloud.ui.utils.AppDialog;
import com.gingersoft.supply_chain.R;
import com.gingersoft.supply_chain.R2;
import com.gingersoft.supply_chain.di.component.DaggerDishesComponent;
......@@ -31,6 +31,7 @@ import com.gingersoft.supply_chain.mvp.ui.widget.ChooseUnitPopup;
import com.jess.arms.di.component.AppComponent;
import com.lxj.xpopup.XPopup;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import java.util.ArrayList;
import java.util.List;
......@@ -51,6 +52,9 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
RecyclerView rvDishesGroup;
@BindView(R2.id.rv_dishes_food)
RecyclerView rvDishes;
@BindView(R2.id.dish_refreshLayout)
SmartRefreshLayout refresh;
private View footView;
private DishesTreeAdapter dishesTreeAdapter;
private DishDetailAdapter dishDetailAdapter;
......@@ -82,34 +86,46 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
public void initData(@Nullable Bundle savedInstanceState) {
//setToolBarNoBack(toolbar, "Dishes");
initTopBar(topbarFoodIngredients, getString(R.string.str_dishes));
refresh.setOnRefreshListener(refreshLayout -> {
if (curSelectDishNode != null) {
mPresenter.getDishesDetailData(curSelectDishNode);
}
});
refresh.setEnableLoadMore(false);
mPresenter.getDishGroupData();
}
private void initDishDetail(DishDetailResultBean dishesResultBean){
List<DishDetailBean> foods=dishesResultBean.getData();
if (dishDetailAdapter == null) {
dishDetailAdapter = new DishDetailAdapter(requireContext(), new ArrayList<>());
// addChildClickViewIds(R.id.tv_dishes_unit,R.id.tv_dishes_del);
dishDetailAdapter = new DishDetailAdapter(new ArrayList<>());
dishDetailAdapter.setOnItemChildClickListener((adapter, view, position) -> {
LogUtil.e("zjs","position="+position+" curSelectDishNode "+(curSelectDishNode==null));
if (curSelectDishNode != null) {
DishDetailBean detailBean=dishDetailAdapter.getItem(position);
int id = view.getId();
if (id == R.id.tv_dishes_del) {
detailBean.setShow(false);
dishDetailAdapter.notifyItemChanged(position);
AppDialog.getInstance().showWaringDialog(mContext, "確定移除食材?", () ->{
if (detailBean.getId() == null) {//刚加 为提交直接删
dishDetailAdapter.removeAt(position);
}else {
detailBean.setDeletes(true);
dishDetailAdapter.addDel(detailBean);
dishDetailAdapter.removeAt(position);
}
});
} else if (id == R.id.tv_dishes_unit) {
List<DeputyUnitBean> foodUnits= detailBean.getFoodUnits();
if (CollectionUtils.isNotNullOrEmpty(foodUnits)) {
List<String> units = new ArrayList<>();
for (int i = 0; i < foodUnits.size(); i++) {
units.add(foodUnits.get(i).getDeputyUnit());
String name=foodUnits.get(i).getDeputyUnit();
units.add(name);
}
if (units.size() > 1) {
if (units.size() > 0) {
ChooseUnitPopup popup = new ChooseUnitPopup(requireContext()).setStringData(units).setOnSelectListener((pos, text) -> {
//將用戶之前輸入的值,修改到新選擇的單位匯中
String unitName= detailBean.getBasicUnitName();
DeputyUnitBean deputyUnitBean = foodUnits.get(pos);
LogUtil.e("zjs"," unitName="+unitName+" deputyUnitBean="+deputyUnitBean.toString());
String selectUnitName=deputyUnitBean.getDeputyUnit();
if (!unitName.equals(selectUnitName)) {
detailBean.setBasicUnitName(selectUnitName);
......@@ -137,8 +153,8 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
dishDetailAdapter.setList(new ArrayList<>());
}
int size=dishDetailAdapter.getData().size();
dishDetailAdapter.clearDel();
getFooterView(size>0);
LogUtil.e("ZJS"," dishDetailAdapter== " +" size="+size);
}
private View getFooterView(boolean showDone) {
......@@ -149,14 +165,15 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
});
footView.findViewById(R.id.tv_dish_done).setOnClickListener(v -> {
if (curSelectDishNode != null) {
List<DishDetailBean> allBeans=dishDetailAdapter.getDels();
List<DishDetailBean> detailBeans= dishDetailAdapter.getData();
if (CollectionUtils.isNotNullOrEmpty(detailBeans)) {
mPresenter.bindDishFoods(curSelectDishNode ,detailBeans);
allBeans.addAll(detailBeans);
}
if (CollectionUtils.isNotNullOrEmpty(allBeans)) {
mPresenter.bindDishFoods(curSelectDishNode ,allBeans);
}
}
LogUtil.e("zjs"," 完成 tv_dish_done");
});
}
if (showDone) {
......@@ -181,7 +198,7 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
int lastPost = pNode.getPos()+ppos;
int myPostion=position-ppos;
boolean isCur=position ==lastPost;
LogUtil.e("ZJS"," lastPost="+lastPost+" myPostion="+myPostion+" isCur="+isCur );
// LogUtil.e("ZJS"," lastPost="+lastPost+" myPostion="+myPostion+" isCur="+isCur );
if (!isCur) {//当前点击的不是上次点击的项目
DishNode lastDishNode= (DishNode) dishesTreeAdapter.getItem(lastPost);
lastDishNode.setSelect(false);
......@@ -193,7 +210,6 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
if (detailBean == null) {
mPresenter.getDishesDetailData(curDishNode);
} else {
LogUtil.e("ZJS", " detailBean= " + detailBean.toString());
loadDishesInfo(curDishNode, detailBean);
}
......@@ -215,6 +231,7 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
@Override
public void loadDishesInfo(DishNode dishNode,DishDetailResultBean dishesDetail) {
refresh.finishRefresh();
curSelectDishNode=dishNode;
initDishDetail(dishesDetail);
}
......@@ -226,12 +243,13 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
@Override
public void loadDishesFail() {
refresh.finishRefresh();
}
@Override
public void bindDishFoods(DishNode dishNode) {
LogUtil.e("zjs"," 绑定车工 "+dishNode.toString());
dishDetailAdapter.clearDel();
mPresenter.getDishesDetailData(dishNode);
}
@Override
......@@ -243,7 +261,6 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
@Override
public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
super.onFragmentResult(requestCode, resultCode, data);
LogUtil.e("zjs"," onFragmentResult ="+requestCode + " resultCode="+resultCode);
if (requestCode == DISHES_ADD) {
if (data != null) {
if (dishDetailAdapter != null && curSelectDishNode != null ) {
......@@ -252,7 +269,6 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
if (purchaseFood != null) {
List<DishDetailBean> foodsNew = new ArrayList<>();
int len=purchaseFood.size();
LogUtil.e("zjs", " purchaseFood =" + purchaseFood.size()+" foodsOld="+foodsOld.size());
if (CollectionUtils.isNotNullOrEmpty(foodsOld)) {
int old=foodsOld.size();
boolean isNew=true;
......@@ -260,10 +276,11 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
PurchaseFoodBean newBean= purchaseFood.get(i);
for (int j = 0; j < old; j++) {
DishDetailBean oldBean=foodsOld.get(j);
LogUtil.e("zjs"," oldBean="+oldBean.toString()+" newBean="+newBean.toString());
if (newBean.getId()==oldBean.getPurchaseFoodId()) {
// LogUtil.e("zjs"," oldBean="+oldBean.toString()+" newBean="+newBean.toString());
if (newBean.getId()==oldBean.getPurchaseFoodId()) {//选择了同一个食材
oldBean.setConsumeQuantity(oldBean.getConsumeQuantity()+newBean.getFoodQuantity());
isNew=false;
dishDetailAdapter.removeDel(oldBean);
dishDetailAdapter.notifyItemChanged(j);
continue;
}
......@@ -272,12 +289,11 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
DishDetailBean addNewBean=new DishDetailBean(newBean,curSelectDishNode);
foodsNew.add(addNewBean);
}
}
}else { //全新
for (int i = 0; i < len; i++) {
PurchaseFoodBean newBean= purchaseFood.get(i);
LogUtil.e("zjs"," 全新 newBean="+newBean.toString());
// LogUtil.e("zjs"," 全新 newBean="+newBean.toString());
DishDetailBean addNewBean=new DishDetailBean(newBean,curSelectDishNode);
foodsNew.add(addNewBean);
}
......@@ -294,6 +310,5 @@ public class DishesFragment extends BaseSupplyChainFragment<DishesPresenter> imp
}
}
}
}
}
\ No newline at end of file
......@@ -452,7 +452,6 @@ public class OtherFunctionFragment extends BaseSupplyChainFragment<OtherFunction
protected void confirm() {
ArrayList<PurchaseFoodBean> purchaseFood = mPresenter.getPurchaseFood();
if (CollectionUtils.isNotNullOrEmpty(purchaseFood)) {
LogUtil.e("zjs"," purchaseFood "+purchaseFood.size());
Bundle bundle = new Bundle();
bundle.putSerializable("zjs", purchaseFood);
setFragmentResult(RESULT_OK, bundle);
......
......@@ -94,14 +94,14 @@
</LinearLayout>
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:id="@+id/dish_refreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.scwang.smartrefresh.layout.header.ClassicsHeader
android:id="@+id/fresh_header"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_height="@dimen/dp_48"
app:srlAccentColor="#aaa"
app:srlDrawableArrow="@drawable/ic_pulling"
app:srlDrawableMarginRight="@dimen/dp_5"
......@@ -113,7 +113,7 @@
app:srlTextPulling="下滑查看上一分類"
app:srlTextRefreshing="正在飛速加載..."
app:srlTextRelease="釋放查看上一分類"
app:srlTextSizeTitle="@dimen/dp_12" />
app:srlTextSizeTitle="@dimen/dp_16" />
<com.gingersoft.supply_chain.mvp.ui.widget.StickyHeaderLayout
android:id="@+id/view_stick_head"
......@@ -128,17 +128,6 @@
</com.gingersoft.supply_chain.mvp.ui.widget.StickyHeaderLayout>
<com.scwang.smartrefresh.layout.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
app:srlDrawableArrow="@drawable/ic_push"
app:srlDrawableMarginRight="@dimen/dp_5"
app:srlDrawableSize="@dimen/dp_12"
app:srlTextFailed="加載完成"
app:srlTextLoading="正在飛速加載中..."
app:srlTextPulling="上拉加載更多"
app:srlTextRelease="釋放查看下一分類"
app:srlTextSizeTitle="@dimen/dp_12" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
</LinearLayout>
......
......@@ -30,6 +30,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="@dimen/dp_4"
android:paddingRight="@dimen/dp_4"
android:textColor="@color/color_18"
tools:text="單位" />
......@@ -40,14 +42,24 @@
android:layout_marginBottom="@dimen/dp_2"
android:background="@color/supply_function_color" />
<TextView
android:id="@+id/tv_dishes_count"
style="@style/WareHouse_item_TextStyle"
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_dishes_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="@dimen/dp_6"
android:layout_marginRight="@dimen/dp_6"
android:layout_marginTop="@dimen/dp_4"
android:layout_marginBottom="@dimen/dp_4"
android:textColor="@color/color_18"
tools:text="數量" />
android:background="@drawable/shape_border_bg_c8"
android:gravity="center"
android:inputType="numberDecimal"
android:maxLines="1"
android:textColorHighlight="@color/theme_color"
android:textCursorDrawable="@drawable/cursor_theme"
android:textSize="@dimen/dp_15"
tools:text="2" />
<View
android:layout_width="1px"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment