You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

467 lines
17 KiB

import 'package:cached_network_image/cached_network_image.dart';
import 'package:dating_touchme_app/controller/global.dart';
import 'package:dating_touchme_app/controller/mine/mine_controller.dart';
import 'package:dating_touchme_app/extension/ex_widget.dart';
import 'package:dating_touchme_app/model/mine/user_count_data.dart';
import 'package:dating_touchme_app/network/user_api.dart';
import 'package:dating_touchme_app/pages/mine/auth_center_page.dart';
import 'package:dating_touchme_app/pages/mine/edit_info_page.dart';
import 'package:dating_touchme_app/pages/mine/my_friend_page.dart';
import 'package:dating_touchme_app/pages/mine/my_wallet_page.dart';
import 'package:dating_touchme_app/pages/mine/rose_page.dart';
import 'package:dating_touchme_app/pages/mine/user_help_center_page.dart';
import 'package:dating_touchme_app/pages/mine/vip_page.dart';
import 'package:dating_touchme_app/pages/setting/setting_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:dating_touchme_app/generated/assets.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../discover/visitor_list_page.dart';
class MinePage extends StatefulWidget {
const MinePage({super.key});
@override
State<MinePage> createState() => _MinePageState();
}
class _MinePageState extends State<MinePage> with AutomaticKeepAliveClientMixin{
late MineController controller;
final countData = UserCountData(friendNum: 0, friendApplyNum: 0, visitorNum:0).obs;
late UserApi _userApi;
final infoList = <Map>[
{"label": "好友", "num": 0, "type": 1},
{"label": "好友申请", "num": 0, "type": 2},
{"label": "访客", "num": 0, "type": 3},
].obs;
@override
void initState() {
super.initState();
// 确保 HomeController 已注册
if (!Get.isRegistered<MineController>()) {
controller = Get.put(MineController());
} else {
controller = Get.find<MineController>();
}
_userApi = Get.find<UserApi>();
getUserCount();
}
getUserCount() async {
try {
final response = await _userApi.userGetDongwoOwnUserCount();
if (response.data.isSuccess && response.data.data != null) {
countData.value = response.data.data ?? UserCountData(friendNum: 0, friendApplyNum: 0, visitorNum:0);
infoList.value = [
{"label": "好友", "num": countData.value.friendNum, "type": 1},
{"label": "好友申请", "num": countData.value.friendApplyNum, "type": 2},
{"label": "访客", "num": countData.value.visitorNum, "type": 3},
];
setState(() {
});
} else {
// 响应失败,抛出异常
throw Exception(response.data.message ?? '获取数据失败');
}
} catch(e){
print('用户数据获取失败: $e');
SmartDialog.showToast('用户数据获取失败');
rethrow;
}
}
@override
Widget build(BuildContext context) {
super.build(context);
var cellStyle = TDCellStyle.cellStyle(context);
cellStyle.cardPadding = EdgeInsets.symmetric(horizontal: 0);
cellStyle.padding = EdgeInsets.only(left: 16, top: 12, bottom: 12, right: 12);
return GetX<MineController>(
init: MineController(),
builder: (controller) {
controller.userData.value = GlobalData().userData;
controller.userId.value = GlobalData().userId;
return Container(
padding: EdgeInsets.symmetric(horizontal: 9.w),
constraints: BoxConstraints(minHeight: ScreenUtil().setHeight(800)),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(248, 242, 255, 1.0), // rgba(248, 242, 255, 1)
Color.fromRGBO(247, 247, 247, 1.0), // rgba(247, 247, 247, 1)
],
stops: [0.0, 1.0],
),
),
child: Column(
children: [
SizedBox(
height: MediaQuery.of(context).padding.top + 54.w,
),
Container(
width: 356.w,
padding: EdgeInsets.only(
left: 6.w,
right: 5.w
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(60.w)),
child: (controller.userData.value?.profilePhoto?.isNotEmpty ?? false) ? CachedNetworkImage(
imageUrl: "${controller.userData.value?.profilePhoto ?? ""}?x-oss-process=image/format,webp/resize,w_120",
width: 60.w,
height: 60.w,
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
) : Image.asset(
Assets.imagesUserAvatar,
width: 60.w,
height: 60.w,
)
),
SizedBox(width: 14.w,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 120.w, // 最大宽度
),
child: Text(
"${controller.userData.value?.nickName ?? ""}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 18.w,
color: const Color.fromRGBO(51, 51, 51, 1),
fontWeight: FontWeight.w700
),
),
),
SizedBox(width: 8.w,),
// Image.asset(
// Assets.imagesVip,
// width: 44.w,
// height: 16.w,
// )
Container(
width: 32.w,
height: 16.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16.w)),
color: const Color.fromRGBO(201, 201, 201, 1)
),
child: Center(
child: Image.asset(
Assets.imagesVipFont,
width: 20.w,
height: 8.w,
),
),
)
],
),
Text(
"ID:${controller.userId.value ?? ""}",
style: TextStyle(
fontSize: 10.w,
color: const Color.fromRGBO(51, 51, 51, 1),
fontWeight: FontWeight.w500
),
)
],
)
],
),
InkWell(
onTap: (){
Get.to(() => EditInfoPage());
},
child: Row(
children: [
Image.asset(
Assets.imagesEdit,
width: 10.w,
height: 10.w,
),
SizedBox(width: 4.w,),
Text(
"编辑资料",
style: TextStyle(
fontSize: 12.w,
color: const Color.fromRGBO(55, 57, 72, 1),
fontWeight: FontWeight.w500
),
)
],
),
)
],
),
),
SizedBox(height: 16.w,),
Container(
// height: 57.w,
padding: EdgeInsets.only(
top: 11.w,
right: 42.w,
bottom: 8.w,
left: 42.w
),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(9.w)),
color: Colors.white,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
...infoList.map((e){
return InfoItem(item: e, getUserCount: getUserCount,);
}),
],
),
),
SizedBox(height: 12.w,),
Stack(
children: [
Image.asset(
Assets.imagesVipBanner,
width: 356.w,
height: 64.w,
),
Positioned(
top: 0.w,
left: 0.w,
child: InkWell(
child: SizedBox(
width: 356.w,
height: 64.w,
).onTap((){
Get.to(() => VipPage());
}),
),
)
],
),
SizedBox(height: 12.w,),
TDCellGroup(
theme: TDCellGroupTheme.cardTheme,
style: cellStyle,
cells: [
TDCell(arrow: true,
leftIconWidget: Image.asset(Assets.imagesRose, height: 22.w, width: 22.w),
titleWidget: Text(
"我的玫瑰",
style: TextStyle(
fontSize: 14.w
),
), onClick: (cell) {
Get.to(() => RosePage());
}
),
TDCell(arrow: true,
leftIconWidget: Image.asset(Assets.imagesWallet, height: 22.w, width: 22.w),
titleWidget: Text(
"我的钱包",
style: TextStyle(
fontSize: 14.w
),
), onClick: (cell) {
Get.to(() => MyWalletPage());
}
),
TDCell(arrow: true,
leftIconWidget: Image.asset(Assets.imagesCert, height: 22.w, width: 22.w),
titleWidget: Text(
"认证中心",
style: TextStyle(
fontSize: 14.w
),
),
noteWidget: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if(GlobalData().userData?.identityCard == null || GlobalData().userData?.profilePhoto == null) TDBadge(TDBadgeType.redPoint),
SizedBox(width: 5.w, height: 9.w),
Text(
GlobalData().userData?.identityCard == null || GlobalData().userData?.profilePhoto == null ? "未认证" : "已认证",
style: TextStyle(fontSize: 12.w, color: const Color.fromRGBO(166, 166, 166, 1)),
)
],
),
onClick: (cell) {
Get.to(() => AuthCenterPage());
}
),
TDCell(arrow: true,
leftIconWidget: Image.asset(Assets.imagesMatchmaker, height: 22.w, width: 22.w),
titleWidget: Text(
"红娘等级",
style: TextStyle(
fontSize: 14.w
),
), onClick: (cell) {
controller.registerMatch();
}
),
],
),
SizedBox(height: 12.w,),
TDCellGroup(
theme: TDCellGroupTheme.cardTheme,
style: cellStyle,
cells: [
TDCell(arrow: true,
leftIconWidget: Image.asset(Assets.imagesSetting, height: 22.w, width: 22.w),
titleWidget: Text(
"设置",
style: TextStyle(
fontSize: 14.w
),
), onClick: (cell) {
Get.to(() => SettingPage());
}
),
TDCell(arrow: true,
leftIconWidget: Image.asset(Assets.imagesCustomer, height: 22.w, width: 22.w),
titleWidget: Text(
"联系客服",
style: TextStyle(
fontSize: 14.w
),
), onClick: (cell) {
SmartDialog.showToast('功能暂未开放');
}
),
TDCell(arrow: true,
leftIconWidget: Image.asset(Assets.imagesMail, height: 22.w, width: 22.w),
titleWidget: Text(
"意见反馈",
style: TextStyle(
fontSize: 14.w
),
), onClick: (cell) {
Get.to(() => UserHelpCenterPage());
}
),
],
),
],
),
);
},
);
}
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
}
class InfoItem extends StatefulWidget {
final Map item;
final Function getUserCount;
const InfoItem({super.key, required this.item, required this.getUserCount});
@override
State<InfoItem> createState() => _InfoItemState();
}
class _InfoItemState extends State<InfoItem> {
@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
alignment: widget.item["type"] == 1 ? Alignment.centerLeft : widget.item["type"] == 2 ? Alignment.center : Alignment.centerRight,
child: Column(
children: [
Stack(
clipBehavior: Clip.none,
children: [
Text(
"${widget.item["num"]}",
style: TextStyle(
fontSize: 18.w,
color: Colors.black,
fontWeight: FontWeight.w700
),
),
if(widget.item["type"] == 2 && widget.item["num"] != 0)Positioned(
right: -5.w,
top: 0,
child: Container(
width: 5.w,
height: 5.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.w)),
color: const Color.fromRGBO(255, 87, 51, 1)
),
),
)
],
),
Text(
widget.item["label"],
style: TextStyle(
fontSize: 10.w,
color: const Color.fromRGBO(166, 166, 166, 1),
),
)
],
)
).onTap((){
if(widget.item['type'] == 3){
Get.to(()=> VisitorListPage())?.then((w) async {
await widget.getUserCount();
setState(() {
});
});
} else {
Get.to(()=> MyFriendPage(index: widget.item['type'] - 1,))?.then((w) async {
await widget.getUserCount();
setState(() {
});
});
}
})
);
}
}