Browse Source

商城更改

zyh
w-R 3 years ago
parent
commit
a84c63ecf6
  1. 214
      lib/store/shopping/shopping_home/search_page.dart

214
lib/store/shopping/shopping_home/search_page.dart

@ -21,13 +21,15 @@ class SearchPage extends StatefulWidget {
final Map<String, dynamic> arguments; final Map<String, dynamic> arguments;
SearchPage({this.arguments}); SearchPage({this.arguments});
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
return _SearchPage(); return _SearchPage();
} }
} }
class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin, WidgetsBindingObserver { class _SearchPage extends State<SearchPage>
with AutomaticKeepAliveClientMixin, WidgetsBindingObserver {
ApiService apiService; ApiService apiService;
MinApiService minService; MinApiService minService;
final TextEditingController editingController = TextEditingController(); final TextEditingController editingController = TextEditingController();
@ -35,7 +37,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
int optionIndex = 0; int optionIndex = 0;
bool isKeyBoardShow = false; bool isKeyBoardShow = false;
List<ProductListBean> productListBeans = []; List<ProductListBean> productListBeans = [];
List<String> hotSearch =[]; List<String> hotSearch = [];
List<String> historySearch = []; List<String> historySearch = [];
FocusNode _focusNode = FocusNode(); FocusNode _focusNode = FocusNode();
bool hasFocus = true; bool hasFocus = true;
@ -71,17 +73,17 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
void initState() { void initState() {
super.initState(); super.initState();
setState(() { setState(() {
if(widget.arguments["hotSearch"] != null) if (widget.arguments["hotSearch"] != null)
hotSearch.addAll(widget.arguments["hotSearch"]); hotSearch.addAll(widget.arguments["hotSearch"]);
}); });
_focusNode.addListener((){ _focusNode.addListener(() {
setState(() { setState(() {
hasFocus = _focusNode.hasFocus; hasFocus = _focusNode.hasFocus;
}); });
}); });
if(widget.arguments["searchKey"] != null){ if (widget.arguments["searchKey"] != null) {
setState(() { setState(() {
editingController.text =widget.arguments["searchKey"]; editingController.text = widget.arguments["searchKey"];
}); });
appletGoods(widget.arguments["searchKey"]); appletGoods(widget.arguments["searchKey"]);
} }
@ -89,11 +91,10 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
} }
/// ///
getHistorySearch()async{ getHistorySearch() async {
SharedPreferences value = await SharedPreferences.getInstance(); SharedPreferences value = await SharedPreferences.getInstance();
var str = value.getString("historySearch"); var str = value.getString("historySearch");
if(str == null ) if (str == null) return;
return;
var strArr = str.split("&"); var strArr = str.split("&");
strArr.removeAt(strArr.length - 1); strArr.removeAt(strArr.length - 1);
setState(() { setState(() {
@ -103,17 +104,15 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
} }
/// ///
setHistorySearch(String text)async{ setHistorySearch(String text) async {
if(text == null || text.trim() == "") if (text == null || text.trim() == "") return;
return;
SharedPreferences value = await SharedPreferences.getInstance(); SharedPreferences value = await SharedPreferences.getInstance();
var str = value.getString("historySearch"); var str = value.getString("historySearch");
if(str == null ) if (str == null) str = "";
str = "";
var strArr = str.split("&"); var strArr = str.split("&");
if(strArr.length >30){ if (strArr.length > 60) {
str = strArr.getRange(0, 29).join("&"); str = strArr.getRange(0, 59).join("&");
} else{ } else {
str = strArr.join("&"); str = strArr.join("&");
} }
str += text + "&"; str += text + "&";
@ -122,7 +121,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
} }
/// ///
delHistorySearch()async{ delHistorySearch() async {
SharedPreferences value = await SharedPreferences.getInstance(); SharedPreferences value = await SharedPreferences.getInstance();
value.setString("historySearch", ""); value.setString("historySearch", "");
getHistorySearch(); getHistorySearch();
@ -130,26 +129,35 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
/// ///
appletGoods(String text) async { appletGoods(String text) async {
if(editingController.text.trim() == ""){ if (editingController.text.trim() == "") {
return; return;
} }
if(minService == null) if (minService == null)
minService = MinApiService( minService = MinApiService(
Dio(), Dio(),
context: context, context: context,
token: widget.arguments["minToken"], token: widget.arguments["minToken"],
tenant:widget.arguments["tenant"], tenant: widget.arguments["tenant"],
storeId: widget.arguments["storeId"], storeId: widget.arguments["storeId"],
); );
BaseData<List<FindMiNiGroupList>> baseData = BaseData<List<FindMiNiGroupList>> baseData = await minService
await minService.findMiNiGroupList({ .findMiNiGroupList({
"id":widget.arguments["storeId"], "id": widget.arguments["storeId"],
"searchKey" :text, "searchKey": text,
"sortType":optionIndex == 0 ? "" : (optionIndex == 1) ? productListBeans[0].sellCount : productListBeans[0].price, "sortType": optionIndex == 0
"asc":optionIndex == 0 ? "" :(priceOrder == 2) ? true:"" ? ""
}).catchError((error) { : (optionIndex == 1)
}).catchError((error) { ? productListBeans[0].sellCount
: productListBeans[0].price,
"asc": optionIndex == 0
? ""
: (priceOrder == 2)
? true
: ""
})
.catchError((error) {})
.catchError((error) {
refreshController.refreshFailed(); refreshController.refreshFailed();
}); });
@ -157,7 +165,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
refreshController.refreshCompleted(); refreshController.refreshCompleted();
setState(() { setState(() {
productListBeans.clear(); productListBeans.clear();
if(baseData.data.length > 0) if (baseData.data.length > 0)
productListBeans.addAll(baseData.data[0].productList); productListBeans.addAll(baseData.data[0].productList);
}); });
} else { } else {
@ -171,7 +179,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
}); });
} }
_onRefresh(){ _onRefresh() {
appletGoods(editingController.text); appletGoods(editingController.text);
refreshController.refreshCompleted(); refreshController.refreshCompleted();
} }
@ -226,8 +234,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
), ),
), ),
Expanded( Expanded(
child: child: Container(
Container(
height: 36.h, height: 36.h,
margin: EdgeInsets.fromLTRB(6.w, 0, 14.w, 0), margin: EdgeInsets.fromLTRB(6.w, 0, 14.w, 0),
padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h), padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h),
@ -244,7 +251,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
], ],
), ),
child: TextField( child: TextField(
focusNode:_focusNode, focusNode: _focusNode,
textInputAction: TextInputAction.search, textInputAction: TextInputAction.search,
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
@ -278,15 +285,15 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
border: InputBorder.none, border: InputBorder.none,
), ),
), ),
) )),
),
Container( Container(
alignment: Alignment.center, alignment: Alignment.center,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
if(editingController.text.trim() == ""){ if (editingController.text.trim() == "") {
SmartDialog.showToast("请输入搜索内容", alignment: Alignment.center); SmartDialog.showToast("请输入搜索内容",
alignment: Alignment.center);
return; return;
} }
appletGoods(editingController.text); appletGoods(editingController.text);
@ -329,7 +336,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
builder: (context, mode) { builder: (context, mode) {
return MyFooter(mode); return MyFooter(mode);
}, },
),onRefresh: () { ),
onRefresh: () {
setState(() { setState(() {
_onRefresh(); _onRefresh();
}); });
@ -340,12 +348,9 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
builder: (context, snapshot) { builder: (context, snapshot) {
return Column( return Column(
children: [ children: [
if(hasFocus) if (hasFocus) hotSearchWords(),
hotSearchWords(), if (hasFocus) historySearchWords(),
if(hasFocus) if (!hasFocus) searchList()
historySearchWords(),
if(!hasFocus)
searchList()
], ],
); );
}, },
@ -365,7 +370,6 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
/// ///
Widget hotSearchWords() { Widget hotSearchWords() {
return Container( return Container(
width: double.infinity,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -380,13 +384,13 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
), ),
SizedBox(height: 16.h), SizedBox(height: 16.h),
GridView.builder( GridView.builder(
itemCount:hotSearch?.length ?? 0, itemCount: hotSearch?.length ?? 0,
shrinkWrap: true, shrinkWrap: true,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
physics: NeverScrollableScrollPhysics(), physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
//Widget数量 //Widget数量
crossAxisCount:4, crossAxisCount: 4,
//Widget之间间距 //Widget之间间距
crossAxisSpacing: 6.w, crossAxisSpacing: 6.w,
//Widget之间间距 //Widget之间间距
@ -398,8 +402,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
if(hotSearch[index] != null){ if (hotSearch[index] != null) {
editingController.text =hotSearch[index]; editingController.text = hotSearch[index];
appletGoods(hotSearch[index]); appletGoods(hotSearch[index]);
} }
}); });
@ -415,6 +419,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
Widget hotSearchItem(String hotSearch) { Widget hotSearchItem(String hotSearch) {
return Container( return Container(
width: double.infinity,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -422,7 +427,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
RoundButton( RoundButton(
padding: EdgeInsets.only(left: 4, right: 4), padding: EdgeInsets.only(left: 4, right: 4),
height: 29.h, height: 29.h,
text:hotSearch, text: hotSearch,
textColor: Color(0xFF181818), textColor: Color(0xFF181818),
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
radius: 4, radius: 4,
@ -437,7 +442,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
/// ///
Widget historySearchWords() { Widget historySearchWords() {
return Container( return Container(
width: double.infinity, // width: double.infinity,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -459,12 +464,12 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
height: 20.h, height: 20.h,
), ),
GestureDetector( GestureDetector(
onTap: (){ onTap: () {
setState(() { setState(() {
delHistorySearch(); delHistorySearch();
}); });
}, },
child:Text( child: Text(
"删除", "删除",
style: TextStyle( style: TextStyle(
fontSize: 15.sp, fontSize: 15.sp,
@ -477,13 +482,13 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
), ),
SizedBox(height: 16.h), SizedBox(height: 16.h),
GridView.builder( GridView.builder(
itemCount:historySearch?.length ?? 0, itemCount: historySearch?.length ?? 0,
shrinkWrap: true, shrinkWrap: true,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
physics: NeverScrollableScrollPhysics(), physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
//Widget数量 //Widget数量
crossAxisCount:4, crossAxisCount: 4,
//Widget之间间距 //Widget之间间距
crossAxisSpacing: 6.w, crossAxisSpacing: 6.w,
//Widget之间间距 //Widget之间间距
@ -495,13 +500,13 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
if(historySearch[index] != null){ if (historySearch[index] != null) {
editingController.text =historySearch[index]; editingController.text = historySearch[index];
appletGoods(historySearch[index]); appletGoods(historySearch[index]);
} }
}); });
}, },
child:historySearchItem(historySearch[index]), child: historySearchItem(historySearch[index]),
); );
}, },
), ),
@ -516,18 +521,25 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Expanded(child: Expanded(
RoundButton( child: Container(
padding: EdgeInsets.only(left: 4, right: 4), padding: EdgeInsets.only(left: 4, right: 4),
height: 29.h, alignment: Alignment.center,
text:historySearch, decoration: BoxDecoration(
textColor: Color(0xFF181818), borderRadius: BorderRadius.circular(4),
fontWeight: MyFontWeight.regular, color: Color(0xFFF5F5F5)),
radius: 4, child: Text(
backgroup: Color(0xFFF5F5F5), historySearch,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
),) fontWeight: MyFontWeight.regular,
color: Color(0xFF181818),
),
),
),
)
], ],
), ),
); );
@ -589,8 +601,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
onTap: () { onTap: () {
setState(() { setState(() {
optionIndex = 2; optionIndex = 2;
priceOrder = 1; // priceOrder = 1;
appletGoods(widget.arguments["searchKey"]); // appletGoods(widget.arguments["searchKey"]);
}); });
}, },
child: Row( child: Row(
@ -610,24 +622,28 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
Column( Column(
children: [ children: [
GestureDetector( GestureDetector(
onTap: (){ onTap: () {
priceOrder = 1; priceOrder = 1;
appletGoods(widget.arguments["searchKey"]); appletGoods(widget.arguments["searchKey"]);
}, },
child:Icon( child: Icon(
Icons.arrow_drop_up, Icons.arrow_drop_up,
color: (optionIndex == 2 && priceOrder == 1) ? Color(0xFF33A061) : Color(0xFF4D4D4D), color: (optionIndex == 2 && priceOrder == 1)
? Color(0xFF33A061)
: Color(0xFF4D4D4D),
size: 16, size: 16,
), ),
), ),
GestureDetector( GestureDetector(
onTap: (){ onTap: () {
priceOrder = 2; priceOrder = 2;
appletGoods(widget.arguments["searchKey"]); appletGoods(widget.arguments["searchKey"]);
}, },
child:Icon( child: Icon(
Icons.arrow_drop_down, Icons.arrow_drop_down,
color: (optionIndex == 2 && priceOrder == 2) ? Color(0xFF33A061) : Color(0xFF4D4D4D), color: (optionIndex == 2 && priceOrder == 2)
? Color(0xFF33A061)
: Color(0xFF4D4D4D),
size: 16, size: 16,
), ),
) )
@ -665,14 +681,14 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
SizedBox(height: 16.h), SizedBox(height: 16.h),
(productListBeans == null || productListBeans?.length == 0) (productListBeans == null || productListBeans?.length == 0)
? NoDataView( ? NoDataView(
src:"assets/image/ding_dan.png", src: "assets/image/ding_dan.png",
isShowBtn: false, isShowBtn: false,
text:"该关键词未搜索到相关商品~", text: "该关键词未搜索到相关商品~",
fontSize: 16.sp, fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h,left: 60.w,right: 60.w), margin: EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w),
): )
GridView.builder( : GridView.builder(
itemCount:productListBeans?.length ?? 0, itemCount: productListBeans?.length ?? 0,
shrinkWrap: true, shrinkWrap: true,
physics: NeverScrollableScrollPhysics(), physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
@ -683,8 +699,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
//Widget之间间距 //Widget之间间距
mainAxisSpacing: 16.w, mainAxisSpacing: 16.w,
//Widget宽高比例 0.59 //Widget宽高比例 0.59
childAspectRatio: childAspectRatio: 185 /
185 / (281 / 2 + (281 / 2) * AppUtils.textScale(context)), (281 / 2 + (281 / 2) * AppUtils.textScale(context)),
), ),
itemBuilder: (context, index) { itemBuilder: (context, index) {
return GestureDetector( return GestureDetector(
@ -692,9 +708,9 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
Navigator.of(context).pushNamed( Navigator.of(context).pushNamed(
'/router/shopping_goods_details', '/router/shopping_goods_details',
arguments: { arguments: {
"id":productListBeans[index].id, "id": productListBeans[index].id,
"storeId":widget.arguments["storeId"], "storeId": widget.arguments["storeId"],
"tenant":widget.arguments["tenant"], "tenant": widget.arguments["tenant"],
}, },
); );
}, },
@ -739,9 +755,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
) )
], ],
), ),
child: child: MImage(
MImage( productListBeans?.imgPath ?? "",
productListBeans?.imgPath ??"",
width: double.infinity, width: double.infinity,
height: 166, height: 166,
fit: BoxFit.cover, fit: BoxFit.cover,
@ -760,7 +775,8 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Expanded(child:Container( Expanded(
child: Container(
margin: EdgeInsets.only(top: 8, right: 8), margin: EdgeInsets.only(top: 8, right: 8),
padding: EdgeInsets.only(left: 2, right: 2), padding: EdgeInsets.only(left: 2, right: 2),
height: 17.h, height: 17.h,
@ -779,16 +795,20 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
color: Colors.white, color: Colors.white,
), ),
), ),
),), ),
Expanded(child: ),
Container(child: Text( Expanded(
child: Container(
child: Text(
"已售${productListBeans?.sellCount ?? 0}", "已售${productListBeans?.sellCount ?? 0}",
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
color: Color(0xFF5D5D5D), color: Color(0xFF5D5D5D),
), ),
),alignment: Alignment.topRight,)), ),
alignment: Alignment.topRight,
)),
], ],
), ),
Text( Text(
@ -817,7 +837,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
), ),
), ),
TextSpan( TextSpan(
text:productListBeans?.price ?? "", text: productListBeans?.price ?? "",
style: TextStyle( style: TextStyle(
fontSize: 18.sp, fontSize: 18.sp,
fontWeight: MyFontWeight.semi_bold, fontWeight: MyFontWeight.semi_bold,

Loading…
Cancel
Save