summaryrefslogtreecommitdiff
path: root/iridescence/src/components/ProductCard.vue
blob: 67fbfbdc53bc5711d32e3fd3da69dcd85d551c51 (plain) (blame)
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
<template>
  <div id="productCard">
    <div class="card">
      <div class="card-image">
        <figure class="image is-square">
          <a href="#">
            <img :src="thumbnail" :alt="name" title="Click to expand." />
          </a>
        </figure>
      </div>
      <div class="card-content">
        <div class="content">
          <p class="title is-4">
            <a href="#">
              {{ name }}
            </a>
          </p>
          <p class="subtitle is-4">
            {{ dollars }}
          </p>
          <p class="subtitle is-6">{{ stock }}</p>
        </div>

        <div class="content">
          {{ shortDescription }}
        </div>
      </div>
    </div>
    <ProductDetail
      v-if="id == 6"
      v-bind="{
        id: id,
        name: name,
        quantity: quantity,
        cents: cents,
        photo_base: photo_base,
        photo_fullsize: photo_fullsize,
        description: description
      }"
    ></ProductDetail>
  </div>
</template>

<script>
import ProductDetail from "@/components/ProductDetail.vue";

export default {
  name: "ProductCard",
  components: { ProductDetail },
  props: {
    id: Number,
    name: String,
    quantity: Number,
    cents: Number,
    photo_thumbnail: String,
    photo_base: String,
    photo_fullsize: String,
    description: String
  },
  computed: {
    stock() {
      if (this.quantity == 0) {
        return "Made to order";
      } else {
        return [this.quantity, "in stock"].join(" ");
      }
    },
    dollars() {
      return "$ " + (this.cents / 100).toFixed(2);
    },
    thumbnail() {
      return process.env.VUE_APP_IMAGE_ROOT + "/" + this.photo_thumbnail;
    },
    shortDescription() {
      let description = this.description.split(" ");
      if (description.length < 10) {
        return this.description;
      } else {
        return description.splice(0, 10).join(" ") + "…";
      }
    }
  }
};
</script>