|
|
@@ -0,0 +1,351 @@
|
|
|
+package cn.muchinfo.rma.view.base.procurement.contraceui;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.ViewTreeObserver;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+
|
|
|
+import com.blankj.utilcode.util.ActivityUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import cn.muchinfo.rma.R;
|
|
|
+import cn.muchinfo.rma.business.contract.SpotContractInfo;
|
|
|
+import cn.muchinfo.rma.global.GlobalDataCollection;
|
|
|
+import cn.muchinfo.rma.global.ViewEnumUtils;
|
|
|
+import cn.muchinfo.rma.global.data.ContractData;
|
|
|
+import cn.muchinfo.rma.view.autoWidget.CustomHorizontalScrollView;
|
|
|
+import cn.muchinfo.rma.view.base.home.contract.AddContractActivity;
|
|
|
+import cn.muchinfo.rma.view.base.home.contract.ContractDetailsActivity;
|
|
|
+import cn.muchinfo.rma.view.base.home.contract.ContractViewModel;
|
|
|
+import cn.muchinfo.rma.view.base.procurement.ContractDetailActivity;
|
|
|
+import cn.muchinfo.rma.view.base.procurement.ProcurementViewModel;
|
|
|
+import cn.muchinfo.rma.view.base.procurement.RightScrollAdapter;
|
|
|
+import kotlin.Unit;
|
|
|
+import kotlin.jvm.functions.Function1;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用于采购和销售的列表adapter
|
|
|
+ */
|
|
|
+public class SpotContractAdapter extends RecyclerView.Adapter<SpotContractAdapter.ItemViewHolder> {
|
|
|
+
|
|
|
+ private Context context;
|
|
|
+ private List<ContractData> datas;
|
|
|
+ private int index = -1;
|
|
|
+ private int position = -1;
|
|
|
+ private List<ItemViewHolder> mViewHolderList = new ArrayList<>();
|
|
|
+ public int offestX = 0;
|
|
|
+ private OnContentScrollListener onContentScrollListener;
|
|
|
+ private ProcurementViewModel viewModel;
|
|
|
+ private String type;//1 未提交 2 待审核 3 履约中 4 已完结
|
|
|
+
|
|
|
+ public interface OnContentScrollListener {
|
|
|
+ void onScroll(MotionEvent event);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setOnContentScrollListener(OnContentScrollListener onContentScrollListener) {
|
|
|
+ this.onContentScrollListener = onContentScrollListener;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public SpotContractAdapter(Context context, String type, ProcurementViewModel viewModel) {
|
|
|
+ this.context = context;
|
|
|
+ this.viewModel = viewModel;
|
|
|
+ this.type = type;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setDatas(List<ContractData> datas) {
|
|
|
+ this.datas = datas;
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPosition(int position) {
|
|
|
+ if (this.position == position) {
|
|
|
+ this.position = -1;
|
|
|
+ notifyItemChanged(index);
|
|
|
+ } else {
|
|
|
+ this.position = position;
|
|
|
+ notifyItemChanged(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @NonNull
|
|
|
+ @Override
|
|
|
+ public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
|
|
+ View view = LayoutInflater.from(context).inflate(R.layout.layout_item_contract, viewGroup, false);
|
|
|
+ return new ItemViewHolder(view);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
+ @Override
|
|
|
+ public void onBindViewHolder(@NonNull final ItemViewHolder itemViewHolder, int i) {
|
|
|
+ this.index = i;
|
|
|
+ ContractData contractData = datas.get(i);
|
|
|
+ itemViewHolder.tvLeftTitle.setText(datas.get(i).getContractno());
|
|
|
+ itemViewHolder.tv_left_bottom_title.setText(ViewEnumUtils.INSTANCE.getContractType(contractData.getContracttype()) + "/" + ViewEnumUtils.INSTANCE.getContractStatus(contractData.getContracctstatus()));
|
|
|
+ //右边滑动部分
|
|
|
+ LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
|
|
|
+ linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
+ itemViewHolder.rvItemRight.setLayoutManager(linearLayoutManager);
|
|
|
+ itemViewHolder.rvItemRight.setHasFixedSize(true);
|
|
|
+ RightScrollAdapter rightScrollAdapter = new RightScrollAdapter(context);
|
|
|
+ rightScrollAdapter.setDatas(datas.get(i).getRightData());
|
|
|
+ itemViewHolder.rvItemRight.setAdapter(rightScrollAdapter);
|
|
|
+ //缓存当前holder
|
|
|
+ if (!mViewHolderList.contains(itemViewHolder)) {
|
|
|
+ mViewHolderList.add(itemViewHolder);
|
|
|
+ }
|
|
|
+ if (i == this.position) {
|
|
|
+ itemViewHolder.roots_view.setBackgroundColor(context.getResources().getColor(R.color.rma_list_select_color));
|
|
|
+ itemViewHolder.allView.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ itemViewHolder.roots_view.setBackgroundColor(context.getResources().getColor(R.color.white));
|
|
|
+ itemViewHolder.allView.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ itemViewHolder.all_click_View.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ setPosition(i);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ itemViewHolder.horItemScrollview.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ setPosition(i);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (type.equals("2")){
|
|
|
+ if (GlobalDataCollection.Companion.getInstance().getThreeLevelMenu("client_spotcontract","client_spotcontract_unaduit","client_spotcontract_cancel")){
|
|
|
+ if (contractData.getContracctstatus().equals("1")){
|
|
|
+ itemViewHolder.contract_undo.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_undo.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_undo.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_undo.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ //撤销
|
|
|
+ itemViewHolder.contract_undo.setOnClickListener(view -> {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("type","3");
|
|
|
+ intent.putExtra("data",contractData);
|
|
|
+ intent.setClass(context, ContractDetailsActivity.class);
|
|
|
+ ActivityUtils.startActivity(intent);
|
|
|
+ });
|
|
|
+ if (type.equals("2")){
|
|
|
+ if (GlobalDataCollection.Companion.getInstance().getThreeLevelMenu("client_spotcontract","client_spotcontract_unaduit","client_spotcontract_check")){
|
|
|
+ if (contractData.getContracctstatus().equals("1")){
|
|
|
+ itemViewHolder.contract_audit.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_audit.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_audit.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_audit.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ //审核
|
|
|
+ itemViewHolder.contract_audit.setOnClickListener(view -> {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("type","2");
|
|
|
+ intent.putExtra("data",contractData);
|
|
|
+ intent.setClass(context, ContractDetailsActivity.class);
|
|
|
+ ActivityUtils.startActivity(intent);
|
|
|
+ });
|
|
|
+ if (type.equals("1")){
|
|
|
+ if (GlobalDataCollection.Companion.getInstance().getThreeLevelMenu("client_spotcontract","client_spotcontract_unsubmit","client_spotcontract_update")){
|
|
|
+ if (contractData.getContracctstatus().equals("1") || contractData.getContracctstatus().equals("0")){
|
|
|
+ itemViewHolder.contract_modify.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_modify.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_modify.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_modify.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ //修改
|
|
|
+ itemViewHolder.contract_modify.setOnClickListener(view -> {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("operationtype","2");
|
|
|
+ intent.putExtra("data",contractData);
|
|
|
+ intent.setClass(context, AddContractActivity.class);
|
|
|
+ ActivityUtils.startActivity(intent);
|
|
|
+ });
|
|
|
+ if (type.equals("3")){
|
|
|
+ if (GlobalDataCollection.Companion.getInstance().getThreeLevelMenu("client_spotcontract","client_spotcontract_agreement","client_spotcontract_finish")){
|
|
|
+ itemViewHolder.contract_completion.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_completion.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_completion.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ //完结合同
|
|
|
+ itemViewHolder.contract_completion.setOnClickListener(view -> {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("type","4");
|
|
|
+ intent.putExtra("data",contractData);
|
|
|
+ intent.setClass(context, ContractDetailsActivity.class);
|
|
|
+ ActivityUtils.startActivity(intent);
|
|
|
+ });
|
|
|
+ if (type.equals("1")){
|
|
|
+ if (GlobalDataCollection.Companion.getInstance().getThreeLevelMenu("client_spotcontract","client_spotcontract_unsubmit","client_spotcontract_recommit")){
|
|
|
+ if (contractData.getContracctstatus().equals("4") || contractData.getContracctstatus().equals("6")){
|
|
|
+ itemViewHolder.contract_resubmit.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_resubmit.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_resubmit.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_resubmit.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ //重新提交
|
|
|
+ itemViewHolder.contract_resubmit.setOnClickListener(view -> {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("operationtype","2");
|
|
|
+ intent.putExtra("data",contractData);
|
|
|
+ intent.setClass(context, AddContractActivity.class);
|
|
|
+ ActivityUtils.startActivity(intent);
|
|
|
+ });
|
|
|
+ if (type.equals("1")){
|
|
|
+ if (GlobalDataCollection.Companion.getInstance().getThreeLevelMenu("client_spotcontract","client_spotcontract_unaduit","client_spotcontract_delete")){
|
|
|
+ itemViewHolder.contract_delete.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_delete.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ itemViewHolder.contract_delete.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ //删除
|
|
|
+ itemViewHolder.contract_delete.setOnClickListener(view -> {
|
|
|
+ viewModel.orderContract(new SpotContractInfo(), "3", "", contractData.getSpotcontractid(), new Function1<Boolean, Unit>() {
|
|
|
+ @Override
|
|
|
+ public Unit invoke(Boolean aBoolean) {
|
|
|
+ viewModel.querySpotContract("1");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ //详情
|
|
|
+ itemViewHolder.contract_details.setOnClickListener(view -> {
|
|
|
+ if (datas.get(i).getContracctstatus().equals("0") || datas.get(i).getContracctstatus().equals("1")){
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("data", datas.get(i));
|
|
|
+ intent.putExtra("type","1");
|
|
|
+ intent.setClass(context, ContractDetailsActivity.class);
|
|
|
+ context.startActivity(intent);
|
|
|
+ }else {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("data", datas.get(i));
|
|
|
+ if (datas.get(i).getContracttype().equals("1")){
|
|
|
+ intent.putExtra("type","1");
|
|
|
+ }else {
|
|
|
+ intent.putExtra("type","2");
|
|
|
+ }
|
|
|
+ intent.putExtra("isFrom","2");
|
|
|
+ intent.setClass(context, ContractDetailActivity.class);
|
|
|
+ context.startActivity(intent);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ itemViewHolder.horItemScrollview.setEventListener(new CustomHorizontalScrollView.EventListener() {
|
|
|
+ @Override
|
|
|
+ public void onEvent(MotionEvent event) {
|
|
|
+ if (null != onContentScrollListener) onContentScrollListener.onScroll(event);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //由于viewHolder的缓存,在1级缓存取出来是2个viewholder,并且不会被重新赋值,所以这里需要处理缓存的viewholder的位移
|
|
|
+ itemViewHolder.horItemScrollview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
+ @Override
|
|
|
+ public void onGlobalLayout() {
|
|
|
+ if (!itemViewHolder.isLayoutFinish()) {
|
|
|
+ itemViewHolder.horItemScrollview.scrollTo(offestX, 0);
|
|
|
+ itemViewHolder.setLayoutFinish(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getItemCount() {
|
|
|
+ return null == datas ? 0 : datas.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ItemViewHolder> getViewHolderCacheList() {
|
|
|
+ return mViewHolderList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getOffestX() {
|
|
|
+ return offestX;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class ItemViewHolder extends RecyclerView.ViewHolder {
|
|
|
+ LinearLayout roots_view;//根部布局
|
|
|
+ TextView contract_details;//详情
|
|
|
+ TextView contract_undo;//撤销
|
|
|
+ TextView contract_audit;//审核
|
|
|
+ TextView contract_modify;//修改
|
|
|
+ TextView contract_completion;//完结合同
|
|
|
+ TextView contract_resubmit;//重新提交
|
|
|
+ TextView contract_delete;//删除
|
|
|
+ ImageView load_more;//更多
|
|
|
+ LinearLayout allView;//隐藏的底部操作空间
|
|
|
+ LinearLayout all_click_View;//item左侧点击控件
|
|
|
+ TextView tvLeftTitle;//左边销售方字段
|
|
|
+ TextView tv_left_bottom_title;//合同编号
|
|
|
+ RecyclerView rvItemRight;//右方的列表
|
|
|
+ ImageView click_icon;//图标
|
|
|
+ public CustomHorizontalScrollView horItemScrollview;//右方的滑动控件
|
|
|
+ private boolean isLayoutFinish;//自定义字段,用于标记layout
|
|
|
+
|
|
|
+ public boolean isLayoutFinish() {
|
|
|
+ return isLayoutFinish;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setLayoutFinish(boolean layoutFinish) {
|
|
|
+ isLayoutFinish = layoutFinish;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ItemViewHolder(@NonNull View itemView) {
|
|
|
+ super(itemView);
|
|
|
+ contract_delete = itemView.findViewById(R.id.contract_delete);
|
|
|
+ contract_undo = itemView.findViewById(R.id.contract_undo);
|
|
|
+ click_icon = itemView.findViewById(R.id.click_icon);
|
|
|
+ contract_resubmit = itemView.findViewById(R.id.contract_resubmit);
|
|
|
+ contract_audit = itemView.findViewById(R.id.contract_audit);
|
|
|
+ contract_modify = itemView.findViewById(R.id.contract_modify);
|
|
|
+ contract_completion = itemView.findViewById(R.id.contract_completion);
|
|
|
+ load_more = itemView.findViewById(R.id.load_more);
|
|
|
+ tvLeftTitle = itemView.findViewById(R.id.tv_left_title);
|
|
|
+ rvItemRight = itemView.findViewById(R.id.rv_item_right);
|
|
|
+ horItemScrollview = itemView.findViewById(R.id.hor_item_scrollview);
|
|
|
+ allView = itemView.findViewById(R.id.all_view);
|
|
|
+ tv_left_bottom_title = itemView.findViewById(R.id.tv_left_bottom_title);
|
|
|
+ all_click_View = itemView.findViewById(R.id.all_click_View);
|
|
|
+
|
|
|
+ contract_details = itemView.findViewById(R.id.contract_details);
|
|
|
+ roots_view = itemView.findViewById(R.id.roots_view);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|