@@ -218,6 +218,7 @@ import { CountService } from "@/services/CountService";
218
218
import Image from " @/components/Image.vue" ;
219
219
import router from " @/router" ;
220
220
import MatchProductModal from " @/components/MatchProductModal.vue" ;
221
+ import { useWebSocketComposables } from ' @/composables/useWebSocketComposables' ;
221
222
222
223
const store = useStore ();
223
224
@@ -228,6 +229,8 @@ const userProfile = computed(() => store.getters["user/getUserProfile"])
228
229
const productStoreSettings = computed (() => store .getters [" user/getProductStoreSettings" ])
229
230
const defaultRecountUpdateBehaviour = computed (() => store .getters [" count/getDefaultRecountUpdateBehaviour" ])
230
231
const currentItemIndex = computed (() => ! currentProduct .value ? 0 : currentProduct .value .scannedId ? itemsList .value ?.findIndex ((item : any ) => item .scannedId === currentProduct .value .scannedId ) : itemsList ?.value .findIndex ((item : any ) => item .productId === currentProduct .value ?.productId && item .importItemSeqId === currentProduct .value ?.importItemSeqId ));
232
+ const currentFacility = computed (() => store .getters [" user/getCurrentFacility" ])
233
+ const webSocketUrl = computed (() => store .getters [" user/getWebSocketUrl" ])
231
234
232
235
const itemsList = computed (() => {
233
236
if (selectedSegment .value === " all" ) {
@@ -239,6 +242,8 @@ const itemsList = computed(() => {
239
242
}
240
243
});
241
244
245
+ const { registerListener } = useWebSocketComposables (webSocketUrl .value );
246
+
242
247
const props = defineProps ([" id" ]);
243
248
const cycleCount = ref ({}) as any ;
244
249
const queryString = ref (" " );
@@ -250,7 +255,7 @@ const inputCount = ref("") as any;
250
255
const selectedCountUpdateType = ref (" add" );
251
256
const isScrolling = ref (false );
252
257
let isScanningInProgress = ref (false );
253
-
258
+ const productIdAdding = ref ();
254
259
255
260
onIonViewDidEnter (async () => {
256
261
emitter .emit (" presentLoader" );
@@ -260,6 +265,7 @@ onIonViewDidEnter(async() => {
260
265
barcodeInputRef .value ?.$el ?.setFocus ();
261
266
selectedCountUpdateType .value = defaultRecountUpdateBehaviour .value
262
267
window .addEventListener (' beforeunload' , handleBeforeUnload );
268
+ registerListener (currentFacility .value .facilityId , handleNewMessage );
263
269
emitter .emit (" dismissLoader" )
264
270
})
265
271
@@ -432,7 +438,10 @@ async function addProductToItemsList() {
432
438
async function findProductFromIdentifier(scannedValue : string ) {
433
439
const product = await store .dispatch (" product/fetchProductByIdentification" , { scannedValue })
434
440
let newItem = {} as any ;
435
- if (product ?.productId ) newItem = await addProductToCount (product .productId )
441
+ if (product ?.productId ) {
442
+ productIdAdding .value = product .productId
443
+ newItem = await addProductToCount (product .productId )
444
+ }
436
445
437
446
setTimeout (() => {
438
447
updateCurrentItemInList (newItem , scannedValue );
@@ -512,6 +521,7 @@ async function updateCurrentItemInList(newItem: any, scannedValue: string) {
512
521
items [currentItemIndex ] = updatedItem
513
522
514
523
store .dispatch (' count/updateCycleCountItems' , items );
524
+ productIdAdding .value = " "
515
525
}
516
526
517
527
async function readyForReview() {
@@ -651,6 +661,7 @@ async function matchProduct(currentProduct: any) {
651
661
addProductModal .onDidDismiss ().then (async (result ) => {
652
662
if (result .data ?.selectedProduct ) {
653
663
const product = result .data .selectedProduct
664
+ productIdAdding .value = product .productId
654
665
const newItem = await addProductToCount (product .productId )
655
666
await updateCurrentItemInList (newItem , currentProduct .scannedId );
656
667
}
@@ -659,6 +670,27 @@ async function matchProduct(currentProduct: any) {
659
670
addProductModal .present ();
660
671
}
661
672
673
+ function handleNewMessage(jsonObj : any ) {
674
+ const updatedItem = jsonObj .message
675
+ if (updatedItem .inventoryCountImportId !== cycleCount .value .inventoryCountImportId ) return ;
676
+ if (productIdAdding .value === updatedItem .productId ) return ;
677
+
678
+ const items = JSON .parse (JSON .stringify (cycleCountItems .value .itemList ))
679
+ const currentItemIndex = items .findIndex ((item : any ) => item .productId === updatedItem .productId && item .importItemSeqId === updatedItem .importItemSeqId );
680
+
681
+ if (currentItemIndex !== - 1 ) {
682
+ items [currentItemIndex ] = updatedItem
683
+ } else {
684
+ store .dispatch (" product/fetchProducts" , { productIds: [updatedItem .productId ] })
685
+ items .push (updatedItem )
686
+ }
687
+
688
+ store .dispatch (' count/updateCycleCountItems' , items );
689
+ if (currentProduct .value .productId === updatedItem .productId ) {
690
+ store .dispatch (' product/currentProduct' , updatedItem );
691
+ }
692
+ }
693
+
662
694
function getVariance(item : any , isRecounting : boolean ) {
663
695
const qty = item .quantity
664
696
if (isRecounting && inputCount .value === " " ) return 0 ;
0 commit comments