@@ -43,5 +43,7 @@ class GoodsDetailsPageBloc extends Bloc<GoodsDetailsPageEvent, GoodsDetailsPageS | |||
} else { | |||
yield GoodsDetailsPageErrorState(); | |||
} | |||
/// 缓存详情跳转过渡样式,可以加快UI渲染。 | |||
await repository.cacheTurnChainStyleData(); | |||
} | |||
} |
@@ -1,10 +1,31 @@ | |||
import 'dart:convert'; | |||
import 'package:zhiying_comm/zhiying_comm.dart'; | |||
import 'package:zhiying_comm/util/turn_chain/turn_chain_util.dart'; | |||
class GoodsDetailsPageRepository { | |||
// 商品详情的封面图片 | |||
String _parentGoodsCoverImg; | |||
// 优惠券 | |||
String _couponPrice; | |||
// 佣金 | |||
String _commission; | |||
// 商品类型 | |||
String _providerName; | |||
// 商品ID | |||
String _goodsId; | |||
/// 缓存详情跳转app样式 | |||
Future<void> cacheTurnChainStyleData() async { | |||
if (!EmptyUtil.isEmpty(_providerName)) { | |||
bool result = await TurnChainUtil.cacheTurnChainDialogStyle(_goodsId, _providerName, _commission, _couponPrice); | |||
Logger.debug('cache result = $result'); | |||
} | |||
} | |||
/// 获取上个页面传进来的数据 | |||
Future<List<Map<String, dynamic>>> fetchParentPageData(final Map<String, dynamic> model) async { | |||
try { | |||
@@ -13,8 +34,8 @@ class GoodsDetailsPageRepository { | |||
String goodId = model['good_id']?.toString(); | |||
if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId)) { | |||
Map<String, dynamic> detailData = model['detail_data']; | |||
String good_image = model['good_image']; | |||
return _baseDataProcess(true, goodId, provider, detailData, good_image); | |||
String goodImage = model['good_image']; | |||
return _baseDataProcess(true, goodId, provider, detailData, goodImage); | |||
} | |||
} | |||
} catch (e, s) { | |||
@@ -42,25 +63,30 @@ class GoodsDetailsPageRepository { | |||
} | |||
/// 数据处理 | |||
List<Map<String, dynamic>> _baseDataProcess(bool parentInput,String goodId, String provider, final Map<String, dynamic> model, String coverImage) { | |||
List<Map<String, dynamic>> _baseDataProcess(bool parentInput, String goodId, String provider, final Map<String, dynamic> model, String coverImage) { | |||
if (!EmptyUtil.isEmpty(provider) && !EmptyUtil.isEmpty(goodId) && !EmptyUtil.isEmpty(model)) { | |||
try { | |||
_couponPrice = model['coupon_price']; | |||
_commission = model['commission']; | |||
_providerName = model['provider_name']; | |||
_goodsId = model['good_id']; | |||
List<Map<String, dynamic>> _pageData = []; | |||
Map<String, dynamic> baseData = {'provider': provider, 'good_id': goodId}; | |||
Map<String, dynamic> baseData = {'provider': provider, 'good_id': _goodsId, 'commission': _commission, 'coupon_price': _couponPrice}; | |||
List<dynamic> modLists = model['mod_list']; | |||
for (int i = 0; i < modLists.length; i++) { | |||
Map<String, dynamic> item = modLists[i]; | |||
// ⚠️ 这里之所以要判断是否是String类型,是因为修改的是父亲页面传进来的model -> data 类型了。把dynamic变成了String | |||
Map<String, dynamic> data = !EmptyUtil.isEmpty(item['data']) ? item['data'] is String ? jsonDecode(item['data']) : item['data'] : new Map<String, dynamic>(); | |||
// ⚠️ 为了商品详情的轮播图能够快速加载,故把上一个页面传进来的第一张图片插入到轮播图集合的第一个图片中 | |||
if(item['mod_name'] == 'product_detail_carousel') { | |||
if (item['mod_name'] == 'product_detail_carousel') { | |||
if (parentInput) { | |||
try { | |||
var imageList = data['image_list']; | |||
if (!EmptyUtil.isEmpty(imageList)) { | |||
_parentGoodsCoverImg = imageList[0]; | |||
}else if (!EmptyUtil.isEmpty(coverImage)){ | |||
} else if (!EmptyUtil.isEmpty(coverImage)) { | |||
_parentGoodsCoverImg = coverImage; | |||
data['image_list'] = [coverImage]; | |||
} | |||
@@ -70,19 +96,19 @@ class GoodsDetailsPageRepository { | |||
} else { | |||
try { | |||
if (!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && !EmptyUtil.isEmpty(data['image_list'])) { | |||
if(data['image_list'][0] != _parentGoodsCoverImg) { | |||
if (data['image_list'][0] != _parentGoodsCoverImg) { | |||
data['image_list'].insert(0, _parentGoodsCoverImg); | |||
} | |||
}else if(!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && EmptyUtil.isEmpty(data['image_list'])){ | |||
} else if (!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && EmptyUtil.isEmpty(data['image_list'])) { | |||
data['image_list'] = [_parentGoodsCoverImg]; | |||
} | |||
}catch(e, s){ | |||
} catch (e, s) { | |||
Logger.error(e, s); | |||
} | |||
} | |||
} | |||
Map<String, dynamic> style =!EmptyUtil.isEmpty(item['style']) ? jsonDecode(item['style']) : new Map<String, dynamic>(); | |||
Map<String, dynamic> style = !EmptyUtil.isEmpty(item['style']) ? jsonDecode(item['style']) : new Map<String, dynamic>(); | |||
style.addAll(baseData); | |||
if (!EmptyUtil.isEmpty(data)) { | |||
@@ -101,5 +127,4 @@ class GoodsDetailsPageRepository { | |||
} | |||
return null; | |||
} | |||
} |
@@ -58,7 +58,7 @@ class _CounponWidgetContainerState extends State<CounponWidgetContainer> { | |||
/// 点击领取 | |||
void _onJump(CounponModel model) async{ | |||
TurnChainUtil.openReceiveCoupon(context, _user, model.provider, model?.convertArgs?.toJson()); | |||
TurnChainUtil.openReceiveCoupon(context, _user, model?.good_id, model.provider, model?.convertArgs?.toJson()); | |||
} | |||
@override | |||
@@ -11,11 +11,12 @@ class CounponModel { | |||
String price_type_color; | |||
String buy_url; | |||
String provider; | |||
String goood_id; | |||
String good_id; | |||
ConvertArgs convertArgs; | |||
String commission; | |||
CounponModel({ | |||
this.goood_id, | |||
this.good_id, | |||
this.provider, | |||
this.bg_img, | |||
this.coupon_endtime, | |||
@@ -29,11 +30,12 @@ class CounponModel { | |||
this.price_type_color, | |||
this.buy_url, | |||
this.convertArgs, | |||
this.commission, | |||
}); | |||
factory CounponModel.fromJson(Map<String, dynamic> json) { | |||
return CounponModel( | |||
goood_id: json['goood_id'], | |||
good_id: json['good_id'], | |||
provider: json['provider'], | |||
bg_img: json['bg_img'], | |||
coupon_endtime: json['coupon_endtime'], | |||
@@ -47,7 +49,7 @@ class CounponModel { | |||
price_type_color: json['price_type_color'], | |||
buy_url: json['buy_url'], | |||
convertArgs: json['convert_args'] != null ? ConvertArgs.fromJson(json['convert_args']) : null, | |||
commission: json['commission'], | |||
); | |||
} | |||
@@ -65,11 +67,11 @@ class CounponModel { | |||
data['price_type_color'] = this.price_type_color; | |||
data['buy_url'] = this.buy_url; | |||
data['provider'] = this.provider; | |||
data['goood_id'] = this.goood_id; | |||
data['good_id'] = this.good_id; | |||
if (this.convertArgs != null) { | |||
data['convert_args'] = this.convertArgs.toJson(); | |||
} | |||
data['commission'] = this.commission; | |||
return data; | |||
} | |||
} | |||
@@ -81,8 +83,9 @@ class ConvertArgs { | |||
String couponPrice; | |||
String activityUrl; | |||
String isShare; | |||
String commission; | |||
ConvertArgs({this.gid, this.goodUrl, this.couponUrl, this.couponPrice, this.activityUrl, this.isShare}); | |||
ConvertArgs({this.gid, this.goodUrl, this.couponUrl, this.couponPrice, this.activityUrl, this.isShare, this.commission}); | |||
ConvertArgs.fromJson(Map<String, dynamic> json) { | |||
gid = json['gid']; | |||
@@ -91,6 +94,7 @@ class ConvertArgs { | |||
couponPrice = json['coupon_price']; | |||
activityUrl = json['activity_url']; | |||
isShare = json['is_share']; | |||
commission = json['commission']; | |||
} | |||
Map<String, dynamic> toJson() { | |||
@@ -101,7 +105,7 @@ class ConvertArgs { | |||
data['coupon_price'] = this.couponPrice; | |||
data['activity_url'] = this.activityUrl; | |||
data['is_share'] = this.isShare; | |||
data['commission'] = this.commission; | |||
return data; | |||
} | |||
} | |||
@@ -116,7 +116,7 @@ class _GooddsDetailsFooterContainerState extends State<GooddsDetailsFooterContai | |||
// builder: (context) => GoodsSharePage(widget.model))); | |||
// } | |||
Map<String, dynamic> result = await TurnChainUtil.getShareTurnChain(context, _user, model.provider, model.convertArgs.toJson()); | |||
Map<String, dynamic> result = await TurnChainUtil.getShareTurnChain(context, _user, model?.good_id, model.provider, model.convertArgs.toJson()); | |||
if (!EmptyUtil.isEmpty(result)) { | |||
model.shareUrlArgs.buyUrl = result['open_app_url']; | |||
Navigator.of(context).push(CupertinoPageRoute(builder: (context) => GoodsSharePage(model.toJson()))); | |||
@@ -125,7 +125,7 @@ class _GooddsDetailsFooterContainerState extends State<GooddsDetailsFooterContai | |||
/// 自购省 | |||
void _saveMoneyOnClick(GoodsDetailsFooterModel model) async { | |||
await TurnChainUtil.openReceiveCoupon(context, _user, model?.provider, model?.convertArgs?.toJson()); | |||
await TurnChainUtil.openReceiveCoupon(context, _user, model?.good_id, model?.provider, model?.convertArgs?.toJson()); | |||
} | |||
@override | |||
@@ -240,11 +240,7 @@ class _GooddsDetailsFooterContainerState extends State<GooddsDetailsFooterContai | |||
TextSpan( | |||
text: model?.share_value ?? '0.0', | |||
style: TextStyle( | |||
fontSize: 15, | |||
fontWeight: FontWeight.bold, | |||
color: HexColor.fromHex(model?.share_earn_color ?? '#FFFFFF'), | |||
fontFamily: 'Din', | |||
package: 'zhiying_base_widget')), | |||
fontSize: 15, fontWeight: FontWeight.bold, color: HexColor.fromHex(model?.share_earn_color ?? '#FFFFFF'), fontFamily: 'Din', package: 'zhiying_base_widget')), | |||
]), | |||
), | |||
Text( | |||
@@ -242,8 +242,9 @@ class ConvertArgs { | |||
String couponPrice; | |||
String activityUrl; | |||
String isShare; | |||
String commission; | |||
ConvertArgs({this.gid, this.goodUrl, this.couponUrl, this.couponPrice, this.activityUrl, this.isShare}); | |||
ConvertArgs({this.gid, this.goodUrl, this.couponUrl, this.couponPrice, this.activityUrl, this.isShare, this.commission}); | |||
ConvertArgs.fromJson(Map<String, dynamic> json) { | |||
gid = json['gid']; | |||
@@ -252,6 +253,7 @@ class ConvertArgs { | |||
couponPrice = json['coupon_price']; | |||
activityUrl = json['activity_url']; | |||
isShare = json['is_share']; | |||
commission = json['commission']; | |||
} | |||
Map<String, dynamic> toJson() { | |||
@@ -262,6 +264,7 @@ class ConvertArgs { | |||
data['coupon_price'] = this.couponPrice; | |||
data['activity_url'] = this.activityUrl; | |||
data['is_share'] = this.isShare; | |||
data['commission'] = this.commission; | |||
return data; | |||
} | |||
} |