From b9dbe08284a42ca662bd247265e5d8c33181c40c Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Tue, 11 May 2021 18:43:37 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E8=BD=AE=E6=92=AD=E5=9B=BE=E9=BB=98=E8=AE=A4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96=202=E3=80=81=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=A0=87=E9=A2=98=E4=B8=8B=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E7=AD=89=E6=8F=90=E7=A4=BA=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bloc/goods_details_page_repository.dart | 41 ++++++++++++++++--- .../tag/goods_details_tag_widget.dart | 29 +++++++++---- .../tag/model/goods_details_tag_model.dart | 9 +++- 3 files changed, 66 insertions(+), 13 deletions(-) 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 0136749..0ae2cfa 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 @@ -6,6 +6,9 @@ class GoodsDetailsPageRepository { // 商品详情的封面图片 String _parentGoodsCoverImg; + // ⚠️ 列表带过来的商品轮播图,避免详情接口获取不到轮播图的情况(1张或者1张以下) + List _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.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); } diff --git a/lib/widgets/goods_details/tag/goods_details_tag_widget.dart b/lib/widgets/goods_details/tag/goods_details_tag_widget.dart index c2d33b1..73e94da 100644 --- a/lib/widgets/goods_details/tag/goods_details_tag_widget.dart +++ b/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: [ - /// 领券立减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: [ + // /// 领券立减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')), + // ], + // ); } diff --git a/lib/widgets/goods_details/tag/model/goods_details_tag_model.dart b/lib/widgets/goods_details/tag/model/goods_details_tag_model.dart index c86394f..cc23e73 100644 --- a/lib/widgets/goods_details/tag/model/goods_details_tag_model.dart +++ b/lib/widgets/goods_details/tag/model/goods_details_tag_model.dart @@ -17,8 +17,12 @@ class GoodsDetailsTagModel { List sourceList; // data + // 弃用 String commissionText; + // 弃用 String couponText; + // commissionText couponText 改成这个 + List labelList; String providerName; String title; @@ -44,6 +48,7 @@ class GoodsDetailsTagModel { this.couponText, this.providerName, this.title, + this.labelList, }); GoodsDetailsTagModel.fromJson(Map json) { @@ -67,12 +72,13 @@ class GoodsDetailsTagModel { tagList.add(new TagList.fromJson(v)); }); } - sourceList = json['source_list'].cast(); + sourceList = json['source_list']?.cast(); commissionText = json['commission_text']; couponText = json['coupon_text']; providerName = json['provider_name']; title = json['title']; + labelList = json['label_list']?.cast(); } Map 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; }