提交 67af8061 authored 作者: lgd's avatar lgd

1.bat页面商店第一个页面,购物车页面

2.//TODO erp用户激活,忘记密码测试,bat,mes,消息,我的,刷新token
上级 71b0faa8
......@@ -121,6 +121,14 @@
android:screenOrientation="portrait"
android:theme="@style/Work.Base"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".ui.activity.bat.StoreSaleCarActivity"
android:configChanges="keyboardHidden|orientation"
android:label="购物车"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Work.Base"
android:windowSoftInputMode="adjustPan" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.wd.workoffice.fileprovider"
......
......@@ -165,6 +165,24 @@ public class ProductBean {
private Object transitPartId;
private Object transitPartTypeCode;
private Object remark;
private String carPrice;
private int carNum;
public String getCarPrice() {
return carPrice;
}
public void setCarPrice(String carPrice) {
this.carPrice = carPrice;
}
public int getCarNum() {
return carNum;
}
public void setCarNum(int carNum) {
this.carNum = carNum;
}
public int getCreatedBy() {
return createdBy;
......
package com.wd.workoffice.bean.event;
/**
* author : flexible
* email : lgd19940421@163.com
* github: https://github.com/FlexibleXd
**/
public class ModifyCarEvent {
String pro;
public ModifyCarEvent(String pro) {
this.pro = pro;
}
public String getPro() {
return pro;
}
public void setPro(String pro) {
this.pro = pro;
}
}
package com.wd.workoffice.ui.activity.bat;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.bean.ProductBean;
import com.wd.workoffice.bean.event.ModifyCarEvent;
import com.wd.workoffice.ui.adapter.StoreCarAdapter;
import com.wd.workoffice.util.DialogUtils;
import com.wd.workoffice.util.MathUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* 商店-销售-购物车
* author : flexible
* email : lgd19940421@163.com
* github: https://github.com/FlexibleXd
**/
public class StoreSaleCarActivity extends WorkToolBarActivity {
@BindView(R.id.tv_num)
TextView tvNum;
@BindView(R.id.tv_price)
TextView tvPrice;
@BindView(R.id.tv_ok)
TextView tvOk;
@BindView(R.id.ll_bottom)
RelativeLayout llBottom;
@BindView(R.id.rv_product)
RecyclerView rvProduct;
private List<ProductBean.RecordsBean> productList;
private StoreCarAdapter productAdapter;
@Override
protected void initView() {
ButterKnife.bind(this);
rvProduct.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
}
@Override
protected void initData() {
productList = new ArrayList<>();
productAdapter = new StoreCarAdapter(R.layout.item_store_car, productList);
productAdapter.bindToRecyclerView(rvProduct);
String pro = getIntent().getStringExtra("pro");
productList.addAll(JSON.parseArray(pro, ProductBean.RecordsBean.class));
productAdapter.notifyDataSetChanged();
changeNumAndPrice();
}
@Override
protected void initEvent() {
productAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
QMUIDialog.MessageDialogBuilder dialog = DialogUtils.okAndCancelDialog(StoreSaleCarActivity.this);
dialog.setMessage("是否删除").addAction("取消", new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
}
}).addAction("确定", new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
productList.remove(position);
productAdapter.notifyDataSetChanged();
EventBus.getDefault().post(new ModifyCarEvent(JSON.toJSONString(productList)));
}
}).show();
}
});
}
@Override
protected int layoutId() {
return R.layout.activity_bat_shopcar;
}
@OnClick(R.id.tv_ok)
public void onViewClicked() {
}
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(ModifyCarEvent event) {
changeNumAndPrice();
}
private void changeNumAndPrice() {
tvNum.setText("共 ".concat(productList.size()+"").concat( " 件"));
String allPrice="";
for (ProductBean.RecordsBean recordsBean : productList) {
allPrice= MathUtils.add(allPrice,MathUtils.multiply(recordsBean.getCarNum()+"",recordsBean.getCarPrice(),2),2);
}
tvPrice.setText("总计: ¥ ".concat(allPrice));
}
}
......@@ -16,6 +16,7 @@ import com.wd.workoffice.app.BaseBean;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.bean.ProcessBean;
import com.wd.workoffice.bean.ProductBean;
import com.wd.workoffice.bean.event.ModifyCarEvent;
import com.wd.workoffice.bean.workEnum.PermissType;
import com.wd.workoffice.retrofit.RtfUtils;
import com.wd.workoffice.retrofit.WorkObserver;
......@@ -23,6 +24,10 @@ import com.wd.workoffice.ui.adapter.StoreProcductAdapter;
import com.wd.workoffice.util.WorkUtils;
import com.wd.workoffice.widget.AddAndReduceView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -64,6 +69,7 @@ public class StoreSaleProductActivity extends WorkToolBarActivity {
private List<ProductBean.RecordsBean> clientList;
private StoreProcductAdapter clientAdapter;
private int page = 1;
private List<ProductBean.RecordsBean> carList = new ArrayList<>();
@Override
protected void initView() {
......@@ -74,13 +80,25 @@ public class StoreSaleProductActivity extends WorkToolBarActivity {
tvProcess.setText("订单流程:" + getIntent().getStringExtra("process"));
}
private void openDialog(ProductBean.RecordsBean recordsBean) {
@Override
protected void onResume() {
super.onResume();
}
private void openDialog(ProductBean.RecordsBean data) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.view_add_cart, null);
TextView tvOk = view.findViewById(R.id.tv_ok);
TextView tvCancel = view.findViewById(R.id.tv_cancel);
AddAndReduceView num = view.findViewById(R.id.ar_num);
EditText etPrice = view.findViewById(R.id.et_price);
for (ProductBean.RecordsBean recordsBean : carList) {
if (data.getId() == recordsBean.getId()) {
etPrice.setText(recordsBean.getCarPrice());
num.setNumber(recordsBean.getCarNum());
}
}
builder.setView(view);
AlertDialog addCartDialog = builder.create();
tvOk.setOnClickListener(new View.OnClickListener() {
......@@ -90,7 +108,7 @@ public class StoreSaleProductActivity extends WorkToolBarActivity {
toast("请填写外部价格");
return;
}
addCart(recordsBean, num.getNumber(), etPrice.getText().toString());
addCart(data, num.getNumber(), etPrice.getText().toString());
addCartDialog.dismiss();
}
});
......@@ -112,6 +130,20 @@ public class StoreSaleProductActivity extends WorkToolBarActivity {
* @param price 单价
*/
private void addCart(ProductBean.RecordsBean chooseProduct, int number, String price) {
boolean isHas = false;
for (ProductBean.RecordsBean recordsBean : carList) {
if (chooseProduct.getId() == recordsBean.getId()) {
isHas = true;
recordsBean.setCarNum(number);
recordsBean.setCarPrice(price);
}
}
if (!isHas) {
chooseProduct.setCarNum(number);
chooseProduct.setCarPrice(price);
carList.add(chooseProduct);
}
toast("加入购物车成功");
}
@Override
......@@ -199,6 +231,11 @@ public class StoreSaleProductActivity extends WorkToolBarActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.cart:
if (carList.size() == 0) {
toast("购物车没有产品");
return super.onOptionsItemSelected(item);
}
startActivity(StoreSaleCarActivity.class, "pro", JSON.toJSONString(carList));
break;
}
return super.onOptionsItemSelected(item);
......@@ -219,4 +256,24 @@ public class StoreSaleProductActivity extends WorkToolBarActivity {
break;
}
}
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(ModifyCarEvent event) {
String pro = event.getPro();
carList.clear();
carList.addAll(JSON.parseArray(pro, ProductBean.RecordsBean.class));
}
}
package com.wd.workoffice.ui.adapter;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wd.workoffice.R;
import com.wd.workoffice.bean.ProductBean;
import com.wd.workoffice.bean.event.ModifyCarEvent;
import com.wd.workoffice.util.MathUtils;
import com.wd.workoffice.widget.AddAndReduceView;
import org.greenrobot.eventbus.EventBus;
import java.util.List;
import flexible.xd.android_base.utils.ToastUtil;
/**
* Created by flexible on 2018/8/13.
*/
public class StoreCarAdapter extends BaseQuickAdapter<ProductBean.RecordsBean, BaseViewHolder> {
public StoreCarAdapter(int layoutResId, List data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, ProductBean.RecordsBean item) {
helper.setText(R.id.tv_name, item.getSimpleCode());
helper.setText(R.id.tv_card, item.getSoleCode());
helper.setText(R.id.tv_card_name, item.getName());
helper.setText(R.id.tv_spec, item.getSpec());
helper.setText(R.id.tv_price, "¥".concat(String.valueOf(item.getInternalPrice())));
helper.setText(R.id.tv_unit, String.valueOf(item.getWeight()).concat("吨"));
helper.addOnClickListener(R.id.tv_delete);
AddAndReduceView num = helper.getView(R.id.ar_num);
num.setOnNumberChangedListener(new AddAndReduceView.OnNumberChangedListener() {
@Override
public void OnNumberChanged(int vs) {
item.setCarNum(vs);
helper.setText(R.id.tv_all_price, MathUtils.multiply(vs+"",item.getCarPrice(),2));
EventBus.getDefault().post(new ModifyCarEvent(JSON.toJSONString(getData())));
}
});
EditText etPrice = helper.getView(R.id.et_price);
etPrice.setText(item.getCarPrice());
etPrice.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) {
}
@Override
public void afterTextChanged(Editable s) {
if (TextUtils.isEmpty(s)){
ToastUtil.showShort("请输入外部单价");
return;
}
item.setCarPrice(s.toString());
helper.setText(R.id.tv_all_price, MathUtils.multiply(item.getCarNum()+"",item.getCarPrice(),2));
EventBus.getDefault().post(new ModifyCarEvent(JSON.toJSONString(getData())));
}
});
num.setNumber(item.getCarNum());
}
}
package com.wd.workoffice.util;
import android.content.Context;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.module.AppGlideModule;
/**
* Created by Flexible on 2018/2/1 0001.
*/
@GlideModule
public final class BaseGlideMoudle extends AppGlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
builder.setMemoryCache(new LruResourceCache(10 * 1024 * 1024));
builder.setBitmapPool(new LruBitmapPool(10 * 1024 * 1024));
}
@Override
public boolean isManifestParsingEnabled() {
return false;
}
}
\ No newline at end of file
......@@ -14,4 +14,8 @@ public class DialogUtils {
QMUIDialog.MenuDialogBuilder dialog = new QMUIDialog.MenuDialogBuilder(context);
return dialog;
}
public static QMUIDialog.MessageDialogBuilder okAndCancelDialog(Context context) {
QMUIDialog.MessageDialogBuilder dialog = new QMUIDialog.MessageDialogBuilder(context);
return dialog;
}
}
package com.wd.workoffice.util;
import android.content.Context;
import android.text.TextUtils;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import java.math.BigDecimal;
/**
* author : flexible
* email : lgd19940421@163.com
* github: https://github.com/FlexibleXd
**/
public class MathUtils {
public static String multiply(String v1, String v2, Integer scale) {
if (TextUtils.isEmpty(v1)) {
v1 = "0";
}
if (TextUtils.isEmpty(v2)) {
v2 = "0";
}
BigDecimal b1 = new BigDecimal(v1.trim());
BigDecimal b2 = new BigDecimal(v2.trim());
return b1.multiply(b2).setScale(scale).toString();
}
public static String add(String v1, String v2, Integer scale) {
if (TextUtils.isEmpty(v1)) {
v1 = "0";
}
if (TextUtils.isEmpty(v2)) {
v2 = "0";
}
BigDecimal b1 = new BigDecimal(v1.trim());
BigDecimal b2 = new BigDecimal(v2.trim());
return b1.add(b2).setScale(scale).toString();
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/ll_bottom"
android:layout_width="match_parent"
android:layout_height="60mm"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_marginLeft="15mm"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/tv_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="共 0 件"
android:textSize="13sp" />
<TextView
android:id="@+id/tv_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10mm"
android:text="总计: ¥ "
android:textSize="16sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_ok"
android:layout_width="80mm"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@color/red_btn_bg"
android:gravity="center"
android:text="申请下单"
android:textColor="@color/white" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_product"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/ll_bottom" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:paddingHorizontal="20mm"
android:paddingVertical="10mm">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="图号TH82739857"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingHorizontal="5mm"
android:text="删除"
android:textColor="@color/red_btn_bg"
android:textSize="14sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15mm"
android:background="#FCFCFD"
android:orientation="vertical"
android:padding="10mm">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="品号"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="品号"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10mm">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="品名"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_card_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="品号"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10mm">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="规格"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_spec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="品号"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10mm">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="内部单价"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="品号"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10mm">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="单位"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
<TextView
android:id="@+id/tv_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="品号"
android:textColor="@color/flexible_text_gray"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="30mm"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="外部单价"
android:textColor="@color/flexible_text_sup"
android:textSize="17sp" />
<EditText
android:id="@+id/et_price"
android:layout_width="150mm"
android:layout_height="30mm"
android:layout_marginLeft="10mm"
android:background="@drawable/shape_add_cart"
android:gravity="right|center_vertical"
android:hint="¥0.00"
android:inputType="numberDecimal"
android:paddingHorizontal="10mm"
android:paddingVertical="4mm"
android:textColor="@color/flexible_text_sup"
android:textColorHint="#91ABBA"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginTop="25mm"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="购买数量"
android:textColor="@color/flexible_text_sup"
android:textSize="17sp" />
<com.wd.workoffice.widget.AddAndReduceView
android:id="@+id/ar_num"
android:layout_width="150mm"
android:layout_height="wrap_content"
android:layout_marginLeft="10mm" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="30mm">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="小计: ¥ "
android:textSize="12sp" />
<TextView
android:id="@+id/tv_all_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2300.00"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -17,7 +17,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10mm"
android:layout_marginTop="14mm"
android:background="#FCFCFD"
android:orientation="vertical"
android:padding="10mm">
......
......@@ -37,11 +37,11 @@
android:layout_height="30mm"
android:layout_marginLeft="10mm"
android:background="@drawable/shape_add_cart"
android:gravity="right"
android:gravity="right|center_vertical"
android:hint="预计开票单价"
android:inputType="numberDecimal"
android:paddingVertical="4mm"
android:paddingHorizontal="10mm"
android:paddingVertical="4mm"
android:textColor="@color/flexible_text_sup"
android:textColorHint="#91ABBA"
android:textSize="16sp" />
......
......@@ -9,4 +9,5 @@
<color name="main_icon">#C3CED7</color>
<color name="flexible_background">#fff6f9fb</color>
<color name="input_background">#F0F5F8</color>
<color name="red_btn_bg">#C45D5D</color>
</resources>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论