diff --git a/lib/network/api_urls.dart b/lib/network/api_urls.dart index 6c0efd8..d9c6515 100644 --- a/lib/network/api_urls.dart +++ b/lib/network/api_urls.dart @@ -8,6 +8,7 @@ class ApiUrls { // 用户相关接口 static const String getBaseUserInfo = 'dating-agency-uec/user/get/base-info'; static const String getMarriageInformationDetail = 'dating-agency-service/user/get/dongwo/marriage-information-detail'; + static const String registerMarriageInformation = 'dating-agency-service/user/register/marriage-information'; // 后续可以在此添加更多API端点 } \ No newline at end of file diff --git a/lib/network/user_api.dart b/lib/network/user_api.dart index 04a78af..889b163 100644 --- a/lib/network/user_api.dart +++ b/lib/network/user_api.dart @@ -29,4 +29,9 @@ abstract class UserApi { Future>> getVerificationCode( @Body() Map data, ); + + @POST(ApiUrls.registerMarriageInformation) + Future>> registerMarriageInformation( + @Body() Map data, + ); } \ No newline at end of file diff --git a/lib/network/user_api.g.dart b/lib/network/user_api.g.dart index eb29b46..3232954 100644 --- a/lib/network/user_api.g.dart +++ b/lib/network/user_api.g.dart @@ -152,6 +152,40 @@ class _UserApi implements UserApi { return httpResponse; } + @override + Future>> registerMarriageInformation( + Map data, + ) async { + final _extra = {}; + final queryParameters = {}; + final _headers = {}; + final _data = {}; + _data.addAll(data); + final _options = _setStreamType>>( + Options(method: 'POST', headers: _headers, extra: _extra) + .compose( + _dio.options, + 'dating-agency-service/user/register/marriage-information', + queryParameters: queryParameters, + data: _data, + ) + .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)), + ); + final _result = await _dio.fetch>(_options); + late BaseResponse _value; + try { + _value = BaseResponse.fromJson( + _result.data!, + (json) => json as dynamic, + ); + } on Object catch (e, s) { + errorLogger?.logError(e, s, _options); + rethrow; + } + final httpResponse = HttpResponse(_value, _result); + return httpResponse; + } + RequestOptions _setStreamType(RequestOptions requestOptions) { if (T != dynamic && !(requestOptions.responseType == ResponseType.bytes || diff --git a/lib/pages/mine/user_info_controller.dart b/lib/pages/mine/user_info_controller.dart index f8ccfbd..97d415f 100644 --- a/lib/pages/mine/user_info_controller.dart +++ b/lib/pages/mine/user_info_controller.dart @@ -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(); + } + // 处理选中的图片 Future processSelectedImage(File imageFile) async { try { @@ -150,13 +160,30 @@ class UserInfoController extends GetxController { // 构建提交参数 Map _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 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) { @@ -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'); // 显示错误提示