QRResult.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import apiCharge from "../../api/apiCharge";
  2. import Dialog from "../../components/Dialog";
  3. import { PageList } from "../Router";
  4. export default {
  5. haveResult() {
  6. return global.QrCodeResult && global.QrCodeResult.connectorPk;
  7. },
  8. setResult(info) {
  9. global.QrCodeResult = info;
  10. },
  11. getResult() {
  12. return global.QrCodeResult;
  13. },
  14. clearResult() {
  15. global.QrCodeResult = {};
  16. },
  17. applyInputStation(text, sitePk, back) {
  18. if (text.indexOf('-') > 0) {
  19. const arr = text.split('-');
  20. if (arr.length >= 2) {
  21. let bid = '', cid = '';
  22. for (let i = 0; i < arr.length; i++) {
  23. let sb = arr[i]?.trim();
  24. if (i == (arr.length-1)) {
  25. cid = sb;
  26. } else {
  27. if (i > 0) {
  28. bid += '-';
  29. }
  30. bid += sb;
  31. }
  32. }
  33. const qr = {
  34. sitePk: sitePk,
  35. chargeBoxId: bid,
  36. connectorId: cid
  37. }
  38. console.log('================QR==================');
  39. console.log(qr);
  40. console.log('================QR==================');
  41. Dialog.showProgressDialog();
  42. apiCharge.checkQRStatus(qr).then(res => {
  43. Dialog.dismissLoading();
  44. if (res.data && res.data.chargeBoxId) {
  45. this.setResult(res.data);
  46. back(true)
  47. }
  48. }).catch(({err, code}) => {
  49. Dialog.dismissLoading();
  50. back(false, '')
  51. Dialog.showDialog({
  52. title: 'Error',
  53. message: err,
  54. showCancel: false,
  55. callback: btn => {
  56. if (code == 5194 && btn == Dialog.BUTTON_OK) {
  57. startPage(PageList.myVehicles);
  58. }
  59. }
  60. });
  61. })
  62. } else {
  63. back(false, 'Station ID is incorrect');
  64. }
  65. } else {
  66. back(false, 'Station ID is incorrect');
  67. }
  68. }
  69. }