|  | @@ -0,0 +1,323 @@
 | 
	
		
			
				|  |  | +package com.hw.nativeapp.ui.activity;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import android.app.ProgressDialog;
 | 
	
		
			
				|  |  | +import android.content.Intent;
 | 
	
		
			
				|  |  | +import android.os.Bundle;
 | 
	
		
			
				|  |  | +import android.os.Handler;
 | 
	
		
			
				|  |  | +import android.util.Log;
 | 
	
		
			
				|  |  | +import android.view.View;
 | 
	
		
			
				|  |  | +import android.widget.CheckBox;
 | 
	
		
			
				|  |  | +import android.widget.TextView;
 | 
	
		
			
				|  |  | +import android.widget.Toast;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import androidx.annotation.Nullable;
 | 
	
		
			
				|  |  | +import androidx.recyclerview.widget.LinearLayoutManager;
 | 
	
		
			
				|  |  | +import androidx.recyclerview.widget.RecyclerView;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | +import com.hjq.bar.OnTitleBarListener;
 | 
	
		
			
				|  |  | +import com.hjq.bar.TitleBar;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.MApplication;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.R;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.httpnet.ErrorConsumer;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.httpnet.ResponseConsumer;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.httpnet.entity.PageAsk;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.httpnet.entity.handleBean;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.ui.activity.adapters.PurchaseInfoAdapter;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.utils.ActivityUtils;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.utils.MaskUtil;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.utils.RxUtil;
 | 
	
		
			
				|  |  | +import com.hw.nativeapp.utils.ToastUtils;
 | 
	
		
			
				|  |  | +import com.scwang.smartrefresh.layout.SmartRefreshLayout;
 | 
	
		
			
				|  |  | +import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
 | 
	
		
			
				|  |  | +import com.scwang.smartrefresh.layout.header.ClassicsHeader;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.util.HashMap;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import butterknife.BindView;
 | 
	
		
			
				|  |  | +import butterknife.OnClick;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +public class PurchaseInfoActivity extends BaseActivity  {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @BindView(R.id.list_stock)
 | 
	
		
			
				|  |  | +    RecyclerView listStock;
 | 
	
		
			
				|  |  | +    @BindView(R.id.refreshLayout)
 | 
	
		
			
				|  |  | +    SmartRefreshLayout refreshLayout;
 | 
	
		
			
				|  |  | +    @BindView(R.id.tx_noDataShow)
 | 
	
		
			
				|  |  | +    TextView tx_noDataShow;
 | 
	
		
			
				|  |  | +    @BindView(R.id.immediately_btn)
 | 
	
		
			
				|  |  | +    TextView immediately_btn;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @BindView(R.id.all_btn)
 | 
	
		
			
				|  |  | +    CheckBox all_btn;
 | 
	
		
			
				|  |  | +    @BindView(R.id.txt_btn)
 | 
	
		
			
				|  |  | +    TextView txt_btn;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private TitleBar titleBar;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private PageAsk pageAsk = new PageAsk();
 | 
	
		
			
				|  |  | +    private handleBean operLocation;
 | 
	
		
			
				|  |  | +    private PurchaseInfoAdapter adapter;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private ProgressDialog progressDialog;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private String qrcodeNo = "";
 | 
	
		
			
				|  |  | +    private String idcard = "";
 | 
	
		
			
				|  |  | +    private JSONArray viewerList = new JSONArray();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private JSONArray dataList = new JSONArray();
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    void initView() {
 | 
	
		
			
				|  |  | +        titleBar = findViewById(R.id.tb_main_bar);
 | 
	
		
			
				|  |  | +        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            @Override
 | 
	
		
			
				|  |  | +            public void onLeftClick(View v) {
 | 
	
		
			
				|  |  | +                ActivityUtils.activityFinish(PurchaseInfoActivity.this, true );
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            @Override
 | 
	
		
			
				|  |  | +            public void onTitleClick(View v) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            @Override
 | 
	
		
			
				|  |  | +            public void onRightClick(View v) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        getPageTransmitParams();
 | 
	
		
			
				|  |  | +        initListView();
 | 
	
		
			
				|  |  | +        initLoadData();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    protected void onCreate(@Nullable Bundle savedInstanceState) {
 | 
	
		
			
				|  |  | +        super.onCreate(savedInstanceState);
 | 
	
		
			
				|  |  | +        setContentView(R.layout.activity_purchase_info);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    protected void onStart() {
 | 
	
		
			
				|  |  | +        super.onStart();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    protected void onDestroy() {
 | 
	
		
			
				|  |  | +        super.onDestroy();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @OnClick({R.id.immediately_btn, R.id.all_btn, R.id.txt_btn})
 | 
	
		
			
				|  |  | +    public void onClick(View v){
 | 
	
		
			
				|  |  | +        switch (v.getId()){
 | 
	
		
			
				|  |  | +            case R.id.immediately_btn:
 | 
	
		
			
				|  |  | +                if(dataList.size() > 0){
 | 
	
		
			
				|  |  | +                    orderSubmit();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                break;
 | 
	
		
			
				|  |  | +            case R.id.all_btn:
 | 
	
		
			
				|  |  | +                for (int i = 0; i < dataList.size(); i++) {
 | 
	
		
			
				|  |  | +                    dataList.getJSONObject(i).put("checkedStatus", all_btn.isChecked());
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                setDataList(true);
 | 
	
		
			
				|  |  | +                break;
 | 
	
		
			
				|  |  | +            case R.id.txt_btn:
 | 
	
		
			
				|  |  | +                boolean isChecked = !all_btn.isChecked();
 | 
	
		
			
				|  |  | +                for (int i = 0; i < dataList.size(); i++) {
 | 
	
		
			
				|  |  | +                    dataList.getJSONObject(i).put("checkedStatus", isChecked);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                all_btn.setChecked(isChecked);
 | 
	
		
			
				|  |  | +                setDataList(true);
 | 
	
		
			
				|  |  | +                break;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    private void setDataList(boolean cleaned){
 | 
	
		
			
				|  |  | +        if (dataList != null && !dataList.isEmpty()){
 | 
	
		
			
				|  |  | +            List<handleBean> rowbeans = JSONArray.parseArray(JSON.toJSONString(dataList), handleBean.class);
 | 
	
		
			
				|  |  | +            reflashLoadData(rowbeans, cleaned);
 | 
	
		
			
				|  |  | +            emptyShow(false);
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  | +            emptyShow(true);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        reflashFinish();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    //获取页面传递参数
 | 
	
		
			
				|  |  | +    private void getPageTransmitParams(){
 | 
	
		
			
				|  |  | +        Intent transmitIntent = getIntent();
 | 
	
		
			
				|  |  | +        qrcodeNo = transmitIntent.getStringExtra("qrcodeNo");
 | 
	
		
			
				|  |  | +        idcard = transmitIntent.getStringExtra("idcard");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void reflashFinish(){
 | 
	
		
			
				|  |  | +        if (refreshLayout != null){
 | 
	
		
			
				|  |  | +            refreshLayout.finishRefresh();
 | 
	
		
			
				|  |  | +            refreshLayout.finishLoadMore();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    private void initListView(){
 | 
	
		
			
				|  |  | +        //线性布局
 | 
	
		
			
				|  |  | +        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
 | 
	
		
			
				|  |  | +        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
 | 
	
		
			
				|  |  | +        listStock.setLayoutManager(linearLayoutManager);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        adapter = new PurchaseInfoAdapter(this);
 | 
	
		
			
				|  |  | +        adapter.setOnOutBtnClickListerer((bean, position) -> {
 | 
	
		
			
				|  |  | +            boolean allStatus = true;
 | 
	
		
			
				|  |  | +            for (int i = 0; i < dataList.size(); i++) {
 | 
	
		
			
				|  |  | +                if(bean.id.equals(dataList.getJSONObject(i).getString("id"))){
 | 
	
		
			
				|  |  | +                    dataList.getJSONObject(i).put("checkedStatus", bean.checkedStatus);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if(!dataList.getJSONObject(i).getBoolean("checkedStatus")) {
 | 
	
		
			
				|  |  | +                    allStatus = false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            all_btn.setChecked(allStatus);
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        listStock.setAdapter(adapter);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //下拉刷新
 | 
	
		
			
				|  |  | +        refreshLayout.setRefreshHeader(new ClassicsHeader(this));
 | 
	
		
			
				|  |  | +        //上拉加载
 | 
	
		
			
				|  |  | +        refreshLayout.setRefreshFooter(new ClassicsFooter(this));
 | 
	
		
			
				|  |  | +        //为下来刷新添加事件
 | 
	
		
			
				|  |  | +        refreshLayout.setOnRefreshListener(refreshlayout -> initLoadData());
 | 
	
		
			
				|  |  | +        //为上拉下载添加事件
 | 
	
		
			
				|  |  | +        refreshLayout.setOnLoadMoreListener(refreshlayout -> {
 | 
	
		
			
				|  |  | +            if (pageAsk.pageNum > pageAsk.pageCount){
 | 
	
		
			
				|  |  | +                ToastUtils.showLongToast(PurchaseInfoActivity.this, "没有太多数据了");
 | 
	
		
			
				|  |  | +                refreshlayout.finishLoadMore();
 | 
	
		
			
				|  |  | +            }else{
 | 
	
		
			
				|  |  | +                getDataList(false);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void initLoadData(){
 | 
	
		
			
				|  |  | +        pageAsk.pageNum = 1;
 | 
	
		
			
				|  |  | +        pageAsk.pageSize = 20;
 | 
	
		
			
				|  |  | +        getDataList(true);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void getDataList(boolean cleaned){
 | 
	
		
			
				|  |  | +        Map< String,String> options = new HashMap<>();
 | 
	
		
			
				|  |  | +        if(qrcodeNo != null && !qrcodeNo.isEmpty()){
 | 
	
		
			
				|  |  | +            options.put("qrcodeNo", qrcodeNo);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(idcard != null && !idcard.isEmpty()){
 | 
	
		
			
				|  |  | +            options.put("idcard", idcard);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        MApplication.getApiService().getValidList( options, System.currentTimeMillis() / 1000)
 | 
	
		
			
				|  |  | +                .compose(RxUtil.applyObservableAsync())
 | 
	
		
			
				|  |  | +                .subscribe(new ResponseConsumer<JSONObject>() {
 | 
	
		
			
				|  |  | +                    @Override
 | 
	
		
			
				|  |  | +                    public void onSuccess(JSONObject data) {
 | 
	
		
			
				|  |  | +                        JSONArray rows = data.getJSONArray("list");
 | 
	
		
			
				|  |  | +                        for (int i = 0; i < rows.size(); i++) {
 | 
	
		
			
				|  |  | +                            rows.getJSONObject(i).put("checkedStatus", false);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        dataList = rows;
 | 
	
		
			
				|  |  | +                        if(dataList.size() > 0){
 | 
	
		
			
				|  |  | +                            immediately_btn.setBackgroundColor(getResources().getColor(R.color.login_bk));
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            immediately_btn.setBackgroundColor(getResources().getColor(R.color.gray));
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        if (rows != null && !rows.isEmpty()){
 | 
	
		
			
				|  |  | +                            List<handleBean> rowbeans = JSONArray.parseArray(JSON.toJSONString(rows), handleBean.class);
 | 
	
		
			
				|  |  | +                            reflashLoadData(rowbeans, cleaned);
 | 
	
		
			
				|  |  | +                            emptyShow(false);
 | 
	
		
			
				|  |  | +                        }else {
 | 
	
		
			
				|  |  | +                            emptyShow(true);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        reflashFinish();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    @Override
 | 
	
		
			
				|  |  | +                    public void onFailed(int code, String msg) {
 | 
	
		
			
				|  |  | +                        reflashFinish();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }, new ErrorConsumer());
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void emptyShow(boolean empty){
 | 
	
		
			
				|  |  | +        if (empty){
 | 
	
		
			
				|  |  | +            tx_noDataShow.setVisibility(View.VISIBLE);
 | 
	
		
			
				|  |  | +            refreshLayout.setVisibility(View.GONE);
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            refreshLayout.setVisibility(View.VISIBLE);
 | 
	
		
			
				|  |  | +            tx_noDataShow.setVisibility(View.GONE);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void reflashLoadData(List<handleBean> rows, boolean cleared){
 | 
	
		
			
				|  |  | +        if (adapter == null){
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (cleared){
 | 
	
		
			
				|  |  | +            adapter.clearDatas();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        adapter.addDatas(rows);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 核销提交
 | 
	
		
			
				|  |  | +    private void orderSubmit(){
 | 
	
		
			
				|  |  | +        JSONObject options = new  JSONObject();
 | 
	
		
			
				|  |  | +        JSONArray listObj = new JSONArray();
 | 
	
		
			
				|  |  | +        for (int i = 0; i < dataList.size(); i++) {
 | 
	
		
			
				|  |  | +            if(dataList.getJSONObject(i).getBooleanValue("checkedStatus")){
 | 
	
		
			
				|  |  | +                listObj.add(dataList.getJSONObject(i));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(listObj == null || listObj.size() == 0) {
 | 
	
		
			
				|  |  | +            Toast msg = Toast.makeText(this, "请勾选需要核销的数据!", Toast.LENGTH_SHORT);
 | 
	
		
			
				|  |  | +//            msg.setGravity(Gravity.CENTER, 0, 0);
 | 
	
		
			
				|  |  | +            msg.show();
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        String [] list = new String[listObj.size()];
 | 
	
		
			
				|  |  | +        for (int i = 0; i < listObj.size(); i++) {
 | 
	
		
			
				|  |  | +            if(listObj.getJSONObject(i).getBooleanValue("checkedStatus")){
 | 
	
		
			
				|  |  | +                list[i] = listObj.getJSONObject(i).getString("id");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        options.put("viewerIds", list);
 | 
	
		
			
				|  |  | +        progressDialog = MaskUtil.showProgressDialog( "正在提交...", PurchaseInfoActivity.this);
 | 
	
		
			
				|  |  | +        new Handler().postDelayed(() -> {
 | 
	
		
			
				|  |  | +            if(progressDialog != null){
 | 
	
		
			
				|  |  | +                progressDialog.dismiss();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }, 30000);
 | 
	
		
			
				|  |  | +        MApplication.getApiService().orderSubmit( options, System.currentTimeMillis() / 1000)
 | 
	
		
			
				|  |  | +                .compose(RxUtil.applyObservableAsync())
 | 
	
		
			
				|  |  | +                .subscribe(new ResponseConsumer<JSONObject>() {
 | 
	
		
			
				|  |  | +                    @Override
 | 
	
		
			
				|  |  | +                    public void onSuccess(JSONObject data) {
 | 
	
		
			
				|  |  | +                        if(progressDialog != null){
 | 
	
		
			
				|  |  | +                            progressDialog.dismiss();
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        if(data.get("wipeStatus") != null && data.getInteger("wipeStatus") == 0) {
 | 
	
		
			
				|  |  | +                            ActivityUtils.launchActivity(PurchaseInfoActivity.this,WriteOffSuccessActivity.class);
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            Bundle bundle = new Bundle();
 | 
	
		
			
				|  |  | +                            bundle.putString("errReason", data.getString("errReason"));
 | 
	
		
			
				|  |  | +                            ActivityUtils.launchActivity(PurchaseInfoActivity.this,WriteOffFailActivity.class, bundle);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    @Override
 | 
	
		
			
				|  |  | +                    public void onFailed(int code, String msg) {
 | 
	
		
			
				|  |  | +                        if(progressDialog != null){
 | 
	
		
			
				|  |  | +                            progressDialog.dismiss();
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }, new ErrorConsumer());
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +}
 |