fix some bugs
This commit is contained in:
+1
-10
@@ -1,19 +1,10 @@
|
||||
import type { TableInput } from '@core/type/baseTable'
|
||||
import useAxios from '@core/utils/useAxios'
|
||||
// import { Customer } from '@/model/customer'
|
||||
import type { Charge, SendWeight, Wallet, WalletChargeTarget, Withdraw } from '@/model/wallet'
|
||||
import type { Charge, SendWeight, Wallet, Withdraw } from '@/model/wallet'
|
||||
|
||||
export const getWalletTable = async (params?: TableInput) =>
|
||||
await useAxios.post<Array<Wallet>>('/admin/wallet/table', params)
|
||||
|
||||
export const getWalletChargeTargets = async () =>
|
||||
await useAxios.get<{ targets: WalletChargeTarget[] }>('/admin/wallet/charge-targets')
|
||||
|
||||
/** شارژ یکپارچه — نقدی یا محصول (product_id=null یعنی ریالی) */
|
||||
export const chargeWalletUnified = async (params: Charge) =>
|
||||
await useAxios.post<boolean>('/admin/wallet/charge_wallet', params)
|
||||
|
||||
/** @deprecated از chargeWalletUnified استفاده کنید */
|
||||
export const chargeWallet = async (params: Charge, type: 'gold' | 'money') =>
|
||||
type === 'money'
|
||||
? await useAxios.post<boolean>('/admin/wallet/charge', params)
|
||||
|
||||
@@ -54,20 +54,6 @@ export interface Withdraw {
|
||||
|
||||
export type WalletChargeDirection = 'charge' | 'discharge'
|
||||
|
||||
export type WalletChargeTargetKind = 'money' | 'metal'
|
||||
|
||||
export interface WalletChargeTarget {
|
||||
key: string
|
||||
kind: WalletChargeTargetKind
|
||||
label: string
|
||||
unit: string
|
||||
product_id?: number | null
|
||||
metal_id?: number
|
||||
uses_main_wallet?: boolean
|
||||
trade_by_quantity?: boolean
|
||||
group_type?: string
|
||||
}
|
||||
|
||||
export interface Charge {
|
||||
value?: number
|
||||
note?: string
|
||||
@@ -75,8 +61,6 @@ export interface Charge {
|
||||
talabBedehi?: boolean
|
||||
direction?: WalletChargeDirection
|
||||
amountAbs?: number | string
|
||||
chargeTargetKey?: string | null
|
||||
product_id?: number | null
|
||||
}
|
||||
|
||||
export interface WithdrawStatus {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<BasicActionSheet
|
||||
v-model:visible="visibleProxy"
|
||||
:title="modalTitle"
|
||||
modal-width="24rem"
|
||||
modal-width="22rem"
|
||||
drawer-height="auto"
|
||||
compact
|
||||
:loading="loading"
|
||||
@@ -24,18 +24,33 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedCustomer" class="dashboard-wallet-modal__balances">
|
||||
<div
|
||||
v-if="selectedCustomer"
|
||||
class="dashboard-wallet-modal__balances"
|
||||
>
|
||||
<div>
|
||||
<span class="text-slate-500">{{ metalLabel.goldWalletShort() }}</span>
|
||||
<p class="font-semibold text-slate-800 dark:text-slate-100">{{ formatGold(selectedCustomer) }}</p>
|
||||
</div>
|
||||
<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">{{ metalLabel.goldWalletShort() }}</a-radio-button>
|
||||
</a-radio-group>
|
||||
</div>
|
||||
|
||||
<WalletChargeForm
|
||||
ref="chargeFormRef"
|
||||
class="dashboard-wallet-modal__form"
|
||||
:model-value="formCharge"
|
||||
:targets="chargeTargets"
|
||||
:variant="walletVariant"
|
||||
/>
|
||||
|
||||
<div class="dashboard-wallet-modal__footer">
|
||||
@@ -63,19 +78,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 { chargeWalletUnified, getWalletChargeTargets } from '@/api/wallet'
|
||||
import { chargeWallet } from '@/api/wallet'
|
||||
import type { Customer } from '@/model/customer'
|
||||
import type { Charge, Wallet, WalletChargeTarget } from '@/model/wallet'
|
||||
import type { Charge, Wallet } from '@/model/wallet'
|
||||
import { usePrice } from '@core/utils/usePrice'
|
||||
import { metalLabel } from '@/utils/adminMetalLabels'
|
||||
|
||||
const props = defineProps<{ visible: boolean }>()
|
||||
const emit = defineEmits<{ (e: 'update:visible', value: boolean): void }>()
|
||||
@@ -88,7 +102,7 @@ const visibleProxy = computed({
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const customers = ref<Customer[]>([])
|
||||
const chargeTargets = ref<WalletChargeTarget[]>([])
|
||||
const walletVariant = ref<'money' | 'gold'>('money')
|
||||
const formCharge = ref<Charge>(createEmptyChargeForm())
|
||||
const chargeFormRef = ref<InstanceType<typeof WalletChargeForm>>()
|
||||
|
||||
@@ -110,12 +124,8 @@ 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(selectedTarget.value, formCharge.value.direction),
|
||||
walletChargeTitle(walletVariant.value, formCharge.value.direction),
|
||||
)
|
||||
|
||||
const okText = computed(() => walletChargeOkText(formCharge.value.direction))
|
||||
@@ -129,25 +139,20 @@ 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 {
|
||||
const [customerList] = await Promise.all([getCustomersList(), loadChargeTargets()])
|
||||
customers.value = customerList ?? []
|
||||
customers.value = (await getCustomersList()) ?? []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
message.error('خطا در بارگذاری لیست مشتریان')
|
||||
@@ -157,11 +162,8 @@ 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() {
|
||||
@@ -187,7 +189,7 @@ async function submit() {
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
await chargeWalletUnified(buildChargePayload(formCharge.value))
|
||||
await chargeWallet(buildChargePayload(formCharge.value), walletVariant.value)
|
||||
message.success(walletChargeSuccessMessage(formCharge.value.direction))
|
||||
closeModal()
|
||||
} catch (e) {
|
||||
@@ -230,7 +232,7 @@ watch(
|
||||
}
|
||||
|
||||
.dashboard-wallet-modal__balances {
|
||||
@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;
|
||||
@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;
|
||||
}
|
||||
|
||||
.dashboard-wallet-modal__footer {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
@info="info"
|
||||
@edit="edit"
|
||||
@add="add"
|
||||
@chargeWallet="walletCharge"
|
||||
@chargeMoney="walletMoneyCharge"
|
||||
@chargeGold="walletGoldCharge"
|
||||
/>
|
||||
|
||||
<!-- <BasicMenu :menu="menu" width="13rem" @onChange="tabSelected" />
|
||||
@@ -213,39 +214,60 @@
|
||||
</BasicActionSheet>
|
||||
<BasicActionSheet
|
||||
v-if="isMobile"
|
||||
v-model:visible="showWalletCharge"
|
||||
:title="walletChargeModalTitle"
|
||||
modal-width="26rem"
|
||||
v-model:visible="showMoneyWalletCharge"
|
||||
:title="moneyChargeTitle"
|
||||
modal-width="24rem"
|
||||
:loading="loading"
|
||||
:show-button="true"
|
||||
:show-cancel="true"
|
||||
:show-ok="true"
|
||||
:ok-text="walletChargeOkLabel"
|
||||
:ok-text="moneyChargeOkText"
|
||||
cancel-text="انصراف"
|
||||
@ok="submitWalletCharge"
|
||||
@close="closeWalletCharge"
|
||||
@ok="chargeMoneyWallet"
|
||||
@close="showMoneyWalletCharge = false"
|
||||
>
|
||||
<WalletChargeForm
|
||||
ref="walletChargeFormRef"
|
||||
:model-value="formCharge"
|
||||
:targets="chargeTargets"
|
||||
/>
|
||||
<WalletChargeForm ref="moneyChargeFormRef" :model-value="formCharge" variant="money" />
|
||||
</BasicActionSheet>
|
||||
<BasicModal
|
||||
v-else
|
||||
v-model:visible="showWalletCharge"
|
||||
width="24rem"
|
||||
:title="walletChargeModalTitle"
|
||||
:ok-text="walletChargeOkLabel"
|
||||
@ok="submitWalletCharge"
|
||||
v-model:visible="showMoneyWalletCharge"
|
||||
width="22rem"
|
||||
:title="moneyChargeTitle"
|
||||
:ok-text="moneyChargeOkText"
|
||||
@ok="chargeMoneyWallet"
|
||||
:loading="loading"
|
||||
@close="closeWalletCharge"
|
||||
@close="showMoneyWalletCharge = false"
|
||||
>
|
||||
<WalletChargeForm
|
||||
ref="walletChargeFormRef"
|
||||
:model-value="formCharge"
|
||||
:targets="chargeTargets"
|
||||
/>
|
||||
<WalletChargeForm ref="moneyChargeFormRef" :model-value="formCharge" variant="money" />
|
||||
</BasicModal>
|
||||
|
||||
<BasicActionSheet
|
||||
v-if="isMobile"
|
||||
v-model:visible="showGoldWalletCharge"
|
||||
:title="goldChargeTitle"
|
||||
modal-width="24rem"
|
||||
:loading="loading"
|
||||
:show-button="true"
|
||||
:show-cancel="true"
|
||||
:show-ok="true"
|
||||
:ok-text="goldChargeOkText"
|
||||
cancel-text="انصراف"
|
||||
@ok="chargeGoldWallet"
|
||||
@close="showGoldWalletCharge = false"
|
||||
>
|
||||
<WalletChargeForm ref="goldChargeFormRef" :model-value="formCharge" variant="gold" />
|
||||
</BasicActionSheet>
|
||||
<BasicModal
|
||||
v-else
|
||||
v-model:visible="showGoldWalletCharge"
|
||||
width="22rem"
|
||||
:title="goldChargeTitle"
|
||||
:ok-text="goldChargeOkText"
|
||||
@ok="chargeGoldWallet"
|
||||
:loading="loading"
|
||||
@close="showGoldWalletCharge = false"
|
||||
>
|
||||
<WalletChargeForm ref="goldChargeFormRef" :model-value="formCharge" variant="gold" />
|
||||
</BasicModal>
|
||||
<BasicInfoModal
|
||||
v-model:visible="userInfoOrderVisible"
|
||||
@@ -277,9 +299,9 @@ 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, WalletChargeTarget } from '@/model/wallet'
|
||||
import type { Charge } from '@/model/wallet'
|
||||
import customers from '@/router/routes/customers'
|
||||
import { chargeWalletUnified, getWalletChargeTargets } from '@/api/wallet'
|
||||
import { chargeWallet } from '@/api/wallet'
|
||||
import { usePrice } from '@core/utils/usePrice'
|
||||
import jalaliday from 'jalaliday'
|
||||
import ordersTbl from '@/pages/menuPages/orders/components/table.vue'
|
||||
@@ -292,10 +314,8 @@ import Icon from '@core/components/BaseIcon/src/Icon.vue'
|
||||
import { isMobile } from '@core/utils/is'
|
||||
import WalletChargeForm from './components/WalletChargeForm.vue'
|
||||
import {
|
||||
applyChargeTarget,
|
||||
buildChargePayload,
|
||||
createEmptyChargeForm,
|
||||
resolveChargeTarget,
|
||||
walletChargeOkText,
|
||||
walletChargeSuccessMessage,
|
||||
walletChargeTitle
|
||||
@@ -354,23 +374,21 @@ const customerItems: Array<Item> = [
|
||||
]
|
||||
|
||||
//wallet
|
||||
const showWalletCharge = ref<boolean>(false)
|
||||
const chargeTargets = ref<WalletChargeTarget[]>([])
|
||||
const showMoneyWalletCharge = ref<boolean>(false)
|
||||
const showGoldWalletCharge = ref<boolean>(false)
|
||||
const userInfoOrderVisible = ref<boolean>(false)
|
||||
|
||||
//form
|
||||
const form = ref<Partial<Customer>>({})
|
||||
const formRef = ref<FormInstance>()
|
||||
const formCharge = ref<Charge>({})
|
||||
const walletChargeFormRef = ref<InstanceType<typeof WalletChargeForm>>()
|
||||
const moneyChargeFormRef = ref<InstanceType<typeof WalletChargeForm>>()
|
||||
const goldChargeFormRef = ref<InstanceType<typeof WalletChargeForm>>()
|
||||
|
||||
const selectedChargeTarget = computed(() =>
|
||||
resolveChargeTarget(chargeTargets.value, formCharge.value.chargeTargetKey)
|
||||
)
|
||||
const walletChargeModalTitle = computed(() =>
|
||||
walletChargeTitle(selectedChargeTarget.value, formCharge.value.direction)
|
||||
)
|
||||
const walletChargeOkLabel = computed(() => walletChargeOkText(formCharge.value.direction))
|
||||
const moneyChargeTitle = computed(() => walletChargeTitle('money', formCharge.value.direction))
|
||||
const goldChargeTitle = computed(() => walletChargeTitle('gold', formCharge.value.direction))
|
||||
const moneyChargeOkText = computed(() => walletChargeOkText(formCharge.value.direction))
|
||||
const goldChargeOkText = computed(() => walletChargeOkText(formCharge.value.direction))
|
||||
|
||||
//info
|
||||
let infoParams = reactive<Info>({})
|
||||
@@ -491,43 +509,40 @@ async function add() {
|
||||
|
||||
function resetFormCharge(customerId: number) {
|
||||
formCharge.value = createEmptyChargeForm(customerId)
|
||||
const firstTarget = chargeTargets.value[0]
|
||||
if (firstTarget) {
|
||||
Object.assign(formCharge.value, applyChargeTarget(formCharge.value, firstTarget))
|
||||
}
|
||||
}
|
||||
|
||||
async function loadChargeTargets() {
|
||||
if (chargeTargets.value.length) return
|
||||
const data = await getWalletChargeTargets()
|
||||
chargeTargets.value = data?.targets ?? []
|
||||
async function walletMoneyCharge(val: Customer) {
|
||||
resetFormCharge(val.id)
|
||||
showMoneyWalletCharge.value = true
|
||||
}
|
||||
|
||||
async function walletCharge(val: Customer) {
|
||||
try {
|
||||
loading.value = true
|
||||
await loadChargeTargets()
|
||||
resetFormCharge(val.id)
|
||||
showWalletCharge.value = true
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
message.error('خطا در بارگذاری گزینههای شارژ')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
async function walletGoldCharge(val: Customer) {
|
||||
resetFormCharge(val.id)
|
||||
showGoldWalletCharge.value = true
|
||||
}
|
||||
|
||||
function closeWalletCharge() {
|
||||
showWalletCharge.value = false
|
||||
}
|
||||
|
||||
async function submitWalletCharge() {
|
||||
walletChargeFormRef.value?.validateFields()?.then(async () => {
|
||||
async function chargeMoneyWallet() {
|
||||
moneyChargeFormRef.value?.validateFields()?.then(async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
await chargeWalletUnified(buildChargePayload(formCharge.value))
|
||||
await chargeWallet(buildChargePayload(formCharge.value), 'money')
|
||||
message.success(walletChargeSuccessMessage(formCharge.value.direction))
|
||||
showWalletCharge.value = false
|
||||
showMoneyWalletCharge.value = false
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function chargeGoldWallet() {
|
||||
goldChargeFormRef.value?.validateFields()?.then(async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
await chargeWallet(buildChargePayload(formCharge.value), 'gold')
|
||||
message.success(walletChargeSuccessMessage(formCharge.value.direction))
|
||||
showGoldWalletCharge.value = false
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Charge, WalletChargeDirection, WalletChargeTarget } from '@/model/wallet'
|
||||
import type { Charge, WalletChargeDirection } from '@/model/wallet'
|
||||
import { m } from '@/utils/metalLabels'
|
||||
|
||||
export function createEmptyChargeForm(customerId?: number): Charge {
|
||||
return {
|
||||
@@ -7,9 +8,7 @@ export function createEmptyChargeForm(customerId?: number): Charge {
|
||||
note: undefined,
|
||||
talabBedehi: false,
|
||||
direction: 'charge',
|
||||
amountAbs: undefined,
|
||||
chargeTargetKey: 'money',
|
||||
product_id: null
|
||||
amountAbs: undefined
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,35 +19,17 @@ export function buildChargePayload(form: Charge): Charge {
|
||||
value: signed,
|
||||
note: form.note,
|
||||
customer_id: form.customer_id,
|
||||
talabBedehi: form.talabBedehi === true,
|
||||
product_id: form.product_id ?? null
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveChargeTarget(
|
||||
targets: WalletChargeTarget[],
|
||||
key?: string | null
|
||||
): WalletChargeTarget | undefined {
|
||||
if (!key) return targets[0]
|
||||
return targets.find((target) => target.key === key)
|
||||
}
|
||||
|
||||
export function applyChargeTarget(form: Charge, target?: WalletChargeTarget): Charge {
|
||||
if (!target) return form
|
||||
return {
|
||||
...form,
|
||||
chargeTargetKey: target.key,
|
||||
product_id: target.kind === 'metal' ? target.product_id ?? null : null
|
||||
talabBedehi: form.talabBedehi === true
|
||||
}
|
||||
}
|
||||
|
||||
export function walletChargeTitle(
|
||||
target: WalletChargeTarget | undefined,
|
||||
variant: 'money' | 'gold',
|
||||
direction: WalletChargeDirection = 'charge'
|
||||
) {
|
||||
const wallet = variant === 'money' ? 'ریالی' : m('طلایی')
|
||||
const action = direction === 'discharge' ? 'دشارژ' : 'شارژ'
|
||||
const wallet = target?.label ?? 'کیف پول'
|
||||
return `${action} ${wallet}`
|
||||
return `${action} کیف پول ${wallet}`
|
||||
}
|
||||
|
||||
export function walletChargeOkText(direction: WalletChargeDirection = 'charge') {
|
||||
@@ -58,10 +39,3 @@ export function walletChargeOkText(direction: WalletChargeDirection = 'charge')
|
||||
export function walletChargeSuccessMessage(direction: WalletChargeDirection = 'charge') {
|
||||
return direction === 'discharge' ? 'دشارژ با موفقیت انجام شد' : 'شارژ با موفقیت انجام شد'
|
||||
}
|
||||
|
||||
export function walletPreviewLabel(target: WalletChargeTarget | undefined): string {
|
||||
if (!target) return 'موجودی کاربر'
|
||||
if (target.kind === 'money') return 'موجودی ریالی'
|
||||
if (target.uses_main_wallet) return `موجودی ${target.label.replace(/\s*\(کیف اصلی\)$/, '')} (کیف اصلی)`
|
||||
return `موجودی ${target.label}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user