|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
|
|
|
|
import 'package:huixiang/utils/font_weight.dart';
|
|
|
|
import 'package:huixiang/view_widget/classic_header.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import '../../generated/l10n.dart';
|
|
|
|
import '../../retrofit/business_api.dart';
|
|
|
|
import '../../retrofit/data/base_data.dart';
|
|
|
|
import '../../retrofit/data/business_goods.dart';
|
|
|
|
import '../../utils/business_instance.dart';
|
|
|
|
import '../../utils/flutter_utils.dart';
|
|
|
|
import '../../view_widget/custom_image.dart';
|
|
|
|
import '../../view_widget/my_appbar.dart';
|
|
|
|
import '../../view_widget/my_footer.dart';
|
|
|
|
import '../../view_widget/no_data_view.dart';
|
|
|
|
|
|
|
|
class GoodsSearchPage extends StatefulWidget {
|
|
|
|
final Map<String, dynamic> arguments;
|
|
|
|
|
|
|
|
GoodsSearchPage({this.arguments});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _GoodsSearchPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GoodsSearchPage extends State<GoodsSearchPage>
|
|
|
|
with WidgetsBindingObserver {
|
|
|
|
final TextEditingController editingController = TextEditingController();
|
|
|
|
final RefreshController refreshController = RefreshController();
|
|
|
|
final ScrollController scrollController = ScrollController();
|
|
|
|
int optionIndex = 0;
|
|
|
|
bool isKeyBoardShow = false;
|
|
|
|
List<ProductListBean> productListBeans = [];
|
|
|
|
List<String> hotSearch = [];
|
|
|
|
List<String> historySearch = [];
|
|
|
|
FocusNode _focusNode = FocusNode();
|
|
|
|
bool hasFocus = true;
|
|
|
|
int priceOrder = 0;
|
|
|
|
int _pageIndex = 1;
|
|
|
|
BusinessApiService businessService;
|
|
|
|
List<AdminProductVoList> adminProductVoList = [];
|
|
|
|
int goodsIndex = 0;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeMetrics() {
|
|
|
|
super.didChangeMetrics();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
setState(() {
|
|
|
|
print("object: ${MediaQuery.of(context).viewInsets.bottom}");
|
|
|
|
if (MediaQuery.of(context).viewInsets.bottom == 0) {
|
|
|
|
if (isKeyBoardShow) {
|
|
|
|
isKeyBoardShow = false;
|
|
|
|
//关闭键盘 软键盘关闭了, 清除输入控件的焦点, 否则重新进入页面会导致软键盘再弹出问题
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
isKeyBoardShow = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
///离开页面记着销毁和清除
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_focusNode.unfocus();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_focusNode.addListener(() {
|
|
|
|
setState(() {
|
|
|
|
hasFocus = _focusNode.hasFocus;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
_onRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
_onRefresh({bool isShowLoad = true}) async {
|
|
|
|
if (isShowLoad)
|
|
|
|
EasyLoading.show(
|
|
|
|
status: S.current.zhengzaijiazai,
|
|
|
|
maskType: EasyLoadingMaskType.black);
|
|
|
|
await queryGoodsList();
|
|
|
|
EasyLoading.dismiss();
|
|
|
|
if (!mounted) return;
|
|
|
|
if (refreshController.isRefresh) refreshController.refreshCompleted();
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
///商品列表
|
|
|
|
queryGoodsList() async {
|
|
|
|
if (businessService == null) {
|
|
|
|
businessService = BusinessApiService(Dio(),
|
|
|
|
context: context,
|
|
|
|
token: BusinessInstance.instance.businessToken,
|
|
|
|
tenant: BusinessInstance.instance.businessTenant,
|
|
|
|
storeId: widget.arguments["storeId"]);
|
|
|
|
}
|
|
|
|
BaseData<BusinessGoods> baseData =
|
|
|
|
await businessService.findAdminProductLis({
|
|
|
|
"groupId": "",
|
|
|
|
"hasStock": "",
|
|
|
|
"keyword": editingController?.text ?? "",
|
|
|
|
"pageIndex": _pageIndex,
|
|
|
|
"pageSize": 10,
|
|
|
|
"status": widget.arguments["onSaleStatus"],
|
|
|
|
}).catchError((error) {
|
|
|
|
SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type),
|
|
|
|
alignment: Alignment.center);
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
refreshController.loadFailed();
|
|
|
|
});
|
|
|
|
if (!mounted) return;
|
|
|
|
if (baseData != null && baseData.isSuccess) {
|
|
|
|
adminProductVoList.addAll(baseData?.data?.adminProductVOList ?? []);
|
|
|
|
if ((baseData?.data?.adminProductVOList ?? []).isEmpty ||
|
|
|
|
adminProductVoList.length == baseData.data.total)
|
|
|
|
refreshController.loadNoData();
|
|
|
|
else
|
|
|
|
refreshController.loadComplete();
|
|
|
|
} else {
|
|
|
|
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
queryGoodsUpdate() async {
|
|
|
|
if (businessService == null) {
|
|
|
|
businessService = BusinessApiService(Dio(),
|
|
|
|
context: context,
|
|
|
|
token: BusinessInstance.instance.businessToken,
|
|
|
|
tenant: BusinessInstance.instance.businessTenant,
|
|
|
|
storeId: widget.arguments["storeId"]);
|
|
|
|
}
|
|
|
|
BaseData baseData =
|
|
|
|
await businessService.goodsUpdate({
|
|
|
|
"productId": adminProductVoList[goodsIndex]?.id ?? "",
|
|
|
|
"sell": widget.arguments["onSaleStatus"] == "1"?false:true,
|
|
|
|
}).catchError((error) {
|
|
|
|
});
|
|
|
|
if (baseData != null && baseData.isSuccess) {
|
|
|
|
_pageIndex = 1;
|
|
|
|
adminProductVoList.clear();
|
|
|
|
await _onRefresh();
|
|
|
|
SmartDialog.showToast(widget.arguments["onSaleStatus"] == "1"?"商品下架成功":"商品上架成功", alignment: Alignment.center);
|
|
|
|
} else {
|
|
|
|
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
|
|
|
behavior: HitTestBehavior.translucent,
|
|
|
|
onTap: () {
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: MyAppBar(
|
|
|
|
title: "搜索",
|
|
|
|
titleColor: Colors.black,
|
|
|
|
leadingColor: Colors.black,
|
|
|
|
background: Colors.white,
|
|
|
|
),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
color: Colors.white,
|
|
|
|
margin: EdgeInsets.only(bottom: 16.h),
|
|
|
|
child:
|
|
|
|
Container(
|
|
|
|
height: 40.h,
|
|
|
|
margin: EdgeInsets.fromLTRB(18.w, 17.h, 18.w, 10.h),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Color(0xFFF7F8FA),
|
|
|
|
borderRadius: BorderRadius.circular(2),
|
|
|
|
),
|
|
|
|
child: TextField(
|
|
|
|
textInputAction: TextInputAction.search,
|
|
|
|
onEditingComplete: () {
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
_pageIndex = 1;
|
|
|
|
adminProductVoList.clear();
|
|
|
|
_onRefresh();
|
|
|
|
},
|
|
|
|
controller: editingController,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "请输入搜索内容",
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
fontSize: 15.sp,
|
|
|
|
color: Color(0xFF808080),
|
|
|
|
fontWeight: MyFontWeight.regular
|
|
|
|
),
|
|
|
|
isCollapsed: true,
|
|
|
|
prefixIcon: Padding(
|
|
|
|
padding: EdgeInsets.only(left: 5.w, right: 5.w),
|
|
|
|
child: Image.asset(
|
|
|
|
"assets/image/icon_search.webp",
|
|
|
|
width: 20.h,
|
|
|
|
height: 20.h,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
prefixIconConstraints: BoxConstraints(),
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
child: SmartRefresher(
|
|
|
|
controller: refreshController,
|
|
|
|
enablePullDown: true,
|
|
|
|
enablePullUp: true,
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
header: MyHeader(
|
|
|
|
color: Color(0xFF30415B),
|
|
|
|
),
|
|
|
|
footer: CustomFooter(
|
|
|
|
builder: (context, mode) {
|
|
|
|
return MyFooter(mode);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
onRefresh: () {
|
|
|
|
_pageIndex = 1;
|
|
|
|
adminProductVoList.clear();
|
|
|
|
_onRefresh(isShowLoad: false);
|
|
|
|
},
|
|
|
|
onLoading: () {
|
|
|
|
_pageIndex++;
|
|
|
|
_onRefresh(isShowLoad: false);
|
|
|
|
},
|
|
|
|
child: (adminProductVoList == null ||
|
|
|
|
adminProductVoList.length == 0)
|
|
|
|
? NoDataView(
|
|
|
|
src: "assets/image/bs_no data_logo.webp",
|
|
|
|
isShowBtn: false,
|
|
|
|
text: "未搜索到相关数据",
|
|
|
|
fontSize: 16.sp,
|
|
|
|
margin: EdgeInsets.all(20.h),
|
|
|
|
)
|
|
|
|
: Container(
|
|
|
|
margin: EdgeInsets.only(bottom:20.h),
|
|
|
|
child: ListView.builder(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
itemCount: adminProductVoList?.length ?? 0,
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: NeverScrollableScrollPhysics(),
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
goodsIndex = position;
|
|
|
|
},
|
|
|
|
child:
|
|
|
|
searchGoodsItem(adminProductVoList[position]),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget searchGoodsItem(AdminProductVoList adminProductVoList) {
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Color(0x0F06152E).withAlpha(12),
|
|
|
|
offset: Offset(0, 2),
|
|
|
|
blurRadius: 4,
|
|
|
|
spreadRadius: 0,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
margin: EdgeInsets.only(bottom: 12.h, left: 16.w, right: 16.w),
|
|
|
|
padding:
|
|
|
|
EdgeInsets.only(left: 12.w, top: 12.h, bottom: 12.h, right: 24.w),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
MImage(
|
|
|
|
adminProductVoList?.productImg ?? "",
|
|
|
|
width: 70.h,
|
|
|
|
height: 70.h,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
radius: BorderRadius.circular(4),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: 12.w,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 11.h, top: 2.h),
|
|
|
|
child: Text(
|
|
|
|
adminProductVoList?.productName ?? "",
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
fontWeight: MyFontWeight.medium,
|
|
|
|
color: Color(0xFF000000),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"库存${adminProductVoList?.stock ?? 0}",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
color: Color(0xFFA29E9E),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: 8.w,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"销量${adminProductVoList?.sellCount ?? 0}",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
color: Color(0xFF999999),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 7.h,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Text.rich(
|
|
|
|
TextSpan(
|
|
|
|
children: [
|
|
|
|
TextSpan(
|
|
|
|
text: "¥",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12.sp,
|
|
|
|
fontWeight: MyFontWeight.medium,
|
|
|
|
color: Color(0xFFF4524D),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text: adminProductVoList?.price ?? "",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14.sp,
|
|
|
|
fontWeight: MyFontWeight.medium,
|
|
|
|
color: Color(0xFFF4524D),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
GestureDetector(
|
|
|
|
behavior: HitTestBehavior.opaque,
|
|
|
|
onTap: (){
|
|
|
|
queryGoodsUpdate();
|
|
|
|
},
|
|
|
|
child:Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
borderRadius: BorderRadius.circular(33),
|
|
|
|
border: Border.all(
|
|
|
|
color: Color(0xFF30415B),
|
|
|
|
width: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(vertical: 2.h, horizontal: 12.w),
|
|
|
|
child: Text(
|
|
|
|
widget.arguments["onSaleStatus"] == "1"?"下架":"上架",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12.sp,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
color: Color(0xFF30415B),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|