Browse Source

搜索的筛选

tags/0.0.4+9
PH2 3 years ago
parent
commit
59a561f8c3
2 changed files with 91 additions and 53 deletions
  1. +2
    -0
      lib/widgets/search_result/sort/model/search_result_sort_model.dart
  2. +89
    -53
      lib/widgets/search_result/sort/search_result_sort_widget.dart

+ 2
- 0
lib/widgets/search_result/sort/model/search_result_sort_model.dart View File

@@ -56,6 +56,7 @@ class SearchResultSortModel {

class SearchResultItemSort {
String name;
// 是否选择
bool isSelect;
List<SearchResultSortSelect> 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});


+ 89
- 53
lib/widgets/search_result/sort/search_result_sort_widget.dart View File

@@ -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<SearchResultSortWidget> {
FocusNode _endPriceNode;

// 是否展开综合
bool _isShowZh = false;
// bool _isShowZh = false;
bool _isShowSX = false;

// 切换显示样式
@@ -52,19 +53,28 @@ class _SearchResultSortWidgetState extends State<SearchResultSortWidget> {
void _onClickZhSort(List<SearchResultSortSelect> 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<SearchResultGoodsListBloc>(context).add(SearchResultGoodsListSortEvent(id: id, args: arg));
}
setState(() {
_expand = false;
_isShowZh = false;
// _isShowZh = false;
_isShowSX = false;
});
}
@@ -91,7 +101,7 @@ class _SearchResultSortWidgetState extends State<SearchResultSortWidget> {
setState(() {
_expand = false;
_isShowSX = false;
_isShowZh = false;
// _isShowZh = false;
});
}

@@ -110,13 +120,13 @@ class _SearchResultSortWidgetState extends State<SearchResultSortWidget> {
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<SearchResultSortWidget> {
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<SearchResultSortWidget> {
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<SearchResultSortWidget> {
setState(() {
_expand = true;
_isShowSX = true;
_isShowZh = true;
});

if (model.isSelect || data.select_list[0].isSelect) {
@@ -181,34 +192,82 @@ class _SearchResultSortWidgetState extends State<SearchResultSortWidget> {
}
}

/// 点击完成
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<SearchResultGoodsListBloc>(context).add(SearchResultGoodsListSortEvent(arg, id));
BlocProvider.of<SearchResultGoodsListBloc>(context).add(SearchResultGoodsListSortEvent(id: id, args: arg, remove: !model.isSelect));
// BlocProvider.of<SearchResultGoodsListBloc>(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<SearchResultGoodsListBloc>(context).add(SearchResultGoodsListSortEvent(arg, id));
BlocProvider.of<SearchResultGoodsListBloc>(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<SearchResultSortWidget> {
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<SearchResultSortWidget> {
Row(
children: <Widget>[
/// 最低价格
// _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<SearchResultSortWidget> {
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<SearchResultSortWidget> {
);
}

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<SearchResultGoodsListBloc>(context).add(SearchResultGoodsListSortEvent(arg, id));
BlocProvider.of<SearchResultGoodsListBloc>(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;
}

}
}

Loading…
Cancel
Save