123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import 'package:plugin_platform/http/http_result.dart';
- import 'package:riverpod_annotation/riverpod_annotation.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:plugin_platform/engine/toast/toast_engine.dart';
- import './services_contact_state.dart';
- import './services_contact_repository.dart';
- part 'services_contact_vm.g.dart';
- @riverpod
- class ServicesContactVm extends _$ServicesContactVm {
- late ServicesContactRepository servicesContactRepository;
- ServicesContactState initState() {
- return ServicesContactState(
- curPage: 1,
- pageSize: 10,
- list: [
- {
- "id": 1,
- "title":
- "The community will hold the activity of making Zongzi on the Loong Boat ……",
- "price": "Monday 14 0ct 2024, 15:00 PM~18:00PM",
- },
- {
- "id": 2,
- "title": "Community basketball competition activities",
- "price": "Monday 14 Oct 2024, 10:19 AM",
- },
- ],
- filterCount: 2,
- );
- }
- @override
- ServicesContactState build() {
-
- servicesContactRepository = ref.read(servicesContactRepositoryProvider);
-
- ServicesContactState state = initState();
-
- return state;
- }
-
- initPageData() {
- Log.d("----property_news_vm-----initPageData");
- refreshListData();
- }
-
- Future onLoadData() async {
- Log.d("----property_news_vm-----initListData");
-
-
-
-
-
-
-
-
- getListData();
- }
- void goNewsDetail(String item) {
- Log.d(item);
-
- }
-
- void getListData<T>() async {
- Log.d("加载listData数据---------------start-----");
- try {
-
- Map<String, dynamic> params = {
- "curPage": state.curPage,
- "pageSize": state.pageSize,
- };
- Log.d("请求参数------$params");
- final result =
- await servicesContactRepository.fetchPropertyNewsList(params);
- Log.d("请求完成结果------${result.data}");
-
- if (result.isSuccess) {
-
- state = state;
- ToastEngine.show("获取数据成功");
- } else {
- ToastEngine.show(result.errorMsg ?? "Network Load Error");
- }
- } catch (e) {
- ToastEngine.show("Error: $e");
- }
- }
-
- Future refreshListData() async {
- Log.d("----property_news_vm-----refreshListData ");
-
- state = state.copyWith(curPage: 1, pageSize: 10);
-
-
- getListData();
- }
- }
|