SCSMTInFragment.java 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. package com.uas.uaspda.fragment;
  2. import android.content.Context;
  3. import android.os.Handler;
  4. import android.os.Message;
  5. import android.text.SpannableString;
  6. import android.text.TextUtils;
  7. import android.util.Log;
  8. import android.view.KeyEvent;
  9. import android.view.View;
  10. import android.view.inputmethod.EditorInfo;
  11. import android.view.inputmethod.InputMethodManager;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.RelativeLayout;
  15. import android.widget.TextView;
  16. import com.alibaba.fastjson.JSON;
  17. import com.android.volley.AuthFailureError;
  18. import com.android.volley.DefaultRetryPolicy;
  19. import com.android.volley.Request;
  20. import com.android.volley.Response;
  21. import com.android.volley.VolleyError;
  22. import com.android.volley.toolbox.StringRequest;
  23. import com.uas.uaspda.R;
  24. import com.uas.uaspda.application.PdaApplication;
  25. import com.uas.uaspda.bean.LineInfoBean;
  26. import com.uas.uaspda.bean.SmtDslBean;
  27. import com.uas.uaspda.global.GloableParams;
  28. import com.uas.uaspda.tools.SharedPreUtil;
  29. import com.uas.uaspda.tools.VolleyUtil;
  30. import com.uas.uaspda.util.CommonUtil;
  31. import com.uas.uaspda.util.Constants;
  32. import com.uas.uaspda.util.JsonUtils;
  33. import com.uas.uaspda.util.LogUtil;
  34. import com.uas.uaspda.util.SoundUtil;
  35. import com.uas.uaspda.view.ClearableEditText;
  36. import com.uas.uaspda.view.TextViewWithButton;
  37. import org.json.JSONArray;
  38. import org.json.JSONException;
  39. import org.json.JSONObject;
  40. import java.util.HashMap;
  41. import java.util.Map;
  42. /**
  43. * SMT上料:上料子页面
  44. * modify:2017-05-15
  45. */
  46. public class SCSMTInFragment extends BaseFragment implements View.OnClickListener, TextViewWithButton.TvHintHelper {
  47. private TextViewWithButton tvLocation, tvBarcode, tvRemainqty, tvFecode, mLocationTextView;
  48. private TextView tvMsgNotice, tvMsgLocation, tvMsgProdcode, tvMsgBarcode, tvMsgQuantity, tvMsgSpec;
  49. private RelativeLayout rlCollect;
  50. private JSONArray smtLocation;
  51. private JSONObject makeCraft;
  52. private TextView mLinecodeTextView, mTableTextView, mMacodeTextView;
  53. private ClearableEditText mCollectEditText;
  54. int requestType = -1;
  55. private Button btnCollect;
  56. private LineInfoBean mLineInfoBean;
  57. private String mSmtLocationCache;
  58. private SmtDslBean mSmtDslBean = new SmtDslBean();
  59. private StringRequest mStringRequest;
  60. private String mNoticeStr = "";
  61. private boolean mOrderSwitch = false;
  62. @Override
  63. protected int getLayout() {
  64. return R.layout.fragment_scmake_smtfeederchild_in;
  65. }
  66. @Override
  67. protected void initViews() {
  68. mOrderSwitch = SharedPreUtil.getInt(mActivity, Constants.FLAG.CACHE_DEFAULT_ORDER_SWITCH + CommonUtil.getUserName(mActivity), 0) == 1;
  69. //获取组件
  70. //->采集信息
  71. btnCollect = (Button) root.findViewById(R.id.btn_collect_smtchildin);
  72. tvLocation = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_location_smtchildin);
  73. tvFecode = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_fecode_smtchildin);
  74. tvBarcode = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_barcode_smtchildin);
  75. tvRemainqty = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_remainqty_smtchildin);
  76. rlCollect = (RelativeLayout) root.findViewById(R.id.rl_innernotice_smtchildin);
  77. mLocationTextView = (TextViewWithButton) root.findViewById(R.id.smt_feeding_in_location_tv);
  78. mLinecodeTextView = (TextView) root.findViewById(R.id.smt_feeding_in_linecode_tv);
  79. mTableTextView = (TextView) root.findViewById(R.id.smt_feeding_in_table_tv);
  80. mMacodeTextView = (TextView) root.findViewById(R.id.smt_feeding_in_macode_tv);
  81. mCollectEditText = (ClearableEditText) root.findViewById(R.id.smt_feeding_in_collect_et);
  82. mCollectEditText.requestFocus();
  83. //->提示信息
  84. tvMsgNotice = (TextView) root.findViewById(R.id.tv_innernotice_msgtitle_scmake);
  85. tvMsgProdcode = (TextView) root.findViewById(R.id.tv_innernotice_1_scmake);
  86. tvMsgLocation = (TextView) root.findViewById(R.id.tv_innernotice_2_scmake);
  87. tvMsgBarcode = (TextView) root.findViewById(R.id.tv_innernotice_3_scmake);
  88. tvMsgQuantity = (TextView) root.findViewById(R.id.tv_innernotice_4_scmake);
  89. tvMsgSpec = (TextView) root.findViewById(R.id.tv_innernotice_5_scmake);
  90. //接口回调
  91. VolleyUtil.setVolleyHandler(handler);
  92. mLineInfoBean = (LineInfoBean) PdaApplication.getDataCacheFromMap(Constants.FLAG.SMT_DEVICE_LINE_CACHE);
  93. // JSONObject paramJson = new JSONObject();
  94. // try {
  95. // makeCraft = new JSONObject(makeCraftStr);
  96. // String ps_id = makeCraft.get("ps_id").toString();
  97. // String mcjob = makeCraft.get("mc_prodcode").toString();
  98. // paramJson.put("ps_id", ps_id);
  99. // paramJson.put("prodcode", mcjob);
  100. // } catch (JSONException e) {
  101. // e.printStackTrace();
  102. // }
  103. // Log.e("SMTINCHILD", "makecraft" + makeCraft.toString());
  104. // //获取网络数据
  105. // showLoadingView();
  106. // requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL;
  107. // VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMTDETAIL_APPLY, VolleyUtil.METHOD_POST,
  108. // VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL, paramJson);
  109. }
  110. @Override
  111. protected void initEvents() {
  112. tvLocation.setTvHintHelper(this);
  113. tvBarcode.setTvHintHelper(this);
  114. tvRemainqty.setTvHintHelper(this);
  115. tvFecode.setTvHintHelper(this);
  116. mLocationTextView.setTvHintHelper(this);
  117. btnCollect.setOnClickListener(this);
  118. mCollectEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  119. @Override
  120. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  121. String collect = mCollectEditText.getText().toString().trim();
  122. if (!TextUtils.isEmpty(collect)) {
  123. if (actionId == EditorInfo.IME_ACTION_DONE
  124. || actionId == EditorInfo.IME_ACTION_SEND
  125. || (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
  126. confirmEvent(collect);
  127. return true;
  128. }
  129. }
  130. return false;
  131. }
  132. });
  133. mLocationTextView.setOnTextClearListener(new TextViewWithButton.OnTextClearListener() {
  134. @Override
  135. public void onTextClear() {
  136. mCollectEditText.setHint("请录入站位编号");
  137. mCollectEditText.setText("");
  138. // tvMsgNotice.setText("");
  139. // tvMsgProdcode.setText("");
  140. // tvMsgLocation.setText("");
  141. // tvMsgBarcode.setText("");
  142. // tvMsgQuantity.setText("");
  143. // tvMsgSpec.setText("");
  144. }
  145. });
  146. }
  147. private void confirmEvent(String collect) {
  148. String location = mLocationTextView.getText().toString().trim();
  149. if (TextUtils.isEmpty(location)) {
  150. locationCheck(collect);
  151. } else {
  152. /* mSmtDslBean.setDsl_barcode(collect);
  153. String dsl_repcode = mSmtDslBean.getDsl_repcode();
  154. if (!TextUtils.isEmpty(dsl_repcode)) {
  155. boolean isExist = false;
  156. String[] repcodes = dsl_repcode.split(",");
  157. for (int j = 0; j < repcodes.length; j++) {
  158. String repcode = repcodes[j];
  159. if (repcode != null && repcode.equals(collect)) {
  160. isExist = true;
  161. }
  162. }
  163. if (isExist) {
  164. } else {
  165. //上料操作
  166. feedLoading();
  167. }
  168. } else {*/
  169. mSmtDslBean.setDsl_fecode(collect);
  170. feedLoading();
  171. // }
  172. }
  173. }
  174. /**
  175. * 站位本地校验
  176. *
  177. * @param collect 采集框采集内容
  178. */
  179. private void locationCheck(String collect) {
  180. tvMsgProdcode.setText("");
  181. tvMsgLocation.setText("");
  182. tvMsgBarcode.setText("");
  183. tvMsgQuantity.setText("");
  184. tvMsgSpec.setText("");
  185. if (!TextUtils.isEmpty(mSmtLocationCache)) {
  186. try {
  187. JSONArray locationArray = new JSONArray(mSmtLocationCache);
  188. boolean isExist = false;
  189. for (int i = 0; i < locationArray.length(); i++) {
  190. JSONObject locationObject = locationArray.getJSONObject(i);
  191. if (collect.equals(JsonUtils.optStringNotNull(locationObject, "PSL_LOCATION"))) {
  192. isExist = true;
  193. mLocationTextView.setText(collect);
  194. mCollectEditText.setText("");
  195. String psl_prodcode = JsonUtils.optStringNotNull(locationObject, "PSL_PRODCODE");
  196. String psl_repcode = JsonUtils.optStringNotNull(locationObject, "PSL_REPCODE");
  197. mSmtDslBean = new SmtDslBean();
  198. mSmtDslBean.setDsl_location(collect);
  199. mSmtDslBean.setDsl_prodcode(psl_prodcode);
  200. mCollectEditText.setHint("请录入飞达编号");
  201. if (!TextUtils.isEmpty(psl_repcode)) {
  202. // if (TextUtils.isEmpty(psl_repcode) || "null".equals(psl_repcode))
  203. // tvMsgNotice.setText("站位采集成功,请采集首选料[" + psl_prodcode + "]的料卷编号");
  204. // else
  205. String[] repcodes = psl_repcode.split(",");
  206. String notice = "站位采集成功,请采集物料\n";
  207. for (int j = 0; j < repcodes.length; j++) {
  208. String repcode = repcodes[j];
  209. notice = notice + repcode + "\n";
  210. }
  211. notice = notice + "的料卷编号/物料编号";
  212. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  213. tvMsgNotice.setText(notice);
  214. } else if (!TextUtils.isEmpty(psl_prodcode)) {
  215. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  216. tvMsgNotice.setText("站位采集成功,请采集物料\n" + psl_prodcode + "\n的飞达编号");
  217. } else {
  218. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  219. tvMsgNotice.setText("站位采集成功,物料编号获取失败");
  220. }
  221. }
  222. }
  223. if (!isExist) {
  224. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  225. String notice = "站位编号错误\n" + mNoticeStr;
  226. SpannableString spannableString = CommonUtil.spanString(notice, mActivity, "站位编号错误\n".length(), notice.length(), R.color.green);
  227. tvMsgNotice.setText(spannableString);
  228. CommonUtil.makeNotice();
  229. mCollectEditText.setText("");
  230. }
  231. } catch (JSONException e) {
  232. e.printStackTrace();
  233. }
  234. } else {
  235. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  236. String notice = "站位编号错误\n" + mNoticeStr;
  237. SpannableString spannableString = CommonUtil.spanString(notice, mActivity, "站位编号错误\n".length(), notice.length(), R.color.green);
  238. tvMsgNotice.setText(spannableString);
  239. CommonUtil.makeNotice();
  240. mCollectEditText.setText("");
  241. }
  242. }
  243. /**
  244. * 站位上料
  245. */
  246. private void feedLoading() {
  247. progressDialog.show();
  248. PdaApplication.mRequestQueue.cancelAll(TAG + "loading");
  249. final String smtDsl = JSON.toJSONString(mSmtDslBean);
  250. String deviceLineMake = "";
  251. if (mLineInfoBean != null)
  252. deviceLineMake = JSON.toJSONString(mLineInfoBean);
  253. final String finalDeviceLineMake = deviceLineMake;
  254. mStringRequest = new StringRequest(Request.Method.POST, GloableParams.ADDRESS_SMT_LOADING,
  255. new Response.Listener<String>() {
  256. @Override
  257. public void onResponse(String s) {
  258. try {
  259. LogUtil.i("inloading", s);
  260. if (progressDialog.isShowing())
  261. progressDialog.dismiss();
  262. JSONObject jsonObject = new JSONObject(s);
  263. JSONObject dataObject = jsonObject.optJSONObject("data");
  264. if (dataObject != null) {
  265. mLocationTextView.setText("");
  266. mCollectEditText.setText("");
  267. mCollectEditText.setHint("请录入站位编号");
  268. mSmtDslBean = new SmtDslBean();
  269. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  270. tvMsgNotice.setText("上料成功");
  271. tvMsgProdcode.setText("料号:" + JsonUtils.optStringNotNull(dataObject, "DSL_PRODCODE"));
  272. tvMsgLocation.setText("位号:" + JsonUtils.optStringNotNull(dataObject, "DSL_LOCATION"));
  273. tvMsgBarcode.setText("料卷号:" + JsonUtils.optStringNotNull(dataObject, "DSL_BARCODE"));
  274. tvMsgQuantity.setText("数量:" + CommonUtil.doubleFormat(JsonUtils.optDoubleNotNull(dataObject, "DSL_REMAINQTY")));
  275. double notCheckCount = JsonUtils.optDoubleNotNull(dataObject, "NotFeedCount");
  276. String notice = "飞达规格:" + JsonUtils.optStringNotNull(dataObject, "DSL_FESPEC");
  277. if (notCheckCount == 0) {
  278. notice = notice + "\n\n上料已完成";
  279. mNoticeStr = "上料已完成";
  280. SoundUtil.play(SoundUtil.SOUND_CERES);
  281. tvMsgSpec.setText(notice);
  282. } else {
  283. String buffer = notice;
  284. notice = notice + "\n\n未上料站位"
  285. + CommonUtil.doubleFormat(notCheckCount) + "条";
  286. String noticeStr = "未上料站位" + CommonUtil.doubleFormat(notCheckCount) + "条";
  287. JSONArray notFeedArray = dataObject.optJSONArray("NotFeedLocation");
  288. if (notFeedArray != null && notFeedArray.length() != 0) {
  289. notice = notice + "\n站位:\n";
  290. noticeStr = noticeStr + "\n站位:\n";
  291. for (int i = 0; i < notFeedArray.length(); i++) {
  292. JSONObject notCheckObject = notFeedArray.optJSONObject(i);
  293. if (notCheckObject != null) {
  294. String psl_location = JsonUtils.optStringNotNull(notCheckObject, "PSL_LOCATION");
  295. if (i == 0 && mOrderSwitch) {
  296. mCollectEditText.setText(psl_location);
  297. confirmEvent(psl_location);
  298. }
  299. notice = notice + psl_location + "\n";
  300. noticeStr = noticeStr + psl_location + "\n";
  301. }
  302. }
  303. notice = notice.substring(0, notice.length() - 1);
  304. noticeStr = noticeStr.substring(0, noticeStr.length() - 1);
  305. }
  306. mNoticeStr = noticeStr;
  307. SpannableString spannableString = CommonUtil.spanString(notice, mActivity, (buffer + "\n\n未上料站位").length(), (buffer + "\n\n未上料站位").length() + CommonUtil.doubleFormat(notCheckCount).length(), R.color.blue_800);
  308. tvMsgSpec.setText(spannableString);
  309. }
  310. }
  311. } catch (JSONException e) {
  312. e.printStackTrace();
  313. }
  314. }
  315. },
  316. new Response.ErrorListener() {
  317. @Override
  318. public void onErrorResponse(VolleyError volleyError) {
  319. if (progressDialog.isShowing())
  320. progressDialog.dismiss();
  321. String errorToast = CommonUtil.showErrorToast(volleyError, false);
  322. if (errorToast != null) {
  323. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  324. String errorNotice = errorToast + "\n" + mNoticeStr;
  325. SpannableString spannableString = CommonUtil.spanString(errorNotice, mActivity, (errorToast + "\n").length(), errorNotice.length(), R.color.green);
  326. tvMsgNotice.setText(spannableString);
  327. if (errorToast.contains("站位已经有在线料卷号")) {
  328. mLocationTextView.setText("");
  329. mCollectEditText.setText("");
  330. } else {
  331. mCollectEditText.setText("");
  332. }
  333. }
  334. }
  335. }) {
  336. @Override
  337. protected Map<String, String> getParams() throws AuthFailureError {
  338. Map<String, String> params = new HashMap<String, String>();
  339. params.put("dsl", smtDsl);
  340. params.put("deviceLineMake", finalDeviceLineMake);
  341. return params;
  342. }
  343. @Override
  344. public Map<String, String> getHeaders() throws AuthFailureError {
  345. return VolleyUtil.getVolleyUtil().setCookies();
  346. }
  347. };
  348. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  349. mStringRequest.setTag(TAG + "loading");
  350. PdaApplication.mRequestQueue.add(mStringRequest);
  351. }
  352. @Override
  353. protected void initDatas() {
  354. //配置界面
  355. ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_feederin_smt);
  356. mSmtLocationCache = SharedPreUtil.getString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, null);
  357. if (mSmtLocationCache != null) {
  358. Log.d("smtLocation", mSmtLocationCache);
  359. }
  360. if (mLineInfoBean != null) {
  361. mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE());
  362. mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面");
  363. mMacodeTextView.setText(mLineInfoBean.getDL_MACODE());
  364. }
  365. getUnloadingLocation();
  366. }
  367. /**
  368. * 获取未上料站位
  369. */
  370. private void getUnloadingLocation() {
  371. progressDialog.show();
  372. String url = GloableParams.ADDRESS_SMT_GET_UNLOADING_LOCATION + "?linecode=" + (mLineInfoBean == null ? "" : mLineInfoBean.getDL_LINECODE());
  373. PdaApplication.mRequestQueue.cancelAll(TAG + "unloading");
  374. mStringRequest = new StringRequest(Request.Method.GET, url,
  375. new Response.Listener<String>() {
  376. @Override
  377. public void onResponse(String s) {
  378. try {
  379. if (progressDialog.isShowing())
  380. progressDialog.dismiss();
  381. JSONObject resultObject = new JSONObject(s);
  382. JSONObject dataObject = resultObject.optJSONObject("data");
  383. if (dataObject != null) {
  384. double NotFeedCount = JsonUtils.optDoubleNotNull(dataObject, "NotFeedCount");
  385. String notice = "";
  386. if (NotFeedCount == 0) {
  387. notice = notice + "上料已完成";
  388. mNoticeStr = notice;
  389. SoundUtil.play(SoundUtil.SOUND_CERES);
  390. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  391. tvMsgNotice.setText(notice);
  392. } else {
  393. notice = notice + "未上料站位"
  394. + CommonUtil.doubleFormat(NotFeedCount) + "条";
  395. JSONArray notFeedArray = dataObject.optJSONArray("NotFeedLocation");
  396. if (notFeedArray != null && notFeedArray.length() != 0) {
  397. notice = notice + "\n站位:\n";
  398. for (int i = 0; i < notFeedArray.length(); i++) {
  399. JSONObject notCheckObject = notFeedArray.optJSONObject(i);
  400. if (notCheckObject != null) {
  401. String psl_location = JsonUtils.optStringNotNull(notCheckObject, "PSL_LOCATION");
  402. if (i == 0 && mOrderSwitch) {
  403. mCollectEditText.setText(psl_location);
  404. confirmEvent(psl_location);
  405. }
  406. notice = notice + psl_location + "\n";
  407. }
  408. }
  409. notice = notice.substring(0, notice.length() - 1);
  410. }
  411. mNoticeStr = notice;
  412. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  413. SpannableString spannableString = CommonUtil.spanString(notice, mActivity, 5, 5 + CommonUtil.doubleFormat(NotFeedCount).length(), R.color.blue_800);
  414. tvMsgNotice.setText(spannableString);
  415. }
  416. }
  417. } catch (Exception e) {
  418. }
  419. }
  420. },
  421. new Response.ErrorListener() {
  422. @Override
  423. public void onErrorResponse(VolleyError volleyError) {
  424. if (progressDialog.isShowing())
  425. progressDialog.dismiss();
  426. String errorToast = CommonUtil.showErrorToast(volleyError, false);
  427. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  428. tvMsgNotice.setText(errorToast);
  429. }
  430. }) {
  431. @Override
  432. public Map<String, String> getHeaders() throws AuthFailureError {
  433. return VolleyUtil.getVolleyUtil().setCookies();
  434. }
  435. };
  436. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  437. mStringRequest.setTag(TAG + "unloading");
  438. PdaApplication.mRequestQueue.add(mStringRequest);
  439. }
  440. @Override
  441. public void onDestroy() {
  442. VolleyUtil.distoryVolley();
  443. super.onDestroy();
  444. }
  445. @Override
  446. public void onDestroyView() {
  447. CommonUtil.closeKeybord(mCollectEditText, mActivity);
  448. super.onDestroyView();
  449. }
  450. //按钮点击事件:当Location为空的时候
  451. private void disposeOnClickLocation() {
  452. Log.e("SMTChildInOnclick", "站位为空");
  453. String tmpLocation = null;
  454. String title = null;
  455. String content = null;
  456. int color = 0;
  457. isAgain = false;
  458. //信息框都清空
  459. tvBarcode.setText("");
  460. tvRemainqty.setText("");
  461. tvFecode.setText("");
  462. try {
  463. //比对smtLocation
  464. for (int i = 0; i < smtLocation.length(); i++) {
  465. JSONObject tmpJson = smtLocation.getJSONObject(i);
  466. tmpLocation = tmpJson.getString("psl_location").trim();
  467. //如果匹配
  468. if (tmpLocation.equals(code)) {
  469. Log.e("SMTCHILD", "匹配");
  470. //显示在站位输入框,添加数据项
  471. tvLocation.setText(tmpLocation);
  472. msl = new JSONObject();
  473. msl.put("msl_location", code);
  474. msl.put("msl_prodcode", tmpJson.getString("psl_prodcode").trim());
  475. msl.put("msl_repcode", tmpJson.getString("psl_repcode").trim());
  476. // msl.put("msl_repcode","无");
  477. msl.put("psl_id", tmpJson.getString("psl_id").trim());
  478. msl.put("msl_fespec", tmpJson.getString("psl_feeder").trim());
  479. //msl = smtLocation.getJSONObject(i);
  480. Log.e("SMTCHILD", msl.toString());
  481. //更改etCollect的Hint
  482. setEtHint();
  483. //提示框中显示信息
  484. title = "站位采集成功";
  485. content = "站位采集成功,请采集物料" + msl.get("msl_prodcode") + "的条码";
  486. color = getResources().getColor(R.color.green);
  487. setNotice(title, content, color);
  488. break;
  489. }
  490. //如果不匹配
  491. else {
  492. Log.e("SMTCHILD", "不匹配");
  493. title = "错误";
  494. content = getString(R.string.notice_smtchild_barcode);
  495. color = getResources().getColor(R.color.text_error);
  496. }
  497. }
  498. } catch (JSONException e) {
  499. e.printStackTrace();
  500. }
  501. setNotice(title, content, color);
  502. }
  503. //按钮点击事件:当料卷号为空的时候
  504. private void disposeOnClickBarcode() {
  505. Log.e("SMTChildInOnclick", "料卷为空");
  506. //请求判断料卷编号是否正确,获取料卷数量
  507. JSONObject paramJson = new JSONObject();
  508. try {
  509. paramJson.put("bar_code", code);
  510. paramJson.put("prod_code", msl.getString("msl_prodcode"));
  511. paramJson.put("rep_code", msl.getString("msl_repcode"));
  512. } catch (JSONException e) {
  513. e.printStackTrace();
  514. }
  515. showLoadingView();
  516. requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN;
  517. VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMT_BARREMAIN_APPLY, VolleyUtil.METHOD_POST,
  518. VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN, paramJson);
  519. }
  520. //按钮点击事件:当飞达编号为空时
  521. private void disposeOnClickFecode() {
  522. //获取飞达编号
  523. String fecodeStr = tvFecode.getText().toString().trim();
  524. //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时
  525. if (fecodeStr.equals("") || fecodeStr == null) {
  526. //tvFecode.setText(code);
  527. try {
  528. msl.put("msl_fecode", code);
  529. } catch (JSONException e) {
  530. e.printStackTrace();
  531. }
  532. //上料操作
  533. requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTIN_UPLOAD;
  534. showLoadingView();
  535. VolleyUtil.getVolleyUtil().requestSMTInUpLoad(getActivity(), GloableParams.ADDRESS_SMTIN_UPLOAD_APPLY, VolleyUtil.METHOD_POST,
  536. requestType, msl.toString(), makeCraft.toString());
  537. }
  538. }
  539. //扫描料卷编号成功
  540. String mslBarcode = null, mslRemainQty = null;
  541. private void disposeBarcodeSuccess(String result) {
  542. String title, content;
  543. int color;
  544. JSONObject tmpJson, msgJson;
  545. try {
  546. tmpJson = new JSONObject(result);
  547. msgJson = tmpJson.getJSONObject("message");
  548. //将message中的值赋值给变量msl中的值
  549. msl.put("msl_barcode", msgJson.getString("bar_code"));
  550. msl.put("msl_prodcode", msgJson.get("bar_prodcode"));
  551. msl.put("msl_remainqty", msgJson.get("bar_remain"));
  552. mslBarcode = code;
  553. mslRemainQty = msgJson.getString("bar_remain");
  554. //料卷编号和数量输入框显示对应的值,清空采集栏中的值
  555. tvBarcode.setText(mslBarcode);
  556. tvRemainqty.setText(mslRemainQty);
  557. //将采集栏中的提示文字修改为“请录入飞达编号”
  558. setEtHint();
  559. //清空提示栏信息
  560. title = "料卷采集成功";
  561. content = "请采集物料" + msl.get("msl_prodcode") + "的飞达编号";
  562. color = getResources().getColor(R.color.green);
  563. setNotice(title, content, color);
  564. } catch (JSONException e) {
  565. e.printStackTrace();
  566. }
  567. }
  568. //上料成功
  569. private void disposeUpLoadSuccess(String result) {
  570. JSONObject msgJson;
  571. String productStr = "无", locationStr = "无", fecodeStr = "无", barcodeStr = "无", qtyStr = "无";
  572. try {
  573. JSONObject tmpJson = new JSONObject(result);
  574. msgJson = tmpJson.getJSONObject("message");
  575. productStr = msgJson.getString("msl_prodcode");
  576. locationStr = msgJson.getString("msl_location");
  577. fecodeStr = msgJson.getString("msl_fecode");
  578. barcodeStr = msgJson.getString("msl_barcode");
  579. qtyStr = msgJson.getString("msl_remainqty");
  580. } catch (JSONException e) {
  581. e.printStackTrace();
  582. }
  583. tvFecode.setText(code);
  584. //信息提示框
  585. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  586. tvMsgNotice.setText("上料成功");
  587. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  588. tvMsgLocation.setText("物料号:" + productStr);
  589. tvMsgProdcode.setText("站位:" + locationStr);
  590. tvMsgBarcode.setText("飞达:" + fecodeStr);
  591. tvMsgQuantity.setText("料卷号:" + barcodeStr);
  592. tvMsgSpec.setText("数量:" + qtyStr);
  593. //新一轮采集
  594. msl = null;
  595. isAgain = true;
  596. setEtHint();
  597. }
  598. /*========================Volley Handler=================================*/
  599. Handler handler = new Handler() {
  600. @Override
  601. public void handleMessage(Message msg) {
  602. switch (msg.what) {
  603. case VolleyUtil.SUCCESS_SUCCESS:
  604. disposeVolleySuccess(msg);
  605. break;
  606. case VolleyUtil.FAILED_FAILED:
  607. disposeVolleyFaild(msg);
  608. break;
  609. }
  610. }
  611. };
  612. //Volley响应失败
  613. private void disposeVolleyFaild(Message msg) {
  614. String noticeMsg = (String) msg.obj;
  615. String title = "失败";
  616. String content = noticeMsg;
  617. setNotice(title, content, getResources().getColor(R.color.red));
  618. progressDialog.dismiss();
  619. }
  620. //Volley响应成功函数
  621. private void disposeVolleySuccess(Message msg) {
  622. Log.e("SCSMTFEEDER", "HandlerSuccess");
  623. String result = (String) msg.obj;
  624. switch (requestType) {
  625. //请求详细数据
  626. case VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL:
  627. Log.e("SCSMTFEEDER", "requestType:" + requestType);
  628. String smtLocationStr = (String) msg.obj;
  629. try {
  630. //保存请求的变量
  631. JSONObject tmpJson = new JSONObject(smtLocationStr);
  632. //如果没有获取到网络数据
  633. boolean isNull = tmpJson.isNull("message");
  634. if (isNull) {
  635. disposeNullServerData();
  636. } else {
  637. smtLocation = tmpJson.getJSONArray("message");
  638. //这里获取了数据 没有填充上去
  639. Log.e("SMTINChild", "smtLocation:" + smtLocation.toString());
  640. }
  641. } catch (JSONException e) {
  642. e.printStackTrace();
  643. }
  644. break;
  645. //物料
  646. case VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN:
  647. Log.e("SMTWULIAO", "BARREMAIN");
  648. disposeBarcodeSuccess(result);
  649. // disposeFecodeCollect();
  650. break;
  651. //上料操作:上料成功以后,需要重新获取输入框文字
  652. case VolleyUtil.FRAGMENT_SCMAKE_SMTIN_UPLOAD:
  653. disposeUpLoadSuccess(result);
  654. break;
  655. }
  656. progressDialog.dismiss();
  657. }
  658. //隐藏采集界面
  659. private void disposeNullServerData() {
  660. rlCollect.setVisibility(View.GONE);
  661. String title = getString(R.string.notice_smtin_nulldata);
  662. setNotice(title, "", getResources().getColor(R.color.text_error));
  663. }
  664. /*========================公用方法=================================*/
  665. /**
  666. * 显示loadingView
  667. */
  668. private void showLoadingView() {
  669. if (!progressDialog.isShowing()) {
  670. progressDialog.show();
  671. }
  672. }
  673. /**
  674. * 键盘
  675. */
  676. InputMethodManager inputManager;
  677. private void hideKeyboard(final EditText view) {
  678. inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
  679. //获取键盘管理对象
  680. inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
  681. }
  682. /**
  683. * 获取输入框焦点
  684. */
  685. private void editTextGetFocus(EditText editText) {
  686. editText.setFocusable(true);
  687. editText.setFocusableInTouchMode(true);
  688. editText.setEnabled(true);
  689. editText.setClickable(true);
  690. editText.requestFocus();
  691. }
  692. /**
  693. * 设置提示信息
  694. */
  695. private void setNotice(String title, String content, int pid) {
  696. tvMsgNotice.setText(title);
  697. tvMsgNotice.setTextColor(pid);
  698. tvMsgProdcode.setText(content);
  699. //清除其它信息
  700. tvMsgSpec.setText("");
  701. tvMsgBarcode.setText("");
  702. tvMsgLocation.setText("");
  703. tvMsgQuantity.setText("");
  704. }
  705. /**
  706. * 设置采集框提示信息
  707. */
  708. @Override
  709. public void setEtHint() {
  710. //获取站位\料卷\飞达编号
  711. String locationStr = tvLocation.getText().toString().trim();
  712. String barcodeStr = tvBarcode.getText().toString().trim();
  713. String remainQty = tvRemainqty.getText().toString().trim();
  714. String fecodeStr = tvFecode.getText().toString().trim();
  715. /*//->if(msl_location为空),如果站位为null
  716. if (isAgain || locationStr.equals("") || locationStr == null) {
  717. etCollect.setHint(R.string.hint_smtchild_location);
  718. }
  719. //->else if(msl_barcode为空) 如果站位不为空,料卷号为空
  720. else if (barcodeStr.equals("") || barcodeStr == null) {
  721. etCollect.setHint(R.string.hint_smtchild_barcode);
  722. }
  723. //->else if(msl_remainqty为空) 如果数量为空
  724. else if (remainQty.equals("") || remainQty == null) {
  725. etCollect.setHint(R.string.hint_smtchild_barcode);
  726. }
  727. //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时
  728. else if (fecodeStr.equals("") || barcodeStr == null) {
  729. etCollect.setHint(R.string.hint_smtchild_fecode);
  730. }*/
  731. }
  732. /**
  733. * 按钮点击事件
  734. */
  735. @Override
  736. public void onClick(View v) {
  737. disposeOnClick();
  738. }
  739. JSONObject msl = new JSONObject();
  740. String code = null;
  741. boolean isAgain = false;
  742. private void disposeOnClick() {
  743. //->获取输入框文字内容
  744. // code = etCollect.getText().toString().trim();
  745. if (code.equals("") || code == null) {
  746. return;
  747. }
  748. Log.e("SCSMT:code", "" + code);
  749. //获取站位\料卷\飞达编号
  750. String locationStr = tvLocation.getText().toString().trim();
  751. String barcodeStr = tvBarcode.getText().toString().trim();
  752. String fecodeStr = tvFecode.getText().toString().trim();
  753. //->if(msl_location为空),如果站位为null,或者是新一轮采集
  754. if (isAgain || locationStr.equals("") || locationStr == null) {
  755. disposeOnClickLocation();
  756. }
  757. //->else if(msl_barcode为空) 如果站位不为空,料卷号为空
  758. else if (barcodeStr.equals("") || barcodeStr == null) {
  759. disposeOnClickBarcode();
  760. }
  761. //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时
  762. else if (fecodeStr.equals("") || barcodeStr == null) {
  763. disposeOnClickFecode();
  764. }
  765. }
  766. @Override
  767. public boolean onKeyDown(int keyCode, KeyEvent event) {
  768. if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  769. if (progressDialog != null && progressDialog.isShowing()) {
  770. // loadingView.dismiss();
  771. return true;
  772. }
  773. }
  774. return false;
  775. }
  776. @Override
  777. public boolean onFragmentBackPressed() {
  778. return false;
  779. }
  780. }