rewards_confirm_vm.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import 'package:cpt_rewards/modules/rewards_confirm/dialog/account_deactivation_dialog.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:plugin_platform/engine/dialog/dialog_engine.dart';
  4. import 'package:plugin_platform/http/http_result.dart';
  5. import 'package:riverpod_annotation/riverpod_annotation.dart';
  6. import 'package:shared/utils/log_utils.dart';
  7. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  8. import 'package:widgets/picker/option_pick_util.dart';
  9. import './rewards_confirm_state.dart';
  10. import './rewards_confirm_repository.dart';
  11. part 'rewards_confirm_vm.g.dart';
  12. @riverpod
  13. class RewardsConfirmVm extends _$RewardsConfirmVm {
  14. late RewardsConfirmRepository rewardsConfirmRepository;
  15. RewardsConfirmState initState() {
  16. return RewardsConfirmState(
  17. curPage: 1,
  18. pageSize: 10,
  19. list: [
  20. {
  21. "id": 1,
  22. "title":
  23. "The community will hold the activity of making Zongzi on the Loong Boat ……",
  24. "price": "Monday 14 0ct 2024, 15:00 PM~18:00PM",
  25. },
  26. {
  27. "id": 2,
  28. "title": "Community basketball competition activities",
  29. "price": "Monday 14 Oct 2024, 10:19 AM",
  30. },
  31. ],
  32. filterCount: 2,
  33. );
  34. }
  35. @override
  36. RewardsConfirmState build() {
  37. // 引入数据仓库
  38. rewardsConfirmRepository = ref.read(rewardsConfirmRepositoryProvider);
  39. // 初始化状态
  40. RewardsConfirmState state = initState();
  41. // 初始化列表数据
  42. return state;
  43. }
  44. // 初始化页面数据
  45. initPageData() {
  46. Log.d("----property_news_vm-----initPageData");
  47. refreshListData();
  48. }
  49. // 上拉加载
  50. Future onLoadData() async {
  51. Log.d("----property_news_vm-----initListData");
  52. // await Future.delayed(const Duration(seconds: 2));
  53. // if(state.list.length >= state.filterCount){
  54. // return;
  55. // }else {
  56. // int curPage = state.curPage + 1;
  57. // state = state.copyWith(curPage: curPage,);
  58. // getListData();
  59. // }
  60. getListData();
  61. }
  62. // 去新闻详情页
  63. void goNewsConfirm(String item) {
  64. Log.d(item);
  65. // PropertyPage.startInstance(context: context, item: item);
  66. }
  67. // 获取list 列表数据
  68. void getListData<T>() async {
  69. Log.d("加载listData数据---------------start-----");
  70. try {
  71. //请求网络
  72. Map<String, dynamic> params = {
  73. "curPage": state.curPage,
  74. "pageSize": state.pageSize,
  75. };
  76. Log.d("请求参数------$params");
  77. final result =
  78. await rewardsConfirmRepository.fetchPropertyNewsList(params);
  79. Log.d("请求完成结果------${result.data}");
  80. //校验成功失败
  81. if (result.isSuccess) {
  82. // state = state.copyWith(serverTime: result.data);
  83. state = state;
  84. ToastEngine.show("获取数据成功");
  85. } else {
  86. ToastEngine.show(result.errorMsg ?? "Network Load Error");
  87. }
  88. } catch (e) {
  89. ToastEngine.show("Error: $e");
  90. }
  91. }
  92. // 下拉刷新
  93. Future refreshListData() async {
  94. Log.d("----property_news_vm-----refreshListData ");
  95. // await Future.delayed(const Duration(seconds: 2));
  96. state = state.copyWith(curPage: 1, pageSize: 10);
  97. // ref.invalidateSelf();
  98. // ref.invalidate(propertyNewsVmProvider);
  99. getListData();
  100. }
  101. void doDeleteAccount() {
  102. DialogEngine.show(widget: AccountDeactivationDialog(
  103. confirmAction: () {
  104. ToastEngine.show("点击了确定");
  105. },
  106. ));
  107. }
  108. }