Skip to content

Commit af2a65f

Browse files
committed
Added discount
1 parent 501fe0a commit af2a65f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

projects/wonder_flowers/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h1>Доставка цветов</h1>
4848
<div class="col">
4949
<div class="form-group">
5050
<label>Стоимость:</label>
51-
<input type="number" class="form-control" v-model.number="cost" disabled>
51+
<input type="text" class="form-control" v-model.number="costs" disabled>
5252
</div>
5353
</div>
5454
<button type="button" class="btn btn-outline-primary btn-block" v-on:click="add">
@@ -81,7 +81,7 @@ <h1>Доставка цветов</h1>
8181
<div class="col">
8282
<div class="form-group">
8383
<label>Итого:</label>
84-
<input type="number" class="form-control" v-model="totalCost" disabled>
84+
<input type="text" class="form-control" v-model="totalCosts" disabled>
8585
</div>
8686
</div>
8787
</div>

projects/wonder_flowers/script.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Vue.component('calc-item', {
1515
<div class="col">\
1616
<div class="form-group">\
1717
<label>Стоимость:</label>\
18-
<input type="number" class="form-control" v-model.number="cost" disabled>\
18+
<input type="text" class="form-control" v-model.number="costs" disabled>\
1919
</div>\
2020
<button type="button" class="btn btn-outline-primary btn-block" v-on:click="remove">Удалить</button>\
2121
</div>\
@@ -29,7 +29,10 @@ Vue.component('calc-item', {
2929
},
3030
computed: {
3131
cost: function () {
32-
return Math.round((330 + Math.atan((this.duration - 30) / 20) * 230) / 10) * 10
32+
return 330 + Math.atan((this.duration - 30) / 20) * 230
33+
},
34+
costs: function () {
35+
return this.round(this.cost) + ' / ' + this.round(this.cost * .85)
3336
}
3437
},
3538
methods: {
@@ -43,6 +46,9 @@ Vue.component('calc-item', {
4346
this.$emit('update', {
4447
duration: this.duration, cost: this.cost, index: this.index
4548
})
49+
},
50+
round: function (n) {
51+
return Math.round(n / 10) * 10
4652
}
4753
}
4854
})
@@ -58,13 +64,19 @@ var app = new Vue({
5864
},
5965
computed: {
6066
cost: function () {
61-
return Math.round((450 + Math.atan((this.duration - 30) / 20) * 230) / 10) * 10
67+
return 450 + Math.atan((this.duration - 30) / 20) * 230
6268
},
6369
totalDuration: function () {
6470
return this.duration + this.additionalDuration
6571
},
6672
totalCost: function () {
6773
return this.cost + this.additionalCost
74+
},
75+
costs: function () {
76+
return this.round(this.cost) + ' / ' + this.round(this.cost * .85)
77+
},
78+
totalCosts: function () {
79+
return this.round(this.totalCost) + ' / ' + this.round(this.totalCost * .85)
6880
}
6981
},
7082
methods: {
@@ -108,6 +120,9 @@ var app = new Vue({
108120
this.additionalCost -= item.cost
109121

110122
this.additional.splice(index, 1)
123+
},
124+
round: function (n) {
125+
return Math.round(n / 10) * 10
111126
}
112127
}
113128
})

0 commit comments

Comments
 (0)