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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | 1x 1x 1x 1x 2x 1x | <template> <div class="row w-100 justify-content-center"> <div class="d-flex flex-column col-md-8 col-12"> <div class="d-flex align-items-start my-3"> <button v-on:click="clearSelectedBundles" class="button"> <BIconArrowLeft /> </button> <div class="w-100 px-3"> <h6 class="m-0 px-2 font-weight-bold">{{ currentBundle.title }}</h6> </div> <button class="border-left" v-on:click="setPreviousBundle" :disabled="!previous" > <BIconChevronLeft /> </button> <button class="border-right" v-on:click="setNextBundle" :disabled="!next" > <BIconChevronRight /> </button> </div> <BundleForm class="block mb-3 p-3" :bundle="currentBundle" v-on:getBundle="getBundle" /> <button class="btn btn-success mb-3" v-on:click="save"> Save bundle </button> </div> </div> </template> <script> import { mapMutations, mapGetters, mapActions } from "vuex"; import { getStrapiMedia } from "~/utils/medias"; import { prevCurrNextItems } from "~/helpers"; import BundleForm from "./BundleForm.vue"; export default { name: "AdminBundle", components: { BundleForm }, data: () => ({ currentBundle: null, }), computed: { ...mapGetters({ bundles: "admin_bundles/bundles", previous: "admin_bundles/previous", selected: "admin_bundles/selected", next: "admin_bundles/next", params: "admin_products/params", total: "admin_products/total", }), }, watch: { selected: function () { this.currentBundle = JSON.parse(JSON.stringify(this.selected)); }, }, methods: { getStrapiMedia, prevCurrNextItems, ...mapActions({ updateBundle: "admin_bundles/updateBundle", getBundles: "admin_bundles/getBundles", }), ...mapMutations({ setParams: "admin_bundles/setParams", clearSelectedBundles: "admin_bundles/clearSelectedBundles", setSelectedBundles: "admin_bundles/setSelectedBundles", }), setNextBundle: async function () { const index = this.findIndex(); const { page, currentPerPage } = this.params; let isMax = false; if ( this.total / currentPerPage - page <= 0 && index === this.bundles.length - 2 ) { isMax = true; } const { selected, next, previous } = this.prevCurrNextItems( this.bundles[index + 1], this.bundles ); if (!isMax && !next) { const { page } = this.params; this.setParams({ ...this.params, page: page + 1 }); await this.getBundles(); const result = this.prevCurrNextItems(this.bundles[0], [ selected, ...this.bundles, ]); this.setSelectedBundles(result); } else { this.setSelectedBundles({ selected, next, previous }); } }, setPreviousBundle: async function () { const index = this.findIndex(); const { page } = this.params; const { selected, next, previous } = this.prevCurrNextItems( this.bundles[index - 1], this.bundles ); let isMin = false; if (page >= 1 && index === 1) { isMin = true; } if (!isMin && !previous) { const { page } = this.params; this.setParams({ ...this.params, page: page - 1 }); await this.getBundles(); const result = this.prevCurrNextItems( this.bundles[this.bundles.length - 1], [...this.bundles, selected] ); this.setSelectedBundles(result); } else { this.setSelectedBundles({ selected, next, previous }); } }, findIndex: function () { return this.bundles.findIndex((item) => item.id === this.selected.id); }, getBundle: function (data) { this.currentBundle = data; }, save: async function () { const products = this.currentBundle.products.map((item) => item.id); const bundle = { ...this.currentBundle, products }; await this.updateBundle(bundle); }, }, async beforeMount() { this.currentBundle = JSON.parse(JSON.stringify(this.selected)); }, }; </script> <style scoped> .button { border-radius: 5px; background: none; } .border-left { border-radius: 5px 0 0 5px; border: 1px solid #000; } .border-right { border-radius: 0 5px 5px 0; border: 1px solid #000; } </style> |