From eab6b0df521e9703b3a92f19d07ffca949ce8552 Mon Sep 17 00:00:00 2001 From: safavimohadeseh78 Date: Wed, 3 Jun 2026 12:10:14 +0330 Subject: [PATCH] add loadServiceFeeFromSettings --- components.d.ts | 13 ------------- src/utils/serviceFee.ts | 24 ++++++++++++++++++++++++ src/views/base/copper&silver/index.vue | 10 ++++------ src/views/base/gold/index.vue | 22 ++++------------------ src/views/base/products/index.vue | 3 ++- 5 files changed, 34 insertions(+), 38 deletions(-) create mode 100644 src/utils/serviceFee.ts diff --git a/components.d.ts b/components.d.ts index 2da2181..1c2a547 100644 --- a/components.d.ts +++ b/components.d.ts @@ -8,24 +8,13 @@ export {} declare module 'vue' { export interface GlobalComponents { AButton: typeof import('ant-design-vue/es')['Button'] - ADivider: typeof import('ant-design-vue/es')['Divider'] AForm: typeof import('ant-design-vue/es')['Form'] AFormItem: typeof import('ant-design-vue/es')['FormItem'] - AInput: typeof import('ant-design-vue/es')['Input'] - AInputPassword: typeof import('ant-design-vue/es')['InputPassword'] - AModal: typeof import('ant-design-vue/es')['Modal'] ARadio: typeof import('ant-design-vue/es')['Radio'] ARadioButton: typeof import('ant-design-vue/es')['RadioButton'] ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup'] - ASelect: typeof import('ant-design-vue/es')['Select'] - ASelectOption: typeof import('ant-design-vue/es')['SelectOption'] ASlider: typeof import('ant-design-vue/es')['Slider'] ASpin: typeof import('ant-design-vue/es')['Spin'] - ASwitch: typeof import('ant-design-vue/es')['Switch'] - ATag: typeof import('ant-design-vue/es')['Tag'] - ATextarea: typeof import('ant-design-vue/es')['Textarea'] - ATooltip: typeof import('ant-design-vue/es')['Tooltip'] - AUpload: typeof import('ant-design-vue/es')['Upload'] BaseDatePicker: typeof import('./src/components/BasicPacks/BaseDatePicker/src/BaseDatePicker.vue')['default'] Basic: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/basic.vue')['default'] BasicActionSheet: typeof import('./src/components/BasicPacks/BasicActionSheet.vue')['default'] @@ -67,8 +56,6 @@ declare module 'vue' { Text: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/text.vue')['default'] Time: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/time.vue')['default'] TransactionSkeleton: typeof import('./src/components/TransactionSkeleton.vue')['default'] - VanActionSheet: typeof import('vant/es')['ActionSheet'] VanDialog: typeof import('vant/es')['Dialog'] - VanField: typeof import('vant/es')['Field'] } } diff --git a/src/utils/serviceFee.ts b/src/utils/serviceFee.ts new file mode 100644 index 0000000..d2cfdda --- /dev/null +++ b/src/utils/serviceFee.ts @@ -0,0 +1,24 @@ +import { ref } from 'vue' +import { getSettings } from '@/api/configuration' + +export const serviceFeePercentage = ref(0.01) + +export async function loadServiceFeeFromSettings() { + try { + const settings = await getSettings() + if (settings && Array.isArray(settings)) { + const feeSetting = settings.find( + (s) => s?.key === 'fee_service_charge_percentage' && s?.is_active === true + ) + if (feeSetting?.value !== undefined && feeSetting?.value !== null) { + serviceFeePercentage.value = Number(feeSetting.value) + } + } + } catch (e) { + console.log(e) + } +} + +export function calcFeeInGrams(goldValue?: number | null) { + return parseFloat(((goldValue ?? 0) * Number(serviceFeePercentage.value)).toFixed(4)) +} diff --git a/src/views/base/copper&silver/index.vue b/src/views/base/copper&silver/index.vue index 51b7c45..1ddafd7 100644 --- a/src/views/base/copper&silver/index.vue +++ b/src/views/base/copper&silver/index.vue @@ -131,7 +131,7 @@
کارمزد:
-
{{ parseFloat(((form.goldValue ?? 0) * 0.01).toFixed(4)) }}
+
{{ feeInGrams }}
گرم @@ -171,7 +171,7 @@
کارمزد:
-
{{ parseFloat(((form.goldValue ?? 0) * 0.01).toFixed(4)) }}
+
{{ feeInGrams }}
گرم
@@ -236,7 +236,7 @@ import { getLastPrices, getUpPrice, lastPrice, setIntervalGetAllPrice, stopPrice import type { Product } from '@/models/products' import { useFundUserStore } from '@/store/fundStore' import {useConfigStore} from "@/store/configStore"; -// import Bg_main from "@/components/bg_main.vue"; +import { calcFeeInGrams } from '@/utils/serviceFee' const infoVisible = ref(false) const walletStore = useWalletStore() @@ -311,9 +311,7 @@ const finalPrice = computed(() => { const payablePrice = computed(() => isBuy.value ? finalPrice.value + feeInRial.value : finalPrice.value - feeInRial.value ) -const feeInGrams = computed(() => - parseFloat(((form.value?.goldValue ?? 0) * 0.01).toFixed(4)) -) +const feeInGrams = computed(() => calcFeeInGrams(form.value?.goldValue)) const unitPrice = computed(() => (props?.ProductItem?.price_profit ?? 0) + (props?.ProductItem?.price ?? 0) ) diff --git a/src/views/base/gold/index.vue b/src/views/base/gold/index.vue index a5be94c..53ec07c 100644 --- a/src/views/base/gold/index.vue +++ b/src/views/base/gold/index.vue @@ -128,7 +128,7 @@
کارمزد:
-
{{ parseFloat(((form.goldValue ?? 0) * (Number(feeAmount))).toFixed(4)) }}
+
{{ feeInGrams }}
گرم
@@ -231,8 +231,7 @@ import { getLastPrices, getUpPrice, lastPrice, setIntervalGetAllPrice, stopPrice import type { Product } from '@/models/products' import { useFundUserStore } from '@/store/fundStore' import {useConfigStore} from "@/store/configStore"; -import { getSettings } from '@/api/configuration' -// import Bg_main from "@/components/bg_main.vue"; +import { calcFeeInGrams, loadServiceFeeFromSettings } from '@/utils/serviceFee' const infoVisible = ref(false) const walletStore = useWalletStore() @@ -245,7 +244,6 @@ const sellItems = ref([]) const priceErrorVisible = ref(false) const buyTableOutput = ref | null>(null) const sellTableOutput = ref | null>(null) -const feeAmount = ref(0.01) const el = ref() interface Prop { @@ -277,9 +275,7 @@ const sellPagination = ref({ const unitPrice = computed(() => isBuy.value ? price.value?.buy ?? 0 : price.value?.sell ?? 0 ) -const feeInGrams = computed(() => - parseFloat(((form.value?.goldValue ?? 0) * Number(feeAmount.value)).toFixed(4)) -) +const feeInGrams = computed(() => calcFeeInGrams(form.value?.goldValue)) const finalPrice = computed(() => (form.value?.goldValue ?? 0) * unitPrice.value) const feeInRial = computed(() => unitPrice.value * feeInGrams.value) const equivalentPrice = computed(() => usePriceWithoutType(feeInRial.value.toFixed(0))) @@ -351,16 +347,6 @@ async function initSellTable() { } } -async function getFeePercentage() { - const settings = await getSettings() - if (settings && Array.isArray(settings)) { - const feeSetting = settings.find(s => s?.key === 'fee_service_charge_percentage' && s?.is_active === true) - if(feeSetting && feeSetting.value !== undefined && feeSetting.value !== null) { - feeAmount.value = feeSetting.value - } - } -} - // if (!userStore.isSingle) { /*useInfiniteScroll( el, @@ -407,7 +393,7 @@ onMounted(async () => { break } await initPrice() - await getFeePercentage() + await loadServiceFeeFromSettings() /* await initSellTable() await initBuyTable()*/ }) diff --git a/src/views/base/products/index.vue b/src/views/base/products/index.vue index 46b35be..6c381ba 100644 --- a/src/views/base/products/index.vue +++ b/src/views/base/products/index.vue @@ -107,6 +107,7 @@ import BasicModal from "@/components/BasicPacks/BasicModal.vue"; import { isProductPriceInactive } from '@/utils/productPrice' import { isBoursecuProject } from '@/utils/config' import { isBoursecuDealProductGroup } from '@/utils/productDealMethod' +import { loadServiceFeeFromSettings } from '@/utils/serviceFee' const activekey = ref('طلا' ||'آبشده') const showFilter = ref(false) @@ -169,7 +170,7 @@ onMounted(async () => { // typeItems.value[index] = val.group_type }) firstItems.value = items.value - await initPrice() + await Promise.all([initPrice(), loadServiceFeeFromSettings()]) // await setIntervalGetLastPrice() // console.log('run product')