185 lines
4.4 KiB
Dart
185 lines
4.4 KiB
Dart
import 'package:circle_app/router/app_routers.dart';
|
|
import 'package:circle_app/util/util.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../network/api.dart';
|
|
import '../../network/dio_manager.dart';
|
|
import 'state.dart';
|
|
|
|
class CircleLogic extends GetxController {
|
|
PageController pageController =
|
|
PageController(initialPage: 1, viewportFraction: 0.8);
|
|
InterestsBean circle = InterestsBean(lists: []);
|
|
final CircleState state = CircleState();
|
|
|
|
Map? statistics;
|
|
int page = 1;
|
|
|
|
@override
|
|
void onInit() async {
|
|
super.onInit();
|
|
var data = await DioManager.instance
|
|
.get(url: Api.getCircleInterests, params: {"page": page});
|
|
var bean = BaseResponse<InterestsBean>.fromJson(
|
|
data, (data) => InterestsBean.fromJson(data));
|
|
if(bean.data is InterestsBean&&bean.isSuccess()){
|
|
circle = bean.data!;
|
|
update();
|
|
}
|
|
|
|
loadCirclePeopleData();
|
|
}
|
|
|
|
loadMore() async {
|
|
page = page++;
|
|
var data = await DioManager.instance
|
|
.get(url: Api.getCircleInterests, params: {"page": page});
|
|
var bean = BaseResponse<InterestsBean>.fromJson(
|
|
data, (data) => InterestsBean.fromJson(data));
|
|
circle = bean.data!;
|
|
update();
|
|
}
|
|
|
|
outCircle(String interest_id, bool isStatus) async {
|
|
var data = await DioManager.instance.post(
|
|
url: Api.outCrrcle + interest_id + "/join",
|
|
params: {"status": isStatus ? "0" : "1"});
|
|
var bean = BaseResponse<String>.fromJson(data, (data) => data);
|
|
if (bean.code == 200) {
|
|
circle.lists.forEach((element) {
|
|
if (element.id.toString() == interest_id.toString()) {
|
|
element.isJoin = !isStatus;
|
|
}
|
|
});
|
|
}
|
|
showToast(bean.msg);
|
|
}
|
|
|
|
//访问我的圈子人数
|
|
loadCirclePeopleData() async {
|
|
var data = await DioManager.instance
|
|
.get(url: Api.getInterestsCount);
|
|
if (data['code'] == 200) {
|
|
statistics = data['data'];
|
|
update();
|
|
}
|
|
}
|
|
|
|
Circle getCircleIndex() {
|
|
return circle.lists[state.index];
|
|
}
|
|
|
|
void pushHome(String userId) {
|
|
Get.toNamed(AppRoutes.UserInfoActivity, arguments: userId);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
class InterestsBean {
|
|
List<Circle> lists;
|
|
|
|
InterestsBean({required this.lists});
|
|
|
|
factory InterestsBean.fromJson(Map<String, dynamic> json) {
|
|
List<dynamic> listsJson = json['lists'];
|
|
List<Circle> lists = listsJson.map((e) => Circle.fromJson(e)).toList();
|
|
return InterestsBean(lists: lists);
|
|
}
|
|
}
|
|
|
|
class Circle {
|
|
int id;
|
|
String image;
|
|
String title;
|
|
String intro;
|
|
double amount;
|
|
bool is_limit;
|
|
double oldAmount;
|
|
String lastCalloutTime;
|
|
bool isJoin;
|
|
dynamic isLike;
|
|
int viewTotal;
|
|
int joinTotal;
|
|
List<JoinUser> lastJoinUsers;
|
|
|
|
Circle({
|
|
required this.id,
|
|
required this.is_limit,
|
|
required this.image,
|
|
required this.title,
|
|
required this.intro,
|
|
required this.amount,
|
|
required this.oldAmount,
|
|
required this.lastCalloutTime,
|
|
required this.isJoin,
|
|
required this.isLike,
|
|
required this.viewTotal,
|
|
required this.joinTotal,
|
|
required this.lastJoinUsers,
|
|
});
|
|
|
|
factory Circle.fromJson(Map<String, dynamic> json) {
|
|
List<dynamic> lastJoinUsersJson = json['last_join_users'];
|
|
List<JoinUser> lastJoinUsers =
|
|
lastJoinUsersJson.map((e) => JoinUser.fromJson(e)).toList();
|
|
|
|
return Circle(
|
|
id: json['id'],
|
|
is_limit: json['is_limit'] ?? false,
|
|
image: json['image'],
|
|
title: json['title'],
|
|
intro: json['intro'],
|
|
amount: json['amount'].toDouble(),
|
|
oldAmount: json['old_amount'].toDouble(),
|
|
lastCalloutTime: json['last_callout_time'],
|
|
isJoin: json['is_join'],
|
|
isLike: json['is_like'],
|
|
viewTotal: json['view_total'],
|
|
joinTotal: json['join_total'],
|
|
lastJoinUsers: lastJoinUsers,
|
|
);
|
|
}
|
|
}
|
|
|
|
class JoinUser {
|
|
int id;
|
|
String avatar;
|
|
String nickname;
|
|
|
|
JoinUser({
|
|
required this.id,
|
|
required this.avatar,
|
|
required this.nickname,
|
|
});
|
|
|
|
factory JoinUser.fromJson(Map<String, dynamic> json) {
|
|
return JoinUser(
|
|
id: json['id'],
|
|
avatar: json['avatar'],
|
|
nickname: json['nickname'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class LastJoinUser {
|
|
int id;
|
|
String avatar;
|
|
String nickname;
|
|
|
|
LastJoinUser({
|
|
required this.id,
|
|
required this.avatar,
|
|
required this.nickname,
|
|
});
|
|
|
|
factory LastJoinUser.fromJson(Map<String, dynamic> json) {
|
|
return LastJoinUser(
|
|
id: json['id'],
|
|
avatar: json['avatar'],
|
|
nickname: json['nickname'],
|
|
);
|
|
}
|
|
}
|