glglove 4 місяців тому
батько
коміт
3bb9d271b5

+ 25 - 10
packages/cpt_community/lib/components/garage_card.dart

@@ -6,6 +6,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
 import 'package:hooks_riverpod/hooks_riverpod.dart';
 import 'package:plugin_platform/engine/toast/toast_engine.dart';
 import 'package:shared/utils/color_utils.dart';
+import 'package:shared/utils/ext_dart.dart';
 import 'package:shared/utils/log_utils.dart';
 import 'package:widgets/ext/ex_widget.dart';
 import 'package:widgets/my_load_image.dart';
@@ -52,6 +53,19 @@ class GarageCard extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
+    List? card_resources = itemObj.getValue<List>("resources", [])?? [];
+    String card_img = card_resources.length>0? card_resources[0]:"";
+    String card_title = itemObj.getValue("title", "");
+    String card_price = itemObj.getValue("price", "");
+    String card_created_at = itemObj.getValue("created_at", "");
+    Map<String, dynamic>? card_account = itemObj.getValue<Map<String,dynamic>>("account", null);
+    String card_avator = card_account?['avator']?? "";
+    String card_publish_name = card_account?['name']?? "";
+    // bool card_followed = card_account?['followed']??false;
+    // String card_content = itemObj.getValue("content", "");
+    bool card_liked = itemObj.getValue("liked", false);
+    int card_likes_count = itemObj.getValue("likes_count", 0);
+    // int card_comments_count = itemObj.getValue("comments_count", 0);
     return Column(
       children: [
         // 图片
@@ -63,7 +77,7 @@ class GarageCard extends StatelessWidget {
               child: ClipRRect(
                 borderRadius: const BorderRadius.only(topLeft: Radius.circular(8), topRight: Radius.circular(8),),
                 child: MyLoadImage(
-                  itemObj['goods_img'],
+                  card_img,
                   width: 166.5,
                   height: 102.5,
                   isCircle: false,
@@ -84,7 +98,7 @@ class GarageCard extends StatelessWidget {
             children: [
               Expanded(
                 child: MyTextView(
-                  itemObj['title'],
+                  card_title,
                   maxLines: 1,
                   isTextEllipsis: true,
                   textAlign: TextAlign.left,
@@ -105,7 +119,7 @@ class GarageCard extends StatelessWidget {
             children: [
               Expanded(
                 child: MyTextView(
-                  itemObj['price'],
+                  card_price,
                   maxLines: 1,
                   isTextEllipsis: true,
                   textAlign: TextAlign.start,
@@ -116,8 +130,8 @@ class GarageCard extends StatelessWidget {
               ),
               // 动态的 收藏数
               CollectionWidget(
-                  collectionNum: itemObj['collection_num'],
-                  isCollection: itemObj['isCollection'],
+                  collectionNum: card_likes_count,
+                  isCollection: card_liked,
                   onClickColleciotn: onClickColleciotn,
               ),
             ],
@@ -133,7 +147,7 @@ class GarageCard extends StatelessWidget {
               children: [
                 if (useType == GarageCardUseType.forSale || useType == GarageCardUseType.forRent)
                   MyLoadImage(
-                    itemObj['publisher_avator'],
+                    card_avator,
                     width: 30,
                     height: 30,
                     isCircle: true,
@@ -148,7 +162,7 @@ class GarageCard extends StatelessWidget {
                     children: [
                       if (useType == GarageCardUseType.forSale || useType == GarageCardUseType.forRent)
                         MyTextView(
-                          itemObj['publisher'],
+                          card_publish_name,
                           maxLines: 1,
                           isTextEllipsis: true,
                           textAlign: TextAlign.start,
@@ -160,7 +174,7 @@ class GarageCard extends StatelessWidget {
                       else
                         const SizedBox.shrink(),
                       MyTextView(
-                        itemObj['publish_time'],
+                        card_created_at,
                         maxLines: 1,
                         isTextEllipsis: true,
                         textAlign: TextAlign.start,
@@ -223,12 +237,13 @@ class CollectionWidget extends HookConsumerWidget {
           )
         ]
         // 点击 收餐/取消收藏
-    ).onTap((){
+    ).onTap(() async{
         // Log.d("点击了收藏按钮  ${isCollectionState.value}");
         // ToastEngine.show("点击了收藏按钮 ${isCollectionState.value}");
-        bool result = onClickColleciotn?.call(isCollectionState.value);
+        bool result = await onClickColleciotn?.call(isCollectionState.value);
         if(result){
           isCollectionState.value = !isCollectionState.value;
+          collectionNumState.value = (collectionNumState.value + (isCollectionState.value? 1: -1))<0? 0: (collectionNumState.value + (isCollectionState.value? 1: -1));
           if(isCollectionState.value){
             ToastEngine.show("Collect Success");
           }else {

+ 1 - 1
packages/cpt_community/lib/modules/community/news/news_page.dart

@@ -99,7 +99,7 @@ class NewsPage extends HookConsumerWidget {
   Widget _buildNewsItem(BuildContext context, WidgetRef ref, Map<String, dynamic> item, vm, int itemIdx){
     String card_title = item.getValue("title", "");
     String card_created_at = item.getValue("created_at", "");
-    Map<String, dynamic>? card_account = item.getValue<Map<String,dynamic>>("account", {});
+    Map<String, dynamic>? card_account = item.getValue<Map<String,dynamic>>("account", null);
     String card_avator = card_account?['avator']?? "";
     bool card_followed = card_account?['followed']??false;
     String card_content = item.getValue("content", "");

+ 6 - 5
packages/cpt_community/lib/modules/garage/for_rent/for_rent_page.dart

@@ -93,7 +93,7 @@ class ForrentPage extends HookConsumerWidget {
                   delegate: SliverChildBuilderDelegate(
                         (context, index) {
                       return  _buildForrentItem(context, ref, state.list[index], vm).onTap((){
-                        vm.handlerGotoDetail(state.list[index]['id']);
+                        vm.handlerGotoDetail(context: context, id: state.list[index]['id'], type: 'forRent');
                       });
                     },
                     childCount: state.list.length,
@@ -130,10 +130,11 @@ class ForrentPage extends HookConsumerWidget {
               Expanded(
                 child: GarageCard(
                     key: UniqueKey(),
-                    itemObj: item,
-                    onClickColleciotn: (dynamic collectionValue){
-                      Log.d("点击了收藏按钮  --${item['id']}-$collectionValue");
-                      return true;
+                    itemObj: item.cast<String, dynamic>(),
+                    onClickColleciotn: (dynamic collectionValue) async {
+                      Log.d("点击了收藏按钮  --id:${item['id']}- $collectionValue");
+                      int id = item['id'];
+                      return await vm.handlerClickCollection(id, collectionValue);
                     }
                 ),
               ),

+ 85 - 95
packages/cpt_community/lib/modules/garage/for_rent/for_rent_vm.dart

@@ -144,109 +144,71 @@ class ForrentVm extends _$ForrentVm {
 
 
   // 获取list 列表数据
-  Future getListData<T>() async {
+  Future getListData<T>({bool? isLoadMore = false}) async {
     if (_needShowPlaceholder) {
       changeLoadingState(LoadState.State_Loading, null);
     }
 
     Log.d("for_rent加载listData数据---------------start--${_page}---");
-    //   try {
-    //     //请求网络
-    //     Map<String, dynamic>  params = {
-    //       "page": _page,
-    //       "limit": _limit,
-    //     };
-    //     Log.d("请求参数------$params");
-    //     final result = await propertyNewsRepository.fetchPropertyNewsList(params);
-    //     Log.d("请求完成结果------${result.data}");
-    //     //校验成功失败
-    //     if (result.isSuccess) {
-    //       // state = state.copyWith(serverTime: result.data);
-    //       state = state;
-    //   handleList(listResult.data?.rows);
-    //       ToastEngine.show("获取数据成功");
-    //     } else {
-    //   errorMessage = listResult.errorMsg;
-    //   changeLoadingState(LoadState.State_Error);
-    //       ToastEngine.show(result.errorMsg ?? "Network Load Error");
-    //     }
-    //   } catch (e) {
-    //     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'
+    //   },
+    // ];
 
-    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'
-      },
-    ];
-
-    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();
 
+    try {
+      //请求网络
+      Map<String, dynamic>  params = {
+        "type": 2,  // 类型(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");
     }
 
-    // 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;
   }
@@ -304,8 +266,36 @@ class ForrentVm extends _$ForrentVm {
   }
 
 
+  // 点击 收藏/取消收藏
+  Future<bool?> handlerClickCollection(int id, bool? isCollection) async{
+    try {
+      //请求网络
+      Map<String, dynamic>  params = {
+        "id": id,
+      };
+      Log.d("请求参数------$params");
+      final result = await commonGarageRepositoryInstance.fetchGarageColleciton(params);
+      //校验成功失败
+      if (result.isSuccess) {
+        // 修改 该id 的 liked 和 likes_count 字段
+        state.list!.forEach((Map<String, dynamic> element) {
+          if(element['id'] == id){
+            element['liked'] = !element['liked'];
+            element['collection_num'] = element['liked'] ? element['collection_num'] + 1 : element['collection_num'] - 1;
+          }
+        });
+        return true;
+      } else {
+        String errorMessage = result.errorMsg!;
+        changeLoadingState(LoadState.State_Error, errorMessage);
+        ToastEngine.show(result.errorMsg ?? "Network Load Error");
+      }
+    } catch (e) {
+      ToastEngine.show("Error: $e");
+    }
+  }
   // 去详情页面
-  void handlerGotoDetail(id){
+  void handlerGotoDetail({BuildContext? context, required int id, String type='forRent'}){
     Log.d("去详情页面");
     appRouter.push(GaragesaleDetailPageRoute(id: id, type: 'forRent'));
   }

+ 7 - 6
packages/cpt_community/lib/modules/garage/for_sale/for_sale_page.dart

@@ -96,7 +96,7 @@ class ForsalePage extends HookConsumerWidget {
                 delegate: SliverChildBuilderDelegate(
                       (context, index) {
                     return  _buildForsaleItem(context, ref, state.list[index], vm).onTap((){
-                      vm.handlerGotoDetail(state.list[index]['id']);
+                      vm.handlerGotoDetail(context: context, id: state.list[index]['id'], type: 'forSale');
                     });
                   },
                   childCount: state.list.length,
@@ -109,7 +109,7 @@ class ForsalePage extends HookConsumerWidget {
     );
   }
 
-  Widget _buildForsaleItem(BuildContext context, WidgetRef ref, item, vm){
+  Widget _buildForsaleItem(BuildContext context, WidgetRef ref, Map<String, dynamic> item, vm){
     return SizedBox(
       width: double.infinity,
       child: Container(
@@ -133,10 +133,11 @@ class ForsalePage extends HookConsumerWidget {
               Expanded(
                 child: GarageCard(
                   key: UniqueKey(),
-                  itemObj: item,
-                  onClickColleciotn: (dynamic collectionValue){
-                    Log.d("点击了收藏按钮  --${item['id']}-$collectionValue");
-                    return true;
+                  itemObj: item.cast<String, dynamic>(),
+                  onClickColleciotn: (dynamic collectionValue) async {
+                    Log.d("点击了收藏按钮  --id:${item['id']}- $collectionValue");
+                    int id = item['id'];
+                    return await vm.handlerClickCollection(id, collectionValue);
                   }
                 ),
               ),

+ 94 - 109
packages/cpt_community/lib/modules/garage/for_sale/for_sale_vm.dart

@@ -119,100 +119,77 @@ class ForsaleVm extends _$ForsaleVm {
     }
 
     Log.d("for_sale_vm加载listData数据---------------start--${_page}---");
-    //   try {
-    //     //请求网络
-    //     Map<String, dynamic>  params = {
-    //       "page": _page,
-    //       "limit": _limit,
-    //     };
-    //     Log.d("请求参数------$params");
-    //     final result = await propertyNewsRepository.fetchPropertyNewsList(params);
-    //     Log.d("请求完成结果------${result.data}");
-    //     //校验成功失败
-    //     if (result.isSuccess) {
-    //       // state = state.copyWith(serverTime: result.data);
-    //       state = state;
-    //   handleList(listResult.data?.rows);
-    //       ToastEngine.show("获取数据成功");
-    //     } else {
-    //   errorMessage = listResult.errorMsg;
-    //   changeLoadingState(LoadState.State_Error);
-    //       ToastEngine.show(result.errorMsg ?? "Network Load Error");
-    //     }
-    //   } catch (e) {
-    //     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'
-      // },
+    //   {
+    //     '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 (_page == 1) {
     //   //刷新的方式
     //   state = state.copyWith(list: listData);
@@ -303,28 +280,36 @@ class ForsaleVm extends _$ForsaleVm {
   }
 
 
-  // 点击 like comments  share
-  void handlerClickActionBtn(String? actionStr, item){
-    final id = item['id'];
-    switch (actionStr) {
-      case 'like':
-        Log.d("点击了 点赞");
-        handlerGotoDetail(id);
-        break;
-      case 'comments':
-        Log.d("点击了 评论");
-        handlerGotoDetail(id);
-        break;
-      case 'share':
-        Log.d("点击了 分享");
-        handlerGotoDetail(id);
-        break;
-      default:
-        break;
+  // 点击 收藏/取消收藏
+  Future<bool?> handlerClickCollection(int id, bool? isCollection) async{
+    try {
+      //请求网络
+      Map<String, dynamic>  params = {
+        "id": id,
+      };
+      Log.d("请求参数------$params");
+      final result = await commonGarageRepositoryInstance.fetchGarageColleciton(params);
+      //校验成功失败
+      if (result.isSuccess) {
+        // 修改 该id 的 liked 和 likes_count 字段
+        state.list!.forEach((Map<String, dynamic> element) {
+          if(element['id'] == id){
+            element['liked'] = !element['liked'];
+            element['collection_num'] = element['liked'] ? element['collection_num'] + 1 : element['collection_num'] - 1;
+          }
+        });
+        return true;
+      } else {
+        String errorMessage = result.errorMsg!;
+        changeLoadingState(LoadState.State_Error, errorMessage);
+        ToastEngine.show(result.errorMsg ?? "Network Load Error");
+      }
+    } catch (e) {
+      ToastEngine.show("Error: $e");
     }
   }
   // 去详情页面
-  void handlerGotoDetail(id){
+  void handlerGotoDetail({BuildContext? context, required int id, String type='forSale'}){
     Log.d("去详情页面");
     appRouter.push(GaragesaleDetailPageRoute(id: id, type: 'forSale'));
   }

+ 32 - 0
packages/cpt_community/lib/respository/common_garage.dart

@@ -96,6 +96,38 @@ class CommonGarageRepository {
     return result.convert();
   }
 
+  // garage 点赞/取消点赞
+  Future<HttpResult<Object>> fetchGarageColleciton(
+      Map<String, dynamic>? data, {
+        CancelToken? cancelToken,
+      }) async {
+    Map<String, dynamic> params = {};
+    params = data!;
+    Map<String, String> headers = {};
+    headers["Content-Type"] = "application/x-www-form-urlencoded";
+    headers["Accept"] = "application/x.yyjobs-api.v1+json";
+
+    final result = await dioEngine.requestNetResult(
+      // ApiConstants.apiServerTime, // api 地址
+      '/api/v1/user/garage-sale/like/click', // api 地址
+      params: params,
+      headers: headers,
+      method: HttpMethod.POST,
+      isShowLoadingDialog: true,  //是否展示默认的Loading弹窗
+      networkDebounce: true,   //是否防抖防止重复请求
+      cancelToken: cancelToken,
+    );
+    //根据返回的结果,封装原始数据为Bean/Entity对象
+    if (result.isSuccess) {
+      //重新赋值data或list
+      final json = result.getDataDynamic();
+      // var data = NewsfeedForyouEntity.fromJson(json!);
+      //重新赋值data或list
+      return result.convert(data: json);
+    }
+    return result.convert();
+  }
+
 
   // 发布 garage
   Future<HttpResult<Object>> fetchPublishGarage(