-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.js
152 lines (139 loc) · 3.46 KB
/
main2.js
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
Vue.component('coin-card', {
props: ['coin'],
template: `
<div class="item-card">
<img :src="coin.image" alt="" class="item-photo">
<div class="item-description">
<h3 class="item-name">{{ coin.name }}</h3>
<h4 class="item-weight">{{ coin.weight }}</h4>
<small class="item-purity">{{ coin.purity }}</small>
<h1 class="item-price">{{ coin.markup }}</h1>
<form class="add-items">
<input type="number" min="0" size="2" placeholder="0" class="item-number" v-model.number="coin.numOfEachProduct">
<div class="add-to-cart button" v-on:click='addToCart()'>Add to Cart</div>
</form>
</div>
</div>
`
})
Vue.component('add-to-cart', {
data: function() {
return {
}
}
})
var app = new Vue({
el: '#app',
data: {
goldSpot: 1334.20,
silverSpot: 16.57,
cart: 0,
numItems: 0,
percentageChange: 1.34,
metalType: 'gold',
products : [
{
productId: 0,
metalType: 'gold',
name: '2018 American Eagle',
weight: '1 oz of Gold',
purity: '.9167 FINE GOLD',
image: './assets/2018-1-oz-american-gold-eagle_360.png',
markup: 1.045,
numOfEachProduct: 0
},
{
productId: 1,
metalType: 'gold',
name: '2018 American Gold Buffalo',
weight: '1 oz of Gold',
purity: '.9999 FINE GOLD',
image: './assets/2018-1-oz-american-gold-buffalo_360.png',
markup: 1.076,
numOfEachProduct: 0
},
{
productId: 2,
metalType: 'gold',
name: '2018 Austrian Gold Philharmonic',
weight: '1 oz of Gold',
purity: '.9999 FINE GOLD',
image: './assets/2018-1-oz-austrian-gold-philharmonic_360.jpeg',
markup: 1.091,
numOfEachProduct: 0
},
{
productId: 3,
metalType: 'gold',
name: '2018 Great Britain Gold Brittania',
weight: '1 oz of Gold',
purity: '.9999 FINE GOLD',
image: './assets/2018-1-oz-great-britain-gold-britannia_360.png',
markup: 1.071,
numOfEachProduct: 0
},
{
productId: 4,
metalType: 'silver',
name: '2018 American Eagle',
weight: '1 oz of Silver',
purity: '.999 FINE SILVER',
image: './assets/2018-1-oz-american-silver-eagle_360.png',
markup: 1.056,
numOfEachProduct: 0
},
{
productId: 5,
metalType: 'silver',
name: '2018 Canadian Silver Maple Leaf',
weight: '1 oz of Silver',
purity: '.9999 FINE SILVER',
image: './assets/2018-1-oz-canadian-silver-maple-leaf_360.png',
markup: 1.071,
numOfEachProduct: 0
},
{
productId: 6,
metalType: 'silver',
name: '2018 Austrian Silver Philharmonic',
weight: '1 oz of Silver',
purity: '.9999 FINE SILVER',
image: './assets/2018-1-oz-austrian-silver-philharmonic_360.jpeg',
markup: 1.042,
numOfEachProduct: 0
},
{
productId: 7,
metalType: 'silver',
name: 'Morgan Silver Dollar 1878-1894',
weight: '.7735 oz of Silver',
purity: '90% Silver 10% Copper',
image: './assets/morgan_silver_dollar_brilliant_uncirculated_360.png',
markup: 1.256,
numOfEachProduct: 0
}
]
},
methods: {
addToCart(index) {
// this is a new change
this.cart += this.products.numOfEachProduct;
this.products.numOfEachProduct = 0;
},
selectGold() {
this.metalType = 'gold';
console.log(this.metalType + ' is selected');
},
selectSilver() {
this.metalType = 'silver';
console.log(this.metalType + ' is selected');
},
toggleMetalType() {
if(this.metalType === 'gold'){
this.metalType = 'silver'
} else {
this.metalType = 'gold'
}
}
},
})