remove toPersianDigits

This commit is contained in:
2026-06-17 13:51:29 +03:30
parent b42b123957
commit 61e10dd45a
13 changed files with 65 additions and 55 deletions
+13 -10
View File
@@ -35,7 +35,7 @@
<script lang="ts" setup>
import {usePrefix} from "@/utils/usePrefix";
import {computed} from "vue";
import {usePrice} from "@/components/BasicPacks/BasicPriceInput/src/utils/usePrice";
import {usePrice} from "@/utils/usePrice";
//Props
interface Prop {
@@ -59,13 +59,14 @@ const addonTextColor = computed(() => props.addonTextColor)
//emits
const localValue = computed({
set(value) {
// console.log(value?.toString().replaceAll(',', ''))
props.type === 'price' ? emits('update:value', value?.toString().replaceAll(',', '')) : emits('update:value', value)
props.type === 'price'
? emits('update:value', value?.toString().replaceAll(',', ''))
: emits('update:value', value)
},
get() {
let a = props.type === 'price' ? props.value ? usePrice(props.value as number, true, '').trim() : '' : props.value
// console.log(props.value)
return a
return props.type === 'price'
? props.value ? usePrice(props.value as number, true, '').trim() : ''
: props.value
},
})
@@ -75,10 +76,12 @@ const props = withDefaults(defineProps<Prop>(), {
const emits = defineEmits(['update:value', 'onchange'])
const handlerChange = (e: any) => {
// emits('onchange', e.target.value)
props.type === 'price' ? emits('update:value', e.target.value?.toString().replaceAll(',', '')) : emits('update:value', e.target.value)
props.type === 'price' ? emits('onchange', e.target.value?.toString().replaceAll(',', '')) : emits('onchange', e.target.value)
// console.log('sas')
props.type === 'price'
? emits('update:value', e.target.value?.toString().replaceAll(',', ''))
: emits('update:value', e.target.value)
props.type === 'price'
? emits('onchange', e.target.value?.toString().replaceAll(',', ''))
: emits('onchange', e.target.value)
}
//css style
@@ -7,7 +7,7 @@
</template>
<script lang="ts" setup>
import {usePrice} from './utils/usePrice'
import {usePrice} from '@/utils/usePrice'
import {computed} from "vue";
import BasicInput from "../../BasicInput.vue";
@@ -23,9 +23,7 @@ const props = withDefaults(defineProps<Props>(), {})
const _val = computed({
set(val: string) {
// const temp = val.toString().replaceAll(',', '')
const temp = val.toString().replaceAll(',', '')
emit('update:value', temp)
emit('update:value', val.toString().replaceAll(',', ''))
},
get() {
return props.value ? usePrice(props.value as number, true, '').trim() : ''
@@ -1,17 +1 @@
export function usePrice(price: number, digit = true, unit = 'ریال') {
let _price = price.toString()
if (digit) {
_price = _price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
return `${_price} ${unit}`
}
export function useTowDecimal(num: string | number): string | number {
const temp = num.toString().match(/^-?\d+(?:\.\d{0,2})?/)
if (temp && temp.length > 0) return temp[0]
return Math.round(+num * 100) / 100
}
export function useFormat(num: string | number, unit = '') {
return usePrice(Math.abs(+useTowDecimal(num)), true, unit)
}
export { usePrice, usePriceWithoutType, useTowDecimal, useFormat } from '@/utils/usePrice'