From e83daaf28b1915452621c93456e87dece430dde3 Mon Sep 17 00:00:00 2001 From: adonis Date: Tue, 14 Jul 2026 13:53:20 +0330 Subject: [PATCH] fix some bugs --- src/components/mobile/utils/wallet.ts | 24 +++++++--- src/model/customer.ts | 1 + src/model/order.ts | 1 + src/model/wallet.ts | 1 + src/pages/menuPages/accounting/index.vue | 44 ++++++++++++++++--- .../configuration/SettingValueField.vue | 30 ++++++++++--- .../orders/components/OrderEditorFormBody.vue | 24 +++++++--- src/pages/menuPages/orders/index.vue | 14 ++++-- src/pages/menuPages/products/base/index.vue | 8 +++- 9 files changed, 119 insertions(+), 28 deletions(-) diff --git a/src/components/mobile/utils/wallet.ts b/src/components/mobile/utils/wallet.ts index e2339da..460ab8f 100644 --- a/src/components/mobile/utils/wallet.ts +++ b/src/components/mobile/utils/wallet.ts @@ -6,9 +6,18 @@ export function getWallets(wallet?: Wallet | Wallet[]): Wallet[] { } /** کیف اصلی مشتری — بدون fund و بدون product */ -export function getMainWallet(wallet?: Wallet | Wallet[]): Wallet | undefined { +export function getMainWallet( + wallet?: Wallet | Wallet[], + ownerType?: number | null +): Wallet | undefined { const wallets = getWallets(wallet) - return wallets.find((w) => w.fund_id == null && w.product_id == null) + return wallets.find((w) => { + if (w.fund_id != null || w.product_id != null) return false + if (ownerType != null && w.owner_type != null && Number(w.owner_type) !== Number(ownerType)) { + return false + } + return true + }) } /** پارس setting `main_wallet_products` — id با کاما یا JSON */ @@ -63,12 +72,12 @@ export function getMainWalletProductIds(): number[] { */ export function getCashBalance( wallet?: Wallet | Wallet[], - options?: { walletCash?: number | null } + options?: { walletCash?: number | null; ownerType?: number | null } ): number { if (options?.walletCash != null) { return Number(options.walletCash) } - return getMainWallet(wallet)?.cash ?? 0 + return getMainWallet(wallet, options?.ownerType)?.cash ?? 0 } /** @@ -77,14 +86,19 @@ export function getCashBalance( */ export function getGoldBalance( wallet?: Wallet | Wallet[], - options?: { walletGold?: number | null; mainWalletProductIds?: number[] } + options?: { walletGold?: number | null; mainWalletProductIds?: number[]; ownerType?: number | null } ): string { if (options?.walletGold != null) { return Number(options.walletGold).toFixed(3) } const mainWalletProductIds = options?.mainWalletProductIds ?? getMainWalletProductIds() + const ownerType = options?.ownerType ?? null const sum = getWallets(wallet).reduce((total, line) => { + if (ownerType != null && line.owner_type != null && Number(line.owner_type) !== Number(ownerType)) { + return total + } + const gold = Number(line.gold ?? 0) if (gold <= 0) return total diff --git a/src/model/customer.ts b/src/model/customer.ts index a3fe420..c61f9d5 100644 --- a/src/model/customer.ts +++ b/src/model/customer.ts @@ -34,6 +34,7 @@ export interface Customer { profit_amount: number add_user_limit: number trade_active: boolean + type?: number type_str: string gold: number moshtari_code?: string | number | null diff --git a/src/model/order.ts b/src/model/order.ts index 158e3fc..b4d3507 100644 --- a/src/model/order.ts +++ b/src/model/order.ts @@ -22,6 +22,7 @@ export interface Order { total_price?: number goldCash?: number goldValue?: number + target_cash?: number total_price_original?: number updated_at?: string pay_at?: string diff --git a/src/model/wallet.ts b/src/model/wallet.ts index c57780a..ed627ec 100644 --- a/src/model/wallet.ts +++ b/src/model/wallet.ts @@ -30,6 +30,7 @@ export interface Wallet { gold: number cash: number fund_id?: number | null + owner_type?: number product_id?: number | null metal_gold?: Record customer: User diff --git a/src/pages/menuPages/accounting/index.vue b/src/pages/menuPages/accounting/index.vue index 5d4229e..22465f4 100644 --- a/src/pages/menuPages/accounting/index.vue +++ b/src/pages/menuPages/accounting/index.vue @@ -86,13 +86,13 @@ is-line :title="metalLabel.goldWalletTitle()" class="mt-2" - :value="getGoldBalance(selectedCustomer?.wallet) || '_'" + :value="selectedCustomerGoldBalance" />
@@ -185,6 +185,26 @@ const userItems = ref() const selectedCustomer = ref() let updateKey = ref(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() diff --git a/src/pages/menuPages/configuration/SettingValueField.vue b/src/pages/menuPages/configuration/SettingValueField.vue index baa7d3c..65dbae5 100644 --- a/src/pages/menuPages/configuration/SettingValueField.vue +++ b/src/pages/menuPages/configuration/SettingValueField.vue @@ -76,11 +76,10 @@ parseTimePickerValue(props.modelValue)) + +function onTimeChange(val: Dayjs | string | null | undefined) { + if (val == null || val === '') { + emit('update:value', '') + emit('blur') + return + } + + const parsed = dayjs.isDayjs(val) ? val : dayjs(String(val), 'HH:mm:ss', true) + emit('update:value', parsed.isValid() ? normalizeTimeValue(parsed.format('HH:mm:ss')) : '') emit('blur') } diff --git a/src/pages/menuPages/orders/components/OrderEditorFormBody.vue b/src/pages/menuPages/orders/components/OrderEditorFormBody.vue index 16a7c89..4973d04 100644 --- a/src/pages/menuPages/orders/components/OrderEditorFormBody.vue +++ b/src/pages/menuPages/orders/components/OrderEditorFormBody.vue @@ -132,13 +132,25 @@ const marketPriceLabel = computed(() => { return usePrice(price) }) -const goldBalanceDisplay = computed( - () => getGoldBalance(props.selectedCustomer?.wallet) || '_' -) +const goldBalanceDisplay = computed(() => { + const customer = props.selectedCustomer + if (customer?.wallet_gold != null) { + return Number(customer.wallet_gold).toFixed(3) + } + return getGoldBalance(customer?.wallet, { ownerType: customer?.type }) || '_' +}) -const cashBalanceDisplay = computed( - () => getCashBalance(props.selectedCustomer?.wallet) || '_' -) +const cashBalanceDisplay = computed(() => { + const customer = props.selectedCustomer + if (!customer) return '_' + + const balance = getCashBalance(customer.wallet, { + walletCash: customer.wallet_cash, + ownerType: customer.type, + }) + + return usePrice(Number(balance ?? 0), true, '').trim() +}) defineExpose({ validateFields: () => formRef.value?.validateFields(), diff --git a/src/pages/menuPages/orders/index.vue b/src/pages/menuPages/orders/index.vue index 6694d23..0602aa8 100644 --- a/src/pages/menuPages/orders/index.vue +++ b/src/pages/menuPages/orders/index.vue @@ -409,11 +409,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 = toOrderNumber(form.value.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 closeAddOrder() diff --git a/src/pages/menuPages/products/base/index.vue b/src/pages/menuPages/products/base/index.vue index 6cddc51..01213c6 100644 --- a/src/pages/menuPages/products/base/index.vue +++ b/src/pages/menuPages/products/base/index.vue @@ -474,13 +474,17 @@ async function saveProduct() { payload.cash_fee_sell_is_percent = normalizeCashFeeFlags(payload.cash_fee_sell_is_percent) if (usesMeltedPriceEditor(payload)) { - // ادیتور آبشده/مقداری قیمت اپ را از روی استنتاج تشخیص می‌دهد، نه ستون app_price - payload.app_price = false + // آبشده/کاتد: بدون پرچم app_price؛ شمش مقداری با وزن + منبع اپ: app_price برای × وزن در اپ if (isMeltedTradeGroup(payload.group_type)) { + payload.app_price = false payload.amount = 1 if (!editId) { payload.trade_by_quantity = true } + } else if (meltedPriceOption.value === 'app' && Number(payload.amount ?? 0) > 0) { + payload.app_price = true + } else { + payload.app_price = false } payload.direct_price = meltedPriceOption.value === 'fixed' ? 1 : 0