Weller 4 vuotta sitten
vanhempi
commit
42e809b6e7
11 muutettua tiedostoa jossa 268 lisäystä ja 161 poistoa
  1. +8
    -5
      lib/pages/goods_details_page/bloc/goods_details_page_bloc.dart
  2. +137
    -83
      lib/pages/goods_details_page/bloc/goods_details_page_repository.dart
  3. +3
    -4
      lib/pages/goods_details_page/goods_details_page.dart
  4. +0
    -1
      lib/pages/team_page/bloc/team_bloc.dart
  5. +64
    -41
      lib/pages/team_page/model/team_data_model.dart
  6. +2
    -2
      lib/pages/team_page/team_page.dart
  7. +17
    -13
      lib/widgets/home/home_goods/models/home_goods_model.dart
  8. +6
    -1
      lib/widgets/team/recommend/bloc/team_recommend_bloc.dart
  9. +15
    -0
      lib/widgets/team/recommend/bloc/team_recommend_repository.dart
  10. +2
    -2
      lib/widgets/team/recommend/bloc/team_recommend_state.dart
  11. +14
    -9
      lib/widgets/team/recommend/team_recommend_widget.dart

+ 8
- 5
lib/pages/goods_details_page/bloc/goods_details_page_bloc.dart Näytä tiedosto

@@ -30,13 +30,16 @@ class GoodsDetailsPageBloc extends Bloc<GoodsDetailsPageEvent, GoodsDetailsPageS
}

Stream<GoodsDetailsPageState> _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();
}


+ 137
- 83
lib/pages/goods_details_page/bloc/goods_details_page_repository.dart Näytä tiedosto

@@ -2,107 +2,161 @@ import 'dart:convert';
import 'package:zhiying_comm/zhiying_comm.dart';

class GoodsDetailsPageRepository {



/// 获取上个页面传进来的数据
Future<List<Map<String, dynamic>>> fetchParentPageData(final Map<String, dynamic> 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<String, dynamic> detailData = model['detail_data'];
return _baseDataProcess(goodId, provider, detailData);
// Logger.log('商品类型 = $provider, 商品ID = $goodId');
// List<Map<String, dynamic>> _pageData = [];
// List<dynamic> modLists = detailData['mod_list'];
// for (int i = 0; i < modLists.length; i++) {
// Map<String, dynamic> item = modLists[i];
// Map<String, dynamic> data = item['data'];
// Map<String, dynamic> 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<List<Map<String, dynamic>>> fetchInitModData(final Map<String, dynamic> model) async{

String provider = model['provider'];
String goodId = model['good_id'];
Future<List<Map<String, dynamic>>> fetchInitModData(final Map<String, dynamic> 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<Map<String, dynamic>> _pageData = [];

List<Map<String, dynamic>> _pageData = [];
/// 合并数据
List<dynamic> modLists = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'];
for(int i = 0; i < modLists.length; i++){
Map<String, dynamic> item = modLists[i];
Map<String, dynamic> data = item['data'];
Map<String, dynamic> style = jsonDecode(item['style']);
// List<dynamic> modLists = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'];
// for (int i = 0; i < modLists.length; i++) {
// Map<String, dynamic> item = modLists[i];
// Map<String, dynamic> data = item['data'];
// Map<String, dynamic> style = jsonDecode(item['style']);
//
// Map<String, dynamic> 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<String, dynamic> baseData = {'provider': provider, 'good_id': goodId};
style.addAll(baseData);
/// 数据处理
List<Map<String, dynamic>> _baseDataProcess(String goodId, String provider, final Map<String, dynamic> model) {
if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId) && !EmptyUtil.isEmpty(model)) {
try {
List<Map<String, dynamic>> _pageData = [];
Map<String, dynamic> baseData = {'provider': provider, 'good_id': goodId};
List<dynamic> modLists = model['mod_list'];
for (int i = 0; i < modLists.length; i++) {
Map<String, dynamic> item = modLists[i];
Map<String, dynamic> data = item['data'] is String ? jsonDecode(item['data']) : item['data'];
Map<String, dynamic> 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<List<Map<String, dynamic>>> fetchModData(final Map<String, dynamic> 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<String, dynamic> resultData = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][i];
// Map<String, dynamic> 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<List<Map<String, dynamic>>> fetchInitData(Map<String, dynamic> 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<Map<String, dynamic>> _loadData(int id, dynamic data) {
// String key = id.toString();
// Map<String, dynamic> json = Map<String, dynamic>.from(data);
// if (json.containsKey(key)) {
// List<dynamic> list = json[key];
// _pageData = list.map((item) {
// return Map<String, dynamic>.from(item);
// }).toList();
// return _pageData;
// }
// return null;
// }
// Future<List<Map<String, dynamic>>> fetchModData(final Map<String, dynamic> 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<String, dynamic> resultData = result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list'][i];
// Map<String, dynamic> 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<List<Map<String, dynamic>>> fetchInitData(Map<String, dynamic> 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<Map<String, dynamic>> _loadData(int id, dynamic data) {
// String key = id.toString();
// Map<String, dynamic> json = Map<String, dynamic>.from(data);
// if (json.containsKey(key)) {
// List<dynamic> list = json[key];
// _pageData = list.map((item) {
// return Map<String, dynamic>.from(item);
// }).toList();
// return _pageData;
// }
// return null;
// }

}

+ 3
- 4
lib/pages/goods_details_page/goods_details_page.dart Näytä tiedosto

@@ -23,7 +23,7 @@ class GoodsDetailsPage extends StatefulWidget {
class _GoodsDetailsPageState extends State<GoodsDetailsPage> {
@override
void initState() {
print("parent data = ${widget.data}");
print("parent data = ${widget?.data}");
super.initState();
}

@@ -36,8 +36,7 @@ class _GoodsDetailsPageState extends State<GoodsDetailsPage> {
],
child: BlocProvider<GoodsDetailsPageBloc>(
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<GoodsDetailsContainer> {
return true;
},
builder: (context, state) {
print('currente state = $state');
print('GoodsDetailsPage currente state = $state');
if (state is GoodsDetailsPageLoadedState) {
return _getMainWidget(state?.model);
}


+ 0
- 1
lib/pages/team_page/bloc/team_bloc.dart Näytä tiedosto

@@ -46,7 +46,6 @@ class TeamBloc extends Bloc<TeamEvent, TeamState> {
}
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();


+ 64
- 41
lib/pages/team_page/model/team_data_model.dart Näytä tiedosto

@@ -1,41 +1,64 @@
class TeamDataModel {
String all_fans;
String direct_fans_count;
String indirect_fans_count;
String referrer_invite_code;
String referrer_phone;
String referrer_username;
String referrer_wechat;
String today_add;
String yesterday_add;

TeamDataModel({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});

factory TeamDataModel.fromJson(Map<String, dynamic> json) {
return TeamDataModel(
all_fans: json['all_fans'],
direct_fans_count: json['direct_fans_count'],
indirect_fans_count: json['indirect_fans_count'],
referrer_invite_code: json['referrer_invite_code'],
referrer_phone: json['referrer_phone'],
referrer_username: json['referrer_username'],
referrer_wechat: json['referrer_wechat'],
today_add: json['today_add'],
yesterday_add: json['yesterday_add'],
);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['all_fans'] = this.all_fans;
data['direct_fans_count'] = this.direct_fans_count;
data['indirect_fans_count'] = this.indirect_fans_count;
data['referrer_invite_code'] = this.referrer_invite_code;
data['referrer_phone'] = this.referrer_phone;
data['referrer_username'] = this.referrer_username;
data['referrer_wechat'] = this.referrer_wechat;
data['today_add'] = this.today_add;
data['yesterday_add'] = this.yesterday_add;
return data;
}
}
import 'package:equatable/equatable.dart';

class TeamDataModel extends Equatable {
String all_fans;
String direct_fans_count;
String indirect_fans_count;
String referrer_invite_code;
String referrer_phone;
String referrer_username;
String referrer_wechat;
String today_add;
String yesterday_add;
String referrerAvatar;

TeamDataModel({
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,
});

factory TeamDataModel.fromJson(Map<String, dynamic> json) {
return TeamDataModel(
all_fans: json['all_fans'],
direct_fans_count: json['direct_fans_count'],
indirect_fans_count: json['indirect_fans_count'],
referrer_invite_code: json['referrer_invite_code'],
referrer_phone: json['referrer_phone'],
referrer_username: json['referrer_username'],
referrer_wechat: json['referrer_wechat'],
today_add: json['today_add'],
yesterday_add: json['yesterday_add'],
referrerAvatar: json['referrer_avatar'],
);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['all_fans'] = this.all_fans;
data['direct_fans_count'] = this.direct_fans_count;
data['indirect_fans_count'] = this.indirect_fans_count;
data['referrer_invite_code'] = this.referrer_invite_code;
data['referrer_phone'] = this.referrer_phone;
data['referrer_username'] = this.referrer_username;
data['referrer_wechat'] = this.referrer_wechat;
data['today_add'] = this.today_add;
data['yesterday_add'] = this.yesterday_add;
data['referrer_avatar'] = this.referrerAvatar;
return data;
}




@override
List<Object> 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];
}

+ 2
- 2
lib/pages/team_page/team_page.dart Näytä tiedosto

@@ -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);
}

/// 骨架屏幕


+ 17
- 13
lib/widgets/home/home_goods/models/home_goods_model.dart Näytä tiedosto

@@ -12,19 +12,22 @@ class HomeGoodsModel extends Equatable {
String marketPrice;
String currentPrice;
String inorderCount;
Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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<Object> get props => [this.goodId, this.provider, this.providerName];
}


+ 6
- 1
lib/widgets/team/recommend/bloc/team_recommend_bloc.dart Näytä tiedosto

@@ -37,7 +37,12 @@ class TeamRecommendBloc extends Bloc<TeamRecommendEvent, TeamRecommendState> {

/// 初始化数据
Stream<TeamRecommendState> _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();
}
}

/// 关联推荐人


+ 15
- 0
lib/widgets/team/recommend/bloc/team_recommend_repository.dart Näytä tiedosto

@@ -14,4 +14,19 @@ class TeamRecommendRepository {
}
return null;
}

/// 获取网络数据
Future<TeamDataModel> 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;
}

}

+ 2
- 2
lib/widgets/team/recommend/bloc/team_recommend_state.dart Näytä tiedosto

@@ -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<Object> get props => [this.model];


+ 14
- 9
lib/widgets/team/recommend/team_recommend_widget.dart Näytä tiedosto

@@ -21,7 +21,7 @@ class TeamRecommendWidget extends StatelessWidget {
Widget build(BuildContext context) {
return BlocProvider<TeamRecommendBloc>(
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() {
@@ -231,7 +233,7 @@ class _TeamRecommendWidgetState extends State<_TeamRecommendWidgetContainer> {
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
/// 头像widget
_getAvatarWidget(),
_getAvatarWidget(dataModel),

const SizedBox(width: 12),

@@ -242,11 +244,14 @@ class _TeamRecommendWidgetState extends State<_TeamRecommendWidgetContainer> {
}

/// 头像widget
Widget _getAvatarWidget() {
Widget _getAvatarWidget(TeamDataModel dataModel) {
return Container(
width: 55,
height: 55,
color: Colors.red,
// height: 55,
// color: Colors.red,
child: CachedNetworkImage(
imageUrl: dataModel?.referrerAvatar ?? '',
),
);
}



Ladataan…
Peruuta
Tallenna