|
1 | 1 | <template>
|
2 | 2 | <div class="container f-col p-3">
|
3 | 3 |
|
4 |
| - <div class="flex my-3"> |
5 |
| - <label class="col-start">Target</label> |
6 |
| - <div class="col-end"> |
7 |
| - <input type="number" min="0" step="0.01" autofocus |
8 |
| - v-model.number.lazy="target" @change="targetChanged()"/> |
9 |
| - </div> |
| 4 | + <div class="f-row items-center justify-between mb-5"> |
| 5 | + <label for="target" class="inline-block"> |
| 6 | + Target |
| 7 | + </label> |
| 8 | + <input type="number" id="target" min="0" step="0.01" autofocus |
| 9 | + class="inline-block w-1/3" |
| 10 | + v-model.number.lazy="target" @change="targetChanged($event)"/> |
| 11 | + <auto-toggle-button v-model="auto"></auto-toggle-button> |
10 | 12 | </div>
|
11 | 13 |
|
12 |
| - <div class="flex"> |
13 |
| - <div class="col-start-full"> |
14 |
| - <solution-buttons v-if="solutions && mode === 'auto'" |
15 |
| - :solutions="solutions" |
16 |
| - @select="selectSolution"/> |
17 |
| - </div> |
18 |
| - |
19 |
| - <span class="col-end pb-1"> |
20 |
| - <button class="btn btn-primary" type="button" v-if="mode === 'manual'" @click="mode = 'auto'">Auto</button> |
21 |
| - <button class="btn btn-primary" type="button" v-if="mode === 'auto'" @click="mode = 'manual'">Manual</button> |
22 |
| - </span> |
| 14 | + <div class="solution-buttons-container px-5"> |
| 15 | + <solution-buttons v-if="solutions && auto" |
| 16 | + :solutions="solutions" |
| 17 | + @select="selectSolution"/> |
23 | 18 | </div>
|
24 | 19 |
|
25 | 20 | <hr>
|
|
40 | 35 | <hr>
|
41 | 36 |
|
42 | 37 | <div class="f-col">
|
43 |
| - <div class="f-row my-2"> |
| 38 | + <div class="f-row mt-2"> |
44 | 39 | <span class="col-start">Ticket total</span>
|
45 | 40 | <div class="col-end-value">
|
46 | 41 | <span class="input-value result-value">{{ ticketTotal | fixed2 }}</span>
|
47 | 42 | </div>
|
48 | 43 | </div>
|
49 |
| - <div class="f-row my-2" :class="{'invisible': !target}"> |
| 44 | + <div class="f-row mt-2" :class="{'invisible': !target}"> |
50 | 45 | <span class="col-start">
|
51 | 46 | {{ balanceLabel }}
|
52 | 47 | </span>
|
|
58 | 53 | </div>
|
59 | 54 | </div>
|
60 | 55 |
|
61 |
| - <div class="flex justify-end mt-4"> |
| 56 | + <div class="flex justify-end mt-4 text-base"> |
62 | 57 | <div class="col-end">
|
63 | 58 | <button class="btn btn-primary" type="button"
|
64 | 59 | @click="reset()"
|
|
75 | 70 | import {cloneDeep, map, round, sumBy} from 'lodash';
|
76 | 71 | import {mapGetters} from 'vuex'
|
77 | 72 |
|
| 73 | + import AutoToggleButton from '@/components/AutoToggleButton'; |
78 | 74 | import SolutionButtons from "@/components/SolutionButtons";
|
79 | 75 | import TicketQuantityRow from "@/components/TicketQuantityRow";
|
80 | 76 | import TicketQuantity from '@/models/ticket-quantity';
|
|
83 | 79 | export default {
|
84 | 80 | name: 'Calc',
|
85 | 81 | components: {
|
| 82 | + AutoToggleButton, |
86 | 83 | SolutionButtons,
|
87 | 84 | TicketQuantityRow,
|
88 | 85 | },
|
|
92 | 89 | data() {
|
93 | 90 | return {
|
94 | 91 | target: null,
|
95 |
| - mode: 'auto', |
96 | 92 | ticketQuantities: [],
|
97 | 93 | solutions: null,
|
| 94 | + auto: true, |
98 | 95 | };
|
99 | 96 | },
|
100 | 97 | created() {
|
|
105 | 102 | 'tickets'
|
106 | 103 | ]),
|
107 | 104 | calcButtonsDisabled() {
|
108 |
| - return this.mode === 'auto'; |
| 105 | + return this.auto; |
109 | 106 | },
|
110 | 107 | ticketTotal() {
|
111 | 108 | return round(
|
|
133 | 130 | }
|
134 | 131 | },
|
135 | 132 | methods: {
|
136 |
| - targetChanged() { |
| 133 | + targetChanged(event) { |
137 | 134 |
|
138 | 135 | if (this.tickets.length === 0) { return; }
|
139 | 136 |
|
140 | 137 | this.solutions = new Calculator(this.tickets)
|
141 | 138 | .optimizeCalc(this.target);
|
| 139 | +
|
| 140 | + // Force blur to hide keyboard |
| 141 | + event.target.blur(); |
142 | 142 | },
|
143 | 143 | selectSolution(solution) {
|
144 | 144 | this.ticketQuantities = cloneDeep(solution.ticketQuantities);
|
145 | 145 | },
|
146 | 146 | reset() {
|
147 | 147 | this.target = null;
|
148 | 148 | this.ticketQuantities.forEach(tq => tq.quantity = 0);
|
149 |
| - this.mode = 'auto'; |
| 149 | + this.auto = true; |
150 | 150 | this.solutions = null;
|
151 | 151 | }
|
152 | 152 | },
|
|
158 | 158 | .col-start {
|
159 | 159 | @apply flex-grow pl-2;
|
160 | 160 | }
|
161 |
| - .col-start-full { |
162 |
| - @apply flex-grow; |
163 |
| - max-width: calc(100% - 10rem); |
164 |
| - } |
165 | 161 | .col-end {
|
166 | 162 | @apply inline-block text-center;
|
167 |
| - width: 10rem; |
| 163 | + width: 8rem; |
168 | 164 | }
|
169 | 165 | .col-end-value {
|
170 |
| - @apply text-right pr-8; |
| 166 | + @apply text-right pr-6; |
171 | 167 | }
|
172 | 168 |
|
173 | 169 | hr {
|
174 | 170 | width: 104%;
|
175 | 171 | margin-left: -2%;
|
176 | 172 | }
|
177 | 173 |
|
| 174 | + .solution-buttons-container { |
| 175 | + min-height: 2.5rem; /*min-h-10*/ |
| 176 | + } |
| 177 | +
|
178 | 178 | .result-value {
|
179 |
| - @apply bg-gray-300 py-1 px-3 rounded-lg; |
| 179 | + @apply inline-block bg-gray-300 py-1 px-3 rounded-lg align-bottom leading-tight; |
| 180 | + min-width: 4.5rem; |
180 | 181 | }
|
181 | 182 | .has-remaining { @apply text-positive; }
|
182 | 183 | .has-extra { @apply text-negative; }
|
|
0 commit comments