diff --git a/src/api/wallet.js b/src/api/wallet.js index 0d4ea91..4b55472 100644 --- a/src/api/wallet.js +++ b/src/api/wallet.js @@ -392,3 +392,29 @@ export const apiExchange = async (data) => { throw error } } + +/** + * 获取金币代理最小收入金额 + * @returns {Promise} 返回当前的余额信息 + */ +export const apiGetFreightThreshold = async (account) => { + try { + const response = await get(`/wallet/freight/threshold?account=${account}`) + return response + } catch (error) { + console.error('Failed to fetch get freight threshold:', error) + console.error('error:' + error.response.errorMsg) + throw error + } +} + +// 金币代理设置最小收入金额 +export const apiSetThreshold = async (data) => { + try { + const response = await post('/wallet/freight/threshold', data) + return response + } catch (error) { + console.error('Failed to set threshold:', error) + throw error + } +} diff --git a/src/views/RechargeAgency/index.vue b/src/views/RechargeAgency/index.vue index a866ca4..d9075f0 100644 --- a/src/views/RechargeAgency/index.vue +++ b/src/views/RechargeAgency/index.vue @@ -89,7 +89,7 @@ - +
@@ -322,13 +322,20 @@ import { ref, computed, onMounted, onUnmounted } from 'vue' import { useRouter } from 'vue-router' import { useI18n } from 'vue-i18n' +import { getUserId } from '@/utils/userStore.js' import { setDocumentDirection } from '@/locales/i18n' import { getSelectedUser } from '@/utils/coinSellerStore.js' import { showError, showSuccess } from '@/utils/toast.js' import { usePageInitializationWithConfig } from '@/utils/pageConfig.js' import { handleAvatarImageError } from '@/utils/imageHandler.js' -import { checkFreightDealer, getFreightBalance, freightRecharge } from '@/api/wallet.js' +import { + checkFreightDealer, + getFreightBalance, + freightRecharge, + apiGetFreightThreshold, //获取金币代理最小收入金额 + apiSetThreshold, // 金币代理设置最小收入金额 +} from '@/api/wallet.js' import GeneralHeader from '@/components/GeneralHeader.vue' import maskLayer from '@/components/MaskLayer.vue' @@ -347,43 +354,40 @@ const checkingAccess = ref(true) const coinsAmount = ref('0') const loadingBalance = ref(false) -const AmountList = ref([ - { - id: 1, - type: '>$0', - selectedStatus: true, - }, - { - id: 2, - type: '>=$10', - selectedStatus: false, - }, - { - id: 3, - type: '>=$20', - selectedStatus: false, - }, - { - id: 4, - type: '>=$50', - selectedStatus: false, - }, -]) -const selectedAmount = ref({}) -// 是否为每月一号 -const isFirstDay = ref(false) +const AmountList = computed(() => { + return [ + { + id: 1, + type: '>$0', + value: 0, + selectedStatus: freightThreshold.value.deliveryThreshold == 0, + }, + { + id: 2, + type: '>=$10', + value: 10, + selectedStatus: freightThreshold.value.deliveryThreshold == 10, + }, + { + id: 3, + type: '>=$50', + value: 50, + selectedStatus: freightThreshold.value.deliveryThreshold == 50, + }, + ] +}) -// 更新是否为每月一号 -const updateIsFirstDay = () => { - const today = new Date() - isFirstDay.value = today.getDate() === 1 -} +const selectedAmount = ref({}) +// 是否可以设置 +const isAbleSelect = ref(false) + +const freightThreshold = ref(null) // 选项样式 const amountStyle = (amountItem) => { if (amountItem.selectedStatus) { return 'border: 1px solid #7726ff;background: #fff;' - } else if (isFirstDay.value) { + } else if (isAbleSelect.value) { return 'border: 1px solid transparent;background: transparent;' } else { return 'border: 1px solid transparent;background: rgba(0, 0, 0, 0.2);' @@ -411,8 +415,8 @@ const closedPopup = () => { // 选择限制转账金额 const selectAmount = (amountItem) => { - // 非每月一号 - if (!isFirstDay.value || amountItem.selectedStatus) return + // 不可选择或者已选择 + if (!isAbleSelect.value || amountItem.selectedStatus) return console.log('选择限制转账金额', amountItem) selectedAmount.value = amountItem //设置选中的金额 @@ -432,8 +436,7 @@ const Confirm = () => { console.log('确认选择') // 发送接口 - try { - } catch (error) {} + setThreshold() closedPopup() } @@ -479,6 +482,30 @@ const fetchFreightBalance = async () => { } } +// 获取金币代理最小收入金额 +const getFreightThreshold = async () => { + const resFreightThreshold = await apiGetFreightThreshold(userInfo.id) + console.log('任务列表:', resFreightThreshold) + if (resFreightThreshold.status && resFreightThreshold.body) { + freightThreshold.value = resFreightThreshold.body + isAbleSelect.value = !resFreightThreshold.body?.settinged //是否可以设置 + } +} + +// 金币代理设置最小收入金额 +const setThreshold = async () => { + try { + let data = { + deliveryThreshold: selectedAmount.value.value, + } + await apiSetThreshold(data) // 金币代理设置最小收入金额 + selectedAmount.value = {} + getFreightThreshold() //获取金币代理最小收入金额 + } catch (error) { + console.log('设置失败:', error) + } +} + // 初始化用户信息 const initializeUser = () => { const savedUser = getSelectedUser() @@ -569,24 +596,11 @@ const { userInfo } = usePageInitializationWithConfig('COIN_SELLER', { checkDealerAccess() fetchFreightBalance() initializeUser() + getFreightThreshold() //获取金币代理最小收入金额 }, }) -// 定时检查(可选) -let dayCheckInterval = null - -onMounted(() => { - // 初始化 - updateIsFirstDay() - // 每小时检查一次是否进入新一天 - dayCheckInterval = setInterval(updateIsFirstDay, 60 * 60 * 1000) -}) - -onUnmounted(() => { - if (dayCheckInterval) { - clearInterval(dayCheckInterval) - } -}) +onMounted(() => {})