added charge for all product

This commit is contained in:
2026-07-11 11:42:12 +03:30
parent 65fe1c3996
commit 2647a50698
12 changed files with 463 additions and 478 deletions
@@ -35,11 +35,11 @@
<a-form-item :label="amountLabel" name="amountAbs" :rules="amountRules">
<BasicInput
v-model:value="modelValue.amountAbs"
:addon-before="unit"
:type="variant === 'money' ? 'price' : 'number'"
:addon-before="resolvedUnit"
:type="resolvedInputType"
:place-holder="amountPlaceholder"
/>
<div v-if="variant === 'money' && Number(modelValue.amountAbs) > 10" class="wallet-charge-form__hint">
<div v-if="isMoney && Number(modelValue.amountAbs) > 10" class="wallet-charge-form__hint">
معادل {{ usePrice(Number(modelValue.amountAbs) / 10, true, 'تومان') }}
</div>
</a-form-item>
@@ -56,48 +56,63 @@ import type { FormInstance } from 'ant-design-vue'
import type { Charge } from '@/model/wallet'
import { inputRules } from '@/utils/inputRules'
import { usePrice } from '@core/utils/usePrice'
import { m } from '@/utils/metalLabels'
const props = defineProps<{
variant: 'money' | 'gold'
modelValue: Charge
}>()
const props = withDefaults(
defineProps<{
/** @deprecated از unitLabel و isMoney استفاده کنید */
variant?: 'money' | 'gold'
modelValue: Charge
/** واحد نمایش: ریال، گرم، عدد، ... */
unitLabel?: string
/** true = ورودی قیمتی (ریال)، false = عددی */
isMoney?: boolean
/** نام کیف پول برای پیش‌نمایش */
walletLabel?: string
}>(),
{
variant: 'money',
},
)
const formRef = ref<FormInstance>()
const unit = computed(() => (props.variant === 'money' ? 'ریال' : 'گرم'))
const resolvedUnit = computed(
() => props.unitLabel ?? (props.variant === 'money' ? 'ریال' : 'گرم'),
)
const isMoney = computed(() => props.isMoney ?? props.variant === 'money')
const resolvedInputType = computed(() => (isMoney.value ? 'price' : 'number'))
const isDischarge = computed(() => props.modelValue.direction === 'discharge')
const formClass = computed(() =>
isDischarge.value ? 'wallet-charge-form--discharge' : 'wallet-charge-form--charge'
isDischarge.value ? 'wallet-charge-form--discharge' : 'wallet-charge-form--charge',
)
const previewClass = computed(() =>
isDischarge.value
? 'wallet-charge-form__preview--discharge'
: 'wallet-charge-form__preview--charge'
: 'wallet-charge-form__preview--charge',
)
const previewSign = computed(() => (isDischarge.value ? '−' : '+'))
const previewText = computed(() => {
const action = isDischarge.value ? 'کسر از' : 'افزایش'
const wallet = props.variant === 'money' ? 'موجودی ریالی' : m('موجودی طلایی')
const wallet = props.walletLabel ?? (isMoney.value ? 'موجودی ریالی' : 'موجودی محصول')
return `${action} ${wallet} کاربر`
})
const amountLabel = computed(() =>
isDischarge.value ? `مقدار دشارژ (${unit.value})` : `مقدار شارژ (${unit.value})`
isDischarge.value ? `مقدار دشارژ (${resolvedUnit.value})` : `مقدار شارژ (${resolvedUnit.value})`,
)
const noteLabel = computed(() => (isDischarge.value ? 'علت دشارژ' : 'علت شارژ'))
const amountPlaceholder = computed(() =>
props.variant === 'money' ? 'مثلاً ۱۰۰٬۰۰۰' : 'مثلاً ۰.۵'
isMoney.value ? 'مثلاً ۱۰۰٬۰۰۰' : 'مثلاً ۰.۵',
)
const notePlaceholder = computed(() =>
isDischarge.value ? 'دلیل کسر موجودی' : 'دلیل افزایش موجودی'
isDischarge.value ? 'دلیل کسر موجودی' : 'دلیل افزایش موجودی',
)
const amountRules = [
@@ -109,12 +124,12 @@ const amountRules = [
return Promise.reject('مقدار باید بیشتر از صفر باشد')
}
return Promise.resolve()
}
}
},
},
]
defineExpose({
validateFields: () => formRef.value?.validateFields()
validateFields: () => formRef.value?.validateFields(),
})
</script>