|
|
|
@ -1,10 +1,10 @@ |
|
|
|
import 'dart:io'; |
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
|
|
import 'package:image_picker/image_picker.dart'; |
|
|
|
import 'package:dating_touchme_app/network/user_api.dart'; |
|
|
|
import 'package:dating_touchme_app/pages/main_page.dart'; |
|
|
|
|
|
|
|
class UserInfoController extends GetxController { |
|
|
|
// 用户信息表单字段 |
|
|
|
@ -20,6 +20,9 @@ class UserInfoController extends GetxController { |
|
|
|
|
|
|
|
// GetStorage实例,用于存储用户信息 |
|
|
|
final storage = GetStorage(); |
|
|
|
|
|
|
|
// UserApi实例 |
|
|
|
late UserApi _userApi; |
|
|
|
|
|
|
|
// 选择性别 |
|
|
|
void selectGender(String selectedGender) { |
|
|
|
@ -93,6 +96,13 @@ class UserInfoController extends GetxController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
// 从全局依赖中获取UserApi |
|
|
|
_userApi = Get.find<UserApi>(); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理选中的图片 |
|
|
|
Future<void> processSelectedImage(File imageFile) async { |
|
|
|
try { |
|
|
|
@ -150,13 +160,30 @@ class UserInfoController extends GetxController { |
|
|
|
|
|
|
|
// 构建提交参数 |
|
|
|
Map<String, dynamic> _buildSubmitParams() { |
|
|
|
// 从birthday字符串中提取年份 |
|
|
|
int birthYear = 0; |
|
|
|
if (birthday.value.isNotEmpty) { |
|
|
|
// 假设birthday格式为YYYY-MM-DD |
|
|
|
final parts = birthday.value.split('-'); |
|
|
|
if (parts.isNotEmpty) { |
|
|
|
birthYear = int.tryParse(parts[0]) ?? 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 学历代码映射 |
|
|
|
Map<String, String> educationCodeMap = { |
|
|
|
'大专以下': '0', |
|
|
|
'大专': '1', |
|
|
|
'本科': '2', |
|
|
|
'硕士及以上': '3' |
|
|
|
}; |
|
|
|
|
|
|
|
return { |
|
|
|
'gender': gender.value == 'male' ? 1 : 2, // 1:男, 2:女 |
|
|
|
'nickname': nickname.value, |
|
|
|
'birthday': birthday.value, |
|
|
|
'education': education.value, |
|
|
|
if (invitationCode.value.isNotEmpty) 'invitationCode': invitationCode.value, |
|
|
|
if (avatarUrl.value.isNotEmpty) 'avatarUrl': avatarUrl.value, |
|
|
|
'birthYear': birthYear, |
|
|
|
'educationCode': educationCodeMap[education.value] ?? '0', |
|
|
|
'genderCode': gender.value == 'male' ? '0' : '1', // 1:男, 2:女 |
|
|
|
'matchmakerInvitationCode': invitationCode.value, |
|
|
|
'nickName': nickname.value, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
@ -172,23 +199,15 @@ class UserInfoController extends GetxController { |
|
|
|
try { |
|
|
|
// 构建请求参数 |
|
|
|
final params = _buildSubmitParams(); |
|
|
|
|
|
|
|
// 调用UserApi中的完善用户信息接口 |
|
|
|
// 注意:这里需要在UserApi中添加updateUserInfo方法 |
|
|
|
// 由于目前没有看到完整的API定义,这里先模拟成功 |
|
|
|
// 实际项目中应该调用真实的API |
|
|
|
|
|
|
|
// 模拟网络延迟 |
|
|
|
await Future.delayed(const Duration(seconds: 1)); |
|
|
|
|
|
|
|
// 打印提交的信息 |
|
|
|
print('提交用户信息参数: $params'); |
|
|
|
|
|
|
|
// 模拟成功响应 |
|
|
|
// final response = await _userApi.updateUserInfo(params); |
|
|
|
// 调用注册婚姻信息接口 |
|
|
|
final response = await _userApi.registerMarriageInformation(params); |
|
|
|
|
|
|
|
// 处理响应 |
|
|
|
// if (response.data.isSuccess) { |
|
|
|
if (response.data.isSuccess) { |
|
|
|
// 更新本地存储的用户信息 |
|
|
|
final currentUserInfo = storage.read('userInfo') ?? {}; |
|
|
|
if (currentUserInfo is Map<String, dynamic>) { |
|
|
|
@ -203,14 +222,15 @@ class UserInfoController extends GetxController { |
|
|
|
|
|
|
|
// 显示成功提示 |
|
|
|
SmartDialog.showToast('信息提交成功!'); |
|
|
|
// 延迟后跳转 |
|
|
|
Future.delayed(const Duration(milliseconds: 1500), () { |
|
|
|
// 跳转到主页面(暂时注释,实际使用时需要导入并替换正确的路由) |
|
|
|
// Get.offAllNamed('/main'); |
|
|
|
}); |
|
|
|
// } else { |
|
|
|
// Get.snackbar('错误', response.data.message); |
|
|
|
// } |
|
|
|
|
|
|
|
// 延迟后跳转 |
|
|
|
Future.delayed(const Duration(milliseconds: 1500), () { |
|
|
|
// 跳转到主页面(根据登录流程,应该跳转到MainPage) |
|
|
|
Get.offAll(() => MainPage()); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
SmartDialog.showToast(response.data.message); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
print('提交用户信息失败: $e'); |
|
|
|
// 显示错误提示 |
|
|
|
|