import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:huixiang/business_system/order/ticket/ticket_list.dart'; import 'package:huixiang/business_system/order/ticket/ticket_records_page.dart'; import 'package:huixiang/business_system/order/ticket/ticket_statistics_page.dart'; import 'package:huixiang/business_system/order/ticket/ticket_tab.dart'; import 'package:intl/intl.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import '../../../utils/font_weight.dart'; import '../../../view_widget/my_appbar.dart'; import '../../../view_widget/my_tab.dart'; class TicketPage extends StatefulWidget { final String storeId; TicketPage(this.storeId); @override State createState() { return _TicketPage(); } } class _TicketPage extends State with SingleTickerProviderStateMixin { final RefreshController refreshController = RefreshController(); final ScrollController scrollController = ScrollController(); final TextEditingController editingController = TextEditingController(); FocusNode _focusNode = FocusNode(); bool isKeyBoardShow = false; List _allKey = []; String selectTimeDate = ""; String selectTimeDateNum = "${DateFormat("yyyy年MM月dd日 00:00:00").format(DateTime.now().subtract(Duration(days:5)))} 至 " "${DateFormat("yyyy年MM月dd日 23:59:59").format(DateTime.now())}"; bool typeScreen = false; bool stateScreen = false; String ticketType; String ticketState = "-1"; TabController tabController; @override void initState() { super.initState(); tabController = TabController(length: 3, vsync: this); tabController.addListener(() { if (!tabController.indexIsChanging) { setState(() {}); FocusScope.of(context).requestFocus(FocusNode()); } }); 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; } }); }); loadFinish(); } loadFinish() { _allKey = [GlobalKey(), GlobalKey(), GlobalKey()]; setState(() {}); } ///离开页面记着销毁和清除 @override void dispose() { _focusNode.unfocus(); super.dispose(); } @override Widget build(BuildContext context) { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { FocusScope.of(context).requestFocus(FocusNode()); }, child: Stack( children: [ Column( children: [ Container( width: double.infinity, height: 1.h, color: Color(0xFFD8D8D8), ), ticketSearch(), tabController.index == 0 ? screen() : timeSelect(), Expanded( child: DefaultTabController( length: 3, child: Scaffold( resizeToAvoidBottomInset: false, appBar: MyAppBar( title: "", leading: false, background: Colors.white, bottom: TabBar( // isScrollable: true, //可滚动 //去掉按钮阴影 overlayColor: MaterialStateProperty.all(Colors.white), indicator: const TicketTab( width: 33, borderSide: BorderSide( width: 2.0, color: Color(0xFF30415B))), labelColor: Colors.black, labelStyle: TextStyle( fontSize: 15.sp, fontWeight: FontWeight.bold, ), unselectedLabelStyle: TextStyle( fontSize: 15.sp, fontWeight: FontWeight.normal, color: Color(0xFF666666)), controller: tabController, //未选中文字颜色 unselectedLabelColor: Color(0xFF0D0D0D), //指示器与文字等宽 tabs: [ MyTab(text: "票券列表"), MyTab(text: "核销记录"), MyTab(text: "核销统计"), ], ), ), body: TabBarView( controller: tabController, children: [ TicketList( _allKey[0], ticketState == "-1" ? "0" : ticketState, ticketType, widget.storeId, editingController.text, typeScreen, stateScreen, MediaQuery.of(context).viewInsets.bottom != 0 ? isKeyBoardShow = true : isKeyBoardShow = false), TicketRecordPage( _allKey[1], 1, widget.storeId, editingController.text, (selectTimeDate == "" || selectTimeDate == null) ? "" :selectTimeDate, MediaQuery.of(context).viewInsets.bottom != 0 ? isKeyBoardShow = true : isKeyBoardShow = false), TicketStatisticsPage( _allKey[2], 2, widget.storeId, editingController.text, selectTime(), MediaQuery.of(context).viewInsets.bottom != 0 ? isKeyBoardShow = true : isKeyBoardShow = false), ], ), ), ), ), SizedBox( height: 76.h, ), ], ), Container( padding: EdgeInsets.symmetric(horizontal: 18.w), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ if (typeScreen && tabController.index == 0) Expanded( child: Container( height: 176.h, decoration: BoxDecoration( color: Colors.white, border: Border.all( color: Color(0x29000000), width: 0.5.w, ), borderRadius: BorderRadius.circular(2), ), margin: EdgeInsets.only(top: 108.h), padding: EdgeInsets.symmetric( horizontal: 16.w, vertical: 8.h), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketType = ""; typeScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "所有", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), )), ), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketType = "ADOPT_WARRANT"; typeScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "认领凭证", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), ), )), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketType = "IDENTITY_CARD"; typeScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "身份卡片", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), ), )), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketType = "NORMAL"; typeScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "常规票券", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), ))), ], ))), if (!typeScreen || !stateScreen) Expanded(child: Container()), SizedBox( width: 14.w, ), if (stateScreen && tabController.index == 0) Expanded( child: Container( height: 210.h, decoration: BoxDecoration( color: Colors.white, border: Border.all( color: Color(0x29000000), width: 0.5.w, ), borderRadius: BorderRadius.circular(2), ), margin: EdgeInsets.only(top: 108.h), padding: EdgeInsets.symmetric( horizontal: 16.w, vertical: 8.h), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketState = "0"; stateScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "全部", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), ))), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketState = "1"; stateScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "可使用", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), ), )), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketState = "7"; stateScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "已取消", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), ), )), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketState = "8"; stateScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "已失效", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), ), )), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { setState(() { ticketState = "9"; stateScreen = false; loadFinish(); }); }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 8.h), child: Text( "已使用", style: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), ), )), ], ))), ], ), ), ], ), ); } /// 搜索框 Widget ticketSearch() { return Container( color: Colors.white, child: Container( height: 40.h, margin: EdgeInsets.only(left: 18.w, right: 18.w, top: 6.h, bottom: 13.h), decoration: BoxDecoration( color: Color(0xFFF7F8FA), borderRadius: BorderRadius.circular(2), ), child: TextField( focusNode: _focusNode, textInputAction: TextInputAction.search, onTap: () { typeScreen = false; stateScreen = false; }, onEditingComplete: () { FocusScope.of(context).requestFocus(FocusNode()); loadFinish(); }, style: TextStyle( fontSize: 15.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF808080), ), controller: editingController, decoration: InputDecoration( hintText: "请输入票券名称/用户名/手机号", hintStyle: TextStyle( color: Color(0xFF808080), fontSize: 15.sp, fontWeight: MyFontWeight.regular), contentPadding: EdgeInsets.symmetric( vertical: 12.h, ), prefixIcon: Image.asset( "assets/image/bs_goods_search.webp", width: 20, height: 20, ), border: InputBorder.none, ), ), ), ); } ///筛选框 Widget screen() { return Container( color: Colors.white, width: double.infinity, padding: EdgeInsets.only(left: 18.w, right: 18.w), child: Row( children: [ Expanded( child: GestureDetector( onTap: () { setState(() { typeScreen = !typeScreen; FocusScope.of(context).requestFocus(FocusNode()); stateScreen = false; }); }, child: Container( decoration: BoxDecoration( color: Color(0XFFF7F8FA), borderRadius: BorderRadius.circular(2), ), padding: EdgeInsets.symmetric(horizontal: 9.w, vertical: 11.h), child: Row( children: [ Expanded( child: Text( ticketType == null ? "类型筛选" : shopTypeSelect(), style: TextStyle( color: Color(0xFF808080), fontSize: 18.sp, fontWeight: MyFontWeight.regular), )), Icon( (typeScreen != null && !typeScreen) ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_up, color: Color(0xFF808080), size: 24, ), ], ), ), ), ), SizedBox( width: 14.w, ), Expanded( child: GestureDetector( onTap: () { setState(() { stateScreen = !stateScreen; FocusScope.of(context).requestFocus(FocusNode()); typeScreen = false; }); }, child: Container( decoration: BoxDecoration( color: Color(0XFFF7F8FA), borderRadius: BorderRadius.circular(2), ), padding: EdgeInsets.symmetric(horizontal: 9.w, vertical: 11.h), child: Row( children: [ Expanded( child: Text( ticketState == "-1" ? "状态筛选" : shopStateSelect(), style: TextStyle( color: Color(0xFF808080), fontSize: 18.sp, fontWeight: MyFontWeight.regular), )), Icon( (stateScreen != null && !stateScreen) ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_up, color: Color(0xFF808080), size: 24, ), ], ), ))), ], ), ); } ///类型筛选 String shopTypeSelect() { if (ticketType == "") { return "所有"; } else if (ticketType == "ADOPT_WARRANT") { return "认领凭证"; } else if (ticketType == "IDENTITY_CARD") { return "身份卡片"; } else if (ticketType == "NORMAL") { return "常规票券"; } } ///类型筛选 String shopStateSelect() { if (ticketState == "0") { return "全部"; } else if (ticketState == "1") { return "可使用"; } else if (ticketState == "7") { return "已取消"; } else if (ticketState == "8") { return "已失效"; } else if (ticketState == "9") { return "已使用"; } } ///时间选择 Widget timeSelect() { return Container( color: Colors.white, child: GestureDetector( onTap: () { Navigator.of(context).pushNamed('/router/custom_page',arguments: {"beyondDateRange": "0"}).then((value) { selectTimeDate = value; loadFinish(); }); }, child: Container( decoration: BoxDecoration( color: Color(0xFFF7F8FA), borderRadius: BorderRadius.circular(2), ), margin: EdgeInsets.only( left: 18.w, right: 18.w, ), padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 12.h), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( (tabController.index == 1 && (selectTimeDate == "" || selectTimeDate == null)) ? "开始时间 至 结束时间" :"${selectTime().substring(0, 11)} ${selectTime().substring(21, 34)}", style: TextStyle( fontSize: 14.sp, color: Color(0xFF30415B), fontWeight: MyFontWeight.regular), ), ], ), ), ), ); } String selectTime() { if (selectTimeDate == "" || selectTimeDate == null) { return selectTimeDateNum; } else return selectTimeDate; } }