diff --git a/src/pages/agent-system/commission-center/index.vue b/src/pages/agent-system/commission-center/index.vue index 1425a09..0bc206b 100644 --- a/src/pages/agent-system/commission-center/index.vue +++ b/src/pages/agent-system/commission-center/index.vue @@ -4,55 +4,40 @@ import { getFundSummary, getCommissionRecords, getCommissionStats } from '@/api/ import type { FundSummary, CommissionRecord, CommissionStats } from '@/api/commission' import SimplePicker from '@/components/SimplePicker.vue' -// 佣金概览 const commissionSummary = ref(null) - -// 店铺ID (从登录信息获取) const shopId = ref(0) - -// 从本地存储获取用户信息 -function getUserInfo() { - const userInfo = uni.getStorageSync('user_info') - return userInfo || null -} - -// 佣金明细列表 const commissionRecords = ref([]) - -// 佣金统计 const commissionStats = ref(null) - -// 加载状态 const loading = ref(false) const loadingRecords = ref(false) - -// 分页参数 const page = ref(1) const pageSize = 20 const total = ref(0) - -// 搜索关键词 const searchKeyword = ref('') - -// 佣金来源筛选 const sourceFilter = ref(undefined) const showSourcePicker = ref(false) +const showSearchTypePicker = ref(false) -// 佣金来源选项 const sourceOptions = [ { label: '全部来源', value: undefined }, { label: '成本价差', value: 'cost_diff' }, { label: '一次性佣金', value: 'one_time' }, ] -// 获取当前选中的来源名称 +const searchType = ref<'iccid' | 'virtual_no' | 'order_no'>('iccid') + +const searchTypeOptions = [ + { label: 'ICCID', value: 'iccid' }, + { label: '虚拟号', value: 'virtual_no' }, + { label: '订单号', value: 'order_no' } +] + const selectedSourceName = computed(() => { - if (sourceFilter.value === undefined) return '佣金来源' + if (sourceFilter.value === undefined) return '来源' const option = sourceOptions.find(o => o.value === sourceFilter.value) - return option?.label || '佣金来源' + return option?.label || '来源' }) -// 格式化金额(分转元,带千分号) function formatAmount(amount: number) { const yuan = (amount / 100).toFixed(2) const parts = yuan.split('.') @@ -60,7 +45,6 @@ function formatAmount(amount: number) { return `¥${parts.join('.')}` } -// 获取佣金来源文本 function getSourceText(source: string) { const map: Record = { cost_diff: '成本价差', @@ -70,316 +54,257 @@ function getSourceText(source: string) { return map[source] || source } -// 获取佣金状态文本 function getStatusText(status: number) { - const map: Record = { - 1: '已入账', - 2: '已失效', - } - return map[status] || '未知' + return status === 1 ? '已入账' : '已失效' } -// 获取佣金状态颜色 -function getStatusColor(status: number) { - const map: Record = { - 1: { bg: '#e8f5e9', text: '#2e7d32' }, // 已入账 - 2: { bg: '#f5f5f5', text: '#999' }, // 已失效 - } - return map[status] || { bg: '#f5f5f5', text: '#999' } -} - -// 格式化时间 function formatTime(time: string) { if (!time) return '-' const date = new Date(time) - const month = String(date.getMonth() + 1).padStart(2, '0') - const day = String(date.getDate()).padStart(2, '0') - const hour = String(date.getHours()).padStart(2, '0') - const minute = String(date.getMinutes()).padStart(2, '0') - return `${month}-${day} ${hour}:${minute}` + return `${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}` } -// 页面加载 onMounted(() => { - // 从登录信息获取 shop_id - const userInfo = getUserInfo() + const userInfo = uni.getStorageSync('user_info') if (userInfo?.shop_id) { shopId.value = userInfo.shop_id } - loadCommissionSummary() loadCommissionStats() loadCommissionRecords() }) -// 加载佣金概览 async function loadCommissionSummary() { try { - const summary = await getFundSummary() - commissionSummary.value = summary - } - catch (error) { + commissionSummary.value = await getFundSummary() + } catch (error) { console.error('加载佣金概览失败:', error) } } -// 加载佣金统计 async function loadCommissionStats() { if (!shopId.value) return - try { - const stats = await getCommissionStats(shopId.value) - commissionStats.value = stats - } - catch (error) { + commissionStats.value = await getCommissionStats(shopId.value) + } catch (error) { console.error('加载佣金统计失败:', error) } } -// 加载佣金明细 -async function loadCommissionRecords() { +async function loadCommissionRecords(isRefresh = false) { if (!shopId.value) return - + if (isRefresh) { + page.value = 1 + commissionRecords.value = [] + } loadingRecords.value = true - try { - const params: any = { - page: page.value, - page_size: pageSize, - } - - // 佣金来源筛选 + const params: any = { page: page.value, page_size: pageSize } if (sourceFilter.value) { params.commission_source = sourceFilter.value } - - // 搜索关键词(支持 ICCID、虚拟号、订单号) if (searchKeyword.value) { const keyword = searchKeyword.value.trim() - // 根据关键词类型判断搜索字段 - if (/^\d{19,20}$/.test(keyword)) { - // ICCID 通常是19-20位数字 - params.iccid = keyword - } - else if (/^\d{15}$/.test(keyword)) { - // 虚拟号通常是15位数字 - params.virtual_no = keyword - } - else { - // 订单号 - params.order_no = keyword - } + if (searchType.value === 'iccid') params.iccid = keyword + else if (searchType.value === 'virtual_no') params.virtual_no = keyword + else params.order_no = keyword } - const response = await getCommissionRecords(shopId.value, params) - if (page.value === 1) { commissionRecords.value = response.items || [] - } - else { + } else { commissionRecords.value.push(...(response.items || [])) } - total.value = response.total || 0 - } - catch (error) { + } catch (error) { console.error('加载佣金明细失败:', error) - } - finally { + } finally { loadingRecords.value = false } } -// 搜索 function handleSearch() { - page.value = 1 - commissionRecords.value = [] - loadCommissionRecords() + loadCommissionRecords(true) } -// 清空搜索 -function clearSearch() { - searchKeyword.value = '' - page.value = 1 - commissionRecords.value = [] - loadCommissionRecords() -} - -// 来源筛选变化 function onSourceConfirm(option: { label: string, value: any }) { sourceFilter.value = option.value - page.value = 1 - commissionRecords.value = [] - loadCommissionRecords() + loadCommissionRecords(true) +} + +function onSearchTypeConfirm(option: { label: string, value: any }) { + searchType.value = option.value } -// 加载更多 function loadMore() { - if (commissionRecords.value.length >= total.value) { - return + if (commissionRecords.value.length < total.value) { + page.value++ + loadCommissionRecords() } - page.value++ - loadCommissionRecords() } -// 刷新 -function refreshList() { - page.value = 1 - commissionRecords.value = [] - loadCommissionSummary() - loadCommissionStats() - loadCommissionRecords() +function onScroll(e: any) { + const { scrollTop, scrollHeight, clientHeight } = e.target + if (scrollHeight - scrollTop - clientHeight < 100) { + loadMore() + } } + \ No newline at end of file diff --git a/src/pages/agent-system/withdraw/index.vue b/src/pages/agent-system/withdraw/index.vue index ee72adb..c3cef0a 100644 --- a/src/pages/agent-system/withdraw/index.vue +++ b/src/pages/agent-system/withdraw/index.vue @@ -6,46 +6,22 @@ import { createWithdrawal, getWithdrawalRecords } from '@/api/withdrawal' import type { WithdrawalRecord } from '@/api/withdrawal' import SimplePicker from '@/components/SimplePicker.vue' -// 佣金概览 const commissionSummary = ref(null) - -// 店铺ID (从登录信息获取) const shopId = ref(0) - -// 从本地存储获取用户信息 -function getUserInfo() { - const userInfo = uni.getStorageSync('user_info') - return userInfo || null -} - -// 提现金额(元) const withdrawAmount = ref('') - -// 账户信息 const accountName = ref('') const accountNumber = ref('') - -// 提现记录 const withdrawRecords = ref([]) - -// 当前Tab const activeTab = ref<'apply' | 'records'>('apply') - -// 加载状态 const loading = ref(false) const submitting = ref(false) const loadingRecords = ref(false) - -// 分页参数 const page = ref(1) const pageSize = 20 const total = ref(0) - -// 状态筛选 const statusFilter = ref(undefined) const showStatusPicker = ref(false) -// 状态选项 const statusOptions = [ { label: '全部状态', value: undefined }, { label: '审核中', value: 1 }, @@ -54,53 +30,22 @@ const statusOptions = [ { label: '已到账', value: 4 }, ] -// 获取当前选中的状态名称 const selectedStatusName = computed(() => { - if (statusFilter.value === undefined) return '全部状态' + if (statusFilter.value === undefined) return '状态' const option = statusOptions.find(o => o.value === statusFilter.value) - return option?.label || '全部状态' + return option?.label || '状态' }) -// Tab选项 const tabs = [ { key: 'apply', label: '申请提现' }, { key: 'records', label: '提现记录' }, ] -// 可提现金额(分转元) const availableAmount = computed(() => { if (!commissionSummary.value) return 0 return commissionSummary.value.available_commission / 100 }) -// 格式化可提现金额显示(带千分号) -const formattedAvailableAmount = computed(() => { - const amount = availableAmount.value.toFixed(2) - const parts = amount.split('.') - parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',') - return parts.join('.') -}) - -// 实际到账金额 (无手续费,带千分号) -const actualAmount = computed(() => { - const amount = parseFloat(withdrawAmount.value) || 0 - const fixed = amount.toFixed(2) - const parts = fixed.split('.') - parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',') - return parts.join('.') -}) - -// 格式化输入金额显示 (带千分号) -const formattedWithdrawAmount = computed(() => { - if (!withdrawAmount.value) return '0.00' - const amount = parseFloat(withdrawAmount.value) || 0 - const fixed = amount.toFixed(2) - const parts = fixed.split('.') - parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',') - return parts.join('.') -}) - -// 格式化金额(分转元,带千分号) function formatAmount(amount: number) { const yuan = (amount / 100).toFixed(2) const parts = yuan.split('.') @@ -108,226 +53,161 @@ function formatAmount(amount: number) { return `¥${parts.join('.')}` } -// 获取提现状态文本 function getStatusText(status: number, statusName?: string) { - if (statusName) return statusName - const map: Record = { - 1: '审核中', - 2: '已通过', - 3: '已拒绝', - 4: '已到账', - } - return map[status] || '未知' + return statusName || (status === 1 ? '审核中' : status === 2 ? '已通过' : status === 3 ? '已拒绝' : status === 4 ? '已到账' : '未知') } -// 获取提现状态颜色 function getStatusColor(status: number) { const map: Record = { - 1: { bg: '#fff3e0', text: '#e65100' }, // 审核中 - 2: { bg: '#e8f5e9', text: '#2e7d32' }, // 已通过 - 3: { bg: '#ffebee', text: '#c62828' }, // 已拒绝 - 4: { bg: '#e3f2fd', text: '#1565c0' }, // 已到账 + 1: { bg: '#fff3e0', text: '#e65100' }, + 2: { bg: '#e8f5e9', text: '#2e7d32' }, + 3: { bg: '#ffebee', text: '#c62828' }, + 4: { bg: '#e3f2fd', text: '#1565c0' }, } return map[status] || { bg: '#f5f5f5', text: '#999' } } -// 格式化时间 function formatTime(time: string) { if (!time) return '-' const date = new Date(time) - const year = date.getFullYear() - const month = String(date.getMonth() + 1).padStart(2, '0') - const day = String(date.getDate()).padStart(2, '0') - const hour = String(date.getHours()).padStart(2, '0') - const minute = String(date.getMinutes()).padStart(2, '0') - return `${year}-${month}-${day} ${hour}:${minute}` + return `${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}` } -// 页面加载 onMounted(() => { - // 从登录信息获取 shop_id - const userInfo = getUserInfo() + const userInfo = uni.getStorageSync('user_info') if (userInfo?.shop_id) { shopId.value = userInfo.shop_id } - loadCommissionSummary() loadWithdrawRecords() }) -// 加载佣金概览 async function loadCommissionSummary() { loading.value = true try { - const summary = await getFundSummary() - commissionSummary.value = summary + commissionSummary.value = await getFundSummary() withdrawAmount.value = availableAmount.value.toFixed(2) - } - catch (error) { + } catch (error) { console.error('加载佣金概览失败:', error) - } - finally { + } finally { loading.value = false } } -// 加载提现记录 -async function loadWithdrawRecords() { +async function loadWithdrawRecords(isRefresh = false) { if (!shopId.value) return - + if (isRefresh) { + page.value = 1 + withdrawRecords.value = [] + } loadingRecords.value = true - try { - const params: any = { - page: page.value, - page_size: pageSize, - } - - // 状态筛选 + const params: any = { page: page.value, page_size: pageSize } if (statusFilter.value !== undefined) { params.status = statusFilter.value } - const response = await getWithdrawalRecords(shopId.value, params) - if (page.value === 1) { withdrawRecords.value = response.items || [] - } - else { + } else { withdrawRecords.value.push(...(response.items || [])) } - total.value = response.total || 0 - } - catch (error) { + } catch (error) { console.error('加载提现记录失败:', error) - } - finally { + } finally { loadingRecords.value = false } } -// 快捷金额按钮 function setQuickAmount(amount: number) { withdrawAmount.value = amount.toString() } -// 全部提现 function setAllAmount() { withdrawAmount.value = availableAmount.value.toFixed(2) } -// 提交提现申请 async function handleSubmit() { - // 校验 const amount = parseFloat(withdrawAmount.value) if (!amount || amount <= 0) { uni.$u.toast('请输入提现金额') return } - if (amount > availableAmount.value) { uni.$u.toast('提现金额超过可用余额') return } - const name = accountName.value.trim() if (!name) { uni.$u.toast('请输入收款人姓名') return } - if (!/^[\u4e00-\u9fa5]{2,20}$|^[a-zA-Z]{2,20}$/.test(name)) { - uni.$u.toast('姓名格式错误') - return - } - const account = accountNumber.value.trim() if (!account) { uni.$u.toast('请输入支付宝账号') return } - const phoneRegex = /^1[3-9]\d{9}$/ - const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ - if (!phoneRegex.test(account) && !emailRegex.test(account)) { - uni.$u.toast('支付宝账号格式错误') - return - } - submitting.value = true - try { - const result = await createWithdrawal(shopId.value, { + await createWithdrawal(shopId.value, { account_name: name, account_number: account, amount: Math.round(amount * 100), withdrawal_method: 'alipay', }) - uni.$u.toast('提现申请已提交') - withdrawAmount.value = '' accountName.value = '' accountNumber.value = '' - await loadCommissionSummary() page.value = 1 await loadWithdrawRecords() - activeTab.value = 'records' - } - catch (error) { + } catch (error) { console.error('提现申请失败:', error) - } - finally { + } finally { submitting.value = false } } -// 切换Tab function handleTabChange(tab: 'apply' | 'records') { activeTab.value = tab if (tab === 'records') { - page.value = 1 + loadWithdrawRecords(true) + } +} + +function onStatusConfirm(option: { label: string, value: any }) { + statusFilter.value = option.value + loadWithdrawRecords(true) +} + +function loadMore() { + if (withdrawRecords.value.length < total.value) { + page.value++ loadWithdrawRecords() } } -// 状态筛选变化 -function onStatusConfirm(option: { label: string, value: any }) { - statusFilter.value = option.value - page.value = 1 - withdrawRecords.value = [] - loadWithdrawRecords() -} - -// 加载更多 -function loadMore() { - if (withdrawRecords.value.length >= total.value) { - return +function onScroll(e: any) { + const { scrollTop, scrollHeight, clientHeight } = e.target + if (scrollHeight - scrollTop - clientHeight < 100) { + loadMore() } - page.value++ - loadWithdrawRecords() }