123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- import 'package:cpt_services/modules/services/dialog/account_deactivation_dialog.dart';
- import 'package:cs_resources/generated/assets.dart';
- import 'package:plugin_platform/engine/dialog/dialog_engine.dart';
- 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_state.dart';
- import 'services_repository.dart';
- part 'services_view_model.g.dart';
- @riverpod
- class ServicesVm extends _$ServicesVm {
- late ServicesRepository servicesRepository;
- ServicesState initState() {
- return ServicesState(
- curPage: 1,
- pageSize: 10,
- list: [
- {
- "id": 1,
- "title": "Part-TimeCleaning",
- "price": Assets.serviceServiceIcon1,
- },
- {
- "id": 2,
- "title": "Move in/outcleaning",
- "price": Assets.serviceServiceIcon2,
- },
- {
- "id": 3,
- "title": "Laundry AnddryCleaning",
- "price": Assets.serviceServiceIcon3,
- },
- {
- "id": 4,
- "title": "SofaCleaning",
- "price": Assets.serviceServiceIcon4,
- },
- {
- "id": 5,
- "title": "MattressCleaning",
- "price": Assets.serviceServiceIcon5,
- },
- {
- "id": 5,
- "title": "MarbleCleaning",
- "price": Assets.serviceServiceIcon6,
- },
- {
- "id": 6,
- "title": "ParquetCleaning",
- "price": Assets.serviceServiceIcon7,
- },
- {
- "id": 6,
- "title": "Removalist",
- "price": Assets.serviceServiceIcon8,
- },
- {
- "id": 7,
- "title": "CarpetCleaning",
- "price": Assets.serviceServiceIcon9,
- },
- {
- "id": 7,
- "title": "InteriorDesign",
- "price": Assets.serviceServiceIcon10,
- },
- {
- "id": 7,
- "title": "DomesticHelper agency",
- "price": Assets.serviceServiceIcon11,
- },
- {
- "id": 7,
- "title": "Recycling AndDisposal Service",
- "price": Assets.serviceServiceIcon12,
- },
- {
- "id": 7,
- "title": "Sell YourPre-Loved Items",
- "price": Assets.serviceServiceIcon13,
- },
- {
- "id": 7,
- "title": "UpholsteryCleaning",
- "price": Assets.serviceServiceIcon14,
- },
- ],
- filterCount: 6,
- );
- }
- @override
- ServicesState build() {
- // 引入数据仓库
- servicesRepository = ref.read(servicesRepositoryProvider);
- // 初始化状态
- ServicesState state = initState();
- // 初始化列表数据
- return state;
- }
- // 初始化页面数据
- initPageData() {
- Log.d("----property_news_vm-----initPageData");
- refreshListData();
- }
- // 上拉加载
- Future onLoadData() async {
- Log.d("----property_news_vm-----initListData");
- // await Future.delayed(const Duration(seconds: 2));
- // if(state.list.length >= state.filterCount){
- // return;
- // }else {
- // int curPage = state.curPage + 1;
- // state = state.copyWith(curPage: curPage,);
- // getListData();
- // }
- getListData();
- }
- // 去新闻详情页
- void goNewsDetail(String item) {
- Log.d(item);
- // PropertyPage.startInstance(context: context, item: item);
- }
- // 获取list 列表数据
- 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 servicesRepository.fetchPropertyNewsList(params);
- Log.d("请求完成结果------${result.data}");
- //校验成功失败
- if (result.isSuccess) {
- // state = state.copyWith(serverTime: result.data);
- 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 ");
- // await Future.delayed(const Duration(seconds: 2));
- state = state.copyWith(curPage: 1, pageSize: 10);
- // ref.invalidateSelf();
- // ref.invalidate(propertyNewsVmProvider);
- getListData();
- }
- void doDeleteAccount() {
- DialogEngine.show(widget: AccountDeactivationDialog(
- confirmAction: () {
- ToastEngine.show("点击了确定");
- },
- ));
- }
- }
|