Преглед изворни кода

1、商品详情轮播图默认数据的优化

2、商品详情标题下领取积分等提示的字段修改
tags/0.0.16+8^0
PH2 пре 3 година
родитељ
комит
b9dbe08284
3 измењених фајлова са 66 додато и 13 уклоњено
  1. +36
    -5
      lib/pages/goods_details_page/bloc/goods_details_page_repository.dart
  2. +22
    -7
      lib/widgets/goods_details/tag/goods_details_tag_widget.dart
  3. +8
    -1
      lib/widgets/goods_details/tag/model/goods_details_tag_model.dart

+ 36
- 5
lib/pages/goods_details_page/bloc/goods_details_page_repository.dart Прегледај датотеку

@@ -6,6 +6,9 @@ class GoodsDetailsPageRepository {
// 商品详情的封面图片
String _parentGoodsCoverImg;

// ⚠️ 列表带过来的商品轮播图,避免详情接口获取不到轮播图的情况(1张或者1张以下)
List<String> _imageList;

// 优惠券
String _couponPrice;

@@ -86,27 +89,55 @@ class GoodsDetailsPageRepository {

// ⚠️ 为了商品详情的轮播图能够快速加载,故把上一个页面传进来的第一张图片插入到轮播图集合的第一个图片中
if (item['mod_name'] == 'product_detail_carousel') {
// parentInput = true 说明数据是从列表传进来的
if (parentInput) {
try {
var imageList = data['image_list'];
// 默认封面图片
_parentGoodsCoverImg = coverImage;
if (!EmptyUtil.isEmpty(imageList)) {
_parentGoodsCoverImg = imageList[0];
if (EmptyUtil.isEmpty(_parentGoodsCoverImg)) {
_parentGoodsCoverImg = imageList[0]?.toString();
} else if (_parentGoodsCoverImg != imageList[0]) {
// 列表轮播图第一张为封面,加快显示
imageList.insert(0, _parentGoodsCoverImg);
data['image_list'] = imageList;
}
// 缓存列表的轮播图
_imageList = List<String>.from(imageList);
} else if (!EmptyUtil.isEmpty(coverImage)) {
_parentGoodsCoverImg = coverImage;
data['image_list'] = [coverImage];
}
// Logger.log('列表传过来的默认图片 = ' + _parentGoodsCoverImg);
} catch (e, s) {
Logger.error(e, s);
}
} else {
try {
if (!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && !EmptyUtil.isEmpty(data['image_list'])) {
if (data['image_list'][0] != _parentGoodsCoverImg) {
data['image_list'].insert(0, _parentGoodsCoverImg);
// 如果存在轮播图,并且轮播图的第一张和列表封面图不一样,就把缓存的图片插到第一张,加快显示
if(data['image_list'].length > 1) {
if (data['image_list'][0] != _parentGoodsCoverImg) {
data['image_list'].insert(0, _parentGoodsCoverImg);
}
} else if (!EmptyUtil.isEmpty(_imageList)) {
data['image_list'] = _imageList;
// 详情接口轮播图只有一张或者一张以下图片的时候
if (_imageList[0] != _parentGoodsCoverImg) {
data['image_list'].insert(0, _parentGoodsCoverImg);
}
}
} else if (!EmptyUtil.isEmpty(_parentGoodsCoverImg) && !EmptyUtil.isEmpty(data) && EmptyUtil.isEmpty(data['image_list'])) {
data['image_list'] = [_parentGoodsCoverImg];
if (!EmptyUtil.isEmpty(_imageList)) {
if (_imageList[0] != _parentGoodsCoverImg) {
_imageList.insert(0, _parentGoodsCoverImg);
}
data['image_list'] = _imageList;
} else {
data['image_list'] = [_parentGoodsCoverImg];
}
}
// Logger.log('详情接口的默认图片 = ' + data['image_list'][0]);
} catch (e, s) {
Logger.error(e, s);
}


+ 22
- 7
lib/widgets/goods_details/tag/goods_details_tag_widget.dart Прегледај датотеку

@@ -37,16 +37,31 @@ class GoodsDetailsTagWidget extends StatelessWidget {
}

Widget _buildMainWidget() {
int labelSize = _model?.labelList?.length ?? 0;
int tagSize = _model?.tagList?.length ?? 0;
if (labelSize == 0 || tagSize == 0 || labelSize != tagSize) {
return Container();
}

return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
/// 领券立减100元 widget
Visibility(visible: !EmptyUtil.isEmpty(_model?.couponText), child: _getCoumstonButtomWidget(_model?.couponText, _model?.tagList[1]?.textColor ?? '#FF4242', _model?.tagList[1]?.bgColor ?? '#FFE0E0')),

/// 收货后返现5.5元
Visibility(visible: !EmptyUtil.isEmpty(_model?.commissionText), child: _getCoumstonButtomWidget(_model?.commissionText, _model?.tagList[0]?.textColor ?? '#B78107', _model?.tagList[0]?.bgColor ?? '#FFEFDA')),
],
children: _model.labelList.asMap().keys.map((index) =>
Visibility(
visible: !EmptyUtil.isEmpty(_model.labelList[index]),
child: _getCoumstonButtomWidget(_model.labelList[index] ?? '', _model?.tagList[index]?.textColor ?? '#FF4242', _model?.tagList[index]?.bgColor ?? '#FFE0E0')),
).toList()
);

// return Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children: <Widget>[
// /// 领券立减100元 widget
// Visibility(visible: !EmptyUtil.isEmpty(_model?.couponText), child: _getCoumstonButtomWidget(_model?.couponText, _model?.tagList[1]?.textColor ?? '#FF4242', _model?.tagList[1]?.bgColor ?? '#FFE0E0')),
//
// /// 收货后返现5.5元
// Visibility(visible: !EmptyUtil.isEmpty(_model?.commissionText), child: _getCoumstonButtomWidget(_model?.commissionText, _model?.tagList[0]?.textColor ?? '#B78107', _model?.tagList[0]?.bgColor ?? '#FFEFDA')),
// ],
// );
}




+ 8
- 1
lib/widgets/goods_details/tag/model/goods_details_tag_model.dart Прегледај датотеку

@@ -17,8 +17,12 @@ class GoodsDetailsTagModel {
List<String> sourceList;

// data
// 弃用
String commissionText;
// 弃用
String couponText;
// commissionText couponText 改成这个
List<String> labelList;
String providerName;
String title;

@@ -44,6 +48,7 @@ class GoodsDetailsTagModel {
this.couponText,
this.providerName,
this.title,
this.labelList,
});

GoodsDetailsTagModel.fromJson(Map<String, dynamic> json) {
@@ -67,12 +72,13 @@ class GoodsDetailsTagModel {
tagList.add(new TagList.fromJson(v));
});
}
sourceList = json['source_list'].cast<String>();
sourceList = json['source_list']?.cast<String>();

commissionText = json['commission_text'];
couponText = json['coupon_text'];
providerName = json['provider_name'];
title = json['title'];
labelList = json['label_list']?.cast<String>();
}

Map<String, dynamic> toJson() {
@@ -100,6 +106,7 @@ class GoodsDetailsTagModel {
data['coupon_text'] = this.couponText;
data['provider_name'] = this.providerName;
data['title'] = this.title;
data['label_list'] = this.labelList;

return data;
}


Loading…
Откажи
Сачувај