You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

483 lines
16 KiB

3 years ago
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
3 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/data/user_bill.dart';
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/retrofit/data/vip_card.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:huixiang/view_widget/no_data_view.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shimmer/shimmer.dart';
3 years ago
class MineShopPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MineShopPage();
}
}
class _MineShopPage extends State<MineShopPage> with WidgetsBindingObserver{
3 years ago
List<VipCard> coupons = [];
ApiService apiService;
int current = 1;
RefreshController refreshController ;
final TextEditingController editingController = TextEditingController();
int optionIndex = 0;
bool isKeyBoardShow = false;
List<String> hotSearch = [];
List<String> historySearch = [];
FocusNode _focusNode = FocusNode();
bool hasFocus = true;
int priceOrder = 0;
int networkStatus = 0;
3 years ago
@override
void initState() {
super.initState();
refreshController = RefreshController();
SharedPreferences.getInstance().then((value) {
apiService =
ApiService(Dio(), context: context, token: value.getString("token"));
queryVipCard();
});
_focusNode.addListener(() {
setState(() {
hasFocus = _focusNode.hasFocus;
});
});
3 years ago
}
@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();
refreshController.dispose();
super.dispose();
3 years ago
}
queryVipCard({bool showLoading = true}) async {
try{
if(showLoading)EasyLoading.show(status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black);
BaseData<List<VipCard>> baseData =
await apiService.vipList({
"keywords":editingController.text,
}).catchError((error) {
networkStatus = -1;
refreshController.refreshFailed();
3 years ago
});
if (baseData != null && baseData.isSuccess) {
coupons.clear();
coupons.addAll(baseData.data);
refreshController.refreshCompleted();
networkStatus = 1;
} else {
refreshController.refreshFailed();
}
}finally{
EasyLoading.dismiss();
setState(() {});
3 years ago
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: (){
FocusScope.of(context).requestFocus(FocusNode());
},
child: Scaffold(
resizeToAvoidBottomInset: false,
appBar: MyAppBar(
title: S.of(context).dianpuchongzhi,
titleColor: Colors.black,
background: Colors.white,
leadingColor: Colors.black,
),
body:Column(
children: [
Container(
color: Colors.white,
padding: EdgeInsets.only(top:10.h,bottom:18.h,),
child: searchShop(),
),
Expanded(child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
controller: refreshController,
onRefresh: queryVipCard,
physics: BouncingScrollPhysics(),
child: networkStatus == 0 ? ListView.builder(
itemCount: 10,
physics: BouncingScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, position) {
return shopItemSm();
},
):((coupons != null && coupons.length > 0)
? ListView.builder(
padding: EdgeInsets.symmetric(vertical: 8.h),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(
'/router/mine_shop_recharge',
arguments: {
"id": coupons[position].id,
"tenantCode":coupons[position].tenantCode,
"storeId":coupons[position].storeList[0].id
}).then((value) {
queryVipCard(showLoading: false);
});
},
child: shopItem(coupons[position]),
);
},
itemCount: coupons != null ? coupons.length : 0,
)
: NoDataView(
src: "assets/image/icon_empty.webp",
isShowBtn: false,
text: "没有找到相应的门店,试试其他的搜索~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h),
)),
),)
],
),
),
);
}
Widget searchShop() {
return Container(
margin: EdgeInsets.fromLTRB(14.w, 0, 14.w, 0),
padding: EdgeInsets.symmetric(vertical: 6.h),
decoration: BoxDecoration(
color: Color(0xFFF5FAF7),
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
),
],
3 years ago
),
child: TextField(
textInputAction: TextInputAction.search,
onEditingComplete: () {
FocusScope.of(context).requestFocus(FocusNode());
queryVipCard();
},
controller: editingController,
style: TextStyle(
fontSize: 14.sp,
),
decoration: InputDecoration(
hintText: "搜索联盟会员店",
hintStyle: TextStyle(
fontSize: 12.sp,
color: Color(0xFFB3B3B3),
),
isCollapsed: true,
prefixIcon:Padding(padding: EdgeInsets.only(left: 5.w,right: 5.w),child: Image.asset(
"assets/image/icon_search.webp",
width: 16.h,
height: 16.h,
),),
prefixIconConstraints: BoxConstraints(),
border: InputBorder.none,
3 years ago
),
),
);
}
int colorByName(String storeName) {
if (storeName == null) return 0xFF32A060;
if (storeName.contains("百年川椒") || storeName.contains("百年川椒")) {
return 0xFFC30D23;
} else if (storeName.contains("海峡姐妹") || storeName.contains("海峽姐妹")) {
return 0xFFE4C796;
} else if (storeName.contains("前进麦味") || storeName.contains("前進麥味")) {
return 0xFF265782;
}
return 0xFF32A060;
}
Widget shopItem(VipCard vipCard) {
return Container(
width:double.infinity,
margin: EdgeInsets.only(bottom: 12.h,top: 14.h,left: 14.w,right: 14.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topLeft: Radius.circular(6),
topRight: Radius.circular(6),
),
color: Color(colorByName(vipCard.tenantName)),
),
padding: EdgeInsets.only(left: 12.w),
height: 62.h,
child: Row(
children: [
MImage(
(vipCard?.storeList?.length ?? 0) > 0
? vipCard.storeList[0].logo
: "",
width: 38,
height: 38,
fit: BoxFit.cover,
radius: BorderRadius.circular(100),
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
),
SizedBox(width: 6,),
Text(
vipCard.tenantName ?? "",
style: TextStyle(
color: Color(0xFFFFFFFF),
fontSize: 15.sp,
fontWeight: MyFontWeight.medium,
),
),
],
),
),
Container(
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
bottomRight: Radius.circular(6),
topRight: Radius.circular(6),
),
color: Colors.white,
),
padding: EdgeInsets.all(12.h),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"店铺余额(元)",
style: TextStyle(
color: Color(0xFF262626),
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
Text(
"No.${vipCard.id}",
style: TextStyle(
color: Color(0xFF262626),
fontSize: 12.sp,
fontFamily: 'JDZhengHT',
3 years ago
fontWeight: MyFontWeight.regular,
),
),
],
),
SizedBox(height:4.h,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(child: Text(
"${vipCard != null ? vipCard.balance : ""}",
style: TextStyle(
color: Color(0xFF262626),
fontSize:24.sp,
fontWeight: MyFontWeight.bold,
),
)),
Text(
"去充值",
3 years ago
style: TextStyle(
color: Color(0xFF262626),
3 years ago
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
SizedBox(width: 2,),
Image.asset(
"assets/image/icon_right_z.webp",
width: 16,
height: 16,
color: Color(0xFF262626),
)
3 years ago
],
),
],
),
),
],
),
);
}
Widget shopItemSm(){
return Container(
width:double.infinity,
margin: EdgeInsets.only(bottom: 12.h,top: 14.h,left: 14.w,right: 14.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
topLeft: Radius.circular(6),
topRight: Radius.circular(6),
),
color: Color(0XFFD8D8D8),
),
padding: EdgeInsets.only(left: 12.w),
height: 62.h,
child: Row(
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 38.h,
height: 38.h,
),
),
SizedBox(width: 6,),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 111.w,
height: 21.h,
),
),
],
),
),
Container(
decoration: BoxDecoration(
borderRadius: new BorderRadius.only(
bottomRight: Radius.circular(6),
topRight: Radius.circular(6),
),
color: Colors.white,
),
padding: EdgeInsets.all(12.h),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 68.w,
height: 17.h,
),
),
Spacer(),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 120.w,
height: 17.h,
),
),
],
),
SizedBox(height:4.h,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 98.w,
height: 33.h,
),
),
Spacer(),
Shimmer.fromColors(
baseColor: Color(0XFFD8D8D8),
highlightColor: Color(0XFFD8D8D8),
child: Container(
color: Color(0XFFD8D8D8),
width: 48.w,
height: 17.h,
),
),
SizedBox(width: 2,),
Image.asset(
"assets/image/icon_right_z.webp",
width: 16,
height: 16,
color: Color(0xFF262626),
)
],
),
],
),
),
],
),
);
}
3 years ago
}