Allow negative toman input for SMS auto-block threshold.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
import {
|
import {
|
||||||
fromGroupedInput,
|
fromGroupedInput,
|
||||||
rialToToman,
|
rialToToman,
|
||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
* Money field bound to **rial** storage values (API/DB).
|
* Money field bound to **rial** storage values (API/DB).
|
||||||
* User types and sees **toman** (÷10 / ×10 at the edges).
|
* User types and sees **toman** (÷10 / ×10 at the edges).
|
||||||
* With `nullable`, empty input emits `null` (for optional thresholds).
|
* With `nullable`, empty input emits `null` (for optional thresholds).
|
||||||
|
* With `allowNegative`, values like `-50,000` are accepted.
|
||||||
*/
|
*/
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@@ -34,7 +35,18 @@ const emit = defineEmits<{
|
|||||||
(e: 'update:value', value: number | null): void
|
(e: 'update:value', value: number | null): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
/** Keeps intermediate input like "-" while typing a negative amount. */
|
||||||
|
const draft = ref<string | null>(null)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.value,
|
||||||
|
() => {
|
||||||
|
draft.value = null
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
const display = computed(() => {
|
const display = computed(() => {
|
||||||
|
if (draft.value !== null) return draft.value
|
||||||
if (props.nullable && (props.value == null || props.value === undefined)) return ''
|
if (props.nullable && (props.value == null || props.value === undefined)) return ''
|
||||||
return toGroupedDisplay(rialToToman(props.value ?? 0))
|
return toGroupedDisplay(rialToToman(props.value ?? 0))
|
||||||
})
|
})
|
||||||
@@ -42,9 +54,16 @@ const display = computed(() => {
|
|||||||
function onInput(raw: string | number) {
|
function onInput(raw: string | number) {
|
||||||
const text = String(raw ?? '').trim()
|
const text = String(raw ?? '').trim()
|
||||||
if (props.nullable && !text) {
|
if (props.nullable && !text) {
|
||||||
|
draft.value = null
|
||||||
emit('update:value', null)
|
emit('update:value', null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Allow typing a leading minus before digits arrive.
|
||||||
|
if (props.allowNegative && text === '-') {
|
||||||
|
draft.value = '-'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
draft.value = null
|
||||||
const toman = fromGroupedInput(text, props.allowNegative)
|
const toman = fromGroupedInput(text, props.allowNegative)
|
||||||
emit('update:value', tomanToRial(toman))
|
emit('update:value', tomanToRial(toman))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -520,15 +520,19 @@ onMounted(async () => {
|
|||||||
<h3>مسدودسازی خودکار ارسال</h3>
|
<h3>مسدودسازی خودکار ارسال</h3>
|
||||||
<p class="hint">
|
<p class="hint">
|
||||||
اگر مبلغی بگذارید و موجودی از آن کمتر شود، ارسال پیامک خودکار قطع میشود (کلید مسدودسازی
|
اگر مبلغی بگذارید و موجودی از آن کمتر شود، ارسال پیامک خودکار قطع میشود (کلید مسدودسازی
|
||||||
روشن نمیشود). خالی بگذارید تا فقط با کلید دستی مسدود شود.
|
روشن نمیشود). معمولاً منفی است؛ مثلاً
|
||||||
|
<strong dir="ltr">-۵۰٬۰۰۰</strong>
|
||||||
|
یعنی تا ۵۰ هزار تومان بدهی اجازه ارسال هست و پایینتر مسدود میشود. خالی بگذارید تا فقط با
|
||||||
|
کلید دستی مسدود شود.
|
||||||
</p>
|
</p>
|
||||||
<div class="threshold-grid">
|
<div class="threshold-grid">
|
||||||
<label>
|
<label>
|
||||||
<span class="tone-label">آستانه مسدودسازی خودکار (تومان)</span>
|
<span class="tone-label">آستانه مسدودسازی خودکار (تومان)</span>
|
||||||
<MoneyInput
|
<MoneyInput
|
||||||
v-model:value="form.autoBlockBelowRials"
|
v-model:value="form.autoBlockBelowRials"
|
||||||
|
allow-negative
|
||||||
nullable
|
nullable
|
||||||
placeholder="خالی = بدون مسدودسازی خودکار"
|
placeholder="مثلاً -50,000 — خالی = غیرفعال"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<a-button type="primary" size="large" :loading="saving" @click="saveThresholds">
|
<a-button type="primary" size="large" :loading="saving" @click="saveThresholds">
|
||||||
|
|||||||
Reference in New Issue
Block a user