From c66d183c305e422eb7fa43948019d355bbac683e Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Wed, 30 Mar 2022 15:13:15 +0530 Subject: [PATCH 1/2] Improved: code to group the items based on the parent and improve logic to select and unselect a product(#24phanv) --- src/views/OrderDetail.vue | 44 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/views/OrderDetail.vue b/src/views/OrderDetail.vue index 7bb45cd2..3f9a16e3 100644 --- a/src/views/OrderDetail.vue +++ b/src/views/OrderDetail.vue @@ -83,23 +83,22 @@
-
-
- {{ item.parentProductName }} - -
- -
- -
+
+ {{ getParentInformation(id, ordersList.items).parentProductName }} - - - - - -
+
+ +
+ +
+ + + + + +
+
@@ -316,15 +315,9 @@ export default defineComponent({ }) return popover.present(); }, - selectOnlyParentProduct(id: any){ - this.ordersList.items.forEach((item: any) => { - item.isSelected = !item.parentProductId === id; - }) - }, isParentProductChecked(parentProductId: string) { - return !(this as any).ordersList.items.filter((item: any) => item.parentProductId === parentProductId).some((item: any) => { - return !item.isSelected - }) + const items = (this as any).ordersList.items.filter((item: any) => item.parentProductId === parentProductId) + return items.every((item: any) => item.isSelected) }, selectProduct(item: any, event: any) { item.isSelected = event.detail.checked; @@ -348,6 +341,9 @@ export default defineComponent({ getGroupItems(parentProductId: any, items: any) { return items.filter((item: any) => item.parentProductId == parentProductId) }, + getParentInformation(id: any, items: any) { + return items.find((item: any) => item.parentProductId == id) + }, selectAllItems() { this.ordersList.items.forEach((item: any) => { item.isSelected = true; @@ -356,7 +352,7 @@ export default defineComponent({ selectParentProduct(parentProductId: any, event: any) { this.ordersList.items.forEach((item: any) => { if (item.parentProductId == parentProductId) { - item.isSelected = event.detail.checked; + item.isSelected = event.detail.check; } }) } From 3c6ab3f02a08b5eff5a72167b95c581a3960cf1b Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Wed, 30 Mar 2022 16:32:19 +0530 Subject: [PATCH 2/2] Improved: property name for event detsil(#24phanv) --- src/views/OrderDetail.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/OrderDetail.vue b/src/views/OrderDetail.vue index 3f9a16e3..2b410226 100644 --- a/src/views/OrderDetail.vue +++ b/src/views/OrderDetail.vue @@ -352,7 +352,7 @@ export default defineComponent({ selectParentProduct(parentProductId: any, event: any) { this.ordersList.items.forEach((item: any) => { if (item.parentProductId == parentProductId) { - item.isSelected = event.detail.check; + item.isSelected = event.detail.checked; } }) }