|
@@ -1,5 +1,7 @@
|
|
|
import 'package:cpt_community/modules/community/community_vm.dart';
|
|
|
+import 'package:cpt_community/respository/common_garage.dart';
|
|
|
import 'package:cs_resources/generated/assets.dart';
|
|
|
+import 'package:domain/entity/garage_sale_rent_entity.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
@@ -12,16 +14,17 @@ import '../../../router/page/community_page_router.dart';
|
|
|
import '../../community/community_page.dart';
|
|
|
import '../../community/community_pageview_idx_data.dart';
|
|
|
import '../garagesale_detail/garagesale_detail_page.dart';
|
|
|
-import 'for_sale_respository.dart';
|
|
|
import 'for_sale_state.dart';
|
|
|
|
|
|
part 'for_sale_vm.g.dart';
|
|
|
|
|
|
@riverpod
|
|
|
class ForsaleVm extends _$ForsaleVm {
|
|
|
- late ForsaleRepository ForsaleRepositoryInstance;
|
|
|
+ late CommonGarageRepository commonGarageRepositoryInstance;
|
|
|
bool _needShowPlaceholder = false; //是否展示LoadingView
|
|
|
-
|
|
|
+ int _page = 1; // 当前页
|
|
|
+ int _limit = 10; // 每页数量
|
|
|
+ int _count = 0; // 总条数
|
|
|
|
|
|
// Refresh 控制器
|
|
|
final EasyRefreshController refreshController = EasyRefreshController(
|
|
@@ -38,7 +41,7 @@ class ForsaleVm extends _$ForsaleVm {
|
|
|
@override
|
|
|
ForsaleState build(){
|
|
|
// 引入数据仓库
|
|
|
- ForsaleRepositoryInstance = ref.read(newsRepositoryProvider);
|
|
|
+ commonGarageRepositoryInstance = ref.read(commonGarageRepositoryProvider);
|
|
|
final state = initState();
|
|
|
Log.d("--------------------------build---------------------");
|
|
|
|
|
@@ -66,19 +69,18 @@ class ForsaleVm extends _$ForsaleVm {
|
|
|
if(isShowing){
|
|
|
Log.d("----for_sale_vm-----loadMore");
|
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
|
- // if(state.list.length >= state.count){
|
|
|
+ // if(state.list.length >= _count){
|
|
|
// return;
|
|
|
// }else {
|
|
|
- // int page = state.page + 1;
|
|
|
+ // int page = _page + 1;
|
|
|
// state = state.copyWith(page: page,);
|
|
|
// getListData();
|
|
|
// }
|
|
|
// 检查 page 是否为 null,并初始化为 1
|
|
|
- int newCurPage = state.page ?? 1;
|
|
|
- state = state.copyWith(page: ++newCurPage);
|
|
|
+ _page++;
|
|
|
getListData();
|
|
|
}else {
|
|
|
- refreshController.finishRefresh();
|
|
|
+ refreshController.finishLoad();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -90,12 +92,10 @@ class ForsaleVm extends _$ForsaleVm {
|
|
|
// 当前pageView 页面正处于显示状态
|
|
|
Log.d("----forsale_vm-----onRefresh ");
|
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
|
- state = state.copyWith(page: 1);
|
|
|
+ _page = 1;
|
|
|
getListData();
|
|
|
}else {
|
|
|
refreshController.finishRefresh();
|
|
|
- // //更新展示的状态
|
|
|
- changeLoadingState(LoadState.State_Success, null);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -103,25 +103,27 @@ class ForsaleVm extends _$ForsaleVm {
|
|
|
Future retryRequest() async {
|
|
|
bool isShowing = await ref.read(communityVmProvider.notifier).isCurrentPageViewShowing(CommunityPageViewIdxData.forSale);
|
|
|
if(isShowing){
|
|
|
- state = state.copyWith(page: 1);
|
|
|
+ _page = 1;
|
|
|
_needShowPlaceholder = true;
|
|
|
getListData();
|
|
|
+ }else {
|
|
|
+ refreshController.finishRefresh();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// 获取list 列表数据
|
|
|
- Future getListData<T>() async {
|
|
|
+ Future getListData<T>({bool? isLoadMore}) async {
|
|
|
if (_needShowPlaceholder) {
|
|
|
changeLoadingState(LoadState.State_Loading, null);
|
|
|
}
|
|
|
|
|
|
- Log.d("for_sale_vm加载listData数据---------------start--${state.page}---");
|
|
|
+ Log.d("for_sale_vm加载listData数据---------------start--${_page}---");
|
|
|
// try {
|
|
|
// //请求网络
|
|
|
// Map<String, dynamic> params = {
|
|
|
- // "page": state.page,
|
|
|
- // "limit": state.limit,
|
|
|
+ // "page": _page,
|
|
|
+ // "limit": _limit,
|
|
|
// };
|
|
|
// Log.d("请求参数------$params");
|
|
|
// final result = await propertyNewsRepository.fetchPropertyNewsList(params);
|
|
@@ -141,93 +143,163 @@ class ForsaleVm extends _$ForsaleVm {
|
|
|
// ToastEngine.show("Error: $e");
|
|
|
// }
|
|
|
|
|
|
- await Future.delayed(const Duration(milliseconds: 1500));
|
|
|
- final List<Map<String, dynamic>> listData = [
|
|
|
- {
|
|
|
- 'id':1,
|
|
|
- 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
- 'price': '\$66',
|
|
|
- 'isCollection': true,
|
|
|
- 'collection_num': 12,
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
- 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
- },
|
|
|
- {
|
|
|
- 'id':2,
|
|
|
- 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
- 'price': '\$88',
|
|
|
- 'isCollection': false,
|
|
|
- 'collection_num': 12,
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
- 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
- },
|
|
|
- {
|
|
|
- 'id':3,
|
|
|
- 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
- 'price': '\$66',
|
|
|
- 'isCollection': true,
|
|
|
- 'collection_num': 12,
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
- 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
- },
|
|
|
- {
|
|
|
- 'id':4,
|
|
|
- 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
- 'price': '\$88',
|
|
|
- 'isCollection': false,
|
|
|
- 'collection_num': 12,
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
- 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
- },
|
|
|
- {
|
|
|
- 'id':5,
|
|
|
- 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
- 'price': '\$66',
|
|
|
- 'isCollection': true,
|
|
|
- 'collection_num': 12,
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
- 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
- },
|
|
|
- {
|
|
|
- 'id':6,
|
|
|
- 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
- 'title': 'Electronic keyboard',
|
|
|
- 'price': '\$88',
|
|
|
- 'isCollection': false,
|
|
|
- 'collection_num': 12,
|
|
|
- 'publisher': 'William Jefferson',
|
|
|
- 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
- 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
- },
|
|
|
- ];
|
|
|
+ // await Future.delayed(const Duration(milliseconds: 1500));
|
|
|
+ // final List<Map<String, dynamic>> listData = [
|
|
|
+ // {
|
|
|
+ // 'id':1,
|
|
|
+ // 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
+ // 'title': 'Electronic keyboard',
|
|
|
+ // 'price': '\$66',
|
|
|
+ // 'isCollection': true,
|
|
|
+ // 'collection_num': 12,
|
|
|
+ // 'publisher': 'William Jefferson',
|
|
|
+ // 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
+ // 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // 'id':2,
|
|
|
+ // 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
+ // 'title': 'Electronic keyboard',
|
|
|
+ // 'price': '\$88',
|
|
|
+ // 'isCollection': false,
|
|
|
+ // 'collection_num': 12,
|
|
|
+ // 'publisher': 'William Jefferson',
|
|
|
+ // 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
+ // 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // 'id':3,
|
|
|
+ // 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
+ // 'title': 'Electronic keyboard',
|
|
|
+ // 'price': '\$66',
|
|
|
+ // 'isCollection': true,
|
|
|
+ // 'collection_num': 12,
|
|
|
+ // 'publisher': 'William Jefferson',
|
|
|
+ // 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
+ // 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // 'id':4,
|
|
|
+ // 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
+ // 'title': 'Electronic keyboard',
|
|
|
+ // 'price': '\$88',
|
|
|
+ // 'isCollection': false,
|
|
|
+ // 'collection_num': 12,
|
|
|
+ // 'publisher': 'William Jefferson',
|
|
|
+ // 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
+ // 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // 'id':5,
|
|
|
+ // 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
+ // 'title': 'Electronic keyboard',
|
|
|
+ // 'price': '\$66',
|
|
|
+ // 'isCollection': true,
|
|
|
+ // 'collection_num': 12,
|
|
|
+ // 'publisher': 'William Jefferson',
|
|
|
+ // 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
+ // 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // 'id':6,
|
|
|
+ // 'goods_img': 'https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500',
|
|
|
+ // 'title': 'Electronic keyboard',
|
|
|
+ // 'price': '\$88',
|
|
|
+ // 'isCollection': false,
|
|
|
+ // 'collection_num': 12,
|
|
|
+ // 'publisher': 'William Jefferson',
|
|
|
+ // 'publish_time': 'June 17,2016 at 7:23 p.m.',
|
|
|
+ // 'publisher_avator': 'https://img1.baidu.com/it/u=3890726495,1572750319&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'
|
|
|
+ // },
|
|
|
+ // ];
|
|
|
|
|
|
- if (state.page == 1) {
|
|
|
- //刷新的方式
|
|
|
- state = state.copyWith(list: listData);
|
|
|
- refreshController.finishRefresh();
|
|
|
- // //更新展示的状态
|
|
|
- changeLoadingState(LoadState.State_Success, null);
|
|
|
- } else {
|
|
|
- //加载更多
|
|
|
- final allList = state.list;
|
|
|
- allList.addAll(listData);
|
|
|
- state = state.copyWith(list: allList);
|
|
|
- refreshController.finishLoad();
|
|
|
+ // if (_page == 1) {
|
|
|
+ // //刷新的方式
|
|
|
+ // state = state.copyWith(list: listData);
|
|
|
+ // refreshController.finishRefresh();
|
|
|
+ // // //更新展示的状态
|
|
|
+ // changeLoadingState(LoadState.State_Success, null);
|
|
|
+ // } else {
|
|
|
+ // //加载更多
|
|
|
+ // final allList = state.list;
|
|
|
+ // allList.addAll(listData);
|
|
|
+ // state = state.copyWith(list: allList);
|
|
|
+ // refreshController.finishLoad();
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 最后赋值
|
|
|
+ // _needShowPlaceholder = false;
|
|
|
|
|
|
+ try {
|
|
|
+ //请求网络
|
|
|
+ Map<String, dynamic> params = {
|
|
|
+ "type": 1, // 类型(1=Sale,2=Rent)
|
|
|
+ "page": _page,
|
|
|
+ "limit": _limit,
|
|
|
+ };
|
|
|
+ Log.d("请求参数------$params");
|
|
|
+ final result = await commonGarageRepositoryInstance.fetchGarageDataList(params);
|
|
|
+ //校验成功失败
|
|
|
+ if (result.isSuccess) {
|
|
|
+ handlerResultList(result.list?.cast<GarageSaleRentEntity>(), isLoadMore ?? false);
|
|
|
+ } else {
|
|
|
+ String errorMessage = result.errorMsg!;
|
|
|
+ changeLoadingState(LoadState.State_Error, errorMessage);
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error");
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ ToastEngine.show("Error: $e");
|
|
|
}
|
|
|
|
|
|
- // 最后赋值
|
|
|
- _needShowPlaceholder = false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void handlerResultList(List<GarageSaleRentEntity>? list, bool isLoadMore) {
|
|
|
+ if (list != null && list.isNotEmpty) {
|
|
|
+ //有数据,判断是刷新还是加载更多的数据
|
|
|
+ if (_page == 1) {
|
|
|
+ //刷新的方式
|
|
|
+ state.list!.clear();
|
|
|
+ state.list!.addAll(list.map((item) => item.toJson()).toList());
|
|
|
+ refreshController.finishRefresh();
|
|
|
+ //更新展示的状态
|
|
|
+ changeLoadingState(LoadState.State_Success, null);
|
|
|
+ } else {
|
|
|
+ //加载更多
|
|
|
+ final allList = state.list;
|
|
|
+ allList!.addAll(list.map((item) => item.toJson()).toList());
|
|
|
+ state = state.copyWith(list: allList);
|
|
|
+ refreshController.finishLoad();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (_page == 1) {
|
|
|
+ //展示无数据的布局
|
|
|
+ state.list!.clear();
|
|
|
+ changeLoadingState(LoadState.State_Empty, null);
|
|
|
+ refreshController.finishRefresh();
|
|
|
+ } else {
|
|
|
+ //展示加载完成,没有更多数据了
|
|
|
+ if (_page == 1) {
|
|
|
+ //展示无数据的布局
|
|
|
+ state.list!.clear();
|
|
|
+ changeLoadingState(LoadState.State_Empty, null);
|
|
|
+ refreshController.finishRefresh();
|
|
|
+ } else {
|
|
|
+ //展示加载完成,没有更多数据了
|
|
|
+ if(state.list!.length == 0){
|
|
|
+ changeLoadingState(LoadState.State_Empty, null);
|
|
|
+ refreshController.finishLoad();
|
|
|
+ }else {
|
|
|
+ if(_needShowPlaceholder){
|
|
|
+ changeLoadingState(LoadState.State_Success, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //更新展示的状态
|
|
|
+ refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|