fix some bugs
This commit is contained in:
@@ -21,12 +21,12 @@
|
||||
<CustomerMobileDetailSheet
|
||||
v-model:visible="sheetVisible"
|
||||
:item="selectedItem"
|
||||
:metals="catalogMetals"
|
||||
@info="forwardAndClose('info', $event)"
|
||||
@edit="forwardAndClose('edit', $event)"
|
||||
@archive="forwardAndClose('archive', $event)"
|
||||
@toggleActive="forward('toggleActive', $event)"
|
||||
@chargeMoney="forwardAndClose('chargeMoney', $event)"
|
||||
@chargeGold="forwardAndClose('chargeGold', $event)"
|
||||
@chargeWallet="forwardAndClose('chargeWallet', $event)"
|
||||
@toggleTrade="forward('toggleTrade', $event)"
|
||||
@confirmUser="forwardAndClose('confirmUser', $event)"
|
||||
/>
|
||||
@@ -40,14 +40,22 @@ import { useMobileDetailSheet } from '@/components/mobile/composables/useMobileD
|
||||
import { useMobileTableList } from '@/components/mobile/composables/useMobileTableList'
|
||||
import CustomerMobileListItem from './CustomerMobileListItem.vue'
|
||||
import CustomerMobileDetailSheet from './CustomerMobileDetailSheet.vue'
|
||||
import type { CustomerMetalColumn } from '../hooks/customerColumns'
|
||||
|
||||
const catalogMetals = ref<CustomerMetalColumn[]>([])
|
||||
|
||||
async function fetchCustomers(params: Parameters<typeof getCustomerTable>[0]) {
|
||||
const data = await getCustomerTable(params)
|
||||
catalogMetals.value = data?.catalogMetals ?? []
|
||||
return data
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'info', item: Customer): void
|
||||
(e: 'edit', item: Customer): void
|
||||
(e: 'archive', item: Customer): void
|
||||
(e: 'toggleActive', item: Customer): void
|
||||
(e: 'chargeMoney', item: Customer): void
|
||||
(e: 'chargeGold', item: Customer): void
|
||||
(e: 'chargeWallet', item: Customer): void
|
||||
(e: 'toggleTrade', item: Customer): void
|
||||
(e: 'confirmUser', item: Customer): void
|
||||
}>()
|
||||
@@ -59,8 +67,7 @@ type SheetAction =
|
||||
| 'edit'
|
||||
| 'archive'
|
||||
| 'toggleActive'
|
||||
| 'chargeMoney'
|
||||
| 'chargeGold'
|
||||
| 'chargeWallet'
|
||||
| 'toggleTrade'
|
||||
| 'confirmUser'
|
||||
|
||||
@@ -74,7 +81,7 @@ function forwardAndClose(action: SheetAction, item: Customer) {
|
||||
}
|
||||
|
||||
const { loading, search, items, hasMore, reload, loadMore, fetch } = useMobileTableList<Customer>({
|
||||
fetchApi: getCustomerTable,
|
||||
fetchApi: fetchCustomers,
|
||||
onFetched: (rows) => syncSelectedItem(rows)
|
||||
})
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
<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-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)">
|
||||
شارژ طلایی
|
||||
<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)"
|
||||
>
|
||||
شارژ / دشارژ کیف پول
|
||||
</BaseButton>
|
||||
<BaseButton
|
||||
v-if="!row.is_legal"
|
||||
@@ -51,7 +54,14 @@
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<MobileStatCard bordered variant="success" label="موجودی طلایی" :value="`${goldBalance(row)} گرم`">
|
||||
<MobileStatCard
|
||||
v-for="entry in metalBalanceEntries(row)"
|
||||
:key="entry.metal_id"
|
||||
bordered
|
||||
variant="success"
|
||||
:label="customerWalletMetalBalanceTitle(entry.metal_id, entry.label)"
|
||||
:value="entry.value"
|
||||
>
|
||||
<template #prefix>
|
||||
<BaseIcon icon="vuesax-linear:coin" size="18" color="#15803d" />
|
||||
</template>
|
||||
@@ -83,7 +93,6 @@
|
||||
<MobileDetailRow label="نوع کاربر" :value="row.type_str || '-'" />
|
||||
<MobileDetailRow label="کد معرف" :value="row.referral_id ?? '-'" />
|
||||
<MobileDetailRow label="نام معرف کاربر" :value="row.referral?.name ?? '-'" />
|
||||
<MobileDetailRow label="گنج (گرم)" :value="row.gold ?? '-'" />
|
||||
<MobileDetailRow label="آخرین بازدید" :value="lastSeen(row)" value-class="text-xs" />
|
||||
</MobileInfoGrid>
|
||||
</template>
|
||||
@@ -98,13 +107,17 @@ import MobileDetailRow from '@/components/mobile/MobileDetailRow.vue'
|
||||
import MobileStatCard from '@/components/mobile/MobileStatCard.vue'
|
||||
import MobileDetailSheet from '@/components/mobile/MobileDetailSheet.vue'
|
||||
import MobileInfoGrid from '@/components/mobile/MobileInfoGrid.vue'
|
||||
import { getCashBalance, getGoldBalance } from '@/components/mobile/utils/wallet'
|
||||
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 type { CustomerMetalColumn } from '../hooks/customerColumns'
|
||||
import { formatMetalDisplayValue, metalCellValue, metalDisplayUnit } from '@/utils/metalWeight'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
item: Customer | null
|
||||
metals?: CustomerMetalColumn[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -113,8 +126,7 @@ const emit = defineEmits<{
|
||||
(e: 'edit', item: Customer): void
|
||||
(e: 'archive', item: Customer): void
|
||||
(e: 'toggleActive', item: Customer): void
|
||||
(e: 'chargeMoney', item: Customer): void
|
||||
(e: 'chargeGold', item: Customer): void
|
||||
(e: 'chargeWallet', item: Customer): void
|
||||
(e: 'toggleTrade', item: Customer): void
|
||||
(e: 'confirmUser', item: Customer): void
|
||||
}>()
|
||||
@@ -124,7 +136,7 @@ const visibleProxy = computed({
|
||||
set: (value: boolean) => emit('update:visible', value)
|
||||
})
|
||||
|
||||
type SheetEmit = 'archive' | 'chargeMoney' | 'chargeGold' | 'info' | 'confirmUser' | 'edit'
|
||||
type SheetEmit = 'archive' | 'chargeWallet' | 'info' | 'confirmUser' | 'edit'
|
||||
|
||||
function closeAndEmit(event: SheetEmit, row: Customer) {
|
||||
visibleProxy.value = false
|
||||
@@ -157,8 +169,24 @@ function cashBalance(row: Customer) {
|
||||
return getCashBalance(row.wallet)
|
||||
}
|
||||
|
||||
function goldBalance(row: Customer) {
|
||||
return getGoldBalance(row.wallet)
|
||||
function metalBalanceEntries(row: Customer) {
|
||||
const metals = props.metals?.length
|
||||
? props.metals
|
||||
: [{ metal_id: 1, label: 'طلا' }]
|
||||
|
||||
return metals
|
||||
.map((metal) => {
|
||||
const value = metalCellValue(row as Record<string, unknown>, metal.metal_id, 'wallet_metal_gold')
|
||||
return {
|
||||
metal_id: metal.metal_id,
|
||||
label: metal.label,
|
||||
value: formatMetalDisplayValue(value, metal.metal_id)
|
||||
}
|
||||
})
|
||||
.filter((entry) => {
|
||||
const numeric = metalCellValue(row as Record<string, unknown>, entry.metal_id, 'wallet_metal_gold')
|
||||
return numeric !== 0
|
||||
})
|
||||
}
|
||||
|
||||
function lastSeen(row: Customer) {
|
||||
|
||||
@@ -6,6 +6,18 @@
|
||||
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"
|
||||
@@ -36,10 +48,10 @@
|
||||
<BasicInput
|
||||
v-model:value="modelValue.amountAbs"
|
||||
:addon-before="unit"
|
||||
:type="variant === 'money' ? 'price' : 'number'"
|
||||
:type="isMoney ? 'price' : 'number'"
|
||||
: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>
|
||||
@@ -51,22 +63,46 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import type { Charge } from '@/model/wallet'
|
||||
import type { Charge, WalletChargeTarget } from '@/model/wallet'
|
||||
import { inputRules } from '@/utils/inputRules'
|
||||
import { usePrice } from '@core/utils/usePrice'
|
||||
import { applyChargeTarget, resolveChargeTarget, walletPreviewLabel } from '../utils/walletChargeForm'
|
||||
|
||||
const props = defineProps<{
|
||||
variant: 'money' | 'gold'
|
||||
modelValue: Charge
|
||||
targets: WalletChargeTarget[]
|
||||
}>()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const unit = computed(() => (props.variant === 'money' ? 'ریال' : 'گرم'))
|
||||
const selectedTarget = computed(() =>
|
||||
resolveChargeTarget(props.targets, props.modelValue.chargeTargetKey)
|
||||
)
|
||||
|
||||
const isMoney = computed(() => selectedTarget.value?.kind === 'money')
|
||||
const unit = computed(() => selectedTarget.value?.unit ?? 'ریال')
|
||||
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'
|
||||
)
|
||||
@@ -81,8 +117,7 @@ const previewSign = computed(() => (isDischarge.value ? '−' : '+'))
|
||||
|
||||
const previewText = computed(() => {
|
||||
const action = isDischarge.value ? 'کسر از' : 'افزایش'
|
||||
const wallet = props.variant === 'money' ? 'موجودی ریالی' : 'موجودی طلایی'
|
||||
return `${action} ${wallet} کاربر`
|
||||
return `${action} ${walletPreviewLabel(selectedTarget.value)}`
|
||||
})
|
||||
|
||||
const amountLabel = computed(() =>
|
||||
@@ -92,7 +127,7 @@ const amountLabel = computed(() =>
|
||||
const noteLabel = computed(() => (isDischarge.value ? 'علت دشارژ' : 'علت شارژ'))
|
||||
|
||||
const amountPlaceholder = computed(() =>
|
||||
props.variant === 'money' ? 'مثلاً ۱۰۰٬۰۰۰' : 'مثلاً ۰.۵'
|
||||
isMoney.value ? 'مثلاً ۱۰۰٬۰۰۰' : 'مثلاً ۰.۵'
|
||||
)
|
||||
|
||||
const notePlaceholder = computed(() =>
|
||||
@@ -112,6 +147,28 @@ 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,14 +49,10 @@
|
||||
:color="record.active ? '#54AD06' : '#ad0627'"
|
||||
/>
|
||||
</a-tooltip>
|
||||
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('chargeMoney', record)">
|
||||
<template #title><span>شارژ کیف پول ریالی</span></template>
|
||||
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('chargeWallet', 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>شارژ کیف پول طلایی</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" />
|
||||
@@ -100,8 +96,7 @@
|
||||
@edit="emits('edit', $event)"
|
||||
@archive="handleArchive"
|
||||
@toggleActive="(item) => changeCustomerActivationFunction(item.id)"
|
||||
@chargeMoney="emits('chargeMoney', $event)"
|
||||
@chargeGold="emits('chargeGold', $event)"
|
||||
@chargeWallet="emits('chargeWallet', $event)"
|
||||
@toggleTrade="(item) => changeCustomerOrderActivationFunction(item.id)"
|
||||
@confirmUser="openConfirmUser"
|
||||
/>
|
||||
@@ -144,7 +139,7 @@ import {
|
||||
confirmUser,
|
||||
getCustomerTable
|
||||
} from '@/api/customer'
|
||||
import { cols } from '@/pages/menuPages/customers/base/hooks/customerColumns'
|
||||
import { buildCustomerColumns } from '@/pages/menuPages/customers/base/hooks/customerColumns'
|
||||
import CustomerMobileCardList from '@/pages/menuPages/customers/base/components/CustomerMobileCardList.vue'
|
||||
import Icon from '@core/components/BaseIcon/src/Icon.vue'
|
||||
import useBaseTable from '@core/components/BaseTable/hooks/useBaseTable'
|
||||
@@ -155,7 +150,7 @@ import { MODAL_ABOVE_ACTION_SHEET_Z_INDEX } from '@/constants/overlayZIndex'
|
||||
import { isMobile } from '@core/utils/is'
|
||||
|
||||
const [submit, reload] = useBaseTable()
|
||||
const emits = defineEmits(['delete', 'edit', 'add', 'info', 'chargeMoney', 'chargeGold'])
|
||||
const emits = defineEmits(['delete', 'edit', 'add', 'info', 'chargeWallet'])
|
||||
|
||||
const loading = ref(false)
|
||||
const confirmVisible = ref(false)
|
||||
@@ -163,8 +158,13 @@ const confirmInfo = ref<Customer>()
|
||||
const mobileListRef = ref<null | { fetch: () => Promise<void> }>(null)
|
||||
|
||||
const tblProps = ref<any>({
|
||||
columns: cols,
|
||||
api: (params: TableInput) => getCustomerTable(params)
|
||||
columns: buildCustomerColumns(),
|
||||
api: async (params: TableInput) => {
|
||||
const data = await getCustomerTable(params)
|
||||
const metals = data?.catalogMetals ?? []
|
||||
tblProps.value.columns = buildCustomerColumns(metals)
|
||||
return data
|
||||
}
|
||||
})
|
||||
|
||||
const fetch = async () => {
|
||||
|
||||
Reference in New Issue
Block a user