| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- package com.uas.yuejiahong.fragment;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Handler;
- import android.text.TextUtils;
- import android.view.KeyEvent;
- import android.view.View;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.android.volley.Request;
- import com.bin.david.form.core.SmartTable;
- import com.bin.david.form.data.column.Column;
- import com.bin.david.form.data.table.TableData;
- import com.bin.david.form.listener.OnColumnItemClickListener;
- import com.scwang.smartrefresh.layout.api.RefreshLayout;
- import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
- import com.uas.yuejiahong.R;
- import com.uas.yuejiahong.bean.LocationCheckBean;
- import com.uas.yuejiahong.global.GloableParams;
- import com.uas.yuejiahong.listener.MyEditorActionListener;
- import com.uas.yuejiahong.util.CameraUtil;
- import com.uas.yuejiahong.util.CommonUtil;
- import com.uas.yuejiahong.util.FastjsonUtil;
- import com.uas.yuejiahong.util.HttpCallback;
- import com.uas.yuejiahong.util.HttpParams;
- import com.uas.yuejiahong.util.VolleyRequest;
- import com.uas.yuejiahong.view.ClearableEditText;
- import com.uuzuche.lib_zxing.activity.CaptureActivity;
- import com.uuzuche.lib_zxing.activity.CodeUtils;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by RaoMeng on 2021/1/8
- * Desc: 移库
- */
- public class LocationTransferFragment extends BaseFragment implements OnColumnItemClickListener<String> {
- private static final int SCAN_BARCODE_CODE = 452;
- private ImageView mScanImageView;
- private int mFocusId;
- private ClearableEditText mOldLocationEditText, mNewLocationEditText,location_transfer_model,location_transfer_quantity;
- private TextView mOldLocationBtn, mNewLocationBtn,location_transfer_model_ok,location_transfer_quantity_ok;
- private SmartTable mSmartTable;
- private TableData<LocationCheckBean> mTableData;
- private Column<String>mBRANDColumn, mProdCodeColumn, mBarcodeColumn, mQuantityColumn;
- private List<LocationCheckBean> mLocationCheckBeans;
- private RefreshLayout mRefreshLayout;
- private int mPageIndex = 1, mPageSize = 20;
- private String mLocation;
- @Override
- protected int getLayout() {
- return R.layout.fragment_location_transfer;
- }
- @Override
- protected void initViews() {
- setTitle("移库");
- mScanImageView = (ImageView) mActivity.findViewById(R.id.btn_actionbar_scan_iv);
- mOldLocationEditText = root.findViewById(R.id.location_transfer_old_location_et);
- mNewLocationEditText = root.findViewById(R.id.location_transfer_new_location_et);
- mOldLocationBtn = root.findViewById(R.id.location_transfer_old_location_btn);
- mNewLocationBtn = root.findViewById(R.id.location_transfer_new_location_btn);
- mRefreshLayout = root.findViewById(R.id.location_transfer_info_srl);
- //型号
- location_transfer_model = root.findViewById(R.id.location_transfer_model);
- location_transfer_model_ok = root.findViewById(R.id.location_transfer_model_ok);
- //数量
- location_transfer_quantity = root.findViewById(R.id.location_transfer_quantity);
- location_transfer_quantity_ok = root.findViewById(R.id.location_transfer_quantity_ok);
- mRefreshLayout.setEnableAutoLoadMore(false);
- mRefreshLayout.setEnableRefresh(false);
- mSmartTable = root.findViewById(R.id.location_transfer_info_st);
- CommonUtil.getDefaultTable(mActivity, mSmartTable);
- mBRANDColumn = new Column<>("仓位", "BRAND");
- mProdCodeColumn = new Column<>("型号", "PRODCODE");
- mBarcodeColumn = new Column<>("物料编号", "BARCODE");
- mQuantityColumn = new Column<>("数量", "QUANTITY");
- mLocationCheckBeans = new ArrayList<>();
- setTableData(mLocationCheckBeans);
- mOldLocationEditText.requestFocus();
- }
- @Override
- protected void initEvents() {
- mScanImageView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (CameraUtil.hasCamera()) {
- if (root.findFocus() != null) {
- mFocusId = root.findFocus().getId();
- Intent intent = new Intent();
- intent.setClass(mActivity, CaptureActivity.class);
- startActivityForResult(intent, SCAN_BARCODE_CODE);
- }
- } else {
- CommonUtil.toastNoRepeat(mActivity, getString(R.string.no_camera_detected));
- }
- }
- });
- // CommonUtil.setEditorActionListener(mOldLocationEditText, new MyEditorActionListener() {
- // @Override
- // public void MyEditorAction(String text, int actionId, KeyEvent event) {
- // mPageIndex = 1;
- // mLocation = text.trim();
- // searchByLocation();
- // }
- // });
- mOldLocationBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mPageIndex = 1;
- mLocation = mOldLocationEditText.getText().toString().trim();
- searchByLocation();
- }
- });
- mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
- @Override
- public void onLoadMore(RefreshLayout refreshLayout) {
- mPageIndex++;
- searchByLocation();
- }
- });
- CommonUtil.setEditorActionListener(mNewLocationEditText, new MyEditorActionListener() {
- @Override
- public void MyEditorAction(String text, int actionId, KeyEvent event) {
- transferToNewLocation();
- }
- });
- mNewLocationBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- transferToNewLocation();
- }
- });
- }
- @Override
- protected void initDatas() {
- mBRANDColumn.setOnColumnItemClickListener(this);
- mProdCodeColumn.setOnColumnItemClickListener(this);
- mBarcodeColumn.setOnColumnItemClickListener(this);
- mQuantityColumn.setOnColumnItemClickListener(this);
- }
- private void transferToNewLocation() {
- String location_transfer_modeltrim = location_transfer_model.getText().toString().trim();
- String location_transfer_quantitytrim = location_transfer_quantity.getText().toString().trim();
- String trim = mNewLocationEditText.getText().toString().trim();//
- mLocation = mOldLocationEditText.getText().toString().trim();
- if (TextUtils.isEmpty(mLocation)) {
- CommonUtil.toastNoRepeat(mActivity, "请采集旧库位");
- return;
- }
- if (TextUtils.isEmpty(location_transfer_modeltrim)) {
- CommonUtil.toastNoRepeat(mActivity, "物料编码不可为空");
- return;
- }
- if (TextUtils.isEmpty(location_transfer_quantitytrim)) {
- CommonUtil.toastNoRepeat(mActivity, "数量不可为空");
- return;
- }
- String newLocation = mNewLocationEditText.getText().toString().trim();
- if (TextUtils.isEmpty(mLocation)) {
- CommonUtil.toastNoRepeat(mActivity, "请采集新库位");
- return;
- }
- if (TextUtils.isEmpty(trim)) {
- CommonUtil.toastNoRepeat(mActivity, "请采集新库位");
- return;
- }
- progressDialog.show();
- VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
- .url(GloableParams.ADDRESS_TRANSFER_TRANSFERTONEWLOCATION)
- .method(Request.Method.POST)
- .addParam("fromLo", mLocation)
- .addParam("toLo", newLocation)
- .addParam("prcode",location_transfer_modeltrim)//物料编号
- .addParam("qty",location_transfer_quantitytrim)//数量
- .build(), new HttpCallback() {
- @Override
- public void onSuccess(int flag, Object o) throws Exception {
- progressDialog.dismiss();
- try {
- mOldLocationEditText.setText("");
- mNewLocationEditText.setText("");
- location_transfer_quantity.setText("");
- location_transfer_model.setText("");
- mLocation = "";
- mLocationCheckBeans.clear();
- setTableData(mLocationCheckBeans);
- CommonUtil.toastNoRepeat(mActivity, "移库成功");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onFail(int flag, String failStr) throws Exception {
- progressDialog.dismiss();
- CommonUtil.toastNoRepeat(mActivity, failStr);
- }
- });
- }
- private void searchByLocation() {
- mLocation = mOldLocationEditText.getText().toString().trim();
- String location_transfer_modeltrim = location_transfer_model.getText().toString().trim();
- if (TextUtils.isEmpty(mLocation)&&TextUtils.isEmpty(location_transfer_modeltrim)) {
- CommonUtil.toastNoRepeat(mActivity, "请采集旧库位");
- mRefreshLayout.finishLoadMore(0);
- return;
- }
- if (!mRefreshLayout.isLoading() && !mRefreshLayout.isRefreshing()) {
- progressDialog.show();
- }
- VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
- .url(GloableParams.ADDRESS_BARSTOCK_SEARCHBYLOCATION)
- .method(Request.Method.POST)
- .addParam("location", mLocation)
- .addParam("page", mPageIndex + "")
- .addParam("pagesize", mPageSize + "")
- .addParam("prodcode", location_transfer_modeltrim)//值为物料编号
- .build(), new HttpCallback() {
- @Override
- public void onSuccess(int flag, Object o) throws Exception {
- progressDialog.dismiss();
- mRefreshLayout.finishRefresh(0);
- mRefreshLayout.finishLoadMore(0);
- try {
- if (mPageIndex == 1) {
- mLocationCheckBeans.clear();
- }
- String result = o.toString();
- JSONObject resultObject = JSON.parseObject(result);
- JSONArray dataArray = resultObject.getJSONArray("data");
- List<LocationCheckBean> locationCheckBeans = new ArrayList<>();
- if (dataArray != null && dataArray.size() > 0) {
- location_transfer_quantity.requestFocus();
- for (int i = 0; i < dataArray.size(); i++) {
- JSONObject dataObject = dataArray.getJSONObject(i);
- if (dataObject != null) {
- LocationCheckBean locationCheckBean = new LocationCheckBean();
- locationCheckBean.setProdcode(FastjsonUtil.getText(dataObject, "PN"));
- locationCheckBean.setBarcode(FastjsonUtil.getText(dataObject, "BARCODE"));
- locationCheckBean.setQuantity(FastjsonUtil.getText(dataObject, "QTY"));
- locationCheckBean.setBrand(FastjsonUtil.getText(dataObject, "BRAND"));
- locationCheckBeans.add(locationCheckBean);
- }
- }
- } else {
- if (mPageIndex == 1) {
- mOldLocationEditText.setText("");
- mOldLocationEditText.requestFocus();
- CommonUtil.toastNoRepeat(mActivity, "数据为空");
- } else {
- CommonUtil.toastNoRepeat(mActivity, "没有更多数据");
- }
- }
- if (mPageIndex == 1) {
- mLocationCheckBeans = locationCheckBeans;
- setTableData(locationCheckBeans);
- } else if (locationCheckBeans.size() > 0) {
- mLocationCheckBeans.addAll(locationCheckBeans);
- mSmartTable.addData(locationCheckBeans, true);
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- mSmartTable.postInvalidate();
- }
- }, 100);
- } else {
- mPageIndex--;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onFail(int flag, String failStr) throws Exception {
- progressDialog.dismiss();
- mOldLocationEditText.setText("");
- CommonUtil.makeNotice();
- CommonUtil.toastNoRepeat(mActivity, failStr);
- mRefreshLayout.finishRefresh(0);
- mRefreshLayout.finishLoadMore(0);
- if (mPageIndex > 1) {
- mPageIndex--;
- } else {
- setTableData(new ArrayList<>());
- }
- }
- });
- }
- private void setTableData(List<LocationCheckBean> locationCheckBeans) {
- mTableData = new TableData<LocationCheckBean>("库位提示", locationCheckBeans,
- mBRANDColumn,mProdCodeColumn, mBarcodeColumn, mQuantityColumn);
- mSmartTable.setTableData(mTableData);
- mSmartTable.postDelayed(new Runnable() {
- @Override
- public void run() {
- mSmartTable.postInvalidate();
- }
- }, 100);
- }
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (resultCode != Activity.RESULT_OK) {
- return;
- }
- if (requestCode == SCAN_BARCODE_CODE && data != null) {
- if (data.getExtras() != null) {
- String result = data.getExtras().getString(CodeUtils.RESULT_STRING);
- if (mFocusId == R.id.location_transfer_old_location_et) {
- mOldLocationEditText.setText(result);
- mOldLocationEditText.setSelection(result.length());
- } else if (mFocusId == R.id.location_transfer_new_location_et) {
- mNewLocationEditText.setText(result);
- mNewLocationEditText.setSelection(result.length());
- }
- }
- }
- }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- return false;
- }
- @Override
- public boolean onFragmentBackPressed() {
- return false;
- }
- @Override
- public void onClick(Column<String> column, String s, String s2, int position) {
- LocationCheckBean locationCheckBean = mLocationCheckBeans.get(position);
- String barcode = locationCheckBean.getBarcode();
- location_transfer_model.setText(barcode);
- }
- }
|