-
-
Notifications
You must be signed in to change notification settings - Fork 406
/
Copy path_id.vue
173 lines (159 loc) · 4.32 KB
/
_id.vue
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
<template>
<div>
<section class="item-contain">
<section class="img">
<img :src="`/products/${product.img}`" />
</section>
<section class="product-info">
<h1>{{ product.name }}</h1>
<star-rating
:rating="product.starrating"
:star-size="15"
:show-rating="false"
active-color="#000"
style="margin: 5px 0"
></star-rating>
<h4 class="price">{{ product.price | dollar }}</h4>
<p>{{ product.description }}</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Iusto velit dolores repudiandae animi quidem, eveniet quod dolor facilis dicta eligendi ullam error. Assumenda in fugiat natus enim similique nam itaque.</p>
<div class="product-options">
<div class="quantity">
<button class="update-num" @click="quantity > 0 ? quantity-- : quantity = 0">-</button>
<input type="number" v-model="quantity" />
<button class="update-num" @click="quantity++">+</button>
</div>
<div v-if="product.sizes" class="size">
<select v-model="size" class="size-picker" @change="showSizeRequiredMessage = false">
<option :value="null" disabled hidden>Size</option>
<option v-for="(size, key) in product.sizes" :key="key" :value="size">{{ size }}</option>
</select>
</div>
</div>
<p v-if="showSizeRequiredMessage" class="size-required-message">Please choose a size</p>
<p>
Available in additional colors:
<strong>
<span :style="`color: ${product.color}`">{{ product.color }}</span>
</strong>
</p>
<p>
<button class="button purchase" @click="cartAdd">Add to Cart</button>
</p>
</section>
</section>
<hr />
<div class="review">
<h2>Reviews</h2>
<!-- maybe an image of a person? -->
<star-rating
:rating="product.starrating"
active-color="#000"
:star-size="15"
:show-rating="false"
style="margin: 5px 0"
></star-rating>
<p>{{ product.review }}</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum iusto placeat consequatur voluptas sit mollitia ratione autem, atque sequi odio laborum, recusandae quia distinctio voluptatibus sint, quae aliquid possimus exercitationem.</p>
</div>
<app-featured-products />
</div>
</template>
<script>
import { mapState } from "vuex";
import StarRating from "vue-star-rating/src/star-rating.vue";
import AppFeaturedProducts from "~/components/AppFeaturedProducts.vue";
export default {
components: {
StarRating,
AppFeaturedProducts
},
data() {
return {
id: this.$route.params.id,
quantity: 1,
size: null,
showSizeRequiredMessage: false,
tempcart: [] // this object should be the same as the json store object, with additional params, quantity and size
};
},
computed: {
...mapState(["storedata"]),
product() {
return this.storedata.find(el => el.id === this.id);
}
},
methods: {
cartAdd() {
if (this.product.sizes && !this.size) {
this.showSizeRequiredMessage = true;
return;
}
let item = this.product;
item = {
...item,
quantity: this.quantity,
size: this.size
};
this.tempcart.push(item);
this.$store.commit("addToCart", {...item});
}
}
};
</script>
<style lang="scss" scoped>
.item-contain {
margin-left: 8%;
width: 80%;
display: grid;
justify-content: space-around;
grid-template-columns: 1fr 2fr;
}
.product-options {
display: flex;
}
input,
select {
width: 60px;
font-size: 25px;
margin: 0 5px;
padding: 5px 10px;
}
.update-num {
background: black;
border-color: black;
color: white;
font-size: 20px;
width: 45px;
}
.size {
margin-left: 10px;
}
.size-picker {
width: 130px;
font-size: 20px;
height: 100%;
border: 0;
background-color: white;
outline: 1px solid #ccc;
outline-offset: -1px;
}
.quantity {
display: flex;
}
.size-required-message {
color: red;
}
@media screen and (max-width: 650px) {
.img img {
width: 100%;
}
.item-contain {
margin-left: 0 !important;
width: 95% !important;
}
.review {
width: 90%;
margin-left: 4%;
}
}
</style>