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
@@ -123,9 +123,9 @@
>
<BasicInfoItem
title="نام قلک"
:value="item?.fund ? item?.fund?.title : 'کیف پول طلایی'"
:value="item?.fund ? item?.fund?.title : metalLabel.goldWallet()"
/>
<BasicInfoItem title="مقدار طلا" :value="`${item?.gold} گرم`" />
<BasicInfoItem :title="metalLabel.goldAmount()" :value="`${item?.gold} گرم`" />
</div>
</div>
</div>
@@ -158,6 +158,7 @@ import type { FormInstance } from 'ant-design-vue'
import BasicActionSheet from '@/components/BasicActionSheet.vue'
import BasicInfoModal from '@/components/BasicInfoModal/index.vue'
import { isMobile } from '@core/utils/is'
import { metalLabel } from '@/utils/adminMetalLabels'
import { message } from 'ant-design-vue/es'
import type { Info } from '@/components/BasicInfoModal/model/Info'
import { toJalaliNoTime, toTime } from '@core/utils/useDataTime'
@@ -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 () => {
@@ -1,212 +1,164 @@
import type { BaseTableColumn } from '@core/type/baseTable'
import {toJalali, toJalaliNoTime, toTime} from '@core/utils/useDataTime'
import { toJalali } from '@core/utils/useDataTime'
import CustomTag from '@/components/CustomTag.vue'
import { usePrice } from '@core/utils/usePrice'
import { getCashBalance, getGoldBalance } from '@/components/mobile/utils/wallet'
/*import BudgetSelect from '@/components/BudgetSelect.vue'
import { useStaticApiListsStore } from '@/store/staticApisStore'
import type { FilterSelect } from '@/model/filterSelect'
import type { DocItem } from '@/model/docType'*/
import { getCashBalance } from '@/components/mobile/utils/wallet'
import { customerWalletMetalBalanceTitle } from '@/utils/adminMetalLabels'
import { formatMetalDisplayValue, metalCellValue } from '@/utils/metalWeight'
//define store
//const store = useStaticApiListsStore()
//document types
/*let docTypes: DocItem[]*/
/*onMounted(async () => {
docTypes = await store.readyDocTypeList()
})
const filteredDocTypes: FilterSelect = docTypes?.map((x: DocItem) => {
return {
label: x.title,
value: x.id
}
})*/
export type CustomerMetalColumn = { metal_id: number; label: string; display_unit?: string }
export const cols: BaseTableColumn[] = [
{
title: 'ردیف',
dataIndex: 'id',
key: 'id',
filterable: false,
sortable: false,
customRender: (record: any) => {
return record.index + 1
}
},
{
title: 'کد کاربری',
dataIndex: 'id',
key: 'id',
type: 'Number'
// className: 'column-money'
},
{
title: 'نام و نام خانوادگی',
dataIndex: 'name',
key: 'name',
type: 'Text'
},
{
title: 'شماره موبایل',
dataIndex: 'mobile',
key: 'mobile',
type: 'Number'
},
{
title: 'نوع کاربر',
dataIndex: 'type_str',
key: 'type_str',
type: 'Text'
},
{
title: 'کد معرف',
dataIndex: 'referral_id',
key: 'referral_id',
type: 'Text'
},
{
title: 'نام معرف کاربر',
dataIndex: 'referral.name',
key: 'referral.name',
type: 'Text'
},
{
title: 'موجودی ریالی (ریال)',
dataIndex: 'wallet.cash',
key: 'wallet.cash',
type: 'Number',
customRender(data) {
return usePrice(getCashBalance(data.record?.wallet, { walletCash: data.record?.wallet_cash }), true, '')
}
},
{
title: 'موجودی طلایی (گرم)',
dataIndex: 'wallet.gold',
key: 'wallet.gold',
type: 'Number',
filterable: false,
customRender(data) {
return getGoldBalance(data.record?.wallet, { walletGold: data.record?.wallet_gold })
}
},
{
title: 'اخرین بازدید',
dataIndex: 'last_seen_at',
key: 'last_seen_at',
type: 'DateTime',
customRender(data) {
return toJalali(data.record.last_seen_at)
}
},
{
title: 'گنج(گرم)',
dataIndex: 'gold',
key: 'gold',
type: 'Number',
filterable: false,
},
{
title: 'وضعیت کاربر',
dataIndex: 'active',
key: 'active',
type: 'Boolean',
customRender: ({ record }) => {
return record.active ? (
<div class="flex justify-center">
<CustomTag textColor="#25855A" bgColor="#E3F4E9" class={'font-bold px-6'}>
فعال
</CustomTag>
</div>
) : (
<div class="flex justify-center">
<CustomTag textColor="#C53030" bgColor="#FECACA" class={'font-bold px-6'}>
غیر فعال
</CustomTag>
</div>
)
}
},
{
title: 'وضعیت سفارش دهی',
dataIndex: 'trade_active',
key: 'trade_active',
sortable: false,
type: 'Boolean',
customRender: ({ record }) => {
return record.trade_active ? (
<div class="flex justify-center">
<CustomTag textColor="#25855A" bgColor="#E3F4E9" class={'font-bold px-6'}>
مجاز
</CustomTag>
</div>
) : (
<div class="flex justify-center">
<CustomTag textColor="#C53030" bgColor="#FECACA" class={'font-bold px-6'}>
غیر مجاز
</CustomTag>
</div>
)
}
},
/*{
title: 'نقش',
dataIndex: 'user_type_record',
key: 'user_type_record',
type: 'Select',
export function buildCustomerColumns(metals: CustomerMetalColumn[] = []): BaseTableColumn[] {
const baseColumns: BaseTableColumn[] = [
{
title: 'ردیف',
dataIndex: 'id',
key: 'id',
filterable: false,
sortable: false,
filterComponentProps: {
multiple: true
},
filterField: 'user_type_obj.id',
filterComponent: ReadyUserTypeSelect,
/!* customRender: (record: any) => {
return record.record.user_type_record?.value
}*!/
customRender: ({ record }) => {
const items = record.is_admin ? (
<CustomTag textColor="#25855A" bgColor="#E3F4E9">
ادمین
</CustomTag>
) : (
record.user_type_obj.map((item: { title: any }, index: any) => {
if (item) {
return (
<CustomTag textColor="#25855A" bgColor="#E3F4E9">
{item?.title}
</CustomTag>
)
}
})
)
return <div class="flex justify-center items-center gap-2">{items}</div>
customRender: (record: any) => {
return record.index + 1
}
},
{
title: 'حوزه',
dataIndex: 'section',
key: 'section'
title: 'کد کاربری',
dataIndex: 'id',
key: 'id',
type: 'Number'
},
{
title: 'نام و نام خانوادگی',
dataIndex: 'name',
key: 'name',
type: 'Text'
},
{
title: 'شماره موبایل',
dataIndex: 'mobile',
type: 'Number',
key: 'mobile'
key: 'mobile',
type: 'Number'
},
{
title: 'تاریخ ثبت',
dataIndex: 'created_at',
key: 'created_at',
type: 'DateTime',
customRender: (record: any) => {
return toJalaliNoTime(record.record.created_at)
title: 'نوع کاربر',
dataIndex: 'type_str',
key: 'type_str',
type: 'Text'
},
{
title: 'کد معرف',
dataIndex: 'referral_id',
key: 'referral_id',
type: 'Text'
},
{
title: 'نام معرف کاربر',
dataIndex: 'referral.name',
key: 'referral.name',
type: 'Text'
},
{
title: 'موجودی ریالی (ریال)',
dataIndex: 'wallet.cash',
key: 'wallet.cash',
type: 'Number',
customRender(data) {
return usePrice(getCashBalance(data.record?.wallet, { walletCash: data.record?.wallet_cash }), true, '')
}
},*/
{
title: 'عملیات',
dataIndex: 'action',
key: 'action',
slot: 'action',
filterable: false
}
]
}
]
const metalColumns: BaseTableColumn[] =
metals.length > 0
? metals.map((metal) => ({
title: customerWalletMetalBalanceTitle(metal.metal_id, metal.label),
dataIndex: `wallet_metal_gold_${metal.metal_id}`,
key: `wallet_metal_${metal.metal_id}`,
type: 'Number',
filterable: false,
customRender(data) {
const value = metalCellValue(data.record, metal.metal_id, 'wallet_metal_gold')
return formatMetalDisplayValue(value, metal.metal_id)
}
}))
: [
{
title: customerWalletMetalBalanceTitle(1, 'طلا'),
dataIndex: 'wallet.gold',
key: 'wallet.gold',
type: 'Number',
filterable: false,
customRender(data) {
const value = Number(data.record?.wallet_gold ?? 0)
return formatMetalDisplayValue(value, 1)
}
}
]
return [
...baseColumns,
...metalColumns,
{
title: 'اخرین بازدید',
dataIndex: 'last_seen_at',
key: 'last_seen_at',
type: 'DateTime',
customRender(data) {
return toJalali(data.record.last_seen_at)
}
},
{
title: 'وضعیت کاربر',
dataIndex: 'active',
key: 'active',
type: 'Boolean',
customRender: ({ record }) => {
return record.active ? (
<div class="flex justify-center">
<CustomTag textColor="#25855A" bgColor="#E3F4E9" class={'font-bold px-6'}>
فعال
</CustomTag>
</div>
) : (
<div class="flex justify-center">
<CustomTag textColor="#C53030" bgColor="#FECACA" class={'font-bold px-6'}>
غیر فعال
</CustomTag>
</div>
)
}
},
{
title: 'وضعیت سفارش دهی',
dataIndex: 'trade_active',
key: 'trade_active',
sortable: false,
type: 'Boolean',
customRender: ({ record }) => {
return record.trade_active ? (
<div class="flex justify-center">
<CustomTag textColor="#25855A" bgColor="#E3F4E9" class={'font-bold px-6'}>
مجاز
</CustomTag>
</div>
) : (
<div class="flex justify-center">
<CustomTag textColor="#C53030" bgColor="#FECACA" class={'font-bold px-6'}>
غیر مجاز
</CustomTag>
</div>
)
}
},
{
title: 'عملیات',
dataIndex: 'action',
key: 'action',
slot: 'action',
filterable: false
}
]
}
export function getCustomerColumns(): BaseTableColumn[] {
return buildCustomerColumns()
}
+71 -88
View File
@@ -6,8 +6,7 @@
@info="info"
@edit="edit"
@add="add"
@chargeMoney="walletMoneyCharge"
@chargeGold="walletGoldCharge"
@chargeWallet="walletCharge"
/>
<!-- <BasicMenu :menu="menu" width="13rem" @onChange="tabSelected" />
@@ -66,9 +65,6 @@
<a-form-item label="میزان پاداش" name="profit_amount">
<BasicInput v-model:value="form.profit_amount" />
</a-form-item>
<a-form-item label="گنج" name="gold">
<BasicInput v-model:value="form.gold" />
</a-form-item>
<a-form-item label="حداکثر معرفی" name="add_user_limit">
<BasicInput v-model:value="form.add_user_limit" />
</a-form-item>
@@ -191,9 +187,9 @@
>
<BasicInfoItem
title="نام قلک"
:value="item?.fund ? item?.fund?.title : 'کیف پول طلایی'"
:value="item?.fund ? item?.fund?.title : metalLabel.goldWallet()"
/>
<BasicInfoItem title="مقدار طلا" :value="`${item?.gold} گرم`" />
<BasicInfoItem :title="metalLabel.goldAmount()" :value="`${item?.gold} گرم`" />
</div>
</div>
</div>
@@ -217,60 +213,39 @@
</BasicActionSheet>
<BasicActionSheet
v-if="isMobile"
v-model:visible="showMoneyWalletCharge"
:title="moneyChargeTitle"
modal-width="24rem"
v-model:visible="showWalletCharge"
:title="walletChargeModalTitle"
modal-width="26rem"
:loading="loading"
:show-button="true"
:show-cancel="true"
:show-ok="true"
:ok-text="moneyChargeOkText"
:ok-text="walletChargeOkLabel"
cancel-text="انصراف"
@ok="chargeMoneyWallet"
@close="showMoneyWalletCharge = false"
@ok="submitWalletCharge"
@close="closeWalletCharge"
>
<WalletChargeForm ref="moneyChargeFormRef" :model-value="formCharge" variant="money" />
<WalletChargeForm
ref="walletChargeFormRef"
:model-value="formCharge"
:targets="chargeTargets"
/>
</BasicActionSheet>
<BasicModal
v-else
v-model:visible="showMoneyWalletCharge"
width="22rem"
:title="moneyChargeTitle"
:ok-text="moneyChargeOkText"
@ok="chargeMoneyWallet"
v-model:visible="showWalletCharge"
width="24rem"
:title="walletChargeModalTitle"
:ok-text="walletChargeOkLabel"
@ok="submitWalletCharge"
:loading="loading"
@close="showMoneyWalletCharge = false"
@close="closeWalletCharge"
>
<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" />
<WalletChargeForm
ref="walletChargeFormRef"
:model-value="formCharge"
:targets="chargeTargets"
/>
</BasicModal>
<BasicInfoModal
v-model:visible="userInfoOrderVisible"
@@ -302,9 +277,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 } from '@/model/wallet'
import type { Charge, WalletChargeTarget } from '@/model/wallet'
import customers from '@/router/routes/customers'
import { chargeWallet } from '@/api/wallet'
import { chargeWalletUnified, getWalletChargeTargets } from '@/api/wallet'
import { usePrice } from '@core/utils/usePrice'
import jalaliday from 'jalaliday'
import ordersTbl from '@/pages/menuPages/orders/components/table.vue'
@@ -317,12 +292,15 @@ 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
} from './utils/walletChargeForm'
import { metalLabel } from '@/utils/adminMetalLabels'
//tabs
const activeKey = ref('اطلاعات جامع')
@@ -376,21 +354,23 @@ const customerItems: Array<Item> = [
]
//wallet
const showMoneyWalletCharge = ref<boolean>(false)
const showGoldWalletCharge = ref<boolean>(false)
const showWalletCharge = ref<boolean>(false)
const chargeTargets = ref<WalletChargeTarget[]>([])
const userInfoOrderVisible = ref<boolean>(false)
//form
const form = ref<Partial<Customer>>({})
const formRef = ref<FormInstance>()
const formCharge = ref<Charge>({})
const moneyChargeFormRef = ref<InstanceType<typeof WalletChargeForm>>()
const goldChargeFormRef = ref<InstanceType<typeof WalletChargeForm>>()
const walletChargeFormRef = ref<InstanceType<typeof WalletChargeForm>>()
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))
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))
//info
let infoParams = reactive<Info>({})
@@ -407,7 +387,7 @@ function infoOrder(val: Order) {
value: val.amount ?? '-'
},
{
key: 'قیمت هر گرم طلا برای مشتری (ریال)',
key: metalLabel.goldGramPriceCustomer(),
value: usePrice(val.price ?? 0) ?? '-'
},
{
@@ -415,7 +395,7 @@ function infoOrder(val: Order) {
value: usePrice(val.total_price ?? 0) ?? '-'
},
{
key: '/قیمت هر گرم طلا بدون سود (ریال)',
key: metalLabel.goldGramPriceOriginalSlash(),
value: usePrice(val.price_original ?? 0) ?? '-'
},
{
@@ -443,7 +423,7 @@ function infoOrder(val: Order) {
value: usePrice(val.service_charge_price ?? 0)
},*/
{
key: 'کارمزد طلایی',
key: metalLabel.goldCommission(),
value: val.service_charge ?? '-' + ' گرم'
},
/* {
@@ -511,40 +491,43 @@ 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 walletMoneyCharge(val: Customer) {
resetFormCharge(val.id)
showMoneyWalletCharge.value = true
async function loadChargeTargets() {
if (chargeTargets.value.length) return
const data = await getWalletChargeTargets()
chargeTargets.value = data?.targets ?? []
}
async function walletGoldCharge(val: Customer) {
resetFormCharge(val.id)
showGoldWalletCharge.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 chargeMoneyWallet() {
moneyChargeFormRef.value?.validateFields()?.then(async () => {
function closeWalletCharge() {
showWalletCharge.value = false
}
async function submitWalletCharge() {
walletChargeFormRef.value?.validateFields()?.then(async () => {
try {
loading.value = true
await chargeWallet(buildChargePayload(formCharge.value), 'money')
await chargeWalletUnified(buildChargePayload(formCharge.value))
message.success(walletChargeSuccessMessage(formCharge.value.direction))
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
showWalletCharge.value = false
} catch (e) {
console.log(e)
} finally {
@@ -1,4 +1,4 @@
import type { Charge, WalletChargeDirection } from '@/model/wallet'
import type { Charge, WalletChargeDirection, WalletChargeTarget } from '@/model/wallet'
export function createEmptyChargeForm(customerId?: number): Charge {
return {
@@ -7,7 +7,9 @@ export function createEmptyChargeForm(customerId?: number): Charge {
note: undefined,
talabBedehi: false,
direction: 'charge',
amountAbs: undefined
amountAbs: undefined,
chargeTargetKey: 'money',
product_id: null
}
}
@@ -18,17 +20,35 @@ export function buildChargePayload(form: Charge): Charge {
value: signed,
note: form.note,
customer_id: form.customer_id,
talabBedehi: form.talabBedehi === true
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
}
}
export function walletChargeTitle(
variant: 'money' | 'gold',
target: WalletChargeTarget | undefined,
direction: WalletChargeDirection = 'charge'
) {
const wallet = variant === 'money' ? 'ریالی' : 'طلایی'
const action = direction === 'discharge' ? 'دشارژ' : 'شارژ'
return `${action} کیف پول ${wallet}`
const wallet = target?.label ?? 'کیف پول'
return `${action} ${wallet}`
}
export function walletChargeOkText(direction: WalletChargeDirection = 'charge') {
@@ -38,3 +58,10 @@ 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}`
}