diff --git a/src/api/bdCenter.js b/src/api/bdCenter.js index 216f5cb..bb26a18 100644 --- a/src/api/bdCenter.js +++ b/src/api/bdCenter.js @@ -59,3 +59,50 @@ export const cancelInvite = async (userId) => { throw error } } + +// 查询BD成员账单列表 +export const getBdMemberBillList = async (type) => { + try { + const response = await get(`/team/bd/member-bill/list?type=${type}`) + return response + } catch (error) { + console.error('Failed to fetch BD member bill list:', error) + console.error('error:' + error.response.errorMsg) + throw error + } +} + +// 查询BD成员账单明细 +export const getBdMemberBillDetailList = async (teamId) => { + try { + const response = await get(`/team/bd/member-bill/detail-list`, { teamId }) + return response + } catch (error) { + console.error('Failed to fetch BD member bill detail list:', error) + console.error('error:' + error.response.errorMsg) + throw error + } +} + +// 查询BD团队月度收入汇总 +export const getBdMonthlyIncome = async (bdUserId) => { + try { + const response = await get(`/team/bd/monthly-income`, { bdUserId }) + return response + } catch (error) { + console.error('Failed to fetch BD monthly income:', error) + console.error('error:' + error.response.errorMsg) + throw error + } +} + +// 提交提现申请 +export const withdrawApply = async (data) => { + try { + const response = await post('/team/bd/withdraw/apply', data) + return response + } catch (error) { + console.error('Failed to fetch withdraw apply:', error) + throw error + } +} diff --git a/src/views/BDCenter/availableIncome.vue b/src/views/BDCenter/availableIncome.vue index c21968c..69a45db 100644 --- a/src/views/BDCenter/availableIncome.vue +++ b/src/views/BDCenter/availableIncome.vue @@ -29,9 +29,9 @@ " > Loading... - {{ - availableIncome - }} + ${{ availableIncome }} @@ -67,7 +67,75 @@ - + +
+
+ +
+
+ +
+ +
+
${{ option.cash }}
+
+
+
+ + +
+ +
+
+ +
Transfer to others
- +
- {{ coin.amount }} +
${{ coin.price }}
@@ -245,77 +313,7 @@
- -
-
- -
-
- -
- {{ option.coins }} -
-
- {{ option.cash }} -
-
-
-
- - -
- -
-
- - +
@@ -464,19 +462,25 @@ import { ref, reactive, onMounted, onUnmounted, computed } from 'vue' import { useRouter } from 'vue-router' import MobileHeader from '@/components/MobileHeader.vue' -import { getBankBalance, userBankTransfer } from '@/api/wallet.js' +import { + getBankBalance, + userBankTransfer, + userSalaryCheckExchange, + userBankExchangeGold, +} from '@/api/wallet.js' import { getSelectedPayee, clearSelectedPayee } from '@/utils/payeeStore.js' import { showError, showSuccess } from '@/utils/toast.js' import { setApplyInfo, getApplyInfo } from '@/utils/applyStore.js' import maskLayer from '@/components/MaskLayer.vue' +import { withdrawApply } from '@/api/bdCenter.js' +import { getUserId } from '@/utils/userStore.js' const router = useRouter() -const availableIncome = ref('$23456') +const availableIncome = ref('') const selectedCoin = ref(null) const selectedExchangeOption = ref(null) -const selectedCashOutOption = ref(null) -const activeAction = ref('Transfer') +const activeAction = ref('Exchange') const loading = ref(false) const maskLayerShow = ref(false) @@ -500,12 +504,6 @@ const CashOut = () => { } } -// 确认提现 -const Receive = () => { - setApplyInfo() - maskLayerShow.value = false -} - // 选中的收款人 const selectedPayee = reactive({ id: null, @@ -530,12 +528,12 @@ const coinOptions = reactive([ // 兑换选项 const exchangeOptions = reactive([ - { id: 1, coins: '10000', cash: '$1' }, - { id: 2, coins: '10000', cash: '$1' }, - { id: 3, coins: '10000', cash: '$1' }, - { id: 4, coins: '10000', cash: '$1' }, - { id: 5, coins: '10000', cash: '$1' }, - { id: 6, coins: '10000', cash: '$1' }, + { id: 1, coins: 10500, cash: 1 }, + { id: 2, coins: 52500, cash: 5 }, + { id: 3, coins: 105000, cash: 10 }, + { id: 4, coins: 525000, cash: 50 }, + { id: 5, coins: 1050000, cash: 100 }, + { id: 6, coins: 2100000, cash: 200 }, ]) const bankCardInfo = ref({}) @@ -559,14 +557,14 @@ const fetchBankBalance = async () => { const response = await getBankBalance() if (response.status && typeof response.body === 'number') { - availableIncome.value = `$${response.body.toFixed(2)}` + availableIncome.value = response.body.toFixed(2) || '0.00' } else { - availableIncome.value = '$0.00' + availableIncome.value = '-' } } catch (error) { console.error('Failed to fetch bank balance:', error) - availableIncome.value = '$0.00' - showError('Failed to load balance. Please try again.') + availableIncome.value = '-' + showError(error.response.errorMsg) } finally { loading.value = false } @@ -587,7 +585,6 @@ const handleAction = (actionName) => { // 重置所有选择 selectedCoin.value = null selectedExchangeOption.value = null - selectedCashOutOption.value = null } // 清除当前选中的收款人 @@ -621,14 +618,6 @@ const selectExchangeOption = (option) => { } } -const selectCashOutOption = (option) => { - if (selectedCashOutOption.value === option.id) { - selectedCashOutOption.value = null - } else { - selectedCashOutOption.value = option.id - } -} - const transfer = async () => { if (!selectedCoin.value) { showError('Please select an amount first') @@ -652,25 +641,18 @@ const transfer = async () => { const response = await userBankTransfer(transferData) if (response.status) { showSuccess(`Successfully transferred $${selectedCoinData.price} to ${selectedPayee.name}`) + selectedCoin.value = null + await fetchBankBalance() } else { showError(`Failed to transfer $${selectedCoinData.price}`) } - - selectedCoin.value = null - await fetchBankBalance() } catch (error) { console.error('Transfer failed:', error) - if (error.errorCode === 5000) { - showError('Insufficient balance') - } else if (error.errorCode === 5010 || error.errorCode === 5009) { - showError('Payment password error') - } else { - showError('Transfer failed, please try again later') - } + showError(error.response.errorMsg) } } -const handleExchange = () => { +const handleExchange = async () => { if (!selectedExchangeOption.value) { showError('Please select an amount first') return @@ -679,19 +661,41 @@ const handleExchange = () => { const selectedOption = exchangeOptions.find( (option) => option.id === selectedExchangeOption.value ) - showSuccess(`Exchanging ${selectedOption.coins} coins for ${selectedOption.cash}`) - selectedExchangeOption.value = null + + try { + // 调用接口进行兑换 + const response = await userBankExchangeGold({ + coinId: selectedOption.id, + amount: selectedOption.cash, + price: selectedOption.cash, + }) + + if (response.status === true || response.errorCode === 0) { + showSuccess(`Successfully exchanged`) + + // 刷新银行余额 + await fetchBankBalance() + } + + selectedExchangeOption.value = null + } catch (error) { + console.error('Exchange failed:', error) + showError(error.response.errorMsg) + } } -const handleCashOut = () => { - if (!selectedCashOutOption.value) { - showError('Please select an amount first') - return +// 确认提现 +const Receive = async () => { + try { + const resApply = await withdrawApply({ ...getApplyInfo(), activityId: getUserId() }) + if (resApply.status) { + setApplyInfo() + } + maskLayerShow.value = false + } catch (error) { + maskLayerShow.value = false + showError(error.response.errorMsg) } - - const selectedOption = cashOutOptions.find((option) => option.id === selectedCashOutOption.value) - showSuccess(`Cashing out ${selectedOption.coins} coins for ${selectedOption.cash}`) - selectedCashOutOption.value = null } // 页面加载时获取银行余额和初始化收款人 @@ -706,7 +710,7 @@ onMounted(() => { onUnmounted(() => { clearPayee() - setApplyInfo() + // setApplyInfo() })