663 lines
17 KiB
Dart
663 lines
17 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:circle_app/main.dart';
|
|
import 'package:circle_app/router/app_routers.dart';
|
|
import 'package:circle_app/util/device.dart';
|
|
import 'package:circle_app/util/util.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_swiper/flutter_swiper.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
import '../../common/Widgets/open_vip_tip/view.dart';
|
|
import '../../network/api.dart';
|
|
import '../../network/dio_manager.dart';
|
|
import '../../util/eventBus.dart';
|
|
import '../select_circle/logic.dart';
|
|
import '../userinfo/logic.dart';
|
|
import 'state.dart';
|
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
|
|
|
class CircleLogic extends GetxController {
|
|
PageController pageController =
|
|
PageController(initialPage: 1, viewportFraction: 0.8);
|
|
SwiperController swiperController = SwiperController();
|
|
final RefreshController refreshController = RefreshController();
|
|
InterestsBean circle = InterestsBean(lists: []);
|
|
final CircleState state = CircleState();
|
|
var statistics = Rx<DataModel>(
|
|
DataModel(visitCount: 0, lastVisitUsers: [], likeMeCount: 0));
|
|
|
|
//Map? statistics;
|
|
int page = 1;
|
|
|
|
int vicinityPage = 1;
|
|
|
|
bool isMore = true;
|
|
int myVip = 0;
|
|
bool isShowCircle = true;
|
|
String cityName = "";
|
|
|
|
List<BannerItem> bannerList = [];
|
|
|
|
AutoScrollController scrollController = AutoScrollController();
|
|
ScrollController listScrollController = ScrollController();
|
|
|
|
@override
|
|
void onInit() async {
|
|
super.onInit();
|
|
var data = await DioManager.instance.get(
|
|
url: Api.getCircleInterests, params: {"page": page, 'page_size': 20});
|
|
var bean = BaseResponse<InterestsBean>.fromJson(
|
|
data, (data) => InterestsBean.fromJson(data));
|
|
if (bean.data is InterestsBean && bean.isSuccess()) {
|
|
circle = bean.data!;
|
|
if (circle.lists.length < 20) {
|
|
isMore = false;
|
|
}
|
|
|
|
update();
|
|
}
|
|
myVip = await getVip();
|
|
loadCirclePeopleData();
|
|
initGerder();
|
|
getCityList();
|
|
|
|
getBanner();
|
|
getNearByList();
|
|
|
|
EventBusManager.on<CommentVipEvent>().listen((event) {
|
|
myVip = event.vip;
|
|
// update();
|
|
});
|
|
}
|
|
|
|
List<MyConfigData> genderList = [];
|
|
|
|
List<MyConfigData> orientationList = [];
|
|
|
|
List<MyConfigData> roleList = [];
|
|
|
|
void initGerder() async {
|
|
var data1 =
|
|
await DioManager.instance.get(url: Api.getCircleList, params: {});
|
|
var bean1 = BaseResponse<ConfigBean>.fromJson(
|
|
data1, (data1) => ConfigBean.fromJson(data1));
|
|
|
|
ConfigBean configBean = bean1.data!;
|
|
|
|
configBean.genderMap.forEach((key, value) {
|
|
genderList.add(MyConfigData(key, value, false));
|
|
});
|
|
|
|
configBean.orientationMap.forEach((key, value) {
|
|
orientationList.add(MyConfigData(key, value, false));
|
|
});
|
|
configBean.roleMap.forEach((key, value) {
|
|
roleList.add(MyConfigData(key, value, false));
|
|
});
|
|
}
|
|
|
|
List<Province> provinceList = [];
|
|
|
|
Map cityMap = {};
|
|
|
|
getCityList() async {
|
|
try {
|
|
String jsonString = await rootBundle.loadString('assets/province.json');
|
|
List<dynamic> jsonData = json.decode(jsonString);
|
|
provinceList =
|
|
jsonData.map((dynamic item) => Province.fromJson(item)).toList();
|
|
cityMap.clear();
|
|
for (int i = 0; i < provinceList.length; i++) {
|
|
Map areaMap = {};
|
|
for (int c = 0; c < provinceList[i].city.length; c++) {
|
|
String cityName = provinceList[i].city[c].name;
|
|
areaMap[cityName] = []; // 不再存储区域列表,直接设置为空列表
|
|
}
|
|
cityMap[provinceList[i].name] = areaMap;
|
|
}
|
|
|
|
} catch (e) {
|
|
print('Error loading JSON file: $e');
|
|
}
|
|
}
|
|
|
|
loadMore() async {
|
|
if (!isMore) return;
|
|
page = page + 1;
|
|
var data = await DioManager.instance.get(
|
|
url: Api.getCircleInterests, params: {"page": page, 'page_size': 20});
|
|
var bean = BaseResponse<InterestsBean>.fromJson(
|
|
data, (data) => InterestsBean.fromJson(data));
|
|
|
|
InterestsBean newcircle = bean.data!;
|
|
if (newcircle.lists.isNotEmpty) {
|
|
if (newcircle.lists.length < 20) {
|
|
isMore = false;
|
|
}
|
|
circle.lists.addAll(newcircle.lists);
|
|
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;
|
|
}
|
|
});
|
|
}
|
|
showOKToast(bean.msg);
|
|
}
|
|
|
|
updateCircleInfo(Circle circleInfo) {
|
|
for (int i = 0; i < circle.lists.length; i++) {
|
|
Circle temp = circle.lists[i];
|
|
if (temp.id == circleInfo.id) {
|
|
circle.lists[i] = circleInfo;
|
|
break;
|
|
}
|
|
}
|
|
update();
|
|
}
|
|
|
|
setCircle(String circleId) {
|
|
circle.lists.forEach((element) {
|
|
if (element.id.toString() == circleId.toString()) {
|
|
element.isJoin = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
//访问我的圈子人数
|
|
loadCirclePeopleData() async {
|
|
var data = await DioManager.instance.get(url: Api.getInterestsCount);
|
|
var myAlbumBean = BaseResponse<DataModel>.fromJson(
|
|
data, (data) => DataModel.fromJson(data));
|
|
|
|
if (data['code'] == 200) {
|
|
statistics.value = myAlbumBean.data;
|
|
// update();
|
|
}
|
|
}
|
|
|
|
Circle getCircleIndex() {
|
|
return circle.lists[state.index];
|
|
}
|
|
|
|
void pushHome(String userId) {
|
|
Get.toNamed(AppRoutes.UserInfoActivity, arguments: userId);
|
|
}
|
|
|
|
void getPipeiData() async {
|
|
var data = await DioManager.instance.get(url: Api.getMatch);
|
|
if (data['code'] == 200) {
|
|
//发送消息
|
|
bool isSuccess = await createCustomMsg(
|
|
data['data']['account_id'].toString().split('_').last,
|
|
data['data']['account_id']);
|
|
if (!isSuccess) {
|
|
await sendTextMsg(data['data']['account_id']);
|
|
}
|
|
} else if (data['code'] == 21201) {
|
|
showOKToast(data['msg']);
|
|
showRechargeDialog();
|
|
} else {
|
|
showOKToast(data['msg']);
|
|
}
|
|
}
|
|
|
|
showRechargeDialog() {
|
|
Get.bottomSheet(
|
|
Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
body: Open_vip_tipPage(true),
|
|
),
|
|
isScrollControlled: true,
|
|
enableDrag: false);
|
|
}
|
|
|
|
void getBanner() async {
|
|
|
|
var data =
|
|
await DioManager.instance.get(url: Api.getNearbyBeanner, params: {});
|
|
var bean = BaseResponse<BannerList>.fromJson(
|
|
data, (data) => BannerList.fromJson(data));
|
|
bannerList.clear();
|
|
bannerList.addAll(bean.data.banners);
|
|
cityName = bean.data.city;
|
|
}
|
|
|
|
int offset = 0;
|
|
int deep = 0;
|
|
List<VicinityItemBean> vicinityList = [];
|
|
|
|
void getNearByList() async {
|
|
List<String> genders = [];
|
|
genderList.forEach((element) {
|
|
if (element.isSelect) {
|
|
genders.add(element.id);
|
|
}
|
|
});
|
|
List<String> roles = [];
|
|
roleList.forEach((element) {
|
|
if (element.isSelect) roles.add(element.id);
|
|
});
|
|
|
|
List<String> orientations = [];
|
|
orientationList.forEach((element) {
|
|
if (element.isSelect) orientations.add(element.id);
|
|
});
|
|
if(offset==0){
|
|
getBanner();
|
|
}
|
|
|
|
var data = await DioManager.instance.post(url: Api.postNearbyList, params: {
|
|
"offset": offset,
|
|
'deep': deep,
|
|
'city': cityName,
|
|
"genders": genders,
|
|
"roles": roles,
|
|
"orientations": orientations
|
|
});
|
|
var bean = BaseResponse<VicinityBean>.fromJson(
|
|
data, (data) => VicinityBean.fromJson(data));
|
|
try {
|
|
offset = bean.data.offset;
|
|
deep = bean.data.deep;
|
|
} catch (Exception) {}
|
|
|
|
if (vicinityPage == 1) {
|
|
cityName = bean.data.city;
|
|
vicinityList.clear();
|
|
}
|
|
try{
|
|
vicinityList.addAll(bean.data.users);
|
|
} on Exception{}
|
|
|
|
if (vicinityPage == 1) {
|
|
refreshController.refreshCompleted();
|
|
} else {
|
|
refreshController.loadComplete();
|
|
}
|
|
|
|
update();
|
|
}
|
|
}
|
|
|
|
class VicinityBean {
|
|
String city;
|
|
int offset;
|
|
int deep;
|
|
List<VicinityItemBean> users;
|
|
|
|
VicinityBean(
|
|
{required this.city,
|
|
required this.users,
|
|
required this.offset,
|
|
required this.deep});
|
|
|
|
factory VicinityBean.fromJson(Map<String, dynamic> json) {
|
|
List<dynamic> listsJson = json['users'];
|
|
List<VicinityItemBean> lists =
|
|
listsJson.map((e) => VicinityItemBean.fromJson(e)).toList();
|
|
return VicinityBean(
|
|
users: lists,
|
|
city: json['city'],
|
|
offset: json['offset'],
|
|
deep: json['deep']);
|
|
}
|
|
}
|
|
|
|
class VicinityItemBean {
|
|
final int id;
|
|
final String nickname;
|
|
final String avatar;
|
|
final String signature;
|
|
final String birthday;
|
|
final int age;
|
|
final int vip;
|
|
final int gender;
|
|
final int role;
|
|
final int orientation;
|
|
final double lng;
|
|
final double lat;
|
|
final String city;
|
|
final List<Interest> interests;
|
|
final List<String> images;
|
|
final String avatarThumb;
|
|
final String genderName;
|
|
final String roleName;
|
|
final String orientationName;
|
|
final String bgPicUrl;
|
|
final String onlineFlag;
|
|
final bool isOnline;
|
|
|
|
VicinityItemBean({
|
|
required this.id,
|
|
required this.nickname,
|
|
required this.avatar,
|
|
required this.signature,
|
|
required this.birthday,
|
|
required this.age,
|
|
required this.vip,
|
|
required this.gender,
|
|
required this.role,
|
|
required this.orientation,
|
|
required this.lng,
|
|
required this.lat,
|
|
required this.city,
|
|
required this.interests,
|
|
required this.images,
|
|
required this.avatarThumb,
|
|
required this.genderName,
|
|
required this.roleName,
|
|
required this.orientationName,
|
|
required this.bgPicUrl,
|
|
required this.onlineFlag,
|
|
required this.isOnline,
|
|
});
|
|
|
|
factory VicinityItemBean.fromJson(Map<String, dynamic> json) {
|
|
var interestList = json['interests'] as List;
|
|
List<Interest> interests =
|
|
interestList.map((interest) => Interest.fromJson(interest)).toList();
|
|
|
|
return VicinityItemBean(
|
|
id: json['id'],
|
|
nickname: json['nickname'],
|
|
avatar: json['avatar'],
|
|
signature: json['signature'],
|
|
birthday: json['birthday'],
|
|
age: json['age'],
|
|
vip: json['vip'],
|
|
gender: json['gender'],
|
|
role: json['role'],
|
|
orientation: json['orientation'],
|
|
lng: json['lng'],
|
|
lat: json['lat'],
|
|
city: json['city'],
|
|
interests: interests,
|
|
images: List<String>.from(json['images']),
|
|
avatarThumb: json['avatar_thumb'],
|
|
genderName: json['gender_name'],
|
|
roleName: json['role_name'],
|
|
orientationName: json['orientation_name'],
|
|
bgPicUrl: json['bg_picUrl'],
|
|
onlineFlag: json['online_flag'],
|
|
isOnline: json['isOnline'],
|
|
);
|
|
}
|
|
}
|
|
|
|
// class Interest {
|
|
// final int id;
|
|
// final String title;
|
|
// final String intro;
|
|
// final String image;
|
|
// final double amount;
|
|
// final double oldAmount;
|
|
// final String iosItem;
|
|
// final DateTime lastCalloutTime;
|
|
// final DateTime lastJoinTime;
|
|
// final bool isJoin;
|
|
// final bool isLike;
|
|
// final bool isLimit;
|
|
// final int viewTotal;
|
|
// final int joinTotal;
|
|
//
|
|
// Interest({
|
|
// required this.id,
|
|
// required this.title,
|
|
// required this.intro,
|
|
// required this.image,
|
|
// required this.amount,
|
|
// required this.oldAmount,
|
|
// required this.iosItem,
|
|
// required this.lastCalloutTime,
|
|
// required this.lastJoinTime,
|
|
// required this.isJoin,
|
|
// required this.isLike,
|
|
// required this.isLimit,
|
|
// required this.viewTotal,
|
|
// required this.joinTotal,
|
|
// });
|
|
// factory Interest.fromJson(Map<String, dynamic> json) {
|
|
// return Interest(
|
|
// id: json['id'],
|
|
// title: json['title'],
|
|
// intro: json['intro'],
|
|
// image: json['image'],
|
|
// amount: json['amount'],
|
|
// oldAmount: json['oldAmount'],
|
|
// iosItem: json['iosItem'],
|
|
// lastCalloutTime: DateTime.parse(json['lastCalloutTime']),
|
|
// lastJoinTime: DateTime.parse(json['lastJoinTime']),
|
|
// isJoin: json['isJoin'],
|
|
// isLike: json['isLike'],
|
|
// isLimit: json['isLimit'],
|
|
// viewTotal: json['viewTotal'],
|
|
// joinTotal: json['joinTotal'],
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
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;
|
|
String ios_item;
|
|
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.ios_item,
|
|
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'],
|
|
ios_item: json['ios_item'] ?? '',
|
|
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'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class DataModel {
|
|
int visitCount = 0;
|
|
|
|
List<dynamic> lastVisitUsers = [];
|
|
|
|
int likeMeCount = 0;
|
|
|
|
DataModel(
|
|
{required this.visitCount,
|
|
required this.lastVisitUsers,
|
|
required this.likeMeCount});
|
|
|
|
factory DataModel.fromJson(Map<String, dynamic> json) {
|
|
return DataModel(
|
|
visitCount: json['visit_count'],
|
|
lastVisitUsers: json['last_visit_users'],
|
|
likeMeCount: json['like_me_count'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class Province {
|
|
String name;
|
|
List<CityBean> city;
|
|
|
|
Province({required this.name, required this.city});
|
|
|
|
factory Province.fromJson(Map<String, dynamic> json) {
|
|
List<dynamic> cityData = json['city'];
|
|
List<CityBean> cityList =
|
|
cityData.map((dynamic item) => CityBean.fromJson(item)).toList();
|
|
|
|
return Province(
|
|
name: json['name'],
|
|
city: cityList,
|
|
);
|
|
}
|
|
|
|
@override
|
|
String getPickerViewText() {
|
|
return this.name;
|
|
}
|
|
}
|
|
|
|
class CityBean {
|
|
String name;
|
|
List<String> area;
|
|
|
|
CityBean({required this.name, required this.area});
|
|
|
|
factory CityBean.fromJson(Map<String, dynamic> json) {
|
|
List<dynamic> areaData = json['area'];
|
|
List<String> areaList =
|
|
areaData.map((dynamic item) => item.toString()).toList();
|
|
|
|
return CityBean(
|
|
name: json['name'],
|
|
area: areaList,
|
|
);
|
|
}
|
|
}
|
|
|
|
class BannerItem {
|
|
final String name;
|
|
final int type;
|
|
final String? param;
|
|
final String scene;
|
|
final String picUrl;
|
|
|
|
BannerItem({
|
|
required this.name,
|
|
required this.type,
|
|
this.param,
|
|
required this.scene,
|
|
required this.picUrl,
|
|
});
|
|
|
|
factory BannerItem.fromJson(Map<String, dynamic> json) {
|
|
return BannerItem(
|
|
name: json['name'],
|
|
type: json['type'],
|
|
param: json['param'],
|
|
scene: json['scene'],
|
|
picUrl: json['pic_url'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class BannerList {
|
|
final String city;
|
|
final List<BannerItem> banners;
|
|
|
|
BannerList({required this.banners, required this.city});
|
|
|
|
factory BannerList.fromJson(Map<String, dynamic> json) {
|
|
final bannerList = json['banners'] as List<dynamic>;
|
|
final banners =
|
|
bannerList.map((item) => BannerItem.fromJson(item)).toList();
|
|
|
|
return BannerList(banners: banners, city: json['city']);
|
|
}
|
|
}
|