// 佣金记录mock数据
export const commissionMockData = {
  // 佣金记录列表
  list: [
    {
      id: 1,
      commission_no: 'COM202501150001',
      username: 'john_doe',
      phone: '13800138001',
      amount: 150,
      description: '邀请用户注册奖励',
      order_no: 'ORD202501150001',
      status: 'processing',
      status_text: '处理中',
      type: 'invite_reward',
      type_text: '邀请奖励',
      create_time: '2025-01-15 10:30:00',
      settle_time: '',
      user_id: 1001,
    },
    {
      id: 2,
      commission_no: 'COM202501150002',
      username: 'jane_smith',
      phone: '13800138002',
      amount: 300,
      description: '拼团成功奖励',
      order_no: 'ORD202501150002',
      status: 'settled',
      status_text: '已到账',
      type: 'group_reward',
      type_text: '拼团奖励',
      create_time: '2025-01-15 09:20:00',
      settle_time: '2025-01-15 12:30:00',
      user_id: 1002,
    },
    {
      id: 3,
      commission_no: 'COM202501150003',
      username: 'mike_wilson',
      phone: '13800138003',
      amount: 200,
      description: '开团成功奖励',
      order_no: 'ORD202501150003',
      status: 'settled',
      status_text: '已到账',
      type: 'leader_reward',
      type_text: '开团奖励',
      create_time: '2025-01-15 08:15:00',
      settle_time: '2025-01-15 11:45:00',
      user_id: 1003,
    },
    {
      id: 4,
      commission_no: 'COM202501150004',
      username: 'sarah_jones',
      phone: '13800138004',
      amount: 50,
      description: '每日签到奖励',
      order_no: '',
      status: 'unsettled',
      status_text: '未到账',
      type: 'checkin_reward',
      type_text: '签到奖励',
      create_time: '2025-01-15 07:00:00',
      settle_time: '',
      user_id: 1004,
    },
    {
      id: 5,
      commission_no: 'COM202501150005',
      username: 'david_brown',
      phone: '13800138005',
      amount: 120,
      description: '下线拼团奖励',
      order_no: 'ORD202501150005',
      status: 'processing',
      status_text: '处理中',
      type: 'group_sub_reward',
      type_text: '拼团奖励-下线',
      create_time: '2025-01-14 16:30:00',
      settle_time: '',
      user_id: 1005,
    },
    {
      id: 6,
      commission_no: 'COM202501150006',
      username: 'lisa_davis',
      phone: '13800138006',
      amount: 80,
      description: '下线开团奖励',
      order_no: 'ORD202501150006',
      status: 'settled',
      status_text: '已到账',
      type: 'leader_sub_reward',
      type_text: '开团奖励-下线',
      create_time: '2025-01-14 15:20:00',
      settle_time: '2025-01-14 18:30:00',
      user_id: 1006,
    },
  ],

  // 获取列表数据
  getList(params = {}) {
    const {
      page = 1,
      size = 10,
      username = '',
      phone = '',
      commission_no = '',
      status = 'all',
      type = '',
      start_time = '',
      end_time = '',
    } = params;

    let filteredData = [...this.list];

    // 搜索过滤
    if (username) {
      filteredData = filteredData.filter((item) =>
        item.username.toLowerCase().includes(username.toLowerCase()),
      );
    }
    if (phone) {
      filteredData = filteredData.filter((item) => item.phone.includes(phone));
    }
    if (commission_no) {
      filteredData = filteredData.filter((item) => item.commission_no.includes(commission_no));
    }
    if (status && status !== 'all') {
      filteredData = filteredData.filter((item) => item.status === status);
    }
    if (type) {
      filteredData = filteredData.filter((item) => item.type === type);
    }

    // 时间过滤
    if (start_time && end_time) {
      filteredData = filteredData.filter((item) => {
        const itemTime = new Date(item.create_time);
        const startTime = new Date(start_time);
        const endTime = new Date(end_time);
        return itemTime >= startTime && itemTime <= endTime;
      });
    }

    // 分页
    const total = filteredData.length;
    const startIndex = (page - 1) * size;
    const endIndex = startIndex + size;
    const data = filteredData.slice(startIndex, endIndex);

    return {
      error: 0,
      msg: 'success',
      data: {
        data,
        total,
        per_page: size,
        current_page: page,
        last_page: Math.ceil(total / size),
      },
    };
  },

  // 获取详情数据
  getDetail(id) {
    const item = this.list.find((item) => item.id == id);
    if (!item) {
      return {
        error: 1,
        msg: '记录不存在',
        data: null,
      };
    }

    return {
      error: 0,
      msg: 'success',
      data: {
        ...item,
        // 详情页面额外字段
        user_balance: '2,500',
        commission_balance: '1,200',
        total_commission: '5,800',
        commission_rate: '5.0',
        source_type: 'order',
        source_type_text: '订单佣金',
      },
    };
  },

  // 导出数据
  export(params = {}) {
    const data = this.getList({ ...params, size: 1000 });
    return {
      error: 0,
      msg: '导出成功',
      data: {
        filename: `commission_export_${new Date().getTime()}.xlsx`,
        url: '/download/commission_export.xlsx',
        total: data.data.total,
      },
    };
  },
};
