import 'package:zhiying_comm/util/empty_util.dart';

class TeamFansListModel {
  String categoryCount;
  List<TeamFansListItemModel> fans;
  String total;

  TeamFansListModel({this.categoryCount, this.fans, this.total});

  factory TeamFansListModel.fromJson(Map<String, dynamic> json) {
    return TeamFansListModel(
      categoryCount: json['category_count'],
      fans: json['fans'] != null ? (json['fans'] as List).map((i) => TeamFansListItemModel.fromJson(i)).toList() : null,
      total: json['total'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['category_count'] = this.categoryCount;
    data['total'] = this.total;
    if (this.fans != null) {
      data['fans'] = this.fans.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class TeamFansListItemModel {
  String avatar;
  String inviteCount;
  String lastLogin;
  String level;
  String levelType;
  String monthFin;
  String monthInviteCount;
  String phone;
  String todayInviteCount;
  String totalFin;
  String username;
  String wechat;
  String weekFin;

  String levelName;
  String levelIcon;
  String levelBgColor;
  String levelBgImage;

  // 获取模糊手机号码
  get blurMobile => !EmptyUtil.isEmpty(phone) ? phone.length == 11 ? '${phone.substring(0, 3)}****${phone.substring(7, phone.length)}' : phone : phone;

  // 获取模糊昵称
  get blurUserName =>
      !EmptyUtil.isEmpty(username) ? username.length > 6 ? '${username.substring(0, 3)}****${username.substring(username.length - 3, phone.length)}' : username : username;

  // 获取模糊微信
  get blurWeChat => !EmptyUtil.isEmpty(wechat) ? wechat.length > 6 ? '${wechat.substring(0, 3)}****${wechat.substring(wechat.length - 3, wechat.length)}' : wechat : wechat;

  TeamFansListItemModel({
    this.avatar,
    this.inviteCount,
    this.lastLogin,
    this.level,
    this.levelType,
    this.monthFin,
    this.monthInviteCount,
    this.phone,
    this.todayInviteCount,
    this.totalFin,
    this.username,
    this.wechat,
    this.weekFin,
    this.levelBgColor,
    this.levelBgImage,
    this.levelIcon,
    this.levelName,
  });

  factory TeamFansListItemModel.fromJson(Map<String, dynamic> json) {
    return TeamFansListItemModel(
      avatar: json['avatar'],
      inviteCount: json['invite_count'],
      lastLogin: json['last_login'],
      level: json['level'],
      levelType: json['level_type'],
      monthFin: json['month_fin'],
      monthInviteCount: json['month_invite_count'],
      phone: json['phone'],
      todayInviteCount: json['today_invite_count'],
      totalFin: json['total_fin'],
      username: json['username'],
      wechat: json['wechat'],
      weekFin: json['week_fin'],
      levelBgColor: json['level_bg_color'],
      levelBgImage: json['level_bg_color'],
      levelIcon: json['level_icon'],
      levelName: json['level_name'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['avatar'] = this.avatar;
    data['invite_count'] = this.inviteCount;
    data['last_login'] = this.lastLogin;
    data['level'] = this.level;
    data['level_type'] = this.levelType;
    data['month_fin'] = this.monthFin;
    data['month_invite_count'] = this.monthInviteCount;
    data['phone'] = this.phone;
    data['today_invite_count'] = this.todayInviteCount;
    data['total_fin'] = this.totalFin;
    data['username'] = this.username;
    data['wechat'] = this.wechat;
    data['week_fin'] = this.weekFin;
    data['level_name'] = this.levelName;
    data['level_icon'] = this.levelIcon;
    data['level_bg_color'] = this.levelBgColor;
    data['level_bg_image'] = this.levelBgImage;
    return data;
  }
}
