fix some bugs

This commit is contained in:
2026-06-23 22:31:07 +03:30
parent 4e7d6bca00
commit 71764f7e9a
68 changed files with 1941 additions and 1288 deletions
@@ -2,7 +2,7 @@
<BasicActionSheet
v-model:visible="visibleProxy"
:title="modalTitle"
modal-width="22rem"
modal-width="24rem"
drawer-height="auto"
compact
:loading="loading"
@@ -24,33 +24,18 @@
/>
</div>
<div
v-if="selectedCustomer"
class="dashboard-wallet-modal__balances"
>
<div>
<span class="text-slate-500">طلایی</span>
<p class="font-semibold text-slate-800 dark:text-slate-100">{{ formatGold(selectedCustomer) }}</p>
</div>
<div v-if="selectedCustomer" class="dashboard-wallet-modal__balances">
<div>
<span class="text-slate-500">ریالی</span>
<p class="font-semibold text-slate-800 dark:text-slate-100">{{ formatCash(selectedCustomer) }}</p>
</div>
</div>
<div class="dashboard-wallet-modal__section">
<label class="dashboard-wallet-modal__label">نوع کیف پول</label>
<a-radio-group v-model:value="walletVariant" button-style="solid" class="flex w-full">
<a-radio-button value="money" class="w-1/2 text-center">ریالی</a-radio-button>
<a-radio-button value="gold" class="w-1/2 text-center">طلایی</a-radio-button>
</a-radio-group>
</div>
<WalletChargeForm
ref="chargeFormRef"
class="dashboard-wallet-modal__form"
:model-value="formCharge"
:variant="walletVariant"
:targets="chargeTargets"
/>
<div class="dashboard-wallet-modal__footer">
@@ -78,16 +63,18 @@ import { message } from 'ant-design-vue'
import BasicActionSheet from '@/components/BasicActionSheet.vue'
import WalletChargeForm from '@/pages/menuPages/customers/base/components/WalletChargeForm.vue'
import {
applyChargeTarget,
buildChargePayload,
createEmptyChargeForm,
resolveChargeTarget,
walletChargeOkText,
walletChargeSuccessMessage,
walletChargeTitle,
} from '@/pages/menuPages/customers/base/utils/walletChargeForm'
import { getCustomersList } from '@/api/customer'
import { chargeWallet } from '@/api/wallet'
import { chargeWalletUnified, getWalletChargeTargets } from '@/api/wallet'
import type { Customer } from '@/model/customer'
import type { Charge, Wallet } from '@/model/wallet'
import type { Charge, Wallet, WalletChargeTarget } from '@/model/wallet'
import { usePrice } from '@core/utils/usePrice'
const props = defineProps<{ visible: boolean }>()
@@ -101,7 +88,7 @@ const visibleProxy = computed({
const loading = ref(false)
const submitting = ref(false)
const customers = ref<Customer[]>([])
const walletVariant = ref<'money' | 'gold'>('money')
const chargeTargets = ref<WalletChargeTarget[]>([])
const formCharge = ref<Charge>(createEmptyChargeForm())
const chargeFormRef = ref<InstanceType<typeof WalletChargeForm>>()
@@ -123,8 +110,12 @@ const selectedCustomer = computed(() =>
customers.value.find((customer) => customer.id === formCharge.value.customer_id),
)
const selectedTarget = computed(() =>
resolveChargeTarget(chargeTargets.value, formCharge.value.chargeTargetKey),
)
const modalTitle = computed(() =>
walletChargeTitle(walletVariant.value, formCharge.value.direction),
walletChargeTitle(selectedTarget.value, formCharge.value.direction),
)
const okText = computed(() => walletChargeOkText(formCharge.value.direction))
@@ -138,20 +129,25 @@ function customerWallet(customer: Customer): Wallet | undefined {
return Array.isArray(wallet) ? wallet[0] : wallet
}
function formatGold(customer: Customer) {
const gold = customerWallet(customer)?.gold ?? customer.wallet_gold ?? customer.gold
return `${Number(gold ?? 0).toLocaleString('fa-IR', { maximumFractionDigits: 3 })} گرم`
}
function formatCash(customer: Customer) {
const cash = customerWallet(customer)?.cash ?? customer.wallet_cash
return usePrice(Number(cash ?? 0), true, '')
}
async function loadChargeTargets() {
const data = await getWalletChargeTargets()
chargeTargets.value = data?.targets ?? []
const firstTarget = chargeTargets.value[0]
if (firstTarget) {
Object.assign(formCharge.value, applyChargeTarget(formCharge.value, firstTarget))
}
}
async function loadCustomers() {
loading.value = true
try {
customers.value = (await getCustomersList()) ?? []
const [customerList] = await Promise.all([getCustomersList(), loadChargeTargets()])
customers.value = customerList ?? []
} catch (e) {
console.error(e)
message.error('خطا در بارگذاری لیست مشتریان')
@@ -161,8 +157,11 @@ async function loadCustomers() {
}
function resetForm() {
walletVariant.value = 'money'
formCharge.value = createEmptyChargeForm()
const firstTarget = chargeTargets.value[0]
if (firstTarget) {
Object.assign(formCharge.value, applyChargeTarget(formCharge.value, firstTarget))
}
}
function handleClose() {
@@ -188,7 +187,7 @@ async function submit() {
submitting.value = true
try {
await chargeWallet(buildChargePayload(formCharge.value), walletVariant.value)
await chargeWalletUnified(buildChargePayload(formCharge.value))
message.success(walletChargeSuccessMessage(formCharge.value.direction))
closeModal()
} catch (e) {
@@ -231,7 +230,7 @@ watch(
}
.dashboard-wallet-modal__balances {
@apply grid grid-cols-2 gap-3 rounded-lg border border-slate-200 bg-slate-50 px-3 py-2.5 text-xs dark:border-slate-600 dark:bg-slate-800/60;
@apply grid grid-cols-1 gap-3 rounded-lg border border-slate-200 bg-slate-50 px-3 py-2.5 text-xs dark:border-slate-600 dark:bg-slate-800/60;
}
.dashboard-wallet-modal__footer {