|
|
@@ -2,20 +2,27 @@ package com.uas.rxusames.fragment;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.drawable.BitmapDrawable;
|
|
|
+import android.os.Bundle;
|
|
|
import android.support.v7.widget.DefaultItemAnimator;
|
|
|
import android.support.v7.widget.DividerItemDecoration;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.util.Log;
|
|
|
import android.util.SparseBooleanArray;
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.widget.ArrayAdapter;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.CheckBox;
|
|
|
import android.widget.LinearLayout;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.PopupWindow;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -25,19 +32,28 @@ import com.android.volley.Request;
|
|
|
import com.android.volley.toolbox.StringRequest;
|
|
|
import com.uas.rxusames.R;
|
|
|
import com.uas.rxusames.activity.FunctionActivity;
|
|
|
+import com.uas.rxusames.bean.CaiPiBlueBean;
|
|
|
import com.uas.rxusames.bean.MaintainitemBean;
|
|
|
import com.uas.rxusames.global.GloableParams;
|
|
|
import com.uas.rxusames.tools.SharedPreUtil;
|
|
|
import com.uas.rxusames.util.CommonUtil;
|
|
|
+import com.uas.rxusames.util.Constants;
|
|
|
import com.uas.rxusames.util.FastjsonUtil;
|
|
|
+import com.uas.rxusames.util.FragmentUtils;
|
|
|
import com.uas.rxusames.util.HttpCallback;
|
|
|
import com.uas.rxusames.util.HttpParams;
|
|
|
import com.uas.rxusames.util.LogUtil;
|
|
|
+import com.uas.rxusames.util.PrintUtils;
|
|
|
+import com.uas.rxusames.util.StringUtil;
|
|
|
+import com.uas.rxusames.util.VolleyRequest;
|
|
|
import com.uas.rxusames.util.VollyRequest;
|
|
|
+import com.uas.rxusames.view.ClearableEditText;
|
|
|
+import com.vincent.filepicker.ToastUtil;
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by RaoMeng on 2024/05/27
|
|
|
@@ -53,6 +69,15 @@ public class PreProcessingReportFragment extends BaseFragment implements View.On
|
|
|
private String ma_code;
|
|
|
private String sc_code;
|
|
|
private TextView tv_ma_code;
|
|
|
+ private ClearableEditText ct_qty;
|
|
|
+ private ClearableEditText ct_sum;
|
|
|
+ private List<CaiPiBlueBean.DataBean> messages = new ArrayList<>();
|
|
|
+ private PopupWindow splitPop;
|
|
|
+ private boolean isConnected = false;
|
|
|
+ private boolean isPrinting = false;
|
|
|
+ private int mPrintDpi = 203;
|
|
|
+ private JSONArray dataArray;
|
|
|
+ private Button btn_oneprint;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
@@ -65,16 +90,46 @@ public class PreProcessingReportFragment extends BaseFragment implements View.On
|
|
|
((FunctionActivity) getActivity()).setMoreBtnVisible(false);
|
|
|
mRecyclerView = root.findViewById(R.id.feeded_rv);
|
|
|
tv_ma_code = root.findViewById(R.id.tv_ma_code);
|
|
|
+ ct_qty = root.findViewById(R.id.ct_qty);
|
|
|
+ ct_sum = root.findViewById(R.id.ct_sum);
|
|
|
+ btn_oneprint = root.findViewById(R.id.btn_oneprint);
|
|
|
jlt_storage_in_barcode_save_btn = root.findViewById(R.id.jlt_storage_in_barcode_save_btn);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ public static String removeBrackets(String input) {
|
|
|
+ // 去除前后的中括号
|
|
|
+ if (input.startsWith("[") && input.endsWith("]")) {
|
|
|
+ input = input.substring(1, input.length() - 1);
|
|
|
+ }
|
|
|
+ return input;
|
|
|
+ }
|
|
|
@Override
|
|
|
protected void initEvents() {
|
|
|
+ getPrintTemplate();
|
|
|
+ btn_oneprint.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+
|
|
|
+
|
|
|
+ if (dataArray != null && dataArray.size() > 0) {
|
|
|
+ printEvent(dataArray);
|
|
|
+ }else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "数据为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
jlt_storage_in_barcode_save_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
+ if (StringUtil.isEmpty(ct_sum.getText().toString().trim())){
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "请输入报工数");
|
|
|
+ return;
|
|
|
+ }
|
|
|
ArrayList<MaintainitemBean> selectedItem = myAdapter.getSelectedItem();
|
|
|
if (selectedItem==null||selectedItem.size()==0){
|
|
|
CommonUtil.toastNoRepeat(mActivity, "请选择料号");
|
|
|
@@ -172,13 +227,18 @@ public class PreProcessingReportFragment extends BaseFragment implements View.On
|
|
|
.addParam("ma_code",ma_code)
|
|
|
.addParam("sc_code",sc_code)
|
|
|
.addParam("prods",prods)
|
|
|
+ .addParam("decode",ct_qty.getText().toString().trim())
|
|
|
+ .addParam("reportqty",ct_sum.getText().toString().trim())
|
|
|
.build(), new HttpCallback() {
|
|
|
@Override
|
|
|
public void onSuccess(int flag, Object o) throws Exception {
|
|
|
progressDialog.dismiss();
|
|
|
- String data = FastjsonUtil.getText(o.toString(), "data");
|
|
|
- CommonUtil.toastNoRepeat(mActivity, data.toString()+"");
|
|
|
|
|
|
+ dataArray = FastjsonUtil.getJSONArray(o.toString(), "data");
|
|
|
+
|
|
|
+ ToastUtil.getInstance(mActivity).showToast("报工成功");
|
|
|
+// initBreakPopupWindow(dataArray);
|
|
|
+ printEvent(dataArray);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -194,6 +254,206 @@ public class PreProcessingReportFragment extends BaseFragment implements View.On
|
|
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
+ //org.json.
|
|
|
+ protected void initBreakPopupWindow(com.alibaba.fastjson.JSONArray listArray) {
|
|
|
+ messages.clear();
|
|
|
+ for (int i = 1; i < listArray.size(); i++) {
|
|
|
+ try {
|
|
|
+ com.alibaba.fastjson.JSONObject barcodeObject = listArray.getJSONObject(i);
|
|
|
+
|
|
|
+ if (barcodeObject != null) {
|
|
|
+ CaiPiBlueBean.DataBean dataBean=new CaiPiBlueBean.DataBean();
|
|
|
+// dataBean.setLotno(JsonUtils.optStringNotNull(barcodeObject, "LOTNO"));
|
|
|
+// dataBean.setQty(JsonUtils.optStringNotNull(barcodeObject, "QTY"));
|
|
|
+ dataBean.setLotno(barcodeObject.getString("LOTNO"));
|
|
|
+ dataBean.setQty(barcodeObject.getString("QTY"));
|
|
|
+ messages.add(dataBean);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ View popView = LayoutInflater.from(getActivity()).inflate(R.layout.popupwindow_whbreaking_batch, null);
|
|
|
+ ListView listView = (ListView) popView.findViewById(R.id.list_view);
|
|
|
+ Button btnPrintf = (Button) popView.findViewById(R.id.btn_print);
|
|
|
+ Button btnPrintfSet = (Button) popView.findViewById(R.id.btn_print_setting);
|
|
|
+ Button btnClose = (Button) popView.findViewById(R.id.btn_close);
|
|
|
+ Button btnBack = (Button) popView.findViewById(R.id.btn_back);
|
|
|
+
|
|
|
+ btnBack.setVisibility(View.GONE);
|
|
|
+ btnClose.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closeSplitPopupWindow();
|
|
|
+// }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ btnPrintf.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (isConnected) {
|
|
|
+ progressDialog.show();
|
|
|
+ listArray.remove(0);
|
|
|
+ printEvent(listArray);
|
|
|
+ } else {
|
|
|
+ closeSplitPopupWindow();
|
|
|
+ BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
|
|
|
+
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, listArray.toString());
|
|
|
+ Log.e("listArrayone",listArray.toString());
|
|
|
+ blueToothPrintFragment.setArguments(bundle);
|
|
|
+ FragmentUtils.switchFragment(PreProcessingReportFragment.this, blueToothPrintFragment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ btnPrintfSet.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closeSplitPopupWindow();
|
|
|
+ BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
|
|
|
+
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, listArray.toString());
|
|
|
+ Log.e("listArraytwo",listArray.toString());
|
|
|
+ blueToothPrintFragment.setArguments(bundle);
|
|
|
+ FragmentUtils.switchFragment(PreProcessingReportFragment.this, blueToothPrintFragment);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ MyAdapter adapter = new MyAdapter(getActivity(), R.layout.item_list_whbreakingbatchfragment, messages);
|
|
|
+ listView.setAdapter(adapter);
|
|
|
+ //当只有一条数据的时候可以加上
|
|
|
+ /*
|
|
|
+ if (messages.size()>1){
|
|
|
+ btnBack.setVisibility(View.GONE);
|
|
|
+ }*/
|
|
|
+ // PopupWindow实例化,参数的意思是 view,长(不包括状态栏),高(不包括状态栏),是否聚焦
|
|
|
+ splitPop = new PopupWindow(popView, LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
|
|
+ splitPop.setAnimationStyle(R.style.MenuAnimationFade);
|
|
|
+ splitPop.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ // 弹出窗口显示内容视图,默认以锚定视图的左下角为起点,这里为点击按钮
|
|
|
+ splitPop.showAtLocation(getActivity().getWindow().getDecorView(), Gravity.CENTER, 0, 0);
|
|
|
+ splitPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closeSplitPopupWindow();
|
|
|
+// specialOut();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommonUtil.setBackgroundAlpha(mActivity, 0.5f);
|
|
|
+
|
|
|
+ }
|
|
|
+ private void closeSplitPopupWindow() {
|
|
|
+ if (splitPop != null) {
|
|
|
+ splitPop.dismiss();
|
|
|
+ splitPop = null;
|
|
|
+ CommonUtil.setBackgroundAlpha(mActivity, 1f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void getPrintTemplate() {
|
|
|
+ VolleyRequest.getInstance().stringRequest(mStringRequest,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_BARINFO_PRINTMODEL)
|
|
|
+ .method(Request.Method.GET)
|
|
|
+ .flag(0)
|
|
|
+ .tag("barinfoPrint")
|
|
|
+ .addParam("caller", "PreBarcode")//Barcode!PDAPrint仓库
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ try {
|
|
|
+ String result = o.toString();
|
|
|
+ Log.e("prints", result);
|
|
|
+ if (FastjsonUtil.validate(result)) {
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ JSONArray dataArray = resultObject.getJSONArray("data");
|
|
|
+ if (dataArray != null && dataArray.size() > 0) {
|
|
|
+ SharedPreUtil.saveString(mActivity, Constants.FLAG.PRINT_TEMPLATE_CACHE, dataArray.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ Log.e("printf", failStr);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void printEvent(com.alibaba.fastjson.JSONArray printArray) {
|
|
|
+ if (isPrinting) {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "正在打印中,请勿重复操作");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ isPrinting = true;
|
|
|
+ if (printArray != null && printArray.size() > 0) {
|
|
|
+ boolean isFail = false;
|
|
|
+ for (int i = 0; i < printArray.size(); i++) {
|
|
|
+ try {
|
|
|
+ JSONObject printObject = printArray.getJSONObject(i);
|
|
|
+ int printResult = PrintUtils.printBar(mActivity, printObject.toString(), mPrintDpi, null);
|
|
|
+ if (printResult <= 0) {
|
|
|
+ isFail = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closeSplitPopupWindow();
|
|
|
+ progressDialog.dismiss();
|
|
|
+ if (isFail) {
|
|
|
+ isConnected = false;
|
|
|
+ SharedPreUtil.saveInt(mActivity, "printConnect", 0);
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印失败,请重新连接打印机");
|
|
|
+
|
|
|
+ BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
|
|
|
+
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, printArray.toString());
|
|
|
+ Log.e("listArraythree",printArray.toString());
|
|
|
+ blueToothPrintFragment.setArguments(bundle);
|
|
|
+ FragmentUtils.switchFragment(PreProcessingReportFragment.this, blueToothPrintFragment);
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印成功");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印失败,条码数据为空");
|
|
|
+ }
|
|
|
+ isPrinting = false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private class MyAdapter extends ArrayAdapter<CaiPiBlueBean.DataBean> {
|
|
|
+ private int resourceId;
|
|
|
+
|
|
|
+ public MyAdapter(Context context, int resource, List<CaiPiBlueBean.DataBean> objects) {
|
|
|
+ super(context, resource, objects);
|
|
|
+ resourceId = resource;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
+ CaiPiBlueBean.DataBean person = getItem(position);
|
|
|
+ convertView = LayoutInflater.from(getContext()).inflate(resourceId,
|
|
|
+ null);
|
|
|
+ TextView tv_bar_code = (TextView) convertView.findViewById(R.id.tv_bar_code);
|
|
|
+ TextView tv_bar_remain = (TextView) convertView.findViewById(R.id.tv_bar_remain);
|
|
|
+ tv_bar_code.setText(person.getLotno());
|
|
|
+ tv_bar_remain.setText(person.getQty());
|
|
|
+ return convertView;
|
|
|
+ }
|
|
|
}
|
|
|
@Override
|
|
|
public void onHiddenChanged(boolean hidden) {
|