From f0c8142df424d297073771cc7f383db4e4b4a00b Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Thu, 29 Oct 2020 14:07:25 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=88=91=E7=9A=84=E6=94=B6=E8=97=8F?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=202=E3=80=81=E5=95=86=E5=93=81=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=AE=9E=E7=8E=B0=E6=94=B6=E8=97=8F=E4=B8=8E=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/favorite_page/favorite_page.dart | 22 -- lib/pages/favorite_page/preview_page.dart | 17 - .../favorites_page/bloc/favorites_bloc.dart | 49 +++ .../favorites_page/bloc/favorites_event.dart | 7 + .../bloc/favorites_repository.dart | 39 +++ .../favorites_page/bloc/favorites_state.dart | 23 ++ lib/pages/favorites_page/favorites_page.dart | 264 ++++++++++++++ .../model/favorites_style_model.dart | 278 +++++++++++++++ .../notifier/favorites_page_notifier.dart | 44 +++ lib/register.dart | 8 +- .../dialog/favorites_dialog_widget.dart | 75 ++++ .../bloc/favorites_goods_list_bloc.dart | 173 ++++++++++ .../bloc/favorites_goods_list_event.dart | 39 +++ .../bloc/favorites_goods_list_repository.dart | 161 +++++++++ .../bloc/favorites_goods_list_state.dart | 35 ++ .../favorites_goods_list_widget.dart | 325 ++++++++++++++++++ .../model/favorites_goods_list_model.dart | 37 ++ .../bloc/goods_details_footer_bloc.dart | 25 +- .../bloc/goods_details_footer_event.dart | 15 + .../bloc/goods_details_footer_repository.dart | 40 ++- .../bloc/goods_details_footer_state.dart | 14 +- .../footer/goods_details_footer_widget.dart | 13 +- .../model/goods_details_footer_model.dart | 172 ++++++++- .../home_goods/home_goods_item_single.dart | 8 +- .../home_goods/models/home_goods_model.dart | 15 + 25 files changed, 1820 insertions(+), 78 deletions(-) delete mode 100644 lib/pages/favorite_page/favorite_page.dart delete mode 100644 lib/pages/favorite_page/preview_page.dart create mode 100644 lib/pages/favorites_page/bloc/favorites_bloc.dart create mode 100644 lib/pages/favorites_page/bloc/favorites_event.dart create mode 100644 lib/pages/favorites_page/bloc/favorites_repository.dart create mode 100644 lib/pages/favorites_page/bloc/favorites_state.dart create mode 100644 lib/pages/favorites_page/favorites_page.dart create mode 100644 lib/pages/favorites_page/model/favorites_style_model.dart create mode 100644 lib/pages/favorites_page/notifier/favorites_page_notifier.dart create mode 100644 lib/widgets/favorites/dialog/favorites_dialog_widget.dart create mode 100644 lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart create mode 100644 lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart create mode 100644 lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart create mode 100644 lib/widgets/favorites/goods_list/bloc/favorites_goods_list_state.dart create mode 100644 lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart create mode 100644 lib/widgets/favorites/goods_list/model/favorites_goods_list_model.dart diff --git a/lib/pages/favorite_page/favorite_page.dart b/lib/pages/favorite_page/favorite_page.dart deleted file mode 100644 index e61aa72..0000000 --- a/lib/pages/favorite_page/favorite_page.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:flutter/material.dart'; - -class FavoritePage extends StatefulWidget { - @override - _FavoritePageState createState() => _FavoritePageState(); -} - -class _FavoritePageState extends State { - GlobalKey _globalKey = GlobalKey(); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('收藏夹'), - ), - body: Column( - children: [], - ), - ); - } -} diff --git a/lib/pages/favorite_page/preview_page.dart b/lib/pages/favorite_page/preview_page.dart deleted file mode 100644 index 026967e..0000000 --- a/lib/pages/favorite_page/preview_page.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:flutter/material.dart'; - -class PreviewPage extends StatelessWidget { - final Image image; - - const PreviewPage({Key key, this.image}) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(), - body: Center( - child: image, - ), - ); - } -} diff --git a/lib/pages/favorites_page/bloc/favorites_bloc.dart b/lib/pages/favorites_page/bloc/favorites_bloc.dart new file mode 100644 index 0000000..dcae1c0 --- /dev/null +++ b/lib/pages/favorites_page/bloc/favorites_bloc.dart @@ -0,0 +1,49 @@ +import 'dart:async'; + +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter/material.dart'; +import 'package:meta/meta.dart'; +import 'package:zhiying_base_widget/pages/favorites_page/bloc/favorites_repository.dart'; +import 'package:zhiying_base_widget/pages/favorites_page/model/favorites_style_model.dart'; +import 'package:zhiying_comm/util/empty_util.dart'; + +part 'favorites_event.dart'; + +part 'favorites_state.dart'; + +class FavoritesBloc extends Bloc { + // FavoritesBloc() : super(FavoritesInitial()); + + FavoritesRepository repository; + + FavoritesBloc(this.repository); + + @override + // TODO: implement initialState + FavoritesState get initialState => FavoritesInitial(); + + @override + Stream mapEventToState( + FavoritesEvent event, + ) async* { + /// 初始化 + if (event is FavoritesInitEvent) { + yield* _mapInitEventToState(event); + } + } + + /// 初始化 + Stream _mapInitEventToState(FavoritesInitEvent event) async* { + var cache = await repository.fetchCachedStyle(); + if (!EmptyUtil.isEmpty(cache)) { + yield FavoritesLoadedState(model: cache); + } + var result = await repository.fetchNetStyle(); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesLoadedState(model: result); + } else { + yield FavoritesErrorState(); + } + } +} diff --git a/lib/pages/favorites_page/bloc/favorites_event.dart b/lib/pages/favorites_page/bloc/favorites_event.dart new file mode 100644 index 0000000..bd2f842 --- /dev/null +++ b/lib/pages/favorites_page/bloc/favorites_event.dart @@ -0,0 +1,7 @@ +part of 'favorites_bloc.dart'; + +@immutable +abstract class FavoritesEvent {} + +/// 初始化数据 +class FavoritesInitEvent extends FavoritesEvent {} diff --git a/lib/pages/favorites_page/bloc/favorites_repository.dart b/lib/pages/favorites_page/bloc/favorites_repository.dart new file mode 100644 index 0000000..e11d47c --- /dev/null +++ b/lib/pages/favorites_page/bloc/favorites_repository.dart @@ -0,0 +1,39 @@ +import 'dart:convert'; + +import 'package:zhiying_base_widget/pages/favorites_page/model/favorites_style_model.dart'; +import 'package:zhiying_base_widget/widgets/empty/empty_widget.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class FavoritesRepository { + /// 请求网络样式 + Future fetchNetStyle() async { + try { + var result = await NetUtil.post('/api/v1/mod/pub.flutter.my_fav', cache: true, method: NetMethod.GET); + if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + var modListData = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][0]['data']; + if(!EmptyUtil.isEmpty(modListData)){ + return FavoritesStyleModel.fromJson(jsonDecode(modListData)); + } + } + } catch (e, s) { + Logger.log(e, s); + } + return null; + } + + /// 获取缓存样式 + Future fetchCachedStyle() async { + try { + var result = await NetUtil.getRequestCachedData(''); + if(!EmptyUtil.isEmpty(result)){ + var modListData = result['mod_list'][0]['data']; + if(!EmptyUtil.isEmpty(modListData)){ + return FavoritesStyleModel.fromJson(jsonDecode(modListData)); + } + } + } catch (e, s) { + Logger.log(e, s); + } + return null; + } +} diff --git a/lib/pages/favorites_page/bloc/favorites_state.dart b/lib/pages/favorites_page/bloc/favorites_state.dart new file mode 100644 index 0000000..5fc4505 --- /dev/null +++ b/lib/pages/favorites_page/bloc/favorites_state.dart @@ -0,0 +1,23 @@ +part of 'favorites_bloc.dart'; + +@immutable +abstract class FavoritesState extends Equatable { + @override + List get props => []; +} + +/// 初始化状态(骨架图) +class FavoritesInitial extends FavoritesState {} + +/// 数据加载成功 +class FavoritesLoadedState extends FavoritesState { + FavoritesStyleModel model; + + FavoritesLoadedState({@required this.model}); + + @override + List get props => [this.model]; +} + +/// 未知错误 +class FavoritesErrorState extends FavoritesState {} diff --git a/lib/pages/favorites_page/favorites_page.dart b/lib/pages/favorites_page/favorites_page.dart new file mode 100644 index 0000000..19ff195 --- /dev/null +++ b/lib/pages/favorites_page/favorites_page.dart @@ -0,0 +1,264 @@ +import 'package:flutter/material.dart'; +import 'package:tab_indicator_styler/tab_indicator_styler.dart'; +import 'package:zhiying_base_widget/pages/favorites_page/bloc/favorites_bloc.dart'; +import 'package:zhiying_base_widget/pages/favorites_page/bloc/favorites_repository.dart'; +import 'package:zhiying_base_widget/widgets/favorites/goods_list/favorites_goods_list_widget.dart'; +import 'package:zhiying_comm/util/empty_util.dart'; +import 'package:zhiying_comm/util/extension/color.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:provider/provider.dart'; +import 'package:zhiying_comm/util/log/let_log.dart'; +import 'package:fluttertoast/fluttertoast.dart'; +import 'package:zhiying_comm/util/router_util.dart'; + +import 'model/favorites_style_model.dart'; +import 'notifier/favorites_page_notifier.dart'; + +class FavoritesPage extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: FavoritesPageNotifier()), + ], + child: BlocProvider( + create: (_) => FavoritesBloc(FavoritesRepository())..add(FavoritesInitEvent()), + child: _FavoritesPageContainer(), + ), + ); + } +} + +class _FavoritesPageContainer extends StatefulWidget { + @override + _FavoritesPageContainerState createState() => _FavoritesPageContainerState(); +} + +class _FavoritesPageContainerState extends State<_FavoritesPageContainer> with TickerProviderStateMixin { + TextEditingController _editingController; + FocusNode _focusNode; + TabController _tabController; + bool _isNotEditing = true; + + /// 点击编辑 + void _onClickEditing() { + RouterUtil.hideKeyboard(context); + setState(() { + _isNotEditing = !_isNotEditing; + }); + Provider.of(context, listen: false).editing(); + } + + /// 点击搜索 + void _onClickSearch() {} + + /// 执行搜索 + void _submitSearch() { + String keyword = _editingController?.text?.toString()?.trim(); + // if (!EmptyUtil.isEmpty(keyword)) { + _tabController.index = 0; + Provider.of(context, listen: false).search(keyword); + // } else { + // Fluttertoast.showToast(msg: '请输入需要搜索的内容~'); + // } + } + + /// tabBar的初始化 + void _tabControllerInit(FavoritesStyleModel model) { + if ((null == _tabController && !EmptyUtil.isEmpty(model?.tabList)) || + (!EmptyUtil.isEmpty(model?.tabList) && null != _tabController && _tabController.length != model.tabList.length)) { + _tabController = TabController(length: model.tabList.length, vsync: this) + ..addListener(() { + if (!_tabController.indexIsChanging) { + RouterUtil.hideKeyboard(context); + Logger.log('tab index = ${_tabController.index}'); + Provider.of(context, listen: false).changeSelectIndex(_tabController.index); + } + }); + } + } + + @override + void initState() { + _editingController = TextEditingController(); + _focusNode = FocusNode(); + super.initState(); + } + + @override + void dispose() { + _focusNode?.unfocus(); + _focusNode?.dispose(); + _editingController?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BlocConsumer( + listener: (context, state) {}, + buildWhen: (prev, current) { + return true; + }, + builder: (context, state) { + if (state is FavoritesLoadedState) { + _tabControllerInit(state?.model); + return _buildMainWidget(state?.model); + } + return _buildSkeletonWidget(); + }, + ); + } + + /// mainWidget + Widget _buildMainWidget(FavoritesStyleModel model) { + return Scaffold( + resizeToAvoidBottomInset: false, + resizeToAvoidBottomPadding: false, + backgroundColor: HexColor.fromHex('#FFFFFF'), + appBar: _buildAppBarWidget(model), + body: Column( + children: [ + /// 搜索框 + Padding(padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 4), child: _buildSearchWidget(model)), + + /// tabBar + Padding(padding: const EdgeInsets.only(top: 4), child: _buildTabBarWidget(model)), + + Expanded( + child: _buildTabBarViewWidget(model), + ), + ], + ), + ); + } + + /// TabBar + Widget _buildTabBarWidget(FavoritesStyleModel model) { + return Container( + padding: const EdgeInsets.only(top: 12.5, bottom: 14.5), + width: double.infinity, + child: TabBar( + isScrollable: true, + labelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold), + unselectedLabelStyle: TextStyle(fontWeight: FontWeight.w400, fontSize: 14), + labelColor: HexColor.fromHex(model?.tabNameSelectedColor ?? '#FF0100'), + unselectedLabelColor: HexColor.fromHex(model?.tabNameColor ?? '#333333'), + indicatorSize: TabBarIndicatorSize.label, + controller: _tabController, + indicatorWeight: 5, + indicator: MaterialIndicator( + topLeftRadius: 1, + topRightRadius: 1, + bottomLeftRadius: 1, + bottomRightRadius: 1, + height: 2, + color: HexColor.fromHex(model?.tabLineColor ?? '#FF0100'), + horizontalPadding: 5, + ), + tabs: model.tabList.map((e) => Text(e?.name ?? '')).toList(), + ), + ); + } + + /// tabBarView + Widget _buildTabBarViewWidget(FavoritesStyleModel model) { + int length = model?.tabList?.length ?? 0; + if (length > 0) { + int index = -1; + return TabBarView( + controller: _tabController, + children: model.tabList.map((e) { + ++index; + return FavoritesGoodsListWidget( + model: model, + type: e?.type, + currentIndex: index, + ); + }).toList(), + ); + } + return Container(color: HexColor.fromHex('#F9F9F9')); + } + + /// 搜索框 + Widget _buildSearchWidget(FavoritesStyleModel model) { + return Container( + alignment: Alignment.center, + width: double.infinity, + height: 35, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(35 / 2), + color: HexColor.fromHex(model?.searchBarBgColor ?? '#F9F9F9'), + ), + child: TextField( + controller: _editingController, + focusNode: _focusNode, + onSubmitted: (text) => _submitSearch(), + textInputAction: TextInputAction.search, + style: TextStyle(color: HexColor.fromHex('#333333'), fontSize: 14, textBaseline: TextBaseline.alphabetic), + textAlign: TextAlign.center, + decoration: InputDecoration( + fillColor: Colors.transparent, + filled: true, + isDense: true, + contentPadding: EdgeInsets.zero, + hintText: model?.searchBarText ?? '搜索商品', + hintStyle: TextStyle(color: HexColor.fromHex(model?.searchBarTextColor ?? '#999999'), fontSize: 14, textBaseline: TextBaseline.alphabetic), + border: InputBorder.none, + enabledBorder: InputBorder.none, + disabledBorder: InputBorder.none, + errorBorder: InputBorder.none, + focusedErrorBorder: InputBorder.none, + focusedBorder: InputBorder.none, + ), + ), + ); + } + + /// appbar + Widget _buildAppBarWidget(FavoritesStyleModel model) { + return AppBar( + backgroundColor: HexColor.fromHex(model?.appBarBgColor ?? '#FFFFFF'), + leading: IconButton( + icon: Icon( + Icons.arrow_back_ios, + size: 22, + color: HexColor.fromHex('#333333'), + ), + onPressed: () => Navigator.maybePop(context), + ), + title: Text( + model?.appBarName ?? '我的收藏', + style: TextStyle(color: HexColor.fromHex(model?.appBarNameColor ?? '#333333'), fontSize: 15, fontWeight: FontWeight.bold), + ), + centerTitle: true, + elevation: 0, + actions: [ + GestureDetector( + onTap: () => _onClickEditing(), + behavior: HitTestBehavior.opaque, + child: Center( + child: Padding( + padding: const EdgeInsets.only(right: 12.5), + child: Text( + _isNotEditing ? model?.appBarRightText ?? '编辑' : model?.appBarRightEditingText ?? '完成', + style: TextStyle( + color: HexColor.fromHex(_isNotEditing ? model?.appBarRightTextColor ?? '#333333' : model?.appBarRightEditingColor ?? '#FF4242'), + fontSize: 14, + fontWeight: FontWeight.bold), + ), + ), + ), + ) + ], + ); + } + + /// 骨架图 + Widget _buildSkeletonWidget() { + return Scaffold( + body: Container(), + ); + } +} diff --git a/lib/pages/favorites_page/model/favorites_style_model.dart b/lib/pages/favorites_page/model/favorites_style_model.dart new file mode 100644 index 0000000..e1c9116 --- /dev/null +++ b/lib/pages/favorites_page/model/favorites_style_model.dart @@ -0,0 +1,278 @@ +import 'package:zhiying_base_widget/widgets/home/home_goods/models/home_goods_list_style_model.dart'; + +class FavoritesStyleModel { + String appBarName; + String appBarNameColor; + String appBarBgImg; + String appBarBgColor; + String appBarRightText; + String appBarRightTextColor; + String appBarRightEditingText; + String appBarRightEditingColor; + String searchBarIcon; + String searchBarText; + String searchBarTextColor; + String searchBarBgColor; + String tabLineColor; + String tabItemNotFoundImg; + List tabList; + HomeGoodsListStyleModel listStyle; + String editLeftConfirmColor; + String editLeftNoConfirmColor; + Bottom bottom; + ConfirmDialog confirmDialog; + + String tabNameColor; + String tabNameSelectedColor; + String editLeftConfirmIcon; + String editLeftNoConfirmIcon; + + FavoritesStyleModel({ + this.appBarName, + this.appBarNameColor, + this.appBarBgImg, + this.appBarBgColor, + this.appBarRightText, + this.appBarRightTextColor, + this.appBarRightEditingText, + this.appBarRightEditingColor, + this.searchBarIcon, + this.searchBarText, + this.searchBarTextColor, + this.searchBarBgColor, + this.tabLineColor, + this.tabItemNotFoundImg, + this.tabList, + this.listStyle, + this.editLeftConfirmColor, + this.editLeftNoConfirmColor, + this.bottom, + this.confirmDialog, + this.tabNameColor, + this.tabNameSelectedColor, + this.editLeftConfirmIcon, + this.editLeftNoConfirmIcon, + }); + + FavoritesStyleModel.fromJson(Map json) { + appBarName = json['app_bar_name']; + appBarNameColor = json['app_bar_name_color']; + appBarBgImg = json['app_bar_bg_img']; + appBarBgColor = json['app_bar_bg_color']; + appBarRightText = json['app_bar_right_text']; + appBarRightTextColor = json['app_bar_right_text_color']; + appBarRightEditingText = json['app_bar_right_editing_text']; + appBarRightEditingColor = json['app_bar_right_editing_color']; + searchBarIcon = json['search_bar_icon']; + searchBarText = json['search_bar_text']; + searchBarTextColor = json['search_bar_text_color']; + searchBarBgColor = json['search_bar_bg_color']; + tabLineColor = json['tab_line_color']; + tabItemNotFoundImg = json['tab_item_not_found_img']; + if (json['tab_list'] != null) { + tabList = new List(); + json['tab_list'].forEach((v) { + tabList.add(new TabList.fromJson(v)); + }); + } + listStyle = json['list_style'] != null ? new HomeGoodsListStyleModel.fromJson(json['list_style']) : null; + editLeftConfirmColor = json['edit_left_confirm_color']; + editLeftNoConfirmColor = json['edit_left_no_confirm_color']; + bottom = json['bottom'] != null ? new Bottom.fromJson(json['bottom']) : null; + confirmDialog = json['confirm_dialog'] != null ? new ConfirmDialog.fromJson(json['confirm_dialog']) : null; + + tabNameColor = json['tab_name_color']; + tabNameSelectedColor = json['tab_name_selected_color']; + editLeftConfirmIcon = json['edit_left_confirm_icon']; + editLeftNoConfirmIcon = json['edit_left_no_confirm_icon']; + + } + + Map toJson() { + final Map data = new Map(); + data['app_bar_name'] = this.appBarName; + data['app_bar_name_color'] = this.appBarNameColor; + data['app_bar_bg_img'] = this.appBarBgImg; + data['app_bar_bg_color'] = this.appBarBgColor; + data['app_bar_right_text'] = this.appBarRightText; + data['app_bar_right_text_color'] = this.appBarRightTextColor; + data['app_bar_right_editing_text'] = this.appBarRightEditingText; + data['app_bar_right_editing_color'] = this.appBarRightEditingColor; + data['search_bar_icon'] = this.searchBarIcon; + data['search_bar_text'] = this.searchBarText; + data['search_bar_text_color'] = this.searchBarTextColor; + data['search_bar_bg_color'] = this.searchBarBgColor; + data['tab_line_color'] = this.tabLineColor; + data['tab_item_not_found_img'] = this.tabItemNotFoundImg; + if (this.tabList != null) { + data['tab_list'] = this.tabList.map((v) => v.toJson()).toList(); + } + if (this.listStyle != null) { + data['list_style'] = this.listStyle.toJson(); + } + data['edit_left_confirm_color'] = this.editLeftConfirmColor; + data['edit_left_no_confirm_color'] = this.editLeftNoConfirmColor; + if (this.bottom != null) { + data['bottom'] = this.bottom.toJson(); + } + if (this.confirmDialog != null) { + data['confirm_dialog'] = this.confirmDialog.toJson(); + } + + data['tab_name_color'] = this.tabNameColor; + data['tab_name_selected_color'] = this.tabNameSelectedColor; + data['edit_left_confirm_icon'] = this.editLeftConfirmIcon; + data['edit_left_no_confirm_icon'] = this.editLeftNoConfirmIcon; + + return data; + } +} + +class TabList { + String type; + String name; + String nameColor; + String nameSelectedColor; + + TabList({this.type, this.name, this.nameColor, this.nameSelectedColor}); + + TabList.fromJson(Map json) { + type = json['type']; + name = json['name']; + nameColor = json['name_color']; + nameSelectedColor = json['name_selected_color']; + } + + Map toJson() { + final Map data = new Map(); + data['type'] = this.type; + data['name'] = this.name; + data['name_color'] = this.nameColor; + data['name_selected_color'] = this.nameSelectedColor; + return data; + } +} + +class Left { + String couonText; + String couponFontColor; + String couponBgColor; + String couponBgImg; + String isImg; + + Left({this.couonText, this.couponFontColor, this.couponBgColor, this.couponBgImg, this.isImg}); + + Left.fromJson(Map json) { + couonText = json['couon_text']; + couponFontColor = json['coupon_font_color']; + couponBgColor = json['coupon_bg_color']; + couponBgImg = json['coupon_bg_img']; + isImg = json['is_img']; + } + + Map toJson() { + final Map data = new Map(); + data['couon_text'] = this.couonText; + data['coupon_font_color'] = this.couponFontColor; + data['coupon_bg_color'] = this.couponBgColor; + data['coupon_bg_img'] = this.couponBgImg; + data['is_img'] = this.isImg; + return data; + } +} + +class Right { + String commissionText; + String commissionFontColor; + String commissionBgColor; + String commissionBgImg; + String isImg; + + Right({this.commissionText, this.commissionFontColor, this.commissionBgColor, this.commissionBgImg, this.isImg}); + + Right.fromJson(Map json) { + commissionText = json['commission_text']; + commissionFontColor = json['commission_font_color']; + commissionBgColor = json['commission_bg_color']; + commissionBgImg = json['commission_bg_img']; + isImg = json['is_img']; + } + + Map toJson() { + final Map data = new Map(); + data['commission_text'] = this.commissionText; + data['commission_font_color'] = this.commissionFontColor; + data['commission_bg_color'] = this.commissionBgColor; + data['commission_bg_img'] = this.commissionBgImg; + data['is_img'] = this.isImg; + return data; + } +} + +class Bottom { + String bgColor; + String leftText; + String leftColor; + String rightText; + String rightColor; + + Bottom({this.bgColor, this.leftText, this.leftColor, this.rightText, this.rightColor}); + + Bottom.fromJson(Map json) { + bgColor = json['bg_color']; + leftText = json['left_text']; + leftColor = json['left_color']; + rightText = json['right_text']; + rightColor = json['right_color']; + } + + Map toJson() { + final Map data = new Map(); + data['bg_color'] = this.bgColor; + data['left_text'] = this.leftText; + data['left_color'] = this.leftColor; + data['right_text'] = this.rightText; + data['right_color'] = this.rightColor; + return data; + } +} + +class ConfirmDialog { + String bgText; + String bgTextColor; + String bgColor; + String leftText; + String leftTextColor; + String leftBtnBgColor; + String rightText; + String rightTextColor; + String rightBtnBgColor; + + ConfirmDialog({this.bgText, this.bgTextColor, this.bgColor, this.leftText, this.leftTextColor, this.leftBtnBgColor, this.rightText, this.rightTextColor, this.rightBtnBgColor}); + + ConfirmDialog.fromJson(Map json) { + bgText = json['bg_text']; + bgTextColor = json['bg_text_color']; + bgColor = json['bg_color']; + leftText = json['left_text']; + leftTextColor = json['left_text_color']; + leftBtnBgColor = json['left_btn_bg_color']; + rightText = json['right_text']; + rightTextColor = json['right_text_color']; + rightBtnBgColor = json['right_btn_bg_color']; + } + + Map toJson() { + final Map data = new Map(); + data['bg_text'] = this.bgText; + data['bg_text_color'] = this.bgTextColor; + data['bg_color'] = this.bgColor; + data['left_text'] = this.leftText; + data['left_text_color'] = this.leftTextColor; + data['left_btn_bg_color'] = this.leftBtnBgColor; + data['right_text'] = this.rightText; + data['right_text_color'] = this.rightTextColor; + data['right_btn_bg_color'] = this.rightBtnBgColor; + return data; + } +} diff --git a/lib/pages/favorites_page/notifier/favorites_page_notifier.dart b/lib/pages/favorites_page/notifier/favorites_page_notifier.dart new file mode 100644 index 0000000..7920fcb --- /dev/null +++ b/lib/pages/favorites_page/notifier/favorites_page_notifier.dart @@ -0,0 +1,44 @@ +import 'package:flutter/material.dart'; +import 'package:zhiying_comm/util/empty_util.dart'; + +class FavoritesPageNotifier with ChangeNotifier { + /// 是否是编辑中 + bool isEditing = false; + + /// 搜索关键字 + String keyword; + + int selectIndex = 0; + + /// 用于区分是编辑还是搜索 + bool editingTypeTag = true; + + /// 用于区分是否修改 + // int changeVal = 0; + + /// 选中的下标 + void changeSelectIndex(int index){ + this.selectIndex = index; + // ++changeVal; + notifyListeners(); + } + + /// 编辑 + void editing() { + this.editingTypeTag = true; + this.isEditing = !isEditing; + // ++changeVal; + notifyListeners(); + } + + /// 搜索 + void search(String keyword) { + // if (!EmptyUtil.isEmpty(keyword)) { + this.editingTypeTag = false; + this.keyword = keyword; + // ++changeVal; + notifyListeners(); + // } + } + +} diff --git a/lib/register.dart b/lib/register.dart index 8708633..158ad42 100644 --- a/lib/register.dart +++ b/lib/register.dart @@ -1,6 +1,6 @@ import 'package:sharesdk_plugin/sharesdk_interface.dart'; import 'package:sharesdk_plugin/sharesdk_register.dart'; -import 'package:zhiying_base_widget/pages/favorite_page/favorite_page.dart'; + import 'package:zhiying_base_widget/pages/feedback_page/feedback_page.dart'; import 'package:zhiying_base_widget/pages/goods_details_page/goods_details_page.dart'; import 'package:zhiying_base_widget/pages/home_page/home_page.dart'; @@ -52,6 +52,7 @@ import 'package:zhiying_base_widget/widgets/wallet/wallet_income/wallet_income.d import 'package:zhiying_comm/util/defalut_widget_creater.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; +import 'pages/favorites_page/favorites_page.dart'; import 'pages/message_notice_page/message_notice_page.dart'; import 'pages/search_page/search_page.dart'; import 'pages/wallet_page/wallet_page.dart'; @@ -142,7 +143,7 @@ class BaseWidgetRegister { // 邀请好友 PageFactory.regist( 'pub.flutter.invite_friends', (model) => InvitedFriendsPage(model)); - PageFactory.regist('pub.flutter.fav', (model) => FavoritePage()); + /// 我的团队 PageFactory.regist('pub.flutter.my_team', (model) => TeamPage(model)); @@ -154,6 +155,9 @@ class BaseWidgetRegister { /// 消息中心 PageFactory.regist( 'pub.flutter.message_center', (model) => MessageNoticePage(model)); + + /// 我的收藏 + PageFactory.regist('pub.flutter.my_fav', (model) => FavoritesPage()); } // 注册控件 diff --git a/lib/widgets/favorites/dialog/favorites_dialog_widget.dart b/lib/widgets/favorites/dialog/favorites_dialog_widget.dart new file mode 100644 index 0000000..39ecb24 --- /dev/null +++ b/lib/widgets/favorites/dialog/favorites_dialog_widget.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/pages/favorites_page/model/favorites_style_model.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class FavoritesDialogWidget extends StatelessWidget { + ConfirmDialog styleModel; + + FavoritesDialogWidget({@required this.styleModel}); + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.transparent, + body: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + width: double.infinity, + padding: const EdgeInsets.only(top: 30, left: 17, right: 17, bottom: 12.5), + decoration: BoxDecoration(color: HexColor.fromHex(styleModel?.bgColor ?? '#FFFFFF'), borderRadius: BorderRadius.circular(8)), + margin: EdgeInsets.only(left: 46, right: 46), + child: Column( + children: [ + /// 标题 + Text(styleModel?.bgText, style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: HexColor.fromHex(styleModel?.bgTextColor ?? '#333333'))), + const SizedBox(height: 44), + Row( + children: [ + Flexible(flex: 1, child: _buildCustomerButtonWidget( + text: styleModel?.leftText ?? '我在想想', + textColor:styleModel?.leftTextColor ?? '#FF4242', + bgColor: styleModel?.leftBtnBgColor ?? '#FFFFFF', + borderColor: styleModel?.leftTextColor ?? '#FF4242', + callback: ()=> Navigator.maybePop(context, 0), + )), + const SizedBox(width: 14), + Flexible(flex: 1, child: _buildCustomerButtonWidget( + text: styleModel?.rightText ?? '确认删除', + textColor: styleModel?.rightTextColor ?? '#FFFFFF', + borderColor: styleModel?.rightTextColor ?? '#FFFFFF', + bgColor: styleModel?.rightBtnBgColor ?? '#FF4242', + callback: ()=> Navigator.maybePop(context, 1), + )), + ], + ) + ], + ), + ) + ], + ), + ); + } + + Widget _buildCustomerButtonWidget({String text, String textColor, String bgColor, String borderColor,GestureTapCallback callback, double height = 30}) { + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: callback, + child: Container( + alignment: Alignment.center, + height: height, + width: double.infinity, + decoration: BoxDecoration( + color: HexColor.fromHex(bgColor), + borderRadius: BorderRadius.circular(height / 2), + border: Border.all(color: HexColor.fromHex(borderColor), width: 0.5), + ), + child: Text( + text ?? '', + style: TextStyle(color: HexColor.fromHex(textColor), fontSize: 13), + ), + ), + ); + } +} diff --git a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart new file mode 100644 index 0000000..4ca4489 --- /dev/null +++ b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart @@ -0,0 +1,173 @@ +import 'dart:async'; + +import 'package:bloc/bloc.dart'; +import 'package:flutter/material.dart'; +import 'package:meta/meta.dart'; +import 'package:zhiying_base_widget/widgets/favorites/goods_list/model/favorites_goods_list_model.dart'; +import 'package:zhiying_base_widget/widgets/home/home_goods/models/home_goods_model.dart'; +import 'package:zhiying_comm/util/empty_util.dart'; + +import 'favorites_goods_list_repository.dart'; + +part 'favorites_goods_list_event.dart'; + +part 'favorites_goods_list_state.dart'; + +class FavoritesGoodsListBloc extends Bloc { + @override + FavoritesGoodsListState get initialState => FavoritesGoodsListInitial(); + + FavoritesGoodsListRepository repository; + + FavoritesGoodsListBloc(this.repository); + + @override + Stream mapEventToState( + FavoritesGoodsListEvent event, + ) async* { + /// 初始化数据 + if (event is FavoritesGoodsListInitEvent) { + yield* _mapInitEventToState(event); + } + + /// 下拉刷新 + if (event is FavoritesGoodsListOnRefreshEvent) { + yield* _mapOnRefreshEventToState(event); + } + + /// 上拉更多 + if (event is FavoritesGoodsListOnLoadEvent) { + yield* _mapOnLoadEventToState(event); + } + + /// 删除 + if (event is FavoritesGoodsListDeleteEvent) { + yield* _mapDeleteEventToState(event); + } + + /// 搜索 + if (event is FavoritesGoodsListSearchEvent) { + yield* _mapSearchEventToState(event); + } + + /// 单个商品选中 + if(event is FavoritesGoodsListSignGoodsSelectEvent){ + yield* _mapSelectSignEventToState(event); + } + + /// 所有商品选中 + if(event is FavoritesGoodsListGoodsSelectAllEvent){ + yield* _mapSelectAllEventToState(event); + } + + if(event is FavoritesGoodsListGoodsCancelAllEvent){ + yield* _mapCancelAllEventToState(event); + } + + // /// 切换样式 + // if (event is FavoritesGoodsListChangeStyleEvent) { + // yield* _mapChangeStyleEventToState(event); + // } + } + + /// 初始化数据 + Stream _mapInitEventToState(FavoritesGoodsListInitEvent event) async* { + var result = await repository.fetchInit(); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListInitErrorState(); + } + } + + /// 下拉刷新 + Stream _mapOnRefreshEventToState(FavoritesGoodsListOnRefreshEvent event) async* { + var result = await repository.fetchRefresh(); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListRefreshSuccessState(); + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListRefreshErrorState(); + yield FavoritesGoodsListErrorState(); + } + } + + /// 上拉更多 + Stream _mapOnLoadEventToState(FavoritesGoodsListOnLoadEvent event) async* { + var result = await repository.fetchLoad(); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListLoadSuccessState(); + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListLoadErrorState(); + yield FavoritesGoodsListErrorState(); + } + } + + /// 删除 + Stream _mapDeleteEventToState(FavoritesGoodsListDeleteEvent event) async* { + int length = repository.getSelectLength(); + if(length > 0) { + var result = await repository.delete(); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListErrorState(); + } + }else{ + yield FavoritesGoodsListNotSelectState(); + } + } + + /// 搜索 + Stream _mapSearchEventToState(FavoritesGoodsListSearchEvent event) async* { + var result = await repository.search(event.keyword); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListInitErrorState(); + } + } + + /// 所有商品选中 + Stream _mapSelectAllEventToState(FavoritesGoodsListGoodsSelectAllEvent event) async*{ + var result = await repository.selectAllData(); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListErrorState(); + } + } + + /// 商品的全部取消 + Stream _mapCancelAllEventToState(FavoritesGoodsListGoodsCancelAllEvent event) async*{ + var result = await repository.cancelSelectAllData(); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListErrorState(); + } + } + + /// 单个商品选中 + Stream _mapSelectSignEventToState(FavoritesGoodsListSignGoodsSelectEvent event) async*{ + var result = await repository.signSelectData(event.index); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListErrorState(); + } + } + + + + // /// 切换样式 + // Stream _mapChangeStyleEventToState(FavoritesGoodsListChangeStyleEvent event) async* { + // var result = await repository.fetchInit(); + // if (!EmptyUtil.isEmpty(result)) { + // yield FavoritesGoodsListLoadedState(dataModel: result); + // } else { + // yield FavoritesGoodsListInitErrorState(); + // } + // } +} diff --git a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart new file mode 100644 index 0000000..d687a76 --- /dev/null +++ b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart @@ -0,0 +1,39 @@ +part of 'favorites_goods_list_bloc.dart'; + +@immutable +abstract class FavoritesGoodsListEvent {} + + +/// 初始化数据 +class FavoritesGoodsListInitEvent extends FavoritesGoodsListEvent {} + +/// 下拉刷新 +class FavoritesGoodsListOnRefreshEvent extends FavoritesGoodsListEvent {} + +/// 上拉更多 +class FavoritesGoodsListOnLoadEvent extends FavoritesGoodsListEvent {} + +/// 关键字搜索 +class FavoritesGoodsListSearchEvent extends FavoritesGoodsListEvent { + final String keyword; + FavoritesGoodsListSearchEvent(this.keyword); +} + +/// 删除 +class FavoritesGoodsListDeleteEvent extends FavoritesGoodsListEvent {} + +/// 切换样式 +class FavoritesGoodsListChangeStyleEvent extends FavoritesGoodsListEvent{} + +/// 商品的当个选中 +class FavoritesGoodsListSignGoodsSelectEvent extends FavoritesGoodsListEvent{ + // final FavoritesGoodsListItemModel model; + final int index; + FavoritesGoodsListSignGoodsSelectEvent(this.index); +} + +/// 商品的全选 +class FavoritesGoodsListGoodsSelectAllEvent extends FavoritesGoodsListEvent{} + +/// 商品的全部取消 +class FavoritesGoodsListGoodsCancelAllEvent extends FavoritesGoodsListEvent{} \ No newline at end of file diff --git a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart new file mode 100644 index 0000000..42d3572 --- /dev/null +++ b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart @@ -0,0 +1,161 @@ +import 'package:flutter/cupertino.dart'; +import 'package:zhiying_base_widget/widgets/favorites/goods_list/model/favorites_goods_list_model.dart'; +import 'package:zhiying_base_widget/widgets/home/home_goods/models/home_goods_model.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class FavoritesGoodsListRepository { + String type; + + final int _MAX = 5; + int _currentPage = 1; + bool _hasMoreData = true; + + FavoritesGoodsListDataModel _oldData = new FavoritesGoodsListDataModel(); + Map _selectIndex = {}; + + FavoritesGoodsListRepository({this.type = 'all'}); + + String keyword; + + /// 返回选中的商品长度 + int getSelectLength() { + return _selectIndex.length; + } + + /// 选中所有 + Future selectAllData() async { + _selectIndex.clear(); + int index = 0; + _oldData.lists.forEach((element) { + element.isSelect = true; + _selectIndex[index] = index; + ++index; + }); + _oldData.isAllSelect = true; + return _oldData; + } + + /// 单个选中状态 + Future signSelectData(final int selectIndex) async { + _oldData.lists[selectIndex].isSelect = !_oldData.lists[selectIndex].isSelect; + + if (_oldData.lists[selectIndex].isSelect) { + // 新增 + _selectIndex[selectIndex] = selectIndex; + } else { + // 移除 + _selectIndex.remove(selectIndex); + } + _oldData.isAllSelect = false; + if (_selectIndex.length == _oldData.lists.length) { + _oldData.isAllSelect = true; + } + return _oldData; + } + + /// 取消选中所有 or 重置选中状态 + Future cancelSelectAllData() async { + _selectIndex.clear(); + _oldData.lists.forEach((element) { + element.isSelect = false; + }); + _oldData.isAllSelect = false; + return _oldData; + } + + /// 关键字搜索 + Future search(String keyword) async { + try { + _selectIndex.clear(); + _oldData.lists.clear(); + _currentPage = 1; + _hasMoreData = true; + + this.keyword = keyword; + return _baseRequest(); + } catch (e, s) { + Logger.error(e, s); + } + return null; + } + + /// 删除数据 + Future delete() async { + try { + // Logger.log('select Index length = ${_selectIndex.length}'); + if (_selectIndex.length > 0) { + List gids = []; + _selectIndex.forEach((key, value) { + gids.add(_oldData.lists[value].goodId); + }); + var result = await NetUtil.post('/api/v1/user/myfav/delete', params: {'gids': gids}, method: NetMethod.POST); + if (NetUtil.isSuccess(result)) { + List tempList = []; + // TODO 这里有问题:移除删除 + for (int i = 0; i < _oldData.lists.length; i++) { + if (!_selectIndex.containsKey(i)) { + tempList.add(_oldData.lists[i]); + } + } + _oldData.lists.clear(); + _selectIndex.clear(); + _oldData.isAllSelect = false; + _oldData.lists = tempList; + return _oldData; + } + } + } catch (e, s) { + Logger.error(e, s); + } + return null; + } + + /// 初始化请求 + Future fetchInit() async { + _currentPage = 1; + _hasMoreData = true; + _oldData?.lists?.clear(); + _selectIndex.clear(); + _oldData.isAllSelect = false; + return _baseRequest(); + } + + /// 下拉刷新 + Future fetchRefresh() async { + return fetchInit(); + } + + /// 上拉更多 + Future fetchLoad() async { + if (_hasMoreData) { + return _baseRequest(); + } + return null; + } + + /// 基础请求 + Future _baseRequest() async { + try { + var result; + if(EmptyUtil.isEmpty(keyword)) { + result = await NetUtil.post('/api/v1/user/myfav/$type?page=${_currentPage.toString()}', params: {}, method: NetMethod.GET); + }else{ + result = await NetUtil.post('/api/v1/user/myfav/s', params: {'keyword': keyword}, method: NetMethod.POST); + } + if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + List data = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]; + data.forEach((element) { + _oldData.lists.add(FavoritesGoodsListItemModel.fromJson(element)); + }); + ++_currentPage; + _hasMoreData = true; + // _hasMoreData = data.length >= _MAX ? true : false; + return _oldData; + } + _hasMoreData = false; + } catch (e, s) { + Logger.error(e, s); + } + return null; + } +} diff --git a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_state.dart b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_state.dart new file mode 100644 index 0000000..fc70477 --- /dev/null +++ b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_state.dart @@ -0,0 +1,35 @@ +part of 'favorites_goods_list_bloc.dart'; + +@immutable +abstract class FavoritesGoodsListState {} + +/// 初始化状态(骨架图) +class FavoritesGoodsListInitial extends FavoritesGoodsListState {} + +/// 初始化失败状态(空数据) +class FavoritesGoodsListInitErrorState extends FavoritesGoodsListState {} + +/// 下拉刷新失败状态 +class FavoritesGoodsListRefreshErrorState extends FavoritesGoodsListState {} + +/// 下拉刷新成功状态 +class FavoritesGoodsListRefreshSuccessState extends FavoritesGoodsListState {} + +/// 上拉更多失败状态 +class FavoritesGoodsListLoadErrorState extends FavoritesGoodsListState {} + +/// 上拉更多成功状态 +class FavoritesGoodsListLoadSuccessState extends FavoritesGoodsListState {} + +/// 数据加载成功 +class FavoritesGoodsListLoadedState extends FavoritesGoodsListState { + // List dataModel; + FavoritesGoodsListDataModel dataModel; + FavoritesGoodsListLoadedState({@required this.dataModel}); +} + +/// 没选中 +class FavoritesGoodsListNotSelectState extends FavoritesGoodsListState{} + +/// 未知错误 +class FavoritesGoodsListErrorState extends FavoritesGoodsListState {} diff --git a/lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart b/lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart new file mode 100644 index 0000000..7f3bb6c --- /dev/null +++ b/lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart @@ -0,0 +1,325 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; +import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart'; +import 'package:zhiying_base_widget/pages/favorites_page/model/favorites_style_model.dart'; +import 'package:zhiying_base_widget/pages/favorites_page/notifier/favorites_page_notifier.dart'; +import 'package:zhiying_base_widget/widgets/favorites/dialog/favorites_dialog_widget.dart'; +import 'package:zhiying_base_widget/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart'; +import 'package:zhiying_base_widget/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart'; +import 'package:zhiying_base_widget/widgets/home/home_goods/home_goods_item_single.dart'; +import 'package:zhiying_base_widget/widgets/home/home_goods/models/home_goods_style_model.dart'; +import 'package:zhiying_base_widget/widgets/home/home_goods/skeleton/home_goods_sk.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:provider/provider.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +import 'model/favorites_goods_list_model.dart'; + +class FavoritesGoodsListWidget extends StatelessWidget { + FavoritesStyleModel model; + String type; + int currentIndex; + + FavoritesGoodsListWidget({@required this.model, @required this.type, this.currentIndex = 0}); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (_) => FavoritesGoodsListBloc(FavoritesGoodsListRepository(type: type)), + child: _FavoritesGoodsListWidgetContainer(model, currentIndex), + ); + } +} + +class _FavoritesGoodsListWidgetContainer extends StatefulWidget { + FavoritesStyleModel styleModel; + int currentIndex; + + _FavoritesGoodsListWidgetContainer(this.styleModel, this.currentIndex); + + @override + __FavoritesGoodsListWidgetContainerState createState() => __FavoritesGoodsListWidgetContainerState(); +} + +class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsListWidgetContainer> with AutomaticKeepAliveClientMixin { + RefreshController _refreshController; + + // 是否编辑中 + bool isEditing = false; + int lastChangeVal = -1; + + /// 下拉刷新 + void _onRefresh() async { + BlocProvider.of(context).add(FavoritesGoodsListOnRefreshEvent()); + } + + /// 上拉更多 + void _onLoad() async { + BlocProvider.of(context).add(FavoritesGoodsListOnLoadEvent()); + } + + /// 商品点击选中 + void _onClickGoods(int index){ + BlocProvider.of(context).add(FavoritesGoodsListSignGoodsSelectEvent(index)); + } + + /// 全选 + void _onClickAllSelecct(FavoritesGoodsListDataModel dataModel) { + + if(!dataModel.isAllSelect) { + BlocProvider.of(context).add(FavoritesGoodsListGoodsSelectAllEvent()); + }else{ + BlocProvider.of(context).add(FavoritesGoodsListGoodsCancelAllEvent()); + } + } + + /// 点击删除 + void _onClickDelete(ConfirmDialog styleModel) async { + + // + var result = await showDialog(context: context, child: FavoritesDialogWidget(styleModel: styleModel,)); + if(result == 1){ + BlocProvider.of(context).add(FavoritesGoodsListDeleteEvent()); + } + } + + @override + bool get wantKeepAlive => true; + + @override + void initState() { + _refreshController = RefreshController(); + BlocProvider.of(context).add(FavoritesGoodsListInitEvent()); + super.initState(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + FavoritesPageNotifier favoritesPageNotifier = Provider.of(context); + + if (null != favoritesPageNotifier) { + isEditing = favoritesPageNotifier.isEditing; + if(favoritesPageNotifier.editingTypeTag) { + + // BlocProvider.of(context).add(FavoritesGoodsListGoodsCancelAllEvent()); + }else{ + // if(favoritesPageNotifier.selectIndex == widget.currentIndex) { + BlocProvider.of(context).add(FavoritesGoodsListSearchEvent(favoritesPageNotifier?.keyword)); + // } + } + } + } + + @override + void dispose() { + _refreshController?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Listener( + onPointerDown: (down)=> RouterUtil.hideKeyboard(context), + child: Container( + color: HexColor.fromHex('#F9F9F9'), + child: BlocConsumer( + listener: (context, state) {}, + buildWhen: (prev, current) { + if (current is FavoritesGoodsListRefreshSuccessState) { + _refreshController?.refreshCompleted(resetFooterState: true); + return false; + } + if (current is FavoritesGoodsListRefreshErrorState) { + _refreshController?.refreshFailed(); + return false; + } + if (current is FavoritesGoodsListLoadSuccessState) { + _refreshController?.loadComplete(); + return false; + } + if (current is FavoritesGoodsListLoadErrorState) { + _refreshController?.loadNoData(); + return false; + } + if (current is FavoritesGoodsListErrorState) { + return false; + } + if(current is FavoritesGoodsListNotSelectState){ + Fluttertoast.showToast(msg: '请选择需要删除的商品~'); + return false; + } + return true; + }, + builder: (context, state) { + /// 初始化失败,空数据 + if (state is FavoritesGoodsListInitErrorState) { + return _buildEmptyWidget(widget?.styleModel); + } + + /// 数据加载成功 + if (state is FavoritesGoodsListLoadedState) { + // Logger.log('__FavoritesGoodsListWidgetContainerState ==== 刷新 size = ${state?.dataModel?.lists?.length}'); + return _buildGoodsListWidget(widget?.styleModel, state?.dataModel); + } + + /// 骨架图 + return _buildSkeletonWidget(widget?.styleModel); + }, + ), + ), + ); + } + + /// 有数据返回 + Widget _buildGoodsListWidget(FavoritesStyleModel styleModel, FavoritesGoodsListDataModel dataModel) { + + + /// 如果数据删除了,则返回空视图 + int length = dataModel?.lists?.length ?? 0; + if(length == 0) return _buildEmptyWidget(styleModel); + + return Stack( + children: [ + /// 数据 + SmartRefresher( + controller: _refreshController, + onRefresh: _onRefresh, + onLoading: _onLoad, + enablePullUp: true, + enablePullDown: true, + child: ListView.builder( + padding: EdgeInsets.only(top: 7.5, left: 12.5, right: isEditing ? 0 : 12.5), + itemCount: dataModel.lists.length, + itemBuilder: (context, index) { + FavoritesGoodsListItemModel item = dataModel.lists[index]; + return Row( + children: [ + Visibility( + visible: isEditing , + child: GestureDetector( + onTap: ()=> _onClickGoods(index), + behavior: HitTestBehavior.opaque, + child: Container( + height: 20, + width: 20, + margin: const EdgeInsets.only(right: 8), + child: CachedNetworkImage( + imageUrl: item.isSelect ? styleModel?.editLeftConfirmIcon : styleModel?.editLeftNoConfirmIcon, + ), + ), + ), + ), + Expanded( + child: HomeGoodsItemSingle( + item, + HomeGoodsStyleModel()..listStyle = styleModel?.listStyle, + marginBottom: 0, + marginLeft: 0, + marginRight: 0, + marginTop: 0, + ), + ) + ], + ); + }), + ), + + /// 编辑 + _buildEditrWidget(widget?.styleModel, dataModel), + ], + ); + } + + /// 编辑的底部Widget + Widget _buildEditrWidget(FavoritesStyleModel styleModel, FavoritesGoodsListDataModel dataModel) { + return Align( + alignment: Alignment.bottomCenter, + child: Visibility( + visible: isEditing , + child: Container( + padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 15.5, bottom: 15.5), + width: double.infinity, + decoration: BoxDecoration( + color: HexColor.fromHex(styleModel?.bottom?.bgColor ?? '#FFFFFF'), borderRadius: BorderRadius.only(topRight: Radius.circular(10), topLeft: Radius.circular(10))), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + GestureDetector( + onTap: () => _onClickAllSelecct(dataModel), + behavior: HitTestBehavior.opaque, + child: Row( + children: [ + Visibility( + visible: dataModel?.isAllSelect ?? false, + replacement: Container( + width: 20, + height: 20, + decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), border: Border.all(color: HexColor.fromHex('#DCDCDC'), width: 0.5)), + ), + child: Container( + height: 20, + width: 20, + child: CachedNetworkImage(imageUrl: styleModel?.editLeftConfirmIcon ?? '',), + ), + ), + const SizedBox(width: 8), + Text( + styleModel?.bottom?.leftText ?? '全选', + style: TextStyle( + fontSize: 15, + color: HexColor.fromHex(styleModel?.bottom?.leftColor ?? '#333333'), + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + GestureDetector( + onTap: () => _onClickDelete(styleModel?.confirmDialog), + behavior: HitTestBehavior.opaque, + child: Text( + styleModel?.bottom?.rightText ?? '删除', + style: TextStyle( + fontSize: 15, + color: HexColor.fromHex(styleModel?.bottom?.rightColor ?? '#FF4242'), + fontWeight: FontWeight.bold, + ), + ), + ), + ], + ), + ), + ), + ); + } + + /// 空数据 + Widget _buildEmptyWidget(FavoritesStyleModel styleModel) { + return SmartRefresher( + controller: _refreshController, + onRefresh: _onRefresh, + enablePullDown: true, + enablePullUp: false, + child: Column( + children: [ + const SizedBox(height: 80), + CachedNetworkImage(imageUrl: styleModel?.tabItemNotFoundImg ?? '', width: 188), + const SizedBox(height: 22), + Text( + '暂时没有商品噢\n快去浏览收藏吧', + style: TextStyle(fontSize: 15, color: HexColor.fromHex('#999999')), + ) + ], + ), + ); + } + + /// 骨架图 + Widget _buildSkeletonWidget(FavoritesStyleModel styleModel) { + return HomeGoodsSkeleton(); + } +} diff --git a/lib/widgets/favorites/goods_list/model/favorites_goods_list_model.dart b/lib/widgets/favorites/goods_list/model/favorites_goods_list_model.dart new file mode 100644 index 0000000..4f5977f --- /dev/null +++ b/lib/widgets/favorites/goods_list/model/favorites_goods_list_model.dart @@ -0,0 +1,37 @@ +import 'package:zhiying_base_widget/widgets/home/home_goods/models/home_goods_model.dart'; + +// ignore: must_be_immutable + +class FavoritesGoodsListDataModel { + // 是否全选 + bool isAllSelect = false; + + List lists = []; + + // FavoritesGoodsListDataModel({this.isEditing, this.isAllSelect, this.lists }); + FavoritesGoodsListDataModel(); + + FavoritesGoodsListDataModel.fromJson(Map json) { + isAllSelect = json['isAllSelect'] ?? false; + if(json['data'] != null){ + json['data'].forEach((v){ + lists.add(new FavoritesGoodsListItemModel.fromJson(v)); + }); + } + } +} + +class FavoritesGoodsListItemModel extends HomeGoodsModel { + bool isSelect; + + FavoritesGoodsListItemModel.fromJson(Map json) { + super.fromJson(json); + isSelect = json['isSelect'] ?? false; + } + + Map toJson() { + final Map data = super.toJson(); + data['isSelect'] = this.isSelect; + return data; + } +} diff --git a/lib/widgets/goods_details/footer/bloc/goods_details_footer_bloc.dart b/lib/widgets/goods_details/footer/bloc/goods_details_footer_bloc.dart index a73b0b1..1852fee 100644 --- a/lib/widgets/goods_details/footer/bloc/goods_details_footer_bloc.dart +++ b/lib/widgets/goods_details/footer/bloc/goods_details_footer_bloc.dart @@ -27,11 +27,22 @@ class GoodsDetailsFooterBloc extends Bloc _mapInitEventToState(GoodsDetailsFooterInitEvent event) async* { - var result = await repository.fetchParentData(event.model); + var result = await repository.fetchParentData(event?.model); if (!EmptyUtil.isEmpty(result)) { print('result = ${result.toString()}'); yield GoodsDetailsFooterLoadedState(model: result); @@ -42,10 +53,20 @@ class GoodsDetailsFooterBloc extends Bloc _mapCollectEventToState(GoodsDetailsFooterCollectEvent event) async* { - var result = await repository.fetchCollect(); + var result = await repository.fetchCollect(event?.model); if (!EmptyUtil.isEmpty(result)) yield GoodsDetailsFooterLoadedState(model: result); else yield GoodsDetailsFooterErrorState(); } + + /// 取消收藏 + Stream _mapDeleteCollectEventToState(GoodsDetailsFooterDeleteCollectEvent event ) async*{ + var result = await repository.fetchDeleteCollect(event?.model); + if(!EmptyUtil.isEmpty(result)) + yield GoodsDetailsFooterLoadedState(model: result); + else + yield GoodsDetailsFooterErrorState(); + } + } diff --git a/lib/widgets/goods_details/footer/bloc/goods_details_footer_event.dart b/lib/widgets/goods_details/footer/bloc/goods_details_footer_event.dart index 6f9f44b..185e857 100644 --- a/lib/widgets/goods_details/footer/bloc/goods_details_footer_event.dart +++ b/lib/widgets/goods_details/footer/bloc/goods_details_footer_event.dart @@ -19,5 +19,20 @@ class GoodsDetailsFooterInitEvent extends GoodsDetailsFooterEvent { /// 点击收藏 class GoodsDetailsFooterCollectEvent extends GoodsDetailsFooterEvent { + final Map model; + + GoodsDetailsFooterCollectEvent({@required this.model}); + + @override + List get props => [this.model]; +} +/// 取消收藏 +class GoodsDetailsFooterDeleteCollectEvent extends GoodsDetailsFooterEvent { + final Map model; + + GoodsDetailsFooterDeleteCollectEvent({@required this.model}); + + @override + List get props => [this.model]; } diff --git a/lib/widgets/goods_details/footer/bloc/goods_details_footer_repository.dart b/lib/widgets/goods_details/footer/bloc/goods_details_footer_repository.dart index e34a8c5..f635d0c 100644 --- a/lib/widgets/goods_details/footer/bloc/goods_details_footer_repository.dart +++ b/lib/widgets/goods_details/footer/bloc/goods_details_footer_repository.dart @@ -4,18 +4,50 @@ import 'package:zhiying_base_widget/widgets/goods_details/footer/model/goods_det import 'package:zhiying_comm/zhiying_comm.dart'; class GoodsDetailsFooterRepository { + + GoodsDetailsFooterModel _oldmodel; + /// 初始化数据 Future fetchParentData(final Map model) async { try { - return GoodsDetailsFooterModel.fromJson(jsonDecode(model['data'])); - } catch (e) { - Logger.log('GoodsDetailsFooterRepository e = $e'); + GoodsDetailsFooterModel data = GoodsDetailsFooterModel.fromJson(jsonDecode(model['data'])); + _oldmodel = data; + return data; + } catch (e, s) { + Logger.error(e, s); } return null; } /// 点击收藏 - Future fetchCollect() async{ + Future fetchCollect(final Map model) async { + try { + if (!EmptyUtil.isEmpty(model)) { + var result = await NetUtil.post('/api/v1/user/myfav', params: model, method: NetMethod.POST); + if(NetUtil.isSuccess(result)){ + _oldmodel.isFav = '1'; + return _oldmodel; + } + } + } catch (e, s) { + Logger.error(e, s); + } + return null; + } + + /// 取消收藏 + Future fetchDeleteCollect(final Map model) async{ + try{ + if(!EmptyUtil.isEmpty(model)){ + var result = await NetUtil.post('/api/v1/user/myfav/delete', params: {'gids':[model['good_id']]}, method: NetMethod.POST); + if(NetUtil.isSuccess(result)){ + _oldmodel.isFav = '0'; + return _oldmodel; + } + } + }catch(e, s){ + Logger.error(e,s); + } return null; } diff --git a/lib/widgets/goods_details/footer/bloc/goods_details_footer_state.dart b/lib/widgets/goods_details/footer/bloc/goods_details_footer_state.dart index ae3ae2d..99d7817 100644 --- a/lib/widgets/goods_details/footer/bloc/goods_details_footer_state.dart +++ b/lib/widgets/goods_details/footer/bloc/goods_details_footer_state.dart @@ -1,15 +1,15 @@ part of 'goods_details_footer_bloc.dart'; -abstract class GoodsDetailsFooterState extends Equatable { +abstract class GoodsDetailsFooterState { const GoodsDetailsFooterState(); - @override - List get props => []; + // @override + // List get props => []; } class GoodsDetailsFooterInitial extends GoodsDetailsFooterState { - @override - List get props => []; + // @override + // List get props => []; } /// 数据加载完毕 @@ -18,8 +18,8 @@ class GoodsDetailsFooterLoadedState extends GoodsDetailsFooterState { GoodsDetailsFooterLoadedState({@required this.model}); - @override - List get props => [this.model]; + // @override + // List get props => [this.model]; } /// 数据加载出错 diff --git a/lib/widgets/goods_details/footer/goods_details_footer_widget.dart b/lib/widgets/goods_details/footer/goods_details_footer_widget.dart index dcf400d..0c8c826 100644 --- a/lib/widgets/goods_details/footer/goods_details_footer_widget.dart +++ b/lib/widgets/goods_details/footer/goods_details_footer_widget.dart @@ -75,7 +75,14 @@ class _GooddsDetailsFooterContainerState } /// 收藏 - void _collectOnClick() {} + void _collectOnClick(GoodsDetailsFooterModel model) { + bool isCollect = model.isFav == '0'; + if(isCollect){ // 收藏 + BlocProvider.of(context).add(GoodsDetailsFooterCollectEvent(model: model?.favArgs?.toJson())); + }else{ // 取消收藏 + BlocProvider.of(context).add(GoodsDetailsFooterDeleteCollectEvent(model: model?.favArgs?.toJson())); + } + } /// 分享 void _shareOnClick(GoodsDetailsFooterModel model) async { @@ -221,13 +228,13 @@ class _GooddsDetailsFooterContainerState )), GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () => _collectOnClick(), + onTap: () => _collectOnClick(model), child: Padding( padding: const EdgeInsets.only(right: 0), child: _getCustomWidget( model?.collect ?? '收藏', model?.collect_color ?? '999999', - model?.collect_icon ?? ''))) + model?.isFav == '0' ? model?.collect_icon ?? '' : model?.collected_icon ?? ''))) ], ); } diff --git a/lib/widgets/goods_details/footer/model/goods_details_footer_model.dart b/lib/widgets/goods_details/footer/model/goods_details_footer_model.dart index 1ba8d57..25c7224 100644 --- a/lib/widgets/goods_details/footer/model/goods_details_footer_model.dart +++ b/lib/widgets/goods_details/footer/model/goods_details_footer_model.dart @@ -2,6 +2,7 @@ class GoodsDetailsFooterModel { String collect; String collect_color; String collect_icon; + String collected_icon; String home; String home_color; String home_icon; @@ -18,28 +19,46 @@ class GoodsDetailsFooterModel { String share_value; String self_buy_value; - GoodsDetailsFooterModel( - {this.collect, - this.collect_color, - this.collect_icon, - this.home, - this.home_color, - this.home_icon, - this.save_earn, - this.save_earn_bg1_color, - this.save_earn_bg2_color, - this.save_earn_color, - this.save_earn_val_color, - this.share_earn, - this.share_earn_bg1_color, - this.share_earn_bg2_color, - this.share_earn_color, - this.share_earn_val_color, - this.share_value, - this.self_buy_value}); + String isFav; + String buyUrl; + String shareUrl; + FavArgs favArgs; + ShareUrlArgs shareUrlArgs; + + GoodsDetailsFooterModel({ + this.buyUrl, + this.favArgs, + this.isFav, + this.shareUrl, + this.shareUrlArgs, + this.collect, + this.collect_color, + this.collect_icon, + this.home, + this.home_color, + this.home_icon, + this.save_earn, + this.save_earn_bg1_color, + this.save_earn_bg2_color, + this.save_earn_color, + this.save_earn_val_color, + this.share_earn, + this.share_earn_bg1_color, + this.share_earn_bg2_color, + this.share_earn_color, + this.share_earn_val_color, + this.share_value, + this.self_buy_value, + this.collected_icon, + }); factory GoodsDetailsFooterModel.fromJson(Map json) { return GoodsDetailsFooterModel( + isFav: json['is_fav'], + buyUrl: json['buy_url'], + shareUrl: json['share_url'], + favArgs: json['fav_args'] != null ? new FavArgs.fromJson(json['fav_args']) : null, + shareUrlArgs: json['share_url_args'] != null ? new ShareUrlArgs.fromJson(json['share_url_args']) : null, collect: json['collect'], collect_color: json['collect_color'], collect_icon: json['collect_icon'], @@ -58,6 +77,7 @@ class GoodsDetailsFooterModel { share_earn_val_color: json['share_earn_val_color'], share_value: json['share_value'], self_buy_value: json['self_buy_value'], + collected_icon: json['collected_icon'], ); } @@ -81,6 +101,120 @@ class GoodsDetailsFooterModel { data['share_earn_val_color'] = this.share_earn_val_color; data['share_value'] = this.share_value; data['self_buy_value'] = this.self_buy_value; + data['collected_icon'] = this.collected_icon; + + data['is_fav'] = this.isFav; + data['buy_url'] = this.buyUrl; + data['share_url'] = this.shareUrl; + if (this.favArgs != null) { + data['fav_args'] = this.favArgs.toJson(); + } + if (this.shareUrlArgs != null) { + data['share_url_args'] = this.shareUrlArgs.toJson(); + } + + return data; + } +} + +class FavArgs { + String provider; + String providerName; + String goodId; + String goodImage; + String goodTitle; + String shopName; + String coupon; + String couponUrl; + String commission; + String marketPrice; + String currentPrice; + String inorderCount; + Null detailData; + + FavArgs( + {this.provider, + this.providerName, + this.goodId, + this.goodImage, + this.goodTitle, + this.shopName, + this.coupon, + this.couponUrl, + this.commission, + this.marketPrice, + this.currentPrice, + this.inorderCount, + this.detailData}); + + FavArgs.fromJson(Map json) { + provider = json['provider']; + providerName = json['provider_name']; + goodId = json['good_id']; + goodImage = json['good_image']; + goodTitle = json['good_title']; + shopName = json['shop_name']; + coupon = json['coupon']; + couponUrl = json['coupon_url']; + commission = json['commission']; + marketPrice = json['market_price']; + currentPrice = json['current_price']; + inorderCount = json['inorder_count']; + detailData = json['detail_data']; + } + + Map toJson() { + final Map data = new Map(); + data['provider'] = this.provider; + data['provider_name'] = this.providerName; + data['good_id'] = this.goodId; + data['good_image'] = this.goodImage; + data['good_title'] = this.goodTitle; + data['shop_name'] = this.shopName; + data['coupon'] = this.coupon; + data['coupon_url'] = this.couponUrl; + data['commission'] = this.commission; + data['market_price'] = this.marketPrice; + data['current_price'] = this.currentPrice; + data['inorder_count'] = this.inorderCount; + data['detail_data'] = this.detailData; + return data; + } +} + +class ShareUrlArgs { + String buyUrl; + String coupon; + String couponPrice; + String marketPrice; + String posterImage; + String selfbuyCommission; + String title; + String type; + + ShareUrlArgs({this.buyUrl, this.coupon, this.couponPrice, this.marketPrice, this.posterImage, this.selfbuyCommission, this.title, this.type}); + + ShareUrlArgs.fromJson(Map json) { + buyUrl = json['buy_url']; + coupon = json['coupon']; + couponPrice = json['coupon_price']; + marketPrice = json['market_price']; + posterImage = json['poster_image']; + selfbuyCommission = json['selfbuy_commission']; + title = json['title']; + type = json['type']; + } + + Map toJson() { + final Map data = new Map(); + data['buy_url'] = this.buyUrl; + data['coupon'] = this.coupon; + data['coupon_price'] = this.couponPrice; + data['market_price'] = this.marketPrice; + data['poster_image'] = this.posterImage; + data['selfbuy_commission'] = this.selfbuyCommission; + data['title'] = this.title; + data['type'] = this.type; return data; } } diff --git a/lib/widgets/home/home_goods/home_goods_item_single.dart b/lib/widgets/home/home_goods/home_goods_item_single.dart index edcdb20..48bf7fe 100644 --- a/lib/widgets/home/home_goods/home_goods_item_single.dart +++ b/lib/widgets/home/home_goods/home_goods_item_single.dart @@ -14,8 +14,12 @@ class HomeGoodsItemSingle extends StatelessWidget { final HomeGoodsModel goods; final HomeGoodsStyleModel style; Map data; + final double marginLeft; + final double marginRight; + final double marginTop; + final double marginBottom; - HomeGoodsItemSingle(this.goods, this.style, {Key key, this.data}) + HomeGoodsItemSingle(this.goods, this.style, {Key key, this.data, this.marginBottom = 4, this.marginTop = 4, this.marginLeft= 12.5, this.marginRight = 12.5}) : super(key: key) { if (this.data != null && this.data.containsKey('data')) { String data = this.data['data']; @@ -36,7 +40,7 @@ class HomeGoodsItemSingle extends StatelessWidget { return GestureDetector( onTap: () => _onJumpGoodsDetails(context, goods), child: Container( - margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 4, bottom: 4), + margin: EdgeInsets.only(left: marginLeft, right: marginRight, top: marginTop, bottom: marginBottom), padding: EdgeInsets.all(7.5), decoration: BoxDecoration( color: Colors.white, diff --git a/lib/widgets/home/home_goods/models/home_goods_model.dart b/lib/widgets/home/home_goods/models/home_goods_model.dart index d180c9c..563b860 100644 --- a/lib/widgets/home/home_goods/models/home_goods_model.dart +++ b/lib/widgets/home/home_goods/models/home_goods_model.dart @@ -44,6 +44,21 @@ class HomeGoodsModel extends Equatable { detailData = json['detail_data']; } + void fromJson(Map json) { + provider = json['provider']; + providerName = json['provider_name']; + goodId = json['good_id']; + goodImage = json['good_image']; + goodTitle = json['good_title']; + shopName = json['shop_name']; + coupon = json['coupon']; + commission = json['commission']; + marketPrice = json['market_price']; + currentPrice = json['current_price']; + inorderCount = json['inorder_count']; + detailData = json['detail_data']; + } + Map toJson() { final Map data = new Map(); data['provider'] = this.provider;