Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse calc 1 #12

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/pages/ReverseCalc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const emptyResult: Result = {
tax: 0,
};

const screenWidth = window.innerWidth;

const flattenStipend = (options: typeof Stipend): typeof convertedStipend => {
const newOptions: typeof convertedStipend = Object.assign({}, convertedStipend);
let property: keyof typeof Stipend;
Expand Down Expand Up @@ -100,7 +102,7 @@ const inputSum = ref<string>('');
function formatInput(input: string) {
if (input.length === 0) {
return true;
} else if (/^[0-9]+\.?[0-9]{0,2}$/.test(input)) {
} else if (/^[0-9]+[\\.,]?[0-9]{0,2}$/.test(input)) {
return true;
} else {
return 'Недопустимые символы';
Expand All @@ -109,9 +111,8 @@ function formatInput(input: string) {

let result: Result = emptyResult;
const recount = computed(() => {
result =
combinations.find(o => o.sum <= Number(inputSum.value) + 1 && o.sum >= Number(inputSum.value) - 1) ??
emptyResult;
const tempInput = inputSum.value.replace(',', '.');
result = combinations.find(o => o.sum <= Number(tempInput) + 1 && o.sum >= Number(tempInput) - 1) ?? emptyResult;
return result;
});

Expand Down Expand Up @@ -149,16 +150,16 @@ const formattedStipend = (stipend: number): string => {
<template>
<div class="container">
<div class="rounded calc">
<IrdomSection title="Введите полученную сумму">
<IrdomSection class="mb-0" title="Введите полученную сумму">
<v-text-field
v-model="inputSum"
label="Полученная сумма"
:rules="[formatInput]"
@update:model-value="recount"
></v-text-field>
<v-divider />
<v-divider class="ma-0" />
</IrdomSection>
<div>
<div class="ma-0">
<div class="d-flex justify-space-between">
<div class="pay">ГАС</div>
<div id="gas" class="sum-plus">{{ formattedStipend(recount['gas']) }}</div>
Expand All @@ -182,8 +183,10 @@ const formattedStipend = (stipend: number): string => {
</div>
<v-divider />
<div class="your d-flex justify-space-between">
<div class="result">Сумма:</div>
<div id="result" class="stipend">{{ found ? formattedStipend(recount['sum']) : 'Не найдено' }}</div>
<div class="text-h4">Сумма:</div>
<div class="stipend text-h4" :class="screenWidth < 800 ? 'text-h5' : 'text-h4'">
{{ found ? formattedStipend(recount['sum']) : 'Не найдено' }}
</div>
</div>
</div>
</div>
Expand Down
Loading