fix some bugs

This commit is contained in:
2026-07-14 13:53:20 +03:30
parent 76813df062
commit e83daaf28b
9 changed files with 119 additions and 28 deletions
+38 -6
View File
@@ -86,13 +86,13 @@
is-line
:title="metalLabel.goldWalletTitle()"
class="mt-2"
:value="getGoldBalance(selectedCustomer?.wallet) || '_'"
:value="selectedCustomerGoldBalance"
/>
<BasicInfoItem
is-line
title="کیف پول ریالی"
class="mt-1"
:value="getCashBalance(selectedCustomer?.wallet) || '_'"
:value="selectedCustomerCashBalance"
/>
</div>
<div class="flex flex-col gap-2 bg-blue-50 p-2 rounded-lg">
@@ -185,6 +185,26 @@ const userItems = ref<Customer[]>()
const selectedCustomer = ref<Customer>()
let updateKey = ref<number>(0)
const selectedCustomerGoldBalance = computed(() => {
const customer = selectedCustomer.value
if (customer?.wallet_gold != null) {
return Number(customer.wallet_gold).toFixed(3)
}
return getGoldBalance(customer?.wallet, { ownerType: customer?.type }) || '_'
})
const selectedCustomerCashBalance = computed(() => {
const customer = selectedCustomer.value
if (!customer) return '_'
const balance = getCashBalance(customer.wallet, {
walletCash: customer.wallet_cash,
ownerType: customer.type,
})
return usePrice(Number(balance ?? 0), true, '').trim()
})
async function getCustomers() {
try {
loading.value = true
@@ -337,7 +357,11 @@ function info(val: Order) {
userInfoVisible.value = true
}
/** آخرین فیلدی که کاربر ویرایش کرده — برای target_cash هنگام ثبت */
const amountInputLock = ref<'rial' | 'gram' | null>(null)
function calculateCash(val: number) {
amountInputLock.value = 'gram'
// console.log(val)
if (form.value.price) {
if (form.value.direction === 1) {
@@ -351,6 +375,7 @@ function calculateCash(val: number) {
}
function calculateGold(val: number) {
amountInputLock.value = 'rial'
// console.log(val)
// form.value.goldCash = usePriceWithoutType(form.value.goldCash)
if (form.value.price) {
@@ -413,6 +438,7 @@ async function add() {
//reset data
const resetData = () => {
formRef.value?.resetFields()
amountInputLock.value = null
form.value = {
direction: 1,
price: 0,
@@ -447,11 +473,17 @@ async function ok() {
clearSubmitError()
loading.value = true
try {
form.value.amount = form.value.goldValue
delete form.value.goldValue
delete form.value.goldCash
const payload: Order = { ...form.value }
payload.amount = payload.goldValue
await createOrder(form.value)
if (amountInputLock.value === 'rial' && form.value.goldCash != null) {
payload.target_cash = Math.round(Number(String(form.value.goldCash).replaceAll(',', '')))
}
delete payload.goldValue
delete payload.goldCash
await createOrder(payload)
message.success('سفارش با موفقیت ثبت شد')
addOrderVisible.value = false
resetData()