From 2647a5069806d669df0ee26fe091186a0f63251c Mon Sep 17 00:00:00 2001 From: mohammad sedighi Date: Sat, 11 Jul 2026 11:42:12 +0330 Subject: [PATCH] added charge for all product --- src/api/wallet.ts | 9 +- src/model/wallet.ts | 19 ++ .../components/DashboardQuickWalletModal.vue | 276 +----------------- .../menuPages/customers/archive/index.vue | 41 +-- .../components/CustomerMobileCardList.vue | 9 +- .../components/CustomerMobileDetailSheet.vue | 13 +- .../base/components/WalletChargeForm.vue | 51 ++-- .../base/components/WalletChargeModal.vue | 186 ++++++++++++ .../base/components/WalletChargeModalBody.vue | 157 ++++++++++ .../customers/base/components/table.vue | 14 +- src/pages/menuPages/customers/base/index.vue | 137 +-------- .../customers/base/utils/walletChargeForm.ts | 29 +- 12 files changed, 463 insertions(+), 478 deletions(-) create mode 100644 src/pages/menuPages/customers/base/components/WalletChargeModal.vue create mode 100644 src/pages/menuPages/customers/base/components/WalletChargeModalBody.vue diff --git a/src/api/wallet.ts b/src/api/wallet.ts index b1146dd..685a8a1 100644 --- a/src/api/wallet.ts +++ b/src/api/wallet.ts @@ -1,15 +1,22 @@ import type { TableInput } from '@core/type/baseTable' import useAxios from '@core/utils/useAxios' -import type { Charge, SendWeight, Wallet, Withdraw } from '@/model/wallet' +import type { Charge, ChargeTargetsResponse, SendWeight, Wallet, Withdraw } from '@/model/wallet' export const getWalletTable = async (params?: TableInput) => await useAxios.post>('/admin/wallet/table', params) +export const getChargeTargets = async () => + await useAxios.get('/admin/wallet/charge-targets') + +/** @deprecated از chargeWalletUnified استفاده کنید */ export const chargeWallet = async (params: Charge, type: 'gold' | 'money') => type === 'money' ? await useAxios.post('/admin/wallet/charge', params) : await useAxios.post('/admin/wallet/charge_gold', params) +export const chargeWalletUnified = async (params: Charge) => + await useAxios.post('/admin/wallet/charge_wallet', params) + export const getWithdrawTable = async (params: TableInput & { flow_type?: string }) => await useAxios.post>('/admin/wallet/withdraw/table', params) diff --git a/src/model/wallet.ts b/src/model/wallet.ts index 20f0553..7fe283c 100644 --- a/src/model/wallet.ts +++ b/src/model/wallet.ts @@ -102,6 +102,25 @@ export interface Charge { talabBedehi?: boolean direction?: WalletChargeDirection amountAbs?: number | string + product_id?: number +} + +/** گزینهٔ شارژ — نقدی یا محصول فعال */ +export interface ChargeTarget { + key: string + kind: 'money' | 'metal' + label: string + unit: string + product_id?: number + metal_id?: number + uses_main_wallet?: boolean + trade_by_quantity?: boolean + group_type?: string +} + +export interface ChargeTargetsResponse { + targets: ChargeTarget[] + catalogMetals?: Array<{ metal_id: number; label: string; display_unit?: string }> } export interface WithdrawStatus { diff --git a/src/pages/dashboard/components/DashboardQuickWalletModal.vue b/src/pages/dashboard/components/DashboardQuickWalletModal.vue index db31175..7a0e731 100644 --- a/src/pages/dashboard/components/DashboardQuickWalletModal.vue +++ b/src/pages/dashboard/components/DashboardQuickWalletModal.vue @@ -1,282 +1,20 @@ - - diff --git a/src/pages/menuPages/customers/archive/index.vue b/src/pages/menuPages/customers/archive/index.vue index f17c25b..45e3f68 100644 --- a/src/pages/menuPages/customers/archive/index.vue +++ b/src/pages/menuPages/customers/archive/index.vue @@ -131,20 +131,11 @@ - - - - - - - + :customer-id="chargeCustomerId" + @success="refreshTable" + /> @@ -167,9 +158,7 @@ import { cloneDeep } from 'lodash' import type { Item } from '@/model/Item' import type { Customer } from '@/model/customer' import { createCustomer, deleteCustomer, updateCustomer } from '@/api/customer' -import type { Charge } from '@/model/wallet' -import customers from '@/router/routes/customers' -import { chargeWallet } from '@/api/wallet' +import WalletChargeModal from '@/pages/menuPages/customers/base/components/WalletChargeModal.vue' //loading const loading = ref(false) @@ -197,12 +186,11 @@ const confirmItems: Array = [ //wallet const showWalletCharge = ref(false) +const chargeCustomerId = ref(null) //form const form = ref({}) -const formCharge = ref({}) const formRef = ref() -const formChargeRef = ref() const userInfo = ref() //info @@ -234,23 +222,8 @@ async function add() { } async function walletCharge(val: Customer) { + chargeCustomerId.value = val.id showWalletCharge.value = true - formCharge.value.customer_id = val.id -} - -async function charge() { - formChargeRef.value?.validateFields().then(async () => { - try { - loading.value = true - await chargeMoneyWallet(formCharge.value) - message.success('افزایش اعتبار با موفقیت انجام شد') - showWalletCharge.value = false - } catch (e) { - console.log(e) - } finally { - loading.value = false - } - }) } //reset data diff --git a/src/pages/menuPages/customers/base/components/CustomerMobileCardList.vue b/src/pages/menuPages/customers/base/components/CustomerMobileCardList.vue index 38d2f60..7cc9da5 100644 --- a/src/pages/menuPages/customers/base/components/CustomerMobileCardList.vue +++ b/src/pages/menuPages/customers/base/components/CustomerMobileCardList.vue @@ -25,8 +25,7 @@ @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)" /> @@ -55,8 +54,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 }>() @@ -68,8 +66,7 @@ type SheetAction = | 'edit' | 'archive' | 'toggleActive' - | 'chargeMoney' - | 'chargeGold' + | 'chargeWallet' | 'toggleTrade' | 'confirmUser' diff --git a/src/pages/menuPages/customers/base/components/CustomerMobileDetailSheet.vue b/src/pages/menuPages/customers/base/components/CustomerMobileDetailSheet.vue index 1b5b403..57945b4 100644 --- a/src/pages/menuPages/customers/base/components/CustomerMobileDetailSheet.vue +++ b/src/pages/menuPages/customers/base/components/CustomerMobileDetailSheet.vue @@ -5,11 +5,8 @@

{{ row.mobile }}

- - شارژ ریالی - - - {{ metalLabel.goldChargeShort() }} + + شارژ کیف پول () @@ -106,7 +101,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 diff --git a/src/pages/menuPages/customers/base/components/WalletChargeForm.vue b/src/pages/menuPages/customers/base/components/WalletChargeForm.vue index 5f9b8b4..009c231 100644 --- a/src/pages/menuPages/customers/base/components/WalletChargeForm.vue +++ b/src/pages/menuPages/customers/base/components/WalletChargeForm.vue @@ -35,11 +35,11 @@ -
+
معادل {{ usePrice(Number(modelValue.amountAbs) / 10, true, 'تومان') }}
@@ -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() -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(), }) diff --git a/src/pages/menuPages/customers/base/components/WalletChargeModal.vue b/src/pages/menuPages/customers/base/components/WalletChargeModal.vue new file mode 100644 index 0000000..ad2725d --- /dev/null +++ b/src/pages/menuPages/customers/base/components/WalletChargeModal.vue @@ -0,0 +1,186 @@ + + + diff --git a/src/pages/menuPages/customers/base/components/WalletChargeModalBody.vue b/src/pages/menuPages/customers/base/components/WalletChargeModalBody.vue new file mode 100644 index 0000000..ac3dbaf --- /dev/null +++ b/src/pages/menuPages/customers/base/components/WalletChargeModalBody.vue @@ -0,0 +1,157 @@ + + + + + diff --git a/src/pages/menuPages/customers/base/components/table.vue b/src/pages/menuPages/customers/base/components/table.vue index e03acbd..50c689a 100644 --- a/src/pages/menuPages/customers/base/components/table.vue +++ b/src/pages/menuPages/customers/base/components/table.vue @@ -49,14 +49,10 @@ :color="record.active ? '#54AD06' : '#ad0627'" /> - - + + - - - - @@ -188,13 +183,12 @@ 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' import TahesabRetryModal from '@/components/TahesabRetryModal.vue' import PargarRetryModal from '@/components/PargarRetryModal.vue' import { tahesabEnabledSetting, pargarEnabledSetting, initAccountingSettingsFromApi } from '@/utils/config' 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) diff --git a/src/pages/menuPages/customers/base/index.vue b/src/pages/menuPages/customers/base/index.vue index 4c10f47..edf8ba2 100644 --- a/src/pages/menuPages/customers/base/index.vue +++ b/src/pages/menuPages/customers/base/index.vue @@ -6,8 +6,7 @@ @info="info" @edit="edit" @add="add" - @chargeMoney="walletMoneyCharge" - @chargeGold="walletGoldCharge" + @chargeWallet="openWalletCharge" />