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.

251 lines
8.0 KiB

import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:huixiang/business_system/goods/business_goods_page.dart';
import 'package:huixiang/business_system/mine/business_mine_page.dart';
import 'package:huixiang/business_system/order/business_order_page.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../retrofit/data/business_login_info.dart';
import 'home/business_home_page.dart';
import 'home/home_view/home_sideslip_dialog.dart';
class BusinessPage extends StatefulWidget {
final arguments;
BusinessPage({this.arguments});
@override
State<StatefulWidget> createState() {
return _BusinessPage();
}
}
class _BusinessPage extends State<BusinessPage>
with AutomaticKeepAliveClientMixin {
int choiceIndex = 0;
BusinessLoginInfo businessLoginInfo;
int selectStoreIndex = 0;
int switchStore = 0;
GlobalKey homePageKey = GlobalKey();
GlobalKey orderPageKey = GlobalKey();
GlobalKey goodsPageKey = GlobalKey();
GlobalKey minePageKey = GlobalKey();
var clickIndex = 0;
final PageController pageController = PageController();
@override
void initState() {
super.initState();
businessLoginInfo = widget?.arguments["businessLoginInfo"];
selectStoreIndex = widget.arguments["selectStoreIndex"] ?? 0;
}
@override
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
resizeToAvoidBottomInset: false,
body: Stack(
alignment: Alignment.bottomRight,
children: [
Container(
child: PageView(
controller: pageController,
children: [
BusinessHomePage(
homePageKey, businessLoginInfo, selectStoreIndex, showAlertDialog,
(index) {
setState(() {
pageController.jumpToPage(2);
});
}),
BusinessOrderPage(orderPageKey,
businessLoginInfo?.storeList[selectStoreIndex]?.id ?? "0"),
BusinessGoodsPage(goodsPageKey,
businessLoginInfo?.storeList[selectStoreIndex]?.id ?? "0"),
BusinessMinePage(minePageKey, businessLoginInfo,
businessLoginInfo?.storeList[selectStoreIndex]?.id ?? "0"),
],
physics: NeverScrollableScrollPhysics(),
onPageChanged: (index) {
clickIndex = index;
setState(() {});
},
),
),
if (switchStore == 0)
GestureDetector(
onTap: () {
setState(() {
switchStore = 1;
showAlertDialog();
});
},
child: Container(
width: 97.w,
decoration: BoxDecoration(
color: Color(0xFFEBEFF6),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(111),
bottomLeft: Radius.circular(111),
),
),
padding: EdgeInsets.only(left: 12.w, top: 10.h, bottom: 10.h),
margin: EdgeInsets.only(bottom: 170.h),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(right: 4.w),
child: Image.asset(
"assets/image/bs_switch.webp",
width: 12.w,
height: 15.h,
)),
Text(
"切换门店",
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFF30415B),
fontSize: 12.sp,
fontWeight: MyFontWeight.semi_bold,
),
),
],
),
),
),
],
),
extendBody: true,
bottomNavigationBar: Container(
alignment: Platform.isAndroid ? Alignment.center : Alignment.topCenter,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 2),
blurRadius: 4,
spreadRadius: 0,
)
],
borderRadius: BorderRadius.vertical(
top: Radius.circular(4),
),
),
height: 82.h,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
bottomNavigationItem("首页", 0, "assets/image/business_home.webp",
"assets/image/business_ home_h.webp"),
bottomNavigationItem("订单", 1, "assets/image/business_order.webp",
"assets/image/business_order_h.webp"),
// bottomNavigationItem("", 2,"assets/image/business_scan_code.webp","assets/image/business_scan_code.webp"),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context)
.pushNamed('/router/scan_code_page', arguments: {
"storeId":
businessLoginInfo?.storeList[selectStoreIndex]?.id ?? "0"
});
},
child: Container(
padding: EdgeInsets.only(top: 10.h),
child: Image.asset(
"assets/image/business_scan_code.webp",
width: 52.h,
height: 52.h,
),
),
),
bottomNavigationItem("商品", 2, "assets/image/business_goods.webp",
"assets/image/business_goods_h.webp"),
bottomNavigationItem("我的", 3, "assets/image/business_mine.webp",
"assets/image/business_mine_h.webp"),
],
),
),
);
}
Widget bottomNavigationItem(text, index, image, unImage) {
var isSelected = index == clickIndex;
return Expanded(
child: InkWell(
onTap: () {
setState(() {
clickIndex = index;
pageController.jumpToPage(clickIndex);
});
},
child: Container(
width: 45.w,
child: Column(
mainAxisAlignment: Platform.isAndroid
? MainAxisAlignment.center
: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (Platform.isIOS)
SizedBox(
height: 4.h,
),
Image.asset(
isSelected ? image : unImage,
width: 30.h,
height: 30.h,
),
Text(
text,
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.semi_bold,
color: isSelected ? Color(0xFF4C4C4C) : Color(0xFFACACAC),
),
),
],
),
),
),
flex: 1,
);
}
///侧面弹窗
showAlertDialog() async {
try {
int index = await showCupertinoModalPopup(
builder: (context) {
return HomeSideslipDialog(selectStoreIndex, businessLoginInfo);
},
context: context);
if (index != null) {
if (index == -1) {
Navigator.of(context).pop();
return;
}
setState(() {
selectStoreIndex = index;
homePageKey = GlobalKey();
orderPageKey = GlobalKey();
goodsPageKey = GlobalKey();
minePageKey = GlobalKey();
});
}
} finally {
setState(() {
switchStore = 0;
});
}
}
@override
bool get wantKeepAlive => true;
}