Browse Source

商城更改

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

450
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;
var str = value.getString("historySearch");
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 = "";
var str = value.getString("historySearch");
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,43 +121,52 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
}
///
delHistorySearch()async{
delHistorySearch() async {
SharedPreferences value = await SharedPreferences.getInstance();
value.setString("historySearch", "");
getHistorySearch();
value.setString("historySearch", "");
getHistorySearch();
}
///
appletGoods(String text) async {
if(editingController.text.trim() == ""){
if (editingController.text.trim() == "") {
return;
}
if(minService == null)
minService = MinApiService(
Dio(),
context: context,
token: widget.arguments["minToken"],
tenant:widget.arguments["tenant"],
storeId: widget.arguments["storeId"],
);
if (minService == null)
minService = MinApiService(
Dio(),
context: context,
token: widget.arguments["minToken"],
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) {
refreshController.refreshFailed();
});
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();
});
if (baseData != null && baseData.isSuccess) {
refreshController.refreshCompleted();
setState(() {
productListBeans.clear();
if(baseData.data.length > 0)
productListBeans.addAll(baseData.data[0].productList);
productListBeans.clear();
if (baseData.data.length > 0)
productListBeans.addAll(baseData.data[0].productList);
});
} else {
refreshController.refreshFailed();
@ -171,7 +179,7 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
});
}
_onRefresh(){
_onRefresh() {
appletGoods(editingController.text);
refreshController.refreshCompleted();
}
@ -226,67 +234,66 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
),
),
Expanded(
child:
Container(
height: 36.h,
margin: EdgeInsets.fromLTRB(6.w, 0, 14.w, 0),
padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
),
],
child: Container(
height: 36.h,
margin: EdgeInsets.fromLTRB(6.w, 0, 14.w, 0),
padding: EdgeInsets.fromLTRB(0, 6.h, 0, 6.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
),
child: TextField(
focusNode:_focusNode,
textInputAction: TextInputAction.search,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFF292929),
),
onEditingComplete: () {
// startLocation();
],
),
child: TextField(
focusNode: _focusNode,
textInputAction: TextInputAction.search,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFF292929),
),
onEditingComplete: () {
// startLocation();
},
controller: editingController,
// cursorHeight: 30.h,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
vertical: 12.h,
),
prefixIcon: Icon(
Icons.search,
size: 24,
color: Colors.black,
),
suffixIcon: InkWell(
onTap: () {
editingController.clear();
},
controller: editingController,
// cursorHeight: 30.h,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
vertical: 12.h,
),
prefixIcon: Icon(
Icons.search,
size: 24,
color: Colors.black,
),
suffixIcon: InkWell(
onTap: () {
editingController.clear();
},
child: Icon(
Icons.close,
size: 19,
color: Colors.grey,
),
),
border: InputBorder.none,
child: Icon(
Icons.close,
size: 19,
color: Colors.grey,
),
),
)
),
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);
@ -326,26 +333,24 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
header: MyHeader(),
physics: BouncingScrollPhysics(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: () {
setState(() {
_onRefresh();
});
},
),onRefresh: () {
setState(() {
_onRefresh();
});
},
child: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: FutureBuilder(
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(
padding: EdgeInsets.only(left: 4, right: 4),
height: 29.h,
text:historySearch,
textColor: Color(0xFF181818),
fontWeight: MyFontWeight.regular,
radius: 4,
backgroup: Color(0xFFF5F5F5),
fontSize: 12.sp,
),)
Expanded(
child: Container(
padding: EdgeInsets.only(left: 4, right: 4),
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,
),
)
@ -663,45 +679,45 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
],
),
SizedBox(height: 16.h),
(productListBeans == null || productListBeans?.length == 0)
(productListBeans == null || productListBeans?.length == 0)
? NoDataView(
src:"assets/image/ding_dan.png",
isShowBtn: false,
text:"该关键词未搜索到相关商品~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h,left: 60.w,right: 60.w),
):
GridView.builder(
itemCount:productListBeans?.length ?? 0,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
//Widget数量
crossAxisCount: 2,
//Widget之间间距
crossAxisSpacing: 11.w,
//Widget之间间距
mainAxisSpacing: 16.w,
//Widget宽高比例 0.59
childAspectRatio:
185 / (281 / 2 + (281 / 2) * AppUtils.textScale(context)),
),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(
'/router/shopping_goods_details',
arguments: {
"id":productListBeans[index].id,
"storeId":widget.arguments["storeId"],
"tenant":widget.arguments["tenant"],
},
);
},
child: searchListItem(productListBeans[index]),
);
},
)
src: "assets/image/ding_dan.png",
isShowBtn: false,
text: "该关键词未搜索到相关商品~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w),
)
: GridView.builder(
itemCount: productListBeans?.length ?? 0,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
//Widget数量
crossAxisCount: 2,
//Widget之间间距
crossAxisSpacing: 11.w,
//Widget之间间距
mainAxisSpacing: 16.w,
//Widget宽高比例 0.59
childAspectRatio: 185 /
(281 / 2 + (281 / 2) * AppUtils.textScale(context)),
),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(
'/router/shopping_goods_details',
arguments: {
"id": productListBeans[index].id,
"storeId": widget.arguments["storeId"],
"tenant": widget.arguments["tenant"],
},
);
},
child: searchListItem(productListBeans[index]),
);
},
)
],
),
);
@ -739,15 +755,14 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
)
],
),
child:
MImage(
productListBeans?.imgPath ??"",
width: double.infinity,
height: 166,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
),
child: MImage(
productListBeans?.imgPath ?? "",
width: double.infinity,
height: 166,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
),
),
Expanded(
child: Container(
@ -760,35 +775,40 @@ class _SearchPage extends State<SearchPage> with AutomaticKeepAliveClientMixin,
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(child:Container(
margin: EdgeInsets.only(top: 8, right: 8),
padding: EdgeInsets.only(left: 2, right: 2),
height: 17.h,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2),
color: Color(0xFF5A5A5A),
Expanded(
child: Container(
margin: EdgeInsets.only(top: 8, right: 8),
padding: EdgeInsets.only(left: 2, right: 2),
height: 17.h,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2),
color: Color(0xFF5A5A5A),
),
child: Text(
productListBeans.supplierName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.regular,
color: Colors.white,
),
),
),
),
Expanded(
child: Container(
child: Text(
productListBeans.supplierName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
"已售${productListBeans?.sellCount ?? 0}",
style: TextStyle(
fontSize: 10.sp,
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Colors.white,
color: Color(0xFF5D5D5D),
),
),
),),
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