diff --git a/lib/controller/setting/task_controller.dart b/lib/controller/setting/task_controller.dart index 0461c49..9edb9bf 100644 --- a/lib/controller/setting/task_controller.dart +++ b/lib/controller/setting/task_controller.dart @@ -1,4 +1,6 @@ +import 'package:dating_touchme_app/model/live/matchmaker_task.dart'; import 'package:dating_touchme_app/model/mine/matchmaker_requirement_data.dart'; +import 'package:dating_touchme_app/network/home_api.dart'; import 'package:dating_touchme_app/network/user_api.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; @@ -6,23 +8,34 @@ import 'package:get/get.dart'; class TaskController extends GetxController { // UserApi实例 - late UserApi _userApi; - final roseList = [].obs; + late HomeApi _homeApi; + final dayTask = MatchmakerTask().obs; + final weekTask = MatchmakerTask().obs; + final monthTask = MatchmakerTask().obs; final loading = true.obs; @override void onInit() { super.onInit(); - _userApi = Get.find(); + _homeApi = Get.find(); initDataList(); } initDataList() async { try{ loading.value = true; - final result = await _userApi.getMatchmakerRequirement(); + final result = await _homeApi.getMatchmakerTask(taskType: 1); if (result.data.isSuccess && result.data.data != null) { - roseList.value = result.data.data!; + dayTask.value = result.data.data!; + } + final result2 = await _homeApi.getMatchmakerTask(taskType: 2); + if (result2.data.isSuccess && result2.data.data != null) { + weekTask.value = result2.data.data!; + } + // Get.log(weekTask.value.toString()); + final result3 = await _homeApi.getMatchmakerTask(taskType: 3); + if (result3.data.isSuccess && result3.data.data != null) { + monthTask.value = result3.data.data!; } } finally { loading.value = false; diff --git a/lib/model/live/matchmaker_task.dart b/lib/model/live/matchmaker_task.dart new file mode 100644 index 0000000..0bfaca5 --- /dev/null +++ b/lib/model/live/matchmaker_task.dart @@ -0,0 +1,115 @@ +class SubListItem { + final String? subTaskName; + final int? subTaskType; + final String? subTaskDesc; + final int? requiredCount; + final int? completeCount; + final bool? completeStatus; + final String? completeTime; + final int? sort; + + SubListItem({ + this.subTaskName, + this.subTaskType, + this.subTaskDesc, + this.requiredCount, + this.completeCount, + this.completeStatus, + this.completeTime, + this.sort, + }); + + factory SubListItem.fromJson(Map json) { + return SubListItem( + subTaskName: json['subTaskName'] as String?, + subTaskType: json['subTaskType'] as int?, + subTaskDesc: json['subTaskDesc'] as String?, + requiredCount: json['requiredCount'] as int?, + completeCount: json['completeCount'] as int?, + completeStatus: json['completeStatus'] as bool?, + completeTime: json['completeTime'] as String?, + sort: json['sort'] as int?, + ); + } + + Map toJson() { + return { + 'subTaskName': subTaskName, + 'subTaskType': subTaskType, + 'subTaskDesc': subTaskDesc, + 'requiredCount': requiredCount, + 'completeCount': completeCount, + 'completeStatus': completeStatus, + 'completeTime': completeTime, + 'sort': sort, + }; + } +} + +class MatchmakerTask { + final String? userTaskCompleteId; + final int? taskGroup; + final int? taskType; + final int? stageCode; + final String? taskName; + final String? taskDesc; + final String? taskStartDate; + final String? taskEndDate; + final String? rewardValue; + final bool? completeStatus; + final int? rewardReceiveStatus; + final String? completeTime; + final List? subList; + + MatchmakerTask({ + this.userTaskCompleteId, + this.taskGroup, + this.taskType, + this.stageCode, + this.taskName, + this.taskDesc, + this.taskStartDate, + this.taskEndDate, + this.rewardValue, + this.completeStatus, + this.rewardReceiveStatus, + this.completeTime, + this.subList, + }); + + factory MatchmakerTask.fromJson(Map json) { + return MatchmakerTask( + userTaskCompleteId: json['userTaskCompleteId'] as String?, + taskGroup: json['taskGroup'] as int?, + taskType: json['taskType'] as int?, + stageCode: json['stageCode'] as int?, + taskName: json['taskName'] as String?, + taskDesc: json['taskDesc'] as String?, + taskStartDate: json['taskStartDate'] as String?, + taskEndDate: json['taskEndDate'] as String?, + rewardValue: json['rewardValue'] as String?, + completeStatus: json['completeStatus'] as bool?, + rewardReceiveStatus: json['rewardReceiveStatus'] as int?, + completeTime: json['completeTime'] as String?, + subList: (json['subList'] as List?)?.map((e) => SubListItem.fromJson(e as Map)).toList() ?? [], + ); + } + + Map toJson() { + return { + 'userTaskCompleteId': userTaskCompleteId, + 'taskGroup': taskGroup, + 'taskType': taskType, + 'stageCode': stageCode, + 'taskName': taskName, + 'taskDesc': taskDesc, + 'taskStartDate': taskStartDate, + 'taskEndDate': taskEndDate, + 'rewardValue': rewardValue, + 'completeStatus': completeStatus, + 'rewardReceiveStatus': rewardReceiveStatus, + 'completeTime': completeTime, + 'subList': subList?.map((e) => e.toJson()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/network/api_urls.dart b/lib/network/api_urls.dart index f0e9398..0178e7f 100644 --- a/lib/network/api_urls.dart +++ b/lib/network/api_urls.dart @@ -163,4 +163,7 @@ class ApiUrls { static const String userPageMicJoinRtcChannelUser = 'dating-agency-chat-audio/user/page/mic-join/rtc-channel-user'; + + static const String listMatchmakerTask = + 'dating-agency-mall/user/get/user-task-complete'; } diff --git a/lib/network/home_api.dart b/lib/network/home_api.dart index 1663b10..782f9b1 100644 --- a/lib/network/home_api.dart +++ b/lib/network/home_api.dart @@ -1,3 +1,4 @@ +import 'package:dating_touchme_app/model/live/matchmaker_task.dart'; import 'package:dating_touchme_app/network/api_urls.dart'; import 'package:dating_touchme_app/network/response_model.dart'; import 'package:retrofit/retrofit.dart'; @@ -20,4 +21,11 @@ abstract class HomeApi { @Query('pageSize') required int pageSize, @Query('type') required int type, }); + + @GET(ApiUrls.listMatchmakerTask) + Future>> getMatchmakerTask({ + @Query('taskType') required int taskType, + }); + + } \ No newline at end of file diff --git a/lib/network/home_api.g.dart b/lib/network/home_api.g.dart index 84908ed..29b6943 100644 --- a/lib/network/home_api.g.dart +++ b/lib/network/home_api.g.dart @@ -65,6 +65,39 @@ class _HomeApi implements HomeApi { return httpResponse; } + @override + Future>> getMatchmakerTask({ + required int taskType, + }) async { + final _extra = {}; + final queryParameters = {r'taskType': taskType}; + final _headers = {}; + const Map? _data = null; + final _options = _setStreamType>>( + Options(method: 'GET', headers: _headers, extra: _extra) + .compose( + _dio.options, + 'dating-agency-mall/user/get/user-task-complete', + 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) => MatchmakerTask.fromJson(json as Map), + ); + } 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/setting/match_task_page.dart b/lib/pages/setting/match_task_page.dart index d2fbb45..dee886f 100644 --- a/lib/pages/setting/match_task_page.dart +++ b/lib/pages/setting/match_task_page.dart @@ -1,7 +1,6 @@ import 'package:dating_touchme_app/components/page_appbar.dart'; -import 'package:dating_touchme_app/controller/global.dart'; import 'package:dating_touchme_app/controller/setting/task_controller.dart'; -import 'package:dating_touchme_app/model/mine/matchmaker_requirement_data.dart'; +import 'package:dating_touchme_app/model/live/matchmaker_task.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; @@ -34,7 +33,7 @@ class MatchTaskPage extends StatelessWidget { children: [ Row( children: [ - TDText('日任务', style: TextStyle(color: Color(0xFF333333), fontWeight: FontWeight.bold, fontSize: 16.w)), + TDText(controller.dayTask.value.taskName, style: TextStyle(color: Color(0xFF333333), fontWeight: FontWeight.bold, fontSize: 16.w)), SizedBox(width: 4.w), Container( width: 4, @@ -45,17 +44,17 @@ class MatchTaskPage extends StatelessWidget { ), ), SizedBox(width: 4.w), - TDText('任务时间:截止 23:25', style: TextStyle(color: Color(0xFF666666), fontSize: 16.w)), + TDText('任务截止时间:${controller.dayTask.value.taskEndDate}', style: TextStyle(color: Color(0xFF666666), fontSize: 16.w)), ], ), SizedBox(height: 12.w,), - ...controller.roseList.asMap().entries.map((entry){ + ...controller.dayTask.value.subList!.asMap().entries.map((entry){ return TaskItem(item: entry.value); }), - SizedBox(height: 24.w,), - Row( + if(controller.weekTask.value.taskName != null && controller.weekTask.value.taskName!.isNotEmpty) SizedBox(height: 24.w,), + if(controller.weekTask.value.taskName != null && controller.weekTask.value.taskName!.isNotEmpty) Row( children: [ - TDText('月任务', style: TextStyle(color: Color(0xFF333333), fontWeight: FontWeight.bold, fontSize: 16.w)), + TDText(controller.weekTask.value.taskName, style: TextStyle(color: Color(0xFF333333), fontWeight: FontWeight.bold, fontSize: 16.w)), SizedBox(width: 4.w), Container( width: 4, @@ -66,11 +65,32 @@ class MatchTaskPage extends StatelessWidget { ), ), SizedBox(width: 4.w), - TDText('任务时间:截止 03/15 23:59', style: TextStyle(color: Color(0xFF666666), fontSize: 16.w)), + TDText('任务截止时间:${controller.weekTask.value.taskEndDate}', style: TextStyle(color: Color(0xFF666666), fontSize: 16.w)), ], ), - SizedBox(height: 12.w,), - ...controller.roseList.asMap().entries.map((entry){ + if(controller.weekTask.value.taskName != null && controller.weekTask.value.taskName!.isNotEmpty)SizedBox(height: 12.w,), + if(controller.weekTask.value.taskName != null && controller.weekTask.value.taskName!.isNotEmpty)...controller.weekTask.value.subList!.asMap().entries.map((entry){ + return TaskItem(item: entry.value); + }), + if(controller.monthTask.value.taskName != null && controller.monthTask.value.taskName!.isNotEmpty) SizedBox(height: 24.w,), + if(controller.monthTask.value.taskName != null && controller.monthTask.value.taskName!.isNotEmpty) Row( + children: [ + TDText(controller.monthTask.value.taskName, style: TextStyle(color: Color(0xFF333333), fontWeight: FontWeight.bold, fontSize: 16.w)), + SizedBox(width: 4.w), + Container( + width: 4, + height: 4, + decoration: BoxDecoration( + color: Color(0xFF999999), // 圆点颜色 + shape: BoxShape.circle, // 圆形 + ), + ), + SizedBox(width: 4.w), + TDText('任务截止时间:${controller.monthTask.value.taskEndDate}', style: TextStyle(color: Color(0xFF666666), fontSize: 16.w)), + ], + ), + if(controller.monthTask.value.taskName != null && controller.monthTask.value.taskName!.isNotEmpty)SizedBox(height: 12.w,), + if(controller.monthTask.value.taskName != null && controller.monthTask.value.taskName!.isNotEmpty)...controller.monthTask.value.subList!.asMap().entries.map((entry){ return TaskItem(item: entry.value); }), SizedBox(height: 12.w,), @@ -105,7 +125,7 @@ class MatchTaskPage extends StatelessWidget { } class TaskItem extends StatelessWidget { - final MatchmakerRequirement item; + final SubListItem item; const TaskItem({super.key, required this.item }); @override @@ -115,19 +135,45 @@ class TaskItem extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - TDText(item.liveConsumptionAmount! > 0 ? '累计消费' : '累计连麦相亲', style: TextStyle(color: Color(0xFF333333), fontSize: 16.w)), + TDText(item.subTaskName, style: TextStyle(color: Color(0xFF333333), fontSize: 16.w)), SizedBox(height: 4.w), TDProgress( type: TDProgressType.linear, - value: 0.5, + value: _getTaskProgress(item), strokeWidth: 6, progressLabelPosition: TDProgressLabelPosition.right, color: Color(0xFF7562F9), ), SizedBox(height: 2.w), - TDText('目前有效金额:22.66元', style: TextStyle(color: Color(0xFF999999), fontSize: 12.w)), + TDText(_getTaskLabel(item), style: TextStyle(color: Color(0xFF999999), fontSize: 12.w)), ], ), ); } + + double _getTaskProgress(SubListItem item) { + if(item.completeCount! <= 0){ + return 0; + } + if(item.requiredCount! <= 0){ + return 0; + } + double progress = item.completeCount! / item.requiredCount!; + return double.parse(progress.toStringAsFixed(3)); + } + + // 子任务类型。1:每日有效直播时长,2:有效相亲次数,3:直播间打卡人数 + String _getTaskLabel(SubListItem item) { + if(item.subTaskType == 1){ + return '目前直播时长:${item.completeCount}分钟'; + } + if(item.subTaskType == 2){ + return '目前相亲次数:${item.completeCount}次'; + } + if(item.subTaskType == 3){ + return '目前打卡人数:${item.completeCount}人'; + } + return ''; + } + }