Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: code to group the items based on the parent and improve logic to select and unselect a product(#24phanv) #26

Merged
merged 3 commits into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,22 @@
</div>

<div v-else v-for="id in getGroupList(ordersList.items)" :key="id" >
<div v-for="item in getGroupItems(id, ordersList.items)" :key="item">
<div class="list-item list-header">
<ion-label>{{ item.parentProductName }}</ion-label>

<div class="tablet" />

<div class="tablet" />

<div />
<div class="list-item list-header">
<ion-label>{{ getParentInformation(id, ordersList.items).parentProductName }}</ion-label>

<ion-checkbox :checked="isParentProductChecked(id)" @ionChange="selectParentProduct(id, $event)" />

<ion-button fill="clear" color="medium" @click="UpdateProduct($event, id, true, item)">
<ion-icon slot="icon-only" :icon="ellipsisVerticalOutline" />
</ion-button>
</div>
<div class="tablet" />

<div class="tablet" />

<div />

<ion-checkbox :checked="isParentProductChecked(id)" @ionChange="selectParentProduct(id, $event)" />

<ion-button fill="clear" color="medium" @click="UpdateProduct($event, id, true, getParentInformation(id, ordersList.items))">
<ion-icon slot="icon-only" :icon="ellipsisVerticalOutline" />
</ion-button>
</div>
<div v-for="(item, index) in getGroupItems(id, ordersList.items)" :key="index">
<div class="list-item">
<ion-item lines="none">
<ion-thumbnail slot="start">
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -352,6 +345,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;
Expand All @@ -360,7 +356,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.checked;
}
})
}
Expand Down