All files / components/Cart CartOrderItems.vue

0% Statements 0/5
0% Branches 0/2
0% Functions 0/1
0% Lines 0/5

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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202                                                                                                                                                                                                                                                                                                                                                                                                                   
<template>
  <ul class="p-0">
    <li v-for="item in order_items" :key="item.product.id" class="p-3 mb-3">
      <div class="d-flex flex-column">
        <div class="d-flex">
          <div class="image-wrap">
            <PreloaderImage
              :classStyle="'m-auto gold-border'"
              :image="item.product.image[0].url"
            />
          </div>
          <div class="d-flex flex-column px-3">
            <h6 class="block-with-text">{{ item.product.title }}</h6>
            <div>
              <p class="mb-2 grey text-uppercase">
                Price {{ item.product.price | formatNumber }} $
              </p>
            </div>
            <p v-if="item.quantity > 1">
              Total Price
              {{ (item.product.price * item.quantity) | formatNumber }}
              $
            </p>
          </div>
        </div>
        <div class="d-flex flex-column mt-3">
          <div class="d-flex flex-sm-row flex-column">
            <p class="w-25 mb-2 grey mr-2 text-uppercase">Quantity</p>
            <div class="d-flex" v-if="isEdit">
              <button v-if="isEdit" v-on:click="quantityMinus()" class="gold-background">
                -
              </button>
              <p class="my-auto text-uppercase" :class="isEdit && 'mx-3'">
                {{ selectedItem.quantity }}
              </p>
              <button v-if="isEdit" v-on:click="quantityPlus()" class="gold-background">
                +
              </button>
            </div>
            <div class="d-flex" v-else>
                {{ item.quantity }}
            </div>
          </div>
          <div class="d-flex flex-sm-row flex-column">
            <p class="w-25 mb-2 grey mr-2 text-uppercase">Category</p>
            <p v-for="category in item.product.categories" :key="category.id" class="mr-2 mb-2">
              {{ category.name }}
            </p>
          </div>
          <div class="d-flex flex-sm-row flex-column">
            <p class="w-25 mb-2 grey mr-2 text-uppercase">Purchase</p>
            <p class="mb-2" v-if="!isEdit">
              {{ item.purchase_type.title + (item.subscription_type? ' - ' + item.subscription_type.title: '') }}
            </p>
            <PurchaseTypes
              v-else
              cart
              :purType="item.purchase_type ? item.purchase_type.id : null"
              :subType="item.subscription_type ? item.subscription_type.id : null"
              v-on:setTypes="(types) => setTypes(types, item.id)"
            />
          </div>
        </div>
        <div class="w-100 d-flex justify-content-between">
          <div class="d-flex align-items-center pen" v-on:click="editOrSaveItem(item)">
            <span class="icon icon-pen m-2"></span>
            <p class="m-0 pl-1 gold text-uppercase">
              {{ isEdit ? "Save" : "Edit" }}
            </p>
          </div>
          <span class="icon icon-trash m-2" v-on:click="removeItemFromCart(item)"></span>
        </div>
      </div>
    </li>
  </ul>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
 
import PreloaderImage from "~/components/PreloaderImage";
import PurchaseTypes from "~/components/common/PurchaseTypes";
 
export default {
  name: "CartOrderItems",
  props: {
    order_items: Array,
  },
  components: { PreloaderImage, PurchaseTypes },
  data: () => ({
    isEdit: false,
    purchaseTypes: [],
    selectedItem: {
        id: null,
        quantity: 0,
        purchaseTypeId: null,
        subscriptionTypeId: null,
        orderId: null
    }
  }),
  methods: {
    quantityPlus() {
        if (this.selectedItem.quantity < 99) {
            this.selectedItem.quantity += 1
        }
    },
    quantityMinus() {
        if (this.selectedItem.quantity > 1) {
            this.selectedItem.quantity -= 1
        }
    },
    setTypes: function (types, id) {
        this.selectedItem.purchaseTypeId = types.purchase_type;
        this.selectedItem.subscriptionTypeId = types.subscription_type;
    },
    removeItemFromCart(item) {
        this.$store.dispatch('order/removeItem', item);
    },
    editOrSaveItem(item) {
        if (this.isEdit) {
            this.updateCart(this.selectedItem);
            this.isEdit = false;
        } else {
            this.selectedItem.id = item.id;
            this.selectedItem.quantity = item.quantity;
            this.selectedItem.purchaseTypeId = item.purchase_type.id? item.purchase_type: null;
            this.selectedItem.subscriptionTypeId = item.subscription_type? item.subscription_type.id: null;
            this.orderId = item.order.id;
            this.isEdit = true;
        }
    },
    updateCart: async function (data) {
        this.$store.dispatch("order/updateItem", data);
    }
  },
  async mounted () {
    this.purchaseTypes = await this.$strapi.find('purchase-types');
  }
};
</script>
 
<style scoped>
.image-wrap {
  min-width: 25%;
}
 
.cart {
  max-width: 600px;
  z-index: 1;
  position: relative;
  background: #333333;
}
 
li {
  background: #151515;
}
 
.icon {
  display: inline-block;
  width: 18px;
  height: 20px;
  background-size: cover;
}
 
.pen {
  cursor: pointer;
}
 
.icon-pen {
  width: 20px;
  background-image: url("../../assets/icons/pen-solid.svg");
  filter: invert(45%) sepia(61%) saturate(475%) hue-rotate(6deg) brightness(96%)
    contrast(95%);
}
 
.icon-trash {
  background-image: url("../../assets/icons/trash-can-solid.svg");
  filter: invert(39%) sepia(20%) saturate(3094%) hue-rotate(318deg)
    brightness(94%) contrast(92%);
}
 
button {
  color: #fff;
  border: none;
}
 
.block-with-text {
  overflow: hidden;
  position: relative;
  line-height: 1.2em;
  max-height: 2.4em;
  text-align: justify;
  padding-right: 1em;
}
 
.block-with-text:before {
  content: "...";
  position: absolute;
  right: 0;
  bottom: 0;
}
</style>