fix some bugs

This commit is contained in:
2026-06-23 22:31:21 +03:30
parent 71764f7e9a
commit 69da635247
9 changed files with 156 additions and 239 deletions
@@ -26,7 +26,8 @@
@edit="forwardAndClose('edit', $event)"
@archive="forwardAndClose('archive', $event)"
@toggleActive="forward('toggleActive', $event)"
@chargeWallet="forwardAndClose('chargeWallet', $event)"
@chargeMoney="forwardAndClose('chargeMoney', $event)"
@chargeGold="forwardAndClose('chargeGold', $event)"
@toggleTrade="forward('toggleTrade', $event)"
@confirmUser="forwardAndClose('confirmUser', $event)"
/>
@@ -55,7 +56,8 @@ const emit = defineEmits<{
(e: 'edit', item: Customer): void
(e: 'archive', item: Customer): void
(e: 'toggleActive', item: Customer): void
(e: 'chargeWallet', item: Customer): void
(e: 'chargeMoney', item: Customer): void
(e: 'chargeGold', item: Customer): void
(e: 'toggleTrade', item: Customer): void
(e: 'confirmUser', item: Customer): void
}>()
@@ -67,7 +69,8 @@ type SheetAction =
| 'edit'
| 'archive'
| 'toggleActive'
| 'chargeWallet'
| 'chargeMoney'
| 'chargeGold'
| 'toggleTrade'
| 'confirmUser'
@@ -4,15 +4,12 @@
<h2 class="text-base font-700 leading-relaxed text-gray-900">{{ row.name || '-' }}</h2>
<p v-if="row.mobile" class="text-sm text-gray-500" dir="ltr">{{ row.mobile }}</p>
<div class="grid grid-cols-1 gap-2">
<BaseButton
class="w-full"
size="middle"
type="primary"
icon="vuesax-linear:wallet-add"
@click="closeAndEmit('chargeWallet', row)"
>
شارژ / دشارژ کیف پول
<div class="grid grid-cols-2 gap-2">
<BaseButton class="w-full" size="middle" type="primary" icon="vuesax-linear:wallet-add" @click="closeAndEmit('chargeMoney', row)">
شارژ ریالی
</BaseButton>
<BaseButton class="w-full" size="middle" type="primary" icon="vuesax-linear:wallet-money" @click="closeAndEmit('chargeGold', row)">
{{ metalLabel.goldChargeShort() }}
</BaseButton>
<BaseButton
v-if="!row.is_legal"
@@ -110,7 +107,7 @@ import MobileInfoGrid from '@/components/mobile/MobileInfoGrid.vue'
import { getCashBalance } from '@/components/mobile/utils/wallet'
import { toJalali } from '@core/utils/useDataTime'
import { usePrice } from '@core/utils/usePrice'
import { customerWalletMetalBalanceTitle } from '@/utils/adminMetalLabels'
import { customerWalletMetalBalanceTitle, metalLabel } from '@/utils/adminMetalLabels'
import type { CustomerMetalColumn } from '../hooks/customerColumns'
import { formatMetalDisplayValue, metalCellValue, metalDisplayUnit } from '@/utils/metalWeight'
@@ -126,7 +123,8 @@ const emit = defineEmits<{
(e: 'edit', item: Customer): void
(e: 'archive', item: Customer): void
(e: 'toggleActive', item: Customer): void
(e: 'chargeWallet', item: Customer): void
(e: 'chargeMoney', item: Customer): void
(e: 'chargeGold', item: Customer): void
(e: 'toggleTrade', item: Customer): void
(e: 'confirmUser', item: Customer): void
}>()
@@ -136,7 +134,7 @@ const visibleProxy = computed({
set: (value: boolean) => emit('update:visible', value)
})
type SheetEmit = 'archive' | 'chargeWallet' | 'info' | 'confirmUser' | 'edit'
type SheetEmit = 'archive' | 'chargeMoney' | 'chargeGold' | 'info' | 'confirmUser' | 'edit'
function closeAndEmit(event: SheetEmit, row: Customer) {
visibleProxy.value = false
@@ -6,18 +6,6 @@
class="wallet-charge-form"
:class="formClass"
>
<a-form-item label="کیف پول / محصول" name="chargeTargetKey" :rules="targetRules">
<a-select
v-model:value="modelValue.chargeTargetKey"
show-search
placeholder="انتخاب کنید"
class="w-full"
:options="targetOptions"
:filter-option="filterTarget"
@change="onTargetChange"
/>
</a-form-item>
<a-form-item label="نوع عملیات" name="direction">
<a-radio-group
v-model:value="modelValue.direction"
@@ -48,10 +36,10 @@
<BasicInput
v-model:value="modelValue.amountAbs"
:addon-before="unit"
:type="isMoney ? 'price' : 'number'"
:type="variant === 'money' ? 'price' : 'number'"
:place-holder="amountPlaceholder"
/>
<div v-if="isMoney && Number(modelValue.amountAbs) > 10" class="wallet-charge-form__hint">
<div v-if="variant === 'money' && Number(modelValue.amountAbs) > 10" class="wallet-charge-form__hint">
معادل {{ usePrice(Number(modelValue.amountAbs) / 10, true, 'تومان') }}
</div>
</a-form-item>
@@ -63,46 +51,23 @@
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { computed, ref } from 'vue'
import type { FormInstance } from 'ant-design-vue'
import type { Charge, WalletChargeTarget } from '@/model/wallet'
import type { Charge } from '@/model/wallet'
import { inputRules } from '@/utils/inputRules'
import { usePrice } from '@core/utils/usePrice'
import { applyChargeTarget, resolveChargeTarget, walletPreviewLabel } from '../utils/walletChargeForm'
import { m } from '@/utils/metalLabels'
const props = defineProps<{
variant: 'money' | 'gold'
modelValue: Charge
targets: WalletChargeTarget[]
}>()
const formRef = ref<FormInstance>()
const selectedTarget = computed(() =>
resolveChargeTarget(props.targets, props.modelValue.chargeTargetKey)
)
const isMoney = computed(() => selectedTarget.value?.kind === 'money')
const unit = computed(() => selectedTarget.value?.unit ?? 'ریال')
const unit = computed(() => (props.variant === 'money' ? 'ریال' : 'گرم'))
const isDischarge = computed(() => props.modelValue.direction === 'discharge')
const targetOptions = computed(() =>
props.targets.map((target) => ({
value: target.key,
label: target.label
}))
)
const targetRules = [
{
validator: (_rule: unknown, value: string | undefined) => {
if (!value || !resolveChargeTarget(props.targets, value)) {
return Promise.reject('کیف پول یا محصول را انتخاب کنید')
}
return Promise.resolve()
}
}
]
const formClass = computed(() =>
isDischarge.value ? 'wallet-charge-form--discharge' : 'wallet-charge-form--charge'
)
@@ -117,7 +82,8 @@ const previewSign = computed(() => (isDischarge.value ? '−' : '+'))
const previewText = computed(() => {
const action = isDischarge.value ? 'کسر از' : 'افزایش'
return `${action} ${walletPreviewLabel(selectedTarget.value)}`
const wallet = props.variant === 'money' ? 'موجودی ریالی' : m('موجودی طلایی')
return `${action} ${wallet} کاربر`
})
const amountLabel = computed(() =>
@@ -127,7 +93,7 @@ const amountLabel = computed(() =>
const noteLabel = computed(() => (isDischarge.value ? 'علت دشارژ' : 'علت شارژ'))
const amountPlaceholder = computed(() =>
isMoney.value ? 'مثلاً ۱۰۰٬۰۰۰' : 'مثلاً ۰.۵'
props.variant === 'money' ? 'مثلاً ۱۰۰٬۰۰۰' : 'مثلاً ۰.۵'
)
const notePlaceholder = computed(() =>
@@ -147,28 +113,6 @@ const amountRules = [
}
]
function filterTarget(input: string, option?: { label?: string }) {
return String(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
}
function onTargetChange(key: string) {
const target = resolveChargeTarget(props.targets, key)
if (!target) return
Object.assign(props.modelValue, applyChargeTarget(props.modelValue, target))
}
watch(
() => props.targets,
(targets) => {
if (!targets.length) return
const current = resolveChargeTarget(targets, props.modelValue.chargeTargetKey)
if (!current) {
Object.assign(props.modelValue, applyChargeTarget(props.modelValue, targets[0]))
}
},
{ immediate: true }
)
defineExpose({
validateFields: () => formRef.value?.validateFields()
})
@@ -49,10 +49,14 @@
:color="record.active ? '#54AD06' : '#ad0627'"
/>
</a-tooltip>
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('chargeWallet', record)">
<template #title><span>شارژ / دشارژ کیف پول</span></template>
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('chargeMoney', record)">
<template #title><span>شارژ کیف پول ریالی</span></template>
<Icon icon="vuesax-linear:wallet-add" color="#9333ea" />
</a-tooltip>
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('chargeGold', record)">
<template #title><span>{{ metalLabel.goldWalletCharge() }}</span></template>
<Icon icon="vuesax-linear:wallet-money" color="#ea580c" />
</a-tooltip>
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('info', record)">
<template #title><span>مشخصات</span></template>
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
@@ -96,7 +100,8 @@
@edit="emits('edit', $event)"
@archive="handleArchive"
@toggleActive="(item) => changeCustomerActivationFunction(item.id)"
@chargeWallet="emits('chargeWallet', $event)"
@chargeMoney="emits('chargeMoney', $event)"
@chargeGold="emits('chargeGold', $event)"
@toggleTrade="(item) => changeCustomerOrderActivationFunction(item.id)"
@confirmUser="openConfirmUser"
/>
@@ -148,9 +153,10 @@ import { toJalaliNoTime } from '@core/utils/useDataTime'
import type { Customer } from '@/model/customer'
import { MODAL_ABOVE_ACTION_SHEET_Z_INDEX } from '@/constants/overlayZIndex'
import { isMobile } from '@core/utils/is'
import { metalLabel } from '@/utils/adminMetalLabels'
const [submit, reload] = useBaseTable()
const emits = defineEmits(['delete', 'edit', 'add', 'info', 'chargeWallet'])
const emits = defineEmits(['delete', 'edit', 'add', 'info', 'chargeMoney', 'chargeGold'])
const loading = ref(false)
const confirmVisible = ref(false)