Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | 1x 1x 1x 1x 3x 1x | <template> <div class="d-flex flex-column align-items-center position-relative"> <SelectWithSearch :data="bundles" :total="total" :currentPerPage="currentPerPage" :placeholder="'Serch bundles'" v-on:clickItem="addBundle" v-on:setPage="setPage" v-on:setSearchText="setSearchText" class="mb-3 w-100" > <template v-slot:item="bundles"> <BundleCard :bundle="bundles.item" class="w-100 m-0 p-0" /> </template> </SelectWithSearch> <div class="w-100" v-if="selectedBundles.length"> <ul class="d-flex flex-column p-0 w-100 m-0"> <li v-for="(item, index) in selectedBundles" :key="item.bundle.id" class="row w-100 mb-2 mx-auto justify-content-center" > <BundleCard :bundle="item.bundle" class="col-11 m-0 p-0" /> <div class="col-1 d-flex justify-content-center align-items-start p-0" v-on:click="deleteProduct(index)" > <BIconX /> </div> </li> </ul> </div> </div> </template> <script> import { mapActions, mapGetters, mapMutations } from "vuex"; import { warn } from "~/utils/warn"; import SelectWithSearch from "~/components/common/SelectWithSearch.vue"; import BundleCard from "./BundleCard.vue"; export default { name: "BundlesBlock", components: { SelectWithSearch, BundleCard }, data: () => ({ currentPerPage: 10, page: 1, search: "", selectedBundles: [], timer: null, //for lazy search }), computed: { ...mapGetters({ bundles: "admin_bundles/bundles", total: "admin_bundles/total", }), }, watch: { page: async function () { await this.getBnds(); }, search: async function () { const { search } = this; if (search) { clearInterval(this.timer); this.timer = null; this.timer = setTimeout(async () => { await this.getBnds(); }, 1000); } else { clearInterval(this.timer); this.timer = null; await this.getBnds(); } }, }, methods: { ...mapActions({ getBundles: "admin_bundles/getBundles" }), ...mapMutations({ setParams: "admin_bundles/setParams", clearBundles: "admin_bundles/clearBundles", }), getBnds: async function () { const { search, page, currentPerPage } = this; this.setParams({ search, page, currentPerPage }); await this.getBundles({ search, page, currentPerPage, }); }, setSearchText: function (text) { this.search = text; }, setPage: function (page) { this.page = page; }, addBundle: function (item) { const index = this.selectedBundles.findIndex( (p) => p.bundle.id === item.id ); if (index === -1) { const obj = { bundle: item }; this.selectedBundles.push(obj); this.$emit("setBundles", this.selectedBundles); return; } warn("Bundle is selected already"); }, deleteProduct: function (index) { this.selectedBundles.splice(index, 1); this.$emit("setBundles", this.selectedBundles); }, }, async mounted() { this.getBnds(); }, destroyed() { if (this.timer) { clearTimeout(this.timer); this.timer = null; } this.clearBundles(); }, }; </script> <style scoped> </style> |