changes of boursecu

This commit is contained in:
2026-06-03 19:54:23 +03:30
parent eab6b0df52
commit 198f0a164b
12 changed files with 165 additions and 31 deletions
+8 -6
View File
@@ -31,7 +31,7 @@ export function inputLenRules(len: number, title?: string) {
import {computed, ref} from 'vue'
import type {Rule} from 'ant-design-vue/es/form'
import {useWalletStore} from "@/store/walletStore";
import { isCashLikeDealMethod } from '@/utils/productDealMethod'
import { isCashLikeDealMethod, getInsufficientCashWalletMessage, getInsufficientGoldWalletMessage } from '@/utils/productDealMethod'
export const mobileValidation = (title?: string) => {
return {len: 11, message: `شماره همراه باید 11 رقم باشد`}
@@ -136,6 +136,7 @@ let methodP = 'cash'
let amountP =0
let isBuyP=true
let NumP=0
let groupTypeP: string | undefined
const checkNumber = async (_rule: Rule, value: number) => {
@@ -147,15 +148,15 @@ const checkNumber = async (_rule: Rule, value: number) => {
}
if (isBuyP){
if (!walletCash?.walletInfo?.cash && isCashLikeDealMethod(methodP)){
return Promise.reject('موجودی کیف پول ناکافی است')
return Promise.reject(getInsufficientCashWalletMessage(groupTypeP))
}
if (!walletCash?.walletInfo?.gold && methodP == 'gold'){
return Promise.reject('موجودی کیف طلا ناکافی است')
return Promise.reject(getInsufficientGoldWalletMessage(groupTypeP))
}
if (priceP * value > walletCash?.walletInfo?.cash && isCashLikeDealMethod(methodP))
return Promise.reject('موجودی کیف پول ناکافی است')
return Promise.reject(getInsufficientCashWalletMessage(groupTypeP))
if (amountP * value > walletCash?.walletInfo?.gold && methodP == 'gold')
return Promise.reject('موجودی کیف طلا ناکافی است')
return Promise.reject(getInsufficientGoldWalletMessage(groupTypeP))
else
return Promise.resolve();
}else {
@@ -166,11 +167,12 @@ if (isBuyP){
}
}
export const justNumber2 = (price: number, method?: string , amount?:number ,isBuy?:boolean) => {
export const justNumber2 = (price: number, method?: string , amount?:number ,isBuy?:boolean, groupType?: string) => {
priceP = price
methodP = method
amountP=amount
isBuyP=isBuy
groupTypeP = groupType
return {
required: true,
validator: checkNumber,
+67 -5
View File
@@ -2,16 +2,24 @@ import type { SelectItem } from '@/models/SelectItem'
import { isBoursecuProject } from '@/utils/config'
export const BOURSECU_GROUP_MAFTOL = 'مفتول مس'
export const BOURSECU_GROUP_KATAD = 'کاتد مس'
export const BOURSECU_GROUP_KATOD = 'کاتد مس'
export const BOURSECU_GROUP_ABSHODE = 'آبشده'
export const BOURSECU_ASSET_LABEL_KATOD = 'دارایی کاتد مس'
export const BOURSECU_ASSET_LABEL_MAFTOL = 'دارایی مفتول مس'
export const BOURSECU_ASSET_LABEL_GOLD = 'دارایی طلایی'
const DEFAULT_TYPE_DEAL: SelectItem[] = [
{ value: 'نقدی', key: 'cash' },
{ value: 'طلایی', key: 'gold' },
]
const MAFTOL_TYPE_DEAL: SelectItem[] = [
{ value: 'کاتد', key: 'katod' },
{ value: BOURSECU_GROUP_KATOD, key: 'katod' },
{ value: 'نقدی', key: 'cash' },
]
const CASH_ONLY_TYPE_DEAL: SelectItem[] = [
{ value: 'نقدی', key: 'cash' },
]
@@ -30,7 +38,7 @@ export function isBoursecuDealProductGroup(groupType?: string | null) {
const group = normalizeProductGroupType(groupType)
return group === BOURSECU_GROUP_MAFTOL
|| group === BOURSECU_GROUP_KATAD
|| group === BOURSECU_GROUP_KATOD
|| group === BOURSECU_GROUP_ABSHODE
}
@@ -38,9 +46,12 @@ export function isMaftolMesGroup(groupType?: string | null) {
return normalizeProductGroupType(groupType) === BOURSECU_GROUP_MAFTOL
}
export function isKatodMesGroup(groupType?: string | null) {
return normalizeProductGroupType(groupType) === BOURSECU_GROUP_KATOD
}
export function isGoldOnlyDealGroup(groupType?: string | null) {
const group = normalizeProductGroupType(groupType)
return group === BOURSECU_GROUP_KATAD || group === BOURSECU_GROUP_ABSHODE
return normalizeProductGroupType(groupType) === BOURSECU_GROUP_ABSHODE
}
export function getProductDealMethodOptions(groupType?: string | null): SelectItem[] {
@@ -52,6 +63,10 @@ export function getProductDealMethodOptions(groupType?: string | null): SelectIt
return MAFTOL_TYPE_DEAL
}
if (isKatodMesGroup(groupType)) {
return CASH_ONLY_TYPE_DEAL
}
if (isGoldOnlyDealGroup(groupType)) {
return GOLD_ONLY_TYPE_DEAL
}
@@ -66,3 +81,50 @@ export function getDefaultProductDealMethod(groupType?: string | null) {
export function isCashLikeDealMethod(method?: string | null) {
return method === 'cash' || method === 'katod'
}
export const BOURSECU_WALLET_LABEL_GENERIC = 'موجودی کیف'
export function getGoldWalletLabel(groupType?: string | null) {
if (!isBoursecuProject()) return 'موجودی کیف طلا'
const group = normalizeProductGroupType(groupType)
if (group === BOURSECU_GROUP_KATOD) return `موجودی کیف ${BOURSECU_GROUP_KATOD}`
if (group === BOURSECU_GROUP_MAFTOL) return `موجودی کیف ${BOURSECU_GROUP_MAFTOL}`
if (group === BOURSECU_GROUP_ABSHODE) return 'موجودی کیف طلا'
return BOURSECU_WALLET_LABEL_GENERIC
}
export function getCashWalletLabel(groupType?: string | null) {
if (!isBoursecuProject()) return 'موجودی کیف پول'
const group = normalizeProductGroupType(groupType)
if (group === BOURSECU_GROUP_KATOD) return `موجودی کیف ${BOURSECU_GROUP_KATOD}`
if (group === BOURSECU_GROUP_MAFTOL) return `موجودی کیف ${BOURSECU_GROUP_MAFTOL}`
return BOURSECU_WALLET_LABEL_GENERIC
}
export function getWeightUnit() {
return isBoursecuProject() ? 'کیلوگرم' : 'گرم'
}
export function formatBoursecuAssetAmount(amount?: number | null) {
return `${amount ?? 0}${getWeightUnit()}`
}
export function formatGoldWalletBalanceText(gold: number, groupType?: string | null) {
return `${getGoldWalletLabel(groupType)}: ${gold} ${getWeightUnit()}`
}
export function formatCashWalletBalanceText(cashFormatted: string | number, groupType?: string | null) {
return `${getCashWalletLabel(groupType)}: ${cashFormatted} ریال`
}
export function getInsufficientGoldWalletMessage(groupType?: string | null) {
return `${getGoldWalletLabel(groupType)} ناکافی است`
}
export function getInsufficientCashWalletMessage(groupType?: string | null) {
return `${getCashWalletLabel(groupType)} ناکافی است`
}