瀏覽代碼

update app/pages/charge/QRResult.js

wudebin 3 月之前
父節點
當前提交
ac7cf668c1
共有 1 個文件被更改,包括 70 次插入0 次删除
  1. 70 0
      Strides-SPAPP/app/pages/charge/QRResult.js

+ 70 - 0
Strides-SPAPP/app/pages/charge/QRResult.js

@@ -0,0 +1,70 @@
+import apiCharge from "../../api/apiCharge";
+import Dialog from "../../components/Dialog";
+import { PageList } from "../Router";
+
+export default {
+  haveResult() {
+    return global.QrCodeResult && global.QrCodeResult.connectorPk;
+  },
+  setResult(info) {
+    global.QrCodeResult = info;
+  },
+  getResult() {
+    return global.QrCodeResult;
+  },
+  clearResult() {
+    global.QrCodeResult = {};
+  },
+  applyInputStation(text, sitePk, back) {
+    if (text.indexOf('-') > 0) {
+      const arr = text.split('-');
+      if (arr.length >= 2) {
+        let bid = '', cid = '';
+        for (let i = 0; i < arr.length; i++) {
+          let sb = arr[i]?.trim();
+          if (i == (arr.length-1)) {
+            cid = sb;
+          } else {
+            if (i > 0) {
+              bid += '-';
+            }
+            bid += sb;
+          }
+        }
+        const qr = {
+          sitePk: sitePk,
+          chargeBoxId: bid,
+          connectorId: cid
+        }
+        console.log('====================================');
+        console.log(qr);
+        console.log('====================================');
+        Dialog.showProgressDialog();
+        apiCharge.checkQRStatus(qr).then(res => {
+          Dialog.dismissLoading();
+          if (res.data && res.data.chargeBoxId) {
+            this.setResult(res.data);
+            back(true)
+          }
+        }).catch(({err, code}) => {
+          Dialog.dismissLoading();
+          back(false, '')
+          Dialog.showDialog({
+            title: 'Error',
+            message: err,
+            showCancel: false,
+            callback: btn => {
+              if (code == 5194 && btn == Dialog.BUTTON_OK) {
+                startPage(PageList.myVehicles);
+              }
+            }
+          });
+        })
+      } else {
+        back(false, 'Station ID is incorrect');
+      }
+    } else {
+      back(false, 'Station ID is incorrect');
+    }
+  }
+}