mirror of
https://github.com/frappe/books.git
synced 2025-02-10 16:08:35 +00:00
incr: simplify barcode widget
- update exchange rate widget ui - set default outline colour
This commit is contained in:
parent
7656476b6a
commit
b9c872d6dd
@ -1,94 +1,46 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div
|
||||||
<Button :icon="true" @click="openModal = true">{{
|
class="
|
||||||
t`Scan Barcode`
|
flex
|
||||||
}}</Button>
|
items-center
|
||||||
<Modal :open-modal="openModal" @closemodal="openModal = false">
|
border
|
||||||
<FormHeader :form-title="t`Barcode Scanner`" />
|
w-36
|
||||||
<hr />
|
rounded
|
||||||
<div class="p-4">
|
px-2
|
||||||
<div class="w-full flex flex-col justify-center items-center">
|
bg-gray-50
|
||||||
<input
|
focus-within:bg-gray-100
|
||||||
type="text"
|
"
|
||||||
class="
|
>
|
||||||
border
|
<input
|
||||||
w-96
|
ref="scanner"
|
||||||
rounded
|
type="text"
|
||||||
text-base
|
class="text-base placeholder-gray-600 w-full bg-transparent outline-none"
|
||||||
px-3
|
@change="handleChange"
|
||||||
py-2
|
:placeholder="t`Enter barcode`"
|
||||||
placeholder-gray-600
|
/>
|
||||||
bg-gray-50
|
<feather-icon
|
||||||
focus-within:bg-gray-100
|
name="maximize"
|
||||||
"
|
class="w-3 h-3 text-gray-600 cursor-text"
|
||||||
@change="(e) => getItem((e.target as HTMLInputElement)?.value)"
|
@click="() => ($refs.scanner as HTMLInputElement).focus()"
|
||||||
:placeholder="t`Enter barcode`"
|
/>
|
||||||
/>
|
|
||||||
<div v-if="error" class="text-sm text-red-600 mt-4 w-96 text-center">
|
|
||||||
{{ error }}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-if="success"
|
|
||||||
class="text-sm text-green-600 mt-4 w-96 text-center"
|
|
||||||
>
|
|
||||||
{{ success }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { showToast } from 'src/utils/ui';
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import Button from '../Button.vue';
|
|
||||||
import FormHeader from '../FormHeader.vue';
|
|
||||||
import Modal from '../Modal.vue';
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: { Button, Modal, FormHeader },
|
|
||||||
emits: ['item-selected'],
|
emits: ['item-selected'],
|
||||||
watch: {
|
|
||||||
openModal(value: boolean) {
|
|
||||||
if (value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.clear();
|
|
||||||
},
|
|
||||||
error(value: string) {
|
|
||||||
if (!value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.success = '';
|
|
||||||
},
|
|
||||||
success(value: string) {
|
|
||||||
if (!value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.error = '';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
openModal: false,
|
|
||||||
error: '',
|
|
||||||
success: '',
|
|
||||||
} as {
|
|
||||||
openModal: boolean;
|
|
||||||
error: string;
|
|
||||||
success: string;
|
|
||||||
};
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
clear() {
|
handleChange(e: Event) {
|
||||||
this.error = '';
|
const elem = e.target as HTMLInputElement;
|
||||||
this.success = '';
|
this.getItem(elem.value);
|
||||||
|
elem.value = '';
|
||||||
},
|
},
|
||||||
async getItem(code: string) {
|
async getItem(code: string) {
|
||||||
const barcode = code.trim();
|
const barcode = code.trim();
|
||||||
if (!/\d{12,}/.test(barcode)) {
|
if (!/\d{12,}/.test(barcode)) {
|
||||||
return (this.error = this.t`Invalid barcode ${barcode}.`);
|
return this.error(this.t`Invalid barcode value ${barcode}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = (await this.fyo.db.getAll('Item', {
|
const items = (await this.fyo.db.getAll('Item', {
|
||||||
@ -98,12 +50,18 @@ export default defineComponent({
|
|||||||
|
|
||||||
const name = items?.[0]?.name;
|
const name = items?.[0]?.name;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return (this.error = this.t`Item with barcode ${barcode} not found.`);
|
return this.error(this.t`Item with barcode ${barcode} not found.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.success = this.t`Quantity 1 of ${name} added.`;
|
this.success(this.t`${name} added.`);
|
||||||
this.$emit('item-selected', name);
|
this.$emit('item-selected', name);
|
||||||
},
|
},
|
||||||
|
error(message: string) {
|
||||||
|
showToast({ type: 'error', message });
|
||||||
|
},
|
||||||
|
success(message: string) {
|
||||||
|
showToast({ type: 'success', message });
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex items-center bg-gray-100 rounded-md textsm px-1">
|
<div class="flex items-center bg-gray-50 rounded-md textsm px-1 border">
|
||||||
<div
|
<div
|
||||||
class="rate-container"
|
class="rate-container"
|
||||||
:class="disabled ? 'bg-gray-100' : 'bg-gray-25'"
|
:class="disabled ? 'bg-gray-100' : 'bg-gray-25'"
|
||||||
@ -89,12 +89,11 @@ export default defineComponent({
|
|||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
input[type='number'] {
|
input[type='number'] {
|
||||||
@apply w-12 outline-none bg-transparent p-0.5;
|
@apply w-12 bg-transparent p-0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rate-container {
|
.rate-container {
|
||||||
@apply flex items-center rounded-md border border-gray-100 text-gray-900
|
@apply flex items-center rounded-md border-gray-100 text-gray-900 text-sm px-1 focus-within:border-gray-200 bg-transparent;
|
||||||
text-sm outline-none focus-within:bg-gray-50 px-1 focus-within:border-gray-200;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.rate-container > p {
|
.rate-container > p {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
|
outline-color: theme('colors.pink.500');
|
||||||
font-variation-settings: 'slnt' 0deg;
|
font-variation-settings: 'slnt' 0deg;
|
||||||
}
|
}
|
||||||
.italic {
|
.italic {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user