user_friend_model.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import 'dart:convert';
  2. import 'dart:math';
  3. import 'package:azlistview/azlistview.dart';
  4. import 'package:sport/bean/user_friend.dart';
  5. import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
  6. import 'package:sport/services/api/inject_api.dart';
  7. import 'package:sport/services/api/resp.dart';
  8. class UserFriendModel extends ViewStateRefreshListModel<UserFriend>
  9. with InjectApi {
  10. int type;
  11. String kw;
  12. // Map map;
  13. List<SuspensionBean> items = [];
  14. List<SuspensionBean> originItems = [];
  15. List originList = [];
  16. List<String> tags = [];
  17. UserFriendModel(this.type);
  18. @override
  19. Future<List<UserFriend>> loadData({int pageNum}) async {
  20. List<UserFriend> results = [];
  21. switch (type) {
  22. case 2:
  23. results =
  24. (await api.userFansList(kw: kw, page: max(1, pageNum))).results.list;
  25. originList = results;
  26. break;
  27. case 1:
  28. results =
  29. (await api.userFollowList(kw: kw, page: max(1, pageNum))).results.list;
  30. originList = results;
  31. break;
  32. default:
  33. ResultsTest<UserFriend> data = (await api.userFriendsTest(
  34. kw: kw, page: max(1, pageNum), test: "1"))
  35. .results;
  36. items = [];
  37. tags = data.map.keys.toList();
  38. data.map.forEach((key, value) {
  39. value.forEach((element) {
  40. items.add(SuspensionBean(key, UserFriend.fromJson(element)));
  41. });
  42. });
  43. // items.forEach((element) {
  44. // print(element.toJson());
  45. // });
  46. originItems = items;
  47. SuspensionUtil.setShowSuspensionStatus(items);
  48. SuspensionUtil.sortListBySuspensionTag(items);
  49. break;
  50. }
  51. print("[RESULTS]${results}------------------------------");
  52. return results;
  53. }
  54. void submitValue(String value) {
  55. this.kw = value;
  56. refresh(init: true);
  57. }
  58. }
  59. class SuspensionBean extends ISuspensionBean {
  60. final String tag;
  61. final UserFriend user;
  62. SuspensionBean(this.tag, this.user);
  63. @override
  64. String getSuspensionTag() => tag;
  65. Map<String, dynamic> toJson() {
  66. final Map<String, dynamic> data = new Map<String, dynamic>();
  67. data['tag'] = this.tag;
  68. data['user'] = this.user.toJson();
  69. return data;
  70. }
  71. }
  72. class UserFriendListModel extends ISuspensionBean {
  73. String name;
  74. String tagIndex;
  75. String namePinyin;
  76. UserFriendListModel({
  77. this.name,
  78. this.tagIndex,
  79. this.namePinyin,
  80. });
  81. UserFriendListModel.fromJson(Map<String, dynamic> json) : name = json['name'];
  82. Map<String, dynamic> toJson() => {
  83. 'name': name,
  84. // 'tagIndex': tagIndex,
  85. // 'namePinyin': namePinyin,
  86. // 'isShowSuspension': isShowSuspension
  87. };
  88. @override
  89. String getSuspensionTag() => tagIndex;
  90. @override
  91. String toString() => json.encode(this);
  92. }