123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- const DarkModeUtil = require('../../utils/dark-mode.js')
- import { request } from '../../utils/request'
- import { getLoginInfo } from '../../utils/login'
- Page({
- data: {
- isDarkMode: false,
- loading: true,
- earnings: {
- account_balance: '0.00', // 账户余额
- this_day_forecast_income: '0.00', // 今日预估收入
- last_day_forecast_income: '0.00', // 昨日预估收入
- this_month_forecast_income: '0.00', // 本月预估收入
- last_month_forecast_income: '0.00', // 上月预估收入
- total_forecast_income: '0.00', // 总预估收入
- this_month_settlement_income: '0.00', // 本月结算收入
- all_settlement_income: '0.00', // 累计结算收入
- wait_settlement_income: '0.00', // 待结算收入
- withdraw_amount: '0.00' // 已提现金额
- },
- trends: {
- daily: 0, // 日收入趋势:1上升,-1下降,0持平
- monthly: 0 // 月收入趋势:1上升,-1下降,0持平
- },
- incomeList: [],
- page: 1,
- pageSize: 10,
- hasMore: true
- },
- onLoad() {
- // 应用深色模式
- DarkModeUtil.applyPageDarkMode(this)
-
- // 监听深色模式变化
- DarkModeUtil.listenDarkModeChange(this)
- // 加载收益数据
- this.loadEarningsData()
- // 加载收入明细列表
- this.loadIncomeList()
- },
- // 计算趋势
- calculateTrend(current, previous) {
- const currentValue = parseFloat(current) || 0
- const previousValue = parseFloat(previous) || 0
- if (currentValue > previousValue) return 1
- if (currentValue < previousValue) return -1
- return 0
- },
- // 加载收益数据
- async loadEarningsData() {
- try {
- const userInfo = getLoginInfo()
- const res = await request({
- url: '/api/user/myEarnings',
- method: 'GET',
- data: {
- user_id: userInfo.id
- }
- })
- if (res.errno === '0' && res.rst) {
- // 计算日收入和月收入趋势
- const dailyTrend = this.calculateTrend(
- res.rst.this_day_forecast_income,
- res.rst.last_day_forecast_income
- )
- const monthlyTrend = this.calculateTrend(
- res.rst.this_month_forecast_income,
- res.rst.last_month_forecast_income
- )
- this.setData({
- earnings: {
- account_balance: res.rst.account_balance || '0.00',
- this_day_forecast_income: res.rst.this_day_forecast_income || '0.00',
- last_day_forecast_income: res.rst.last_day_forecast_income || '0.00',
- this_month_forecast_income: res.rst.this_month_forecast_income || '0.00',
- last_month_forecast_income: res.rst.last_month_forecast_income || '0.00',
- total_forecast_income: res.rst.total_forecast_income || '0.00',
- this_month_settlement_income: res.rst.this_month_settlement_income || '0.00',
- all_settlement_income: res.rst.all_settlement_income || '0.00',
- wait_settlement_income: res.rst.wait_settlement_income || '0.00',
- withdraw_amount: res.rst.withdraw_amount || '0.00'
- },
- trends: {
- daily: dailyTrend,
- monthly: monthlyTrend
- },
- loading: false
- })
- // 保存原始数据到本地存储
- wx.setStorageSync('earnings_data', res.rst)
- } else {
- console.error('获取收益数据失败:', res)
- wx.showToast({
- title: res.err || '获取收益数据失败',
- icon: 'none'
- })
- }
- } catch (error) {
- console.error('获取收益数据失败:', error)
- wx.showToast({
- title: '获取收益数据失败',
- icon: 'none'
- })
- }
- },
- // 加载收入明细
- async loadIncomeList(refresh = false) {
- if (refresh) {
- this.setData({
- page: 1,
- hasMore: true,
- incomeList: []
- })
- }
- if (!this.data.hasMore) return
- try {
- const userInfo = getLoginInfo()
- const res = await request({
- url: '/api/user/myEarningsDetail',
- method: 'GET',
- data: {
- user_id: userInfo.id,
- page: this.data.page,
- page_size: this.data.pageSize
- }
- })
- if (res.errno === '0' && res.rst && res.rst.data) {
- const newList = res.rst.data.map(item => ({
- id: item.id,
- type: item.type === 1 ? '佣金收入' : '提现',
- amount: item.rebate || '0.00',
- status: this.getStatusText(item.state_of_embodiment),
- createTime: item.create_at,
- note: item.note || ''
- }))
- this.setData({
- incomeList: [...this.data.incomeList, ...newList],
- page: this.data.page + 1,
- hasMore: newList.length >= this.data.pageSize
- })
- } else {
- console.error('获取收入明细失败:', res)
- wx.showToast({
- title: res.err || '获取收入明细失败',
- icon: 'none'
- })
- }
- } catch (error) {
- console.error('获取收入明细失败:', error)
- wx.showToast({
- title: '获取收入明细失败',
- icon: 'none'
- })
- }
- },
- // 获取状态文本
- getStatusText(status) {
- switch (status) {
- case 0: return '申请中'
- case 1: return '已打款'
- case 2: return '已作废'
- default: return '未知状态'
- }
- },
- // 申请提现
- applyWithdraw() {
- if (parseFloat(this.data.earnings.account_balance) <= 0) {
- wx.showToast({
- title: '暂无可提现金额',
- icon: 'none'
- })
- return
- }
- // TODO: 实现提现功能
- },
- // 下拉刷新
- async onPullDownRefresh() {
- try {
- await this.loadEarningsData()
- await this.loadIncomeList(true)
- wx.stopPullDownRefresh()
- } catch (error) {
- console.error('刷新数据失败:', error)
- wx.stopPullDownRefresh()
- }
- },
- // 触底加载更多
- onReachBottom() {
- this.loadIncomeList()
- }
- })
|