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
+80 -65
View File
@@ -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 {