diff --git a/lib/pages/goods_details_page/bloc/goods_details_page_bloc.dart b/lib/pages/goods_details_page/bloc/goods_details_page_bloc.dart index 81cdf21..9a5182f 100644 --- a/lib/pages/goods_details_page/bloc/goods_details_page_bloc.dart +++ b/lib/pages/goods_details_page/bloc/goods_details_page_bloc.dart @@ -30,13 +30,16 @@ class GoodsDetailsPageBloc extends Bloc _mapInitEventToState(GoodsDetailsPageInitEvent event) async* { - var result = await repository.fetchInitModData(event.model); + + // 获取上面传回来的数据 + var parendData = await repository.fetchParentPageData(event?.model); + if(!EmptyUtil.isEmpty(parendData)){ + yield GoodsDetailsPageLoadedState(model: parendData); + } + // 获取服务器的数据 + var result = await repository.fetchInitModData(event?.model); if (!EmptyUtil.isEmpty(result)) { yield GoodsDetailsPageLoadedState(model: result); - // var itemModelData = await repository.fetchModData(event.model); - // if(!EmptyUtil.isEmpty(itemModelData)){ - // yield GoodsDetailsPageLoadedState(model: itemModelData); - // } } else { yield GoodsDetailsPageErrorState(); } diff --git a/lib/pages/goods_details_page/bloc/goods_details_page_repository.dart b/lib/pages/goods_details_page/bloc/goods_details_page_repository.dart index 8beaab1..9f5e117 100644 --- a/lib/pages/goods_details_page/bloc/goods_details_page_repository.dart +++ b/lib/pages/goods_details_page/bloc/goods_details_page_repository.dart @@ -2,107 +2,161 @@ import 'dart:convert'; import 'package:zhiying_comm/zhiying_comm.dart'; class GoodsDetailsPageRepository { - - - + /// 获取上个页面传进来的数据 + Future>> fetchParentPageData(final Map model) async { + try { + if (!EmptyUtil.isEmpty(model) && model.containsKey('detail_data') && !EmptyUtil.isEmpty(model['detail_data'])) { + String provider = model['provider']?.toString(); + String goodId = model['good_id']?.toString(); + if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId)) { + Map detailData = model['detail_data']; + return _baseDataProcess(goodId, provider, detailData); + // Logger.log('商品类型 = $provider, 商品ID = $goodId'); + // List> _pageData = []; + // List modLists = detailData['mod_list']; + // for (int i = 0; i < modLists.length; i++) { + // Map item = modLists[i]; + // Map data = item['data']; + // Map baseData = {'provider': provider, 'good_id': goodId}; + // data.addAll(baseData); + // item['data'] = data; + // _pageData.add(item); + // } + // return _pageData; + } + } + } catch (e, s) { + Logger.error(e, s); + } + return null; + } /// 获取数据 - Future>> fetchInitModData(final Map model) async{ - - String provider = model['provider']; - String goodId = model['good_id']; + Future>> fetchInitModData(final Map model) async { try { + String provider = model['provider']; + String goodId = model['good_id']; if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId)) { Logger.log('商品类型 = $provider, 商品ID = $goodId'); var result = await NetUtil.post('/api/v1/detail/$provider/$goodId', method: NetMethod.GET); if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + return _baseDataProcess(goodId, provider, result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); + // List> _pageData = []; - List> _pageData = []; /// 合并数据 - List modLists = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list']; - for(int i = 0; i < modLists.length; i++){ - Map item = modLists[i]; - Map data = item['data']; - Map style = jsonDecode(item['style']); + // List modLists = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list']; + // for (int i = 0; i < modLists.length; i++) { + // Map item = modLists[i]; + // Map data = item['data']; + // Map style = jsonDecode(item['style']); + // + // Map baseData = {'provider': provider, 'good_id': goodId}; + // style.addAll(baseData); + // + // if (!EmptyUtil.isEmpty(data)) { + // style.addAll(data); + // item['data'] = jsonEncode(style); + // _pageData.add(item); + // } else { + // item['data'] = jsonEncode(style); + // _pageData.add(item); + // } + // } + // + // return _pageData; + } + } + } catch (e, s) { + Logger.error(e, s); + } + return null; + } - Map baseData = {'provider': provider, 'good_id': goodId}; - style.addAll(baseData); + /// 数据处理 + List> _baseDataProcess(String goodId, String provider, final Map model) { + if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId) && !EmptyUtil.isEmpty(model)) { + try { + List> _pageData = []; + Map baseData = {'provider': provider, 'good_id': goodId}; + List modLists = model['mod_list']; + for (int i = 0; i < modLists.length; i++) { + Map item = modLists[i]; + Map data = item['data'] is String ? jsonDecode(item['data']) : item['data']; + Map style = jsonDecode(item['style']); + style.addAll(baseData); - if(!EmptyUtil.isEmpty(data)){ - style.addAll(data); - item['data'] = jsonEncode(style); - _pageData.add(item); - }else{ - item['data'] = jsonEncode(style); - _pageData.add(item); - } + if (!EmptyUtil.isEmpty(data)) { + style.addAll(data); + item['data'] = jsonEncode(style); + _pageData.add(item); + } else { + item['data'] = jsonEncode(style); + _pageData.add(item); } - - return _pageData; } + return _pageData; + } catch (e, s) { + Logger.error(e, s); } - }catch(e){ - Logger.log(e); } return null; } - ///【弃用】获取mod数据 把子mod数据塞在data中 - // Future>> fetchModData(final Map model) async{ - // String provider = model['provider']; - // String goodId = model['good_id']; - // try { - // if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId)) { - // Logger.log('商品类型 = $provider, 商品ID = $goodId'); - // var result = await NetUtil.post('/api/v1/detail/$provider/$goodId', method: NetMethod.GET); - // if(NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { - // for (int i = 0; i < _pageData.length; i++) { - // //result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][i]; - // Map resultData = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][i]; - // Map data = jsonDecode(_pageData[i]['data']); - // if(!EmptyUtil.isEmpty(data)){ - // data.addAll(resultData); - // _pageData[i]['data'] = jsonEncode(data); - // }else{ - // _pageData[i]['data'] = (null != resultData && resultData.length > 0) ? jsonEncode(resultData) : ''; - // } - // } - // return _pageData; - // } - // } - // }catch(e){ - // Logger.log(e); - // } - // return null; - // } - // - // ///【弃用】初始化 - // Future>> fetchInitData(Map model) async { - // int id = 13; - // var result = await NetUtil.post('/api/v1/mod', method: NetMethod.POST, params: {'ids': [id]}); - // try { - // if(NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { - // return _loadData(id, result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); - // } - // } catch (e) { - // Logger.log(e); - // } - // return null; - // } - // - // ///【弃用】处理数据 - // List> _loadData(int id, dynamic data) { - // String key = id.toString(); - // Map json = Map.from(data); - // if (json.containsKey(key)) { - // List list = json[key]; - // _pageData = list.map((item) { - // return Map.from(item); - // }).toList(); - // return _pageData; - // } - // return null; - // } +// Future>> fetchModData(final Map model) async{ +// String provider = model['provider']; +// String goodId = model['good_id']; +// try { +// if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId)) { +// Logger.log('商品类型 = $provider, 商品ID = $goodId'); +// var result = await NetUtil.post('/api/v1/detail/$provider/$goodId', method: NetMethod.GET); +// if(NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { +// for (int i = 0; i < _pageData.length; i++) { +// //result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][i]; +// Map resultData = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][i]; +// Map data = jsonDecode(_pageData[i]['data']); +// if(!EmptyUtil.isEmpty(data)){ +// data.addAll(resultData); +// _pageData[i]['data'] = jsonEncode(data); +// }else{ +// _pageData[i]['data'] = (null != resultData && resultData.length > 0) ? jsonEncode(resultData) : ''; +// } +// } +// return _pageData; +// } +// } +// }catch(e){ +// Logger.log(e); +// } +// return null; +// } +// +// ///【弃用】初始化 +// Future>> fetchInitData(Map model) async { +// int id = 13; +// var result = await NetUtil.post('/api/v1/mod', method: NetMethod.POST, params: {'ids': [id]}); +// try { +// if(NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { +// return _loadData(id, result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); +// } +// } catch (e) { +// Logger.log(e); +// } +// return null; +// } +// +// ///【弃用】处理数据 +// List> _loadData(int id, dynamic data) { +// String key = id.toString(); +// Map json = Map.from(data); +// if (json.containsKey(key)) { +// List list = json[key]; +// _pageData = list.map((item) { +// return Map.from(item); +// }).toList(); +// return _pageData; +// } +// return null; +// } } diff --git a/lib/pages/goods_details_page/goods_details_page.dart b/lib/pages/goods_details_page/goods_details_page.dart index 173cad3..5f7354d 100644 --- a/lib/pages/goods_details_page/goods_details_page.dart +++ b/lib/pages/goods_details_page/goods_details_page.dart @@ -23,7 +23,7 @@ class GoodsDetailsPage extends StatefulWidget { class _GoodsDetailsPageState extends State { @override void initState() { - print("parent data = ${widget.data}"); + print("parent data = ${widget?.data}"); super.initState(); } @@ -36,8 +36,7 @@ class _GoodsDetailsPageState extends State { ], child: BlocProvider( create: (_) => - GoodsDetailsPageBloc(repository: GoodsDetailsPageRepository()) - ..add(GoodsDetailsPageInitEvent(model: widget?.data)), + GoodsDetailsPageBloc(repository: GoodsDetailsPageRepository())..add(GoodsDetailsPageInitEvent(model: widget?.data)), child: GoodsDetailsContainer(widget?.data), ), ); @@ -118,7 +117,7 @@ class _GoodsDetailsContainerState extends State { return true; }, builder: (context, state) { - print('currente state = $state'); + print('GoodsDetailsPage currente state = $state'); if (state is GoodsDetailsPageLoadedState) { return _getMainWidget(state?.model); } diff --git a/lib/pages/team_page/bloc/team_bloc.dart b/lib/pages/team_page/bloc/team_bloc.dart index 8074b41..a32e173 100644 --- a/lib/pages/team_page/bloc/team_bloc.dart +++ b/lib/pages/team_page/bloc/team_bloc.dart @@ -46,7 +46,6 @@ class TeamBloc extends Bloc { } var resultData = await repository.fetchNetData(); if (!EmptyUtil.isEmpty(resultData) && (!EmptyUtil.isEmpty(resultStyle) || !EmptyUtil.isEmpty(cache))) { - Logger.log('================================================= load ================='); yield TeamLoadedState(dataModel: resultData, styleModel: !EmptyUtil.isEmpty(resultStyle) ? resultStyle : cache); } else { yield TeamErrorState(); diff --git a/lib/pages/team_page/model/team_data_model.dart b/lib/pages/team_page/model/team_data_model.dart index ba6cffc..eae9d97 100644 --- a/lib/pages/team_page/model/team_data_model.dart +++ b/lib/pages/team_page/model/team_data_model.dart @@ -1,4 +1,6 @@ -class TeamDataModel { +import 'package:equatable/equatable.dart'; + +class TeamDataModel extends Equatable { String all_fans; String direct_fans_count; String indirect_fans_count; @@ -52,4 +54,11 @@ class TeamDataModel { data['referrer_avatar'] = this.referrerAvatar; return data; } + + + + + @override + List get props => [this.all_fans, this.direct_fans_count, this.indirect_fans_count, this.referrer_invite_code, this.referrer_phone, this.referrer_username, this.referrer_wechat, + this.today_add, this.yesterday_add, this.referrerAvatar]; } diff --git a/lib/pages/team_page/team_page.dart b/lib/pages/team_page/team_page.dart index 51110ea..8e50910 100644 --- a/lib/pages/team_page/team_page.dart +++ b/lib/pages/team_page/team_page.dart @@ -52,10 +52,10 @@ class _TeamPageContainerState extends State<_TeamPageContainer> { return true; }, builder: (context, state) { - print('TeamPage state === $state'); + print('TeamPage state === $state, '); if (state is TeamLoadedState) { _initTabController(state?.styleModel); - return _getMainWidget(state.styleModel, state.dataModel); + return _getMainWidget(state?.styleModel, state?.dataModel); } /// 骨架屏幕 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 334ebed..d180c9c 100644 --- a/lib/widgets/home/home_goods/models/home_goods_model.dart +++ b/lib/widgets/home/home_goods/models/home_goods_model.dart @@ -12,19 +12,22 @@ class HomeGoodsModel extends Equatable { String marketPrice; String currentPrice; String inorderCount; + Map detailData; - HomeGoodsModel( - {this.provider, - this.providerName, - this.goodId, - this.goodImage, - this.goodTitle, - this.shopName, - this.coupon, - this.commission, - this.marketPrice, - this.currentPrice, - this.inorderCount}); + HomeGoodsModel({ + this.provider, + this.providerName, + this.goodId, + this.goodImage, + this.goodTitle, + this.shopName, + this.coupon, + this.commission, + this.marketPrice, + this.currentPrice, + this.inorderCount, + this.detailData, + }); HomeGoodsModel.fromJson(Map json) { provider = json['provider']; @@ -38,6 +41,7 @@ class HomeGoodsModel extends Equatable { marketPrice = json['market_price']; currentPrice = json['current_price']; inorderCount = json['inorder_count']; + detailData = json['detail_data']; } Map toJson() { @@ -53,10 +57,10 @@ class HomeGoodsModel extends Equatable { data['market_price'] = this.marketPrice; data['current_price'] = this.currentPrice; data['inorder_count'] = this.inorderCount; + data['detail_data'] = this.detailData; return data; } @override List get props => [this.goodId, this.provider, this.providerName]; } - diff --git a/lib/widgets/team/recommend/bloc/team_recommend_bloc.dart b/lib/widgets/team/recommend/bloc/team_recommend_bloc.dart index c8480ce..bddd677 100644 --- a/lib/widgets/team/recommend/bloc/team_recommend_bloc.dart +++ b/lib/widgets/team/recommend/bloc/team_recommend_bloc.dart @@ -37,7 +37,12 @@ class TeamRecommendBloc extends Bloc { /// 初始化数据 Stream _mapInitEventToState(TeamRecommendInitEvent event) async* { - yield TeamRecommendLoadedState(event?.dataModel); + var dataModel = await repository.fetchNetData(); + if (!EmptyUtil.isEmpty(dataModel) && !EmptyUtil.isEmpty(dataModel.referrer_username) && !EmptyUtil.isEmpty(dataModel.referrer_invite_code)) { + yield TeamRecommendLoadedState(dataModel); + } else { + yield TeamRecommendErrorState(); + } } /// 关联推荐人 diff --git a/lib/widgets/team/recommend/bloc/team_recommend_repository.dart b/lib/widgets/team/recommend/bloc/team_recommend_repository.dart index a269743..ebe3245 100644 --- a/lib/widgets/team/recommend/bloc/team_recommend_repository.dart +++ b/lib/widgets/team/recommend/bloc/team_recommend_repository.dart @@ -14,4 +14,19 @@ class TeamRecommendRepository { } return null; } + + /// 获取网络数据 + Future fetchNetData() async { + var data = await NetUtil.post('/api/v1/user/myteam', method: NetMethod.GET); + try { + if (NetUtil.isSuccess(data) && !EmptyUtil.isEmpty(data[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + TeamDataModel _dataModel = TeamDataModel.fromJson(data[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); + return _dataModel; + } + } catch (e, s) { + Logger.log('e = $e, s = $s'); + } + return null; + } + } diff --git a/lib/widgets/team/recommend/bloc/team_recommend_state.dart b/lib/widgets/team/recommend/bloc/team_recommend_state.dart index dda193e..0e5ba3b 100644 --- a/lib/widgets/team/recommend/bloc/team_recommend_state.dart +++ b/lib/widgets/team/recommend/bloc/team_recommend_state.dart @@ -10,9 +10,9 @@ class TeamRecommendInitial extends TeamRecommendState { } class TeamRecommendLoadedState extends TeamRecommendState { - TeamDataModel model; + final TeamDataModel model; - TeamRecommendLoadedState(this.model); + const TeamRecommendLoadedState(this.model); @override List get props => [this.model]; diff --git a/lib/widgets/team/recommend/team_recommend_widget.dart b/lib/widgets/team/recommend/team_recommend_widget.dart index d8a624a..1cbb204 100644 --- a/lib/widgets/team/recommend/team_recommend_widget.dart +++ b/lib/widgets/team/recommend/team_recommend_widget.dart @@ -21,7 +21,7 @@ class TeamRecommendWidget extends StatelessWidget { Widget build(BuildContext context) { return BlocProvider( create: (_) => TeamRecommendBloc(TeamRecommendRepository())..add(TeamRecommendInitEvent(dataModel: dataModel)), - child: _TeamRecommendWidgetContainer(styleModel), + child: _TeamRecommendWidgetContainer(styleModel, dataModel), ); } } @@ -29,17 +29,19 @@ class TeamRecommendWidget extends StatelessWidget { class _TeamRecommendWidgetContainer extends StatefulWidget { TeamStyleModel styleModel; - // TeamDataModel dataModel; + TeamDataModel dataModel; - _TeamRecommendWidgetContainer(this.styleModel); + _TeamRecommendWidgetContainer(this.styleModel, dataModel); @override - _TeamRecommendWidgetState createState() => _TeamRecommendWidgetState(); + __TeamRecommendWidgetState createState() => __TeamRecommendWidgetState(); } -class _TeamRecommendWidgetState extends State<_TeamRecommendWidgetContainer> { +class __TeamRecommendWidgetState extends State<_TeamRecommendWidgetContainer> { TextEditingController _textEditingController; FocusNode _focusNode; + TeamStyleModel styleModel; + TeamDataModel dataModel; /// 按钮点击添加事件 void _onClickListener() {