diff --git a/lib/widgets/search_result/sort/model/search_result_sort_model.dart b/lib/widgets/search_result/sort/model/search_result_sort_model.dart index 0cc2631..017655b 100644 --- a/lib/widgets/search_result/sort/model/search_result_sort_model.dart +++ b/lib/widgets/search_result/sort/model/search_result_sort_model.dart @@ -56,6 +56,7 @@ class SearchResultSortModel { class SearchResultItemSort { String name; + // 是否选择 bool isSelect; List select_list; String type; @@ -108,6 +109,7 @@ class SearchResultSortSelect { String id; String name; String query_args; + // 选中 bool isSelect; SearchResultSortSelect({this.name, this.query_args, this.id, this.isSelect}); diff --git a/lib/widgets/search_result/sort/search_result_sort_widget.dart b/lib/widgets/search_result/sort/search_result_sort_widget.dart index e441aae..5f3066d 100644 --- a/lib/widgets/search_result/sort/search_result_sort_widget.dart +++ b/lib/widgets/search_result/sort/search_result_sort_widget.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:math'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -33,7 +34,7 @@ class _SearchResultSortWidgetState extends State { FocusNode _endPriceNode; // 是否展开综合 - bool _isShowZh = false; + // bool _isShowZh = false; bool _isShowSX = false; // 切换显示样式 @@ -52,19 +53,28 @@ class _SearchResultSortWidgetState extends State { void _onClickZhSort(List datas, SearchResultSortSelect model, SearchResultItemSort parent) { String arg = model?.query_args ?? ''; String id = model?.id ?? ''; - parent.isSelect = true; + // parent.isSelect = true; model.isSelect = !model.isSelect; datas.forEach((item) { if (item.name != model.name) { item.isSelect = false; } }); + + parent.isSelect = false; + datas.forEach((item) { + if(item.isSelect) { + parent.isSelect = true; + } + // Logger.log('name = ${item.isSelect}'); + }); + if (!EmptyUtil.isEmpty(id)) { BlocProvider.of(context).add(SearchResultGoodsListSortEvent(id: id, args: arg)); } setState(() { _expand = false; - _isShowZh = false; + // _isShowZh = false; _isShowSX = false; }); } @@ -91,7 +101,7 @@ class _SearchResultSortWidgetState extends State { setState(() { _expand = false; _isShowSX = false; - _isShowZh = false; + // _isShowZh = false; }); } @@ -110,13 +120,13 @@ class _SearchResultSortWidgetState extends State { setState(() { _expand = false; _isShowSX = false; - _isShowZh = false; + // _isShowZh = false; }); } /// 选中价格 void _onClickSXPriceSort(SearchResultItemSort data, SearchResultSortSelect model) { - print('走塞选'); + print('价格筛选'); String arg; //model?.query_args ?? ''; String id = model?.id ?? ''; @@ -124,12 +134,14 @@ class _SearchResultSortWidgetState extends State { String startPriceStr = _startPriceEditingController?.text?.toString()?.trim() ?? ''; String endPriceStr = _endPriceEditingController?.text?.toString()?.trim() ?? ''; if (EmptyUtil.isEmpty(startPriceStr)) { - Fluttertoast.showToast(msg: '请输入最低价格~'); - return; + // Fluttertoast.showToast(msg: '请输入最低价格~'); + // return; + startPriceStr = '0'; } if (EmptyUtil.isEmpty(endPriceStr)) { - Fluttertoast.showToast(msg: '请输入最高价格~'); - return; + // Fluttertoast.showToast(msg: '请输入最高价格~'); + // return; + endPriceStr = '9999999'; } try { int starPrice = int.parse(startPriceStr); @@ -149,7 +161,7 @@ class _SearchResultSortWidgetState extends State { setState(() { _expand = false; _isShowSX = false; - _isShowZh = false; + // _isShowZh = false; }); if (model.isSelect || data.select_list[0].isSelect) { @@ -171,7 +183,6 @@ class _SearchResultSortWidgetState extends State { setState(() { _expand = true; _isShowSX = true; - _isShowZh = true; }); if (model.isSelect || data.select_list[0].isSelect) { @@ -181,34 +192,82 @@ class _SearchResultSortWidgetState extends State { } } + /// 点击完成 void _onClickFinsh(SearchResultItemSort data, SearchResultSortSelect model) { String arg = model?.query_args ?? ''; String id = model?.id ?? ''; + Logger.log('arg = ${arg}, id = ${id}'); if (!EmptyUtil.isEmpty(id)) { + this._onClickSXPriceSort(data, model); // BlocProvider.of(context).add(SearchResultGoodsListSortEvent(arg, id)); - BlocProvider.of(context).add(SearchResultGoodsListSortEvent(id: id, args: arg, remove: !model.isSelect)); + // BlocProvider.of(context).add(SearchResultGoodsListSortEvent(id: id, args: arg, remove: !model.isSelect)); } setState(() { _expand = false; _isShowSX = false; - _isShowZh = false; + // _isShowZh = false; + }); + } + + /// 重置 + void _reset(SearchResultItemSort data ,SearchResultSortSelect model) { + _startPriceEditingController.text = ""; + _endPriceEditingController.text = ""; + String arg = model?.query_args ?? ''; + String id = model?.id ?? ''; + model.isSelect = false; + if (!EmptyUtil.isEmpty(id)) { + // BlocProvider.of(context).add(SearchResultGoodsListSortEvent(arg, id)); + BlocProvider.of(context).add(SearchResultGoodsListSortEvent(id: id, args: arg, remove: false)); + } + setState(() { + _expand = true; + _isShowSX = true; + // _isShowZh = true; }); + + if (model.isSelect || data.select_list[0].isSelect) { + data.isSelect = true; + } else { + data.isSelect = false; + } + } /// 点击当前 void _clickSortType(SearchResultItemSort model) { - if (model.type == 'popup' || model.type == 'popup-filter') { + // 点击了综合 + if (model.type == 'popup') { setState(() { - _expand = true; - if (model.type == 'popup') { - _isShowZh = true; + // 如果是打开状态 需要判断是否是筛选,如果不是筛选(说明是综合自己)直接关闭 + if(_expand) { + if(_isShowSX) { + _isShowSX = false; + } else { + _expand = false; + } + } else { + _expand = true; _isShowSX = false; } - if (model.type == 'popup-filter') { + + }); + } else if(model.type == 'popup-filter') { // 点击了筛选 + setState(() { + if(_expand) { // 如果是展开状态, 说明是筛选自己,直接关闭 + if(_isShowSX) { + _expand = false; + } else { + _isShowSX = true; + } + } else { + _expand = true; _isShowSX = true; - _isShowZh = false; } + + // _isShowZh = false; }); + } else { /// 优惠券 if (model.type == 'select') { @@ -443,16 +502,11 @@ class _SearchResultSortWidgetState extends State { Expanded( child: GestureDetector( behavior: HitTestBehavior.opaque, - onTap: (){ - _onClickFinsh(parendData,model[1]); + onTap: () { + _onClickFinsh(parendData, model[0]); }, child: Container( - child: Center( - child: Text( - "完成", - style: TextStyle(color: HexColor.fromHex("#FFFF4242"), fontSize: 15), - ), - ), + child: Center(child: Text("完成", style: TextStyle(color: HexColor.fromHex("#FFFF4242"), fontSize: 15))), ), )) ], @@ -474,15 +528,19 @@ class _SearchResultSortWidgetState extends State { Row( children: [ /// 最低价格 + // _getCustomTextField( + // controller: _startPriceEditingController, focusNode: _startPriceNode, hintText: '最低价格', hintTextColor: '#999999', onTap: (val) => _onClickSXPriceSort(data, model)), _getCustomTextField( - controller: _startPriceEditingController, focusNode: _startPriceNode, hintText: '最低价格', hintTextColor: '#999999', onTap: (val) => _onClickSXPriceSort(data, model)), + controller: _startPriceEditingController, focusNode: _startPriceNode, hintText: '最低价格', hintTextColor: '#999999'), /// 文字 【至】 Container(margin: const EdgeInsets.symmetric(horizontal: 8), child: Text('至', style: TextStyle(color: HexColor.fromHex('#999999'), fontSize: 14))), /// 最高价格 + // _getCustomTextField( + // controller: _endPriceEditingController, focusNode: _endPriceNode, hintTextColor: '#999999', hintText: '最高价格', onTap: (val) => _onClickSXPriceSort(data, model)), _getCustomTextField( - controller: _endPriceEditingController, focusNode: _endPriceNode, hintTextColor: '#999999', hintText: '最高价格', onTap: (val) => _onClickSXPriceSort(data, model)), + controller: _endPriceEditingController, focusNode: _endPriceNode, hintTextColor: '#999999', hintText: '最高价格'), ], ), ], @@ -533,7 +591,7 @@ class _SearchResultSortWidgetState extends State { textInputAction: TextInputAction.search, textAlign: TextAlign.center, keyboardType: TextInputType.number, - onSubmitted: onTap, + // onSubmitted: onTap ?? null, decoration: InputDecoration( filled: true, fillColor: Colors.transparent, @@ -624,27 +682,5 @@ class _SearchResultSortWidgetState extends State { ); } - void _reset(SearchResultItemSort data ,SearchResultSortSelect model) { - _startPriceEditingController.text = ""; - _endPriceEditingController.text = ""; - String arg = model?.query_args ?? ''; - String id = model?.id ?? ''; - model.isSelect = false; - if (!EmptyUtil.isEmpty(id)) { - // BlocProvider.of(context).add(SearchResultGoodsListSortEvent(arg, id)); - BlocProvider.of(context).add(SearchResultGoodsListSortEvent(id: id, args: arg, remove: false)); - } - setState(() { - _expand = true; - _isShowSX = true; - _isShowZh = true; - }); - - if (model.isSelect || data.select_list[0].isSelect) { - data.isSelect = true; - } else { - data.isSelect = false; - } - } }