AGVPickupFra.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. package com.uas.bgdq.fragment;
  2. import android.graphics.Color;
  3. import android.text.TextUtils;
  4. import android.view.KeyEvent;
  5. import android.view.View;
  6. import android.widget.AdapterView;
  7. import android.widget.ArrayAdapter;
  8. import android.widget.Button;
  9. import android.widget.LinearLayout;
  10. import android.widget.RelativeLayout;
  11. import android.widget.Spinner;
  12. import android.widget.TextView;
  13. import com.alibaba.fastjson.JSON;
  14. import com.alibaba.fastjson.JSONObject;
  15. import com.android.volley.Request;
  16. import com.android.volley.toolbox.StringRequest;
  17. import com.uas.bgdq.R;
  18. import com.uas.bgdq.activity.FunctionActivity;
  19. import com.uas.bgdq.global.GloableParams;
  20. import com.uas.bgdq.listener.MyEditorActionListener;
  21. import com.uas.bgdq.util.CommonUtil;
  22. import com.uas.bgdq.util.FastjsonUtil;
  23. import com.uas.bgdq.util.HttpCallback;
  24. import com.uas.bgdq.util.HttpParams;
  25. import com.uas.bgdq.util.StringUtil;
  26. import com.uas.bgdq.util.VolleyRequest;
  27. import com.uas.bgdq.view.ClearableEditText;
  28. import org.json.JSONException;
  29. import java.util.ArrayList;
  30. import java.util.List;
  31. public
  32. /**
  33. * Created by sw on 2024-12-23
  34. */
  35. class AGVPickupFra extends BaseFragment {
  36. private Spinner masterSpinner;
  37. private String selectedItem = "无";
  38. static ArrayAdapter adapter;
  39. private List<String> masterFuncList;
  40. private StringRequest mStringRequest;
  41. private ClearableEditText mBarcodeEditText;
  42. private Button bt_pickup, bt_cancel_pickup;
  43. private LinearLayout ll_content;
  44. private RelativeLayout rl_msg;
  45. private TextView tv_msg_result, tv_barcode_value, tv_liaohao_value, tv_number_value,
  46. tv_name_value, tv_spec_value, tv_location_value, tv_msg_value;
  47. @Override
  48. protected int getLayout() {
  49. return R.layout.fragment_agv_pickup;
  50. }
  51. @Override
  52. protected void initViews() {
  53. FunctionActivity.setTitle(getResources().getString(R.string.agv_pickup));
  54. masterSpinner = (Spinner) root.findViewById(R.id.sp_login);
  55. mBarcodeEditText = root.findViewById(R.id.barcode_info_collect_barcode_et);
  56. bt_pickup = root.findViewById(R.id.bt_pickup);
  57. bt_cancel_pickup = root.findViewById(R.id.bt_cancel_pickup);
  58. ll_content = root.findViewById(R.id.ll_content);
  59. rl_msg = root.findViewById(R.id.rl_msg);
  60. tv_msg_result = root.findViewById(R.id.tv_msg_result);
  61. tv_barcode_value = root.findViewById(R.id.tv_barcode_value);
  62. tv_liaohao_value = root.findViewById(R.id.tv_liaohao_value);
  63. tv_number_value = root.findViewById(R.id.tv_number_value);
  64. tv_name_value = root.findViewById(R.id.tv_name_value);
  65. tv_spec_value = root.findViewById(R.id.tv_spec_value);
  66. tv_location_value = root.findViewById(R.id.tv_location_value);
  67. tv_msg_value = root.findViewById(R.id.tv_msg_value);
  68. masterFuncList = new ArrayList<String>();
  69. mBarcodeEditText.requestFocus();
  70. }
  71. @Override
  72. protected void initEvents() {
  73. masterSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  74. @Override
  75. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  76. //选中值
  77. selectedItem = parent.getItemAtPosition(position).toString();
  78. }
  79. @Override
  80. public void onNothingSelected(AdapterView<?> parent) {
  81. }
  82. });
  83. CommonUtil.setEditorActionListener(mBarcodeEditText, new MyEditorActionListener() {
  84. @Override
  85. public void MyEditorAction(String text, int actionId, KeyEvent event) {
  86. getBarAcceptCode(text);
  87. }
  88. });
  89. bt_pickup.setOnClickListener(new View.OnClickListener() {
  90. @Override
  91. public void onClick(View v) {
  92. getPickUp(selectedItem,mBarcodeEditText.getText().toString().trim());
  93. }
  94. });
  95. bt_cancel_pickup.setOnClickListener(new View.OnClickListener() {
  96. @Override
  97. public void onClick(View v) {
  98. getCancelPickUp(mBarcodeEditText.getText().toString().trim());
  99. }
  100. });
  101. }
  102. private void getBarAcceptCode(String barcode) {
  103. if (StringUtil.isEmpty(barcode)) {
  104. CommonUtil.toastNoRepeat(mActivity, "请输入条码号");
  105. return;
  106. }
  107. progressDialog.show();
  108. try {
  109. VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
  110. .url(GloableParams.ADDRESS_AGVOUTGETBAR)
  111. .method(Request.Method.GET)
  112. .addParam("barcode", barcode)
  113. .build(), new HttpCallback() {
  114. @Override
  115. public void onSuccess(int flag, Object o) throws Exception {
  116. progressDialog.dismiss();
  117. try {
  118. JSONObject dataObject = FastjsonUtil.getJSONObject(o.toString(), "data");
  119. String BAR_PRODCODE = dataObject.getString("BAR_PRODCODE") == null ? "" : dataObject.getString("BAR_PRODCODE");
  120. String PR_DETAIL = dataObject.getString("PR_DETAIL") == null ? "" : dataObject.getString("PR_DETAIL");
  121. String PR_SPEC = dataObject.getString("PR_SPEC") == null ? "" : dataObject.getString("PR_SPEC");
  122. String PR_ORISPECCODE = dataObject.getString("PR_ORISPECCODE") == null ? "" : dataObject.getString("PR_ORISPECCODE");
  123. String BAR_LOCATION = dataObject.getString("BAR_LOCATION") == null ? "" : dataObject.getString("BAR_LOCATION");
  124. String BAR_CODE = dataObject.getString("BAR_CODE") == null ? "" : dataObject.getString("BAR_CODE");
  125. String BAR_REMAIN = dataObject.getString("BAR_REMAIN") == null ? "" : dataObject.getString("BAR_REMAIN");
  126. String BAR_WHCODE = dataObject.getString("BAR_WHCODE") == null ? "" : dataObject.getString("BAR_WHCODE");
  127. String ok = dataObject.getString("ok") == null ? "" : dataObject.getString("ok");
  128. String msg = dataObject.getString("msg") == null ? "" : dataObject.getString("msg");
  129. tv_msg_result.setVisibility(View.GONE);
  130. tv_msg_result.setText("");
  131. ll_content.setVisibility(View.VISIBLE);
  132. String barCode = mBarcodeEditText.getText().toString().trim();
  133. mBarcodeEditText.setText("");
  134. tv_barcode_value.setText(BAR_CODE);
  135. tv_liaohao_value.setText(BAR_PRODCODE);
  136. tv_number_value.setText(BAR_REMAIN);
  137. tv_name_value.setText(PR_DETAIL);
  138. tv_spec_value.setText(PR_SPEC);
  139. tv_location_value.setText(BAR_LOCATION);
  140. if (!TextUtils.isEmpty(msg)) {
  141. rl_msg.setVisibility(View.VISIBLE);
  142. tv_msg_value.setText(msg);
  143. }
  144. if (!TextUtils.isEmpty(ok) && ok.equals("1")) {
  145. //ok 的值是1 ,则自动再发送取货按钮的请求
  146. //ok 的值是0 ,则只展示数据
  147. getPickUp(selectedItem,barCode);
  148. }
  149. }catch (Exception e){
  150. e.printStackTrace();
  151. }
  152. }
  153. @Override
  154. public void onFail(int flag, String failStr) throws Exception {
  155. progressDialog.dismiss();
  156. CommonUtil.toastNoRepeat(mActivity, failStr);
  157. tv_msg_result.setTextColor(Color.RED);
  158. tv_msg_result.setVisibility(View.VISIBLE);
  159. ll_content.setVisibility(View.GONE);
  160. rl_msg.setVisibility(View.GONE);
  161. tv_msg_result.setText(failStr);
  162. mBarcodeEditText.requestFocus();
  163. mBarcodeEditText.setText(null);
  164. }
  165. });
  166. } catch (Exception e) {
  167. e.printStackTrace();
  168. }
  169. }
  170. private void getPickUp(String trackNo,String barcode) {
  171. if (StringUtil.isEmpty(barcode)) {
  172. CommonUtil.toastNoRepeat(mActivity, "请输入条码号");
  173. return;
  174. }
  175. progressDialog.show();
  176. try {
  177. VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
  178. .url(GloableParams.ADDRESS_AGV_OUT_PICKUP)
  179. .method(Request.Method.POST)
  180. .addParam("trackNo", trackNo)
  181. .addParam("barcode", barcode)
  182. .build(), new HttpCallback() {
  183. @Override
  184. public void onSuccess(int flag, Object o) throws Exception {
  185. progressDialog.dismiss();
  186. tv_msg_result.setVisibility(View.GONE);
  187. tv_msg_result.setText("");
  188. mBarcodeEditText.setText("");
  189. try {
  190. org.json.JSONObject resultObject = new org.json.JSONObject(o.toString());
  191. if (resultObject.optBoolean("success")) {
  192. tv_msg_result.setVisibility(View.VISIBLE);
  193. tv_msg_result.setTextColor(getResources().getColor(R.color.blue));
  194. tv_msg_result.setText("发送取货任务成功");
  195. }
  196. } catch (JSONException e) {
  197. e.printStackTrace();
  198. }
  199. }
  200. @Override
  201. public void onFail(int flag, String failStr) throws Exception {
  202. progressDialog.dismiss();
  203. CommonUtil.toastNoRepeat(mActivity, failStr);
  204. tv_msg_result.setTextColor(Color.RED);
  205. tv_msg_result.setVisibility(View.VISIBLE);
  206. ll_content.setVisibility(View.GONE);
  207. rl_msg.setVisibility(View.GONE);
  208. tv_msg_result.setText(failStr);
  209. mBarcodeEditText.requestFocus();
  210. mBarcodeEditText.setText(null);
  211. }
  212. });
  213. } catch (Exception e) {
  214. e.printStackTrace();
  215. }
  216. }
  217. private void getCancelPickUp(String barcode) {
  218. if (StringUtil.isEmpty(barcode)) {
  219. CommonUtil.toastNoRepeat(mActivity, "请输入条码号");
  220. return;
  221. }
  222. progressDialog.show();
  223. try {
  224. VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
  225. .url(GloableParams.ADDRESS_AGV_OUT_CANCEL_PICKUP)
  226. .method(Request.Method.POST)
  227. .addParam("barcode", barcode)
  228. .build(), new HttpCallback() {
  229. @Override
  230. public void onSuccess(int flag, Object o) throws Exception {
  231. progressDialog.dismiss();
  232. tv_msg_result.setVisibility(View.GONE);
  233. tv_msg_result.setText("");
  234. mBarcodeEditText.setText("");
  235. try {
  236. org.json.JSONObject resultObject = new org.json.JSONObject(o.toString());
  237. if (resultObject.optBoolean("success")) {
  238. tv_msg_result.setVisibility(View.VISIBLE);
  239. tv_msg_result.setTextColor(getResources().getColor(R.color.blue));
  240. tv_msg_result.setText("取消取货操作成功");
  241. }
  242. } catch (JSONException e) {
  243. e.printStackTrace();
  244. }
  245. }
  246. @Override
  247. public void onFail(int flag, String failStr) throws Exception {
  248. progressDialog.dismiss();
  249. CommonUtil.toastNoRepeat(mActivity, failStr);
  250. tv_msg_result.setTextColor(Color.RED);
  251. tv_msg_result.setVisibility(View.VISIBLE);
  252. ll_content.setVisibility(View.GONE);
  253. rl_msg.setVisibility(View.GONE);
  254. tv_msg_result.setText(failStr);
  255. mBarcodeEditText.requestFocus();
  256. mBarcodeEditText.setText(null);
  257. }
  258. });
  259. } catch (Exception e) {
  260. e.printStackTrace();
  261. }
  262. }
  263. @Override
  264. protected void initDatas() {
  265. getSpinnerData();
  266. }
  267. private void getSpinnerData() {
  268. progressDialog.show();
  269. VolleyRequest.getInstance().stringRequest(mStringRequest,
  270. new HttpParams.Builder()
  271. .url(GloableParams.ADDRESS_GETAGV_CODE)
  272. .method(Request.Method.GET)
  273. .tag(TAG)
  274. .flag(1)
  275. .build(), new HttpCallback() {
  276. @Override
  277. public void onSuccess(int flag, Object o) throws Exception {
  278. progressDialog.dismiss();
  279. try {
  280. masterFuncList.clear();
  281. String result = o.toString();
  282. com.alibaba.fastjson.JSONObject resultObject = JSON.parseObject(result);
  283. com.alibaba.fastjson.JSONArray dataArray = resultObject.getJSONArray("data");
  284. if (dataArray != null && dataArray.size() > 0) {
  285. for (Object index : dataArray) {
  286. com.alibaba.fastjson.JSONObject data = (com.alibaba.fastjson.JSONObject) index;
  287. String SH_CODE = data.getString("SH_CODE");
  288. masterFuncList.add(SH_CODE);
  289. }
  290. }
  291. if (masterFuncList.size() > 0) {
  292. adapter.notifyDataSetChanged();
  293. }
  294. } catch (Exception e) {
  295. e.printStackTrace();
  296. progressDialog.dismiss();
  297. }
  298. }
  299. @Override
  300. public void onFail(int flag, String failStr) throws Exception {
  301. progressDialog.dismiss();
  302. CommonUtil.toastNoRepeat(mActivity, failStr);
  303. }
  304. });
  305. adapter = new ArrayAdapter(mActivity, R.layout.item_spinner, R.id.text_spinner, masterFuncList);
  306. masterSpinner.setAdapter(adapter);
  307. }
  308. @Override
  309. public boolean onKeyDown(int keyCode, KeyEvent event) {
  310. return false;
  311. }
  312. @Override
  313. public boolean onFragmentBackPressed() {
  314. return false;
  315. }
  316. }