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

Loading…
Cancel
Save