Skip to content

Commit

Permalink
分类页面子分类点击切换数据
Browse files Browse the repository at this point in the history
分类页面子分类点击切换数据
  • Loading branch information
shaoting0730 committed Mar 24, 2019
1 parent b8ba2dc commit 8858638
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 23 additions & 3 deletions lib/pages/category_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class _RightCategoryNavState extends State<RightCategoryNav> {
return InkWell(
onTap: () {
Provide.value<ChildCategory>(context).changeChildIndex(index);
_getMallGoods(item.mallSubId);
},
child: Container(
padding: EdgeInsets.fromLTRB(5.0, 10.0, 5.0, 8.0),
Expand All @@ -91,6 +92,25 @@ class _RightCategoryNavState extends State<RightCategoryNav> {
),
);
}

// 请求右侧数据
void _getMallGoods(String mallSubId) {
var data = {
'categoryId': Provide.value<ChildCategory>(context).categoryId,
'categorySubId': mallSubId,
'page': 1
};

request('getMallGoods', formData: data).then((val) {
var data = json.decode(val.toString());
CategoryGoodsListModel goodsList = CategoryGoodsListModel.fromJson(data);
Provide.value<CategoryGoodsListProvide>(context)
.getGoodsList(goodsList.data);
});
}



}

// 左侧导航
Expand All @@ -112,12 +132,12 @@ class _LeftCategoryNavState extends State<LeftCategoryNav> {
});
//改变右侧分类数据
Provide.value<ChildCategory>(context)
.getChildCategoryList(list[0].bxMallSubDto);
.getChildCategoryList(list[0].bxMallSubDto,list[0].mallCategoryId);
});
}

// 请求右侧数据
void _getMallGoods({String categoryId}) async {
void _getMallGoods({String categoryId}) {
var data = {
'categoryId': categoryId == null ? '4' : categoryId,
'categorySubId': '',
Expand Down Expand Up @@ -151,7 +171,7 @@ class _LeftCategoryNavState extends State<LeftCategoryNav> {
var childList = list[index].bxMallSubDto;
var categoryId = list[index].mallCategoryId;
// 改变右侧分类数据
Provide.value<ChildCategory>(context).getChildCategoryList(childList);
Provide.value<ChildCategory>(context).getChildCategoryList(childList,categoryId);
// 发送右侧商品请求
_getMallGoods(categoryId: categoryId);
},
Expand Down
4 changes: 3 additions & 1 deletion lib/provide/child_category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import '../model/category_model.dart';
class ChildCategory with ChangeNotifier{
List<BxMallSubDto> childCategoryList = [];
int childIndex = 0; // 右侧子导航高亮索引
String categoryId = "4"; // 大类id,默认4
// 改变右侧分类数据
getChildCategoryList(List<BxMallSubDto> list){
getChildCategoryList(List<BxMallSubDto> list,String id){
childIndex = 0; // 每次点击都需要重置0
categoryId = id;
BxMallSubDto all = BxMallSubDto();
all.mallSubId = "00";
all.mallCategoryId = "00";
Expand Down

0 comments on commit 8858638

Please sign in to comment.