@@ -3,7 +3,9 @@ export default {
33 data () {
44 return {
55 parentId: " " ,
6- mode: " "
6+ mode: " " ,
7+ isLoading: false ,
8+ errorMessage: " "
79 };
810 },
911 mounted () {
@@ -13,16 +15,44 @@ export default {
1315 this .mode = localStorage .getItem (" mode" );
1416 },
1517 methods: {
16- scanParentId () {
18+ async scanParentId () {
1719 // if (this.username) {
1820 // this.$router.push("/mode"); // Navigate to Home after login
1921 // } else {
2022 // alert("Please enter username");
2123 // }
22- this .$router .push (" /location" );
23- },
24+ this .isLoading = true ;
25+ try {
26+ const response = await fetch (` https://stevett.pythonanywhere.com/v1/lookup/parent/${ this .parentId } ?operation_mode=${ this .mode } ` );
27+ const data = await response .json ();
28+
29+ if (data .response_type === " OK" ) {
30+ playSuccessSound ();
31+ this .$router .push (" /transaction" );
32+ } else {
33+ playErrorSound ();
34+ this .errorMessage = data .message ;
35+ }
36+ } catch (error) {
37+ console .error (" API Error:" , error);
38+ alert (" API Error:" , error);
39+ }
40+ finally {
41+ this .isLoading = false ;
42+ }
43+ }
2444 }
2545};
46+
47+ function playErrorSound (){
48+ const errorSound = new Audio (require (' @/assets/sounds/error-sound.mp3' ));
49+ errorSound .play ();
50+ }
51+
52+ function playSuccessSound (){
53+ const successSound = new Audio (require (' @/assets/sounds/success-sound.mp3' ));
54+ successSound .play ();
55+ }
2656 </script >
2757
2858<template >
@@ -41,13 +71,23 @@ export default {
4171
4272 <div class =" mb-3" >
4373 <label for =" parentId" class =" form-label" >Parent ID</label >
44- <input type =" text" class =" form-control" id =" parentId" v-model =" parentId" ref =" parentId" >
74+ <input type =" text" class =" form-control" id =" parentId" v-model =" parentId" @keyup.enter = " scanParentId " ref =" parentId" >
4575 </div >
4676
4777 <div class =" form-group" >
4878 <button class =" btn btn-primary" @click =" scanParentId" style =" width : 237px ; margin-right : 8px " >Cancel</button >
49- <button class =" btn btn-primary" @click =" scanParentId" style =" width : 237px " >Continue</button >
79+ <button class =" btn btn-primary" @click =" scanParentId" style =" width : 237px " >
80+ <span v-if =" isLoading" class =" spinner-border spinner-border-sm" ></span >
81+ <span v-else >Continue</span >
82+ </button >
83+ </div >
84+
85+ <div v-if =" errorMessage" class =" mt-3" >
86+ <p class =" text-danger" >
87+ <i class =" bi bi-exclamation-octagon-fill" style =" padding-right : 5px ;" ></i > {{ errorMessage }}
88+ </p >
5089 </div >
90+
5191 </div >
5292 </div >
5393</template >
0 commit comments