123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- import 'dart:async';
- import 'package:flustars/flustars.dart';
- import 'package:flutter/material.dart';
- import 'package:liftmanager/common/common.dart';
- import 'package:liftmanager/internal/bbs/bbs_router.dart';
- import 'package:liftmanager/internal/heavy/heavy_router.dart';
- import 'package:liftmanager/internal/maintenance/maintenance_router.dart';
- import 'package:liftmanager/internal/message/message_router.dart';
- import 'package:liftmanager/internal/project/project_router.dart';
- import 'package:liftmanager/internal/repair/repair_router.dart';
- import 'package:liftmanager/internal/sign/sign_router.dart';
- import 'package:liftmanager/internal/team/team_router.dart';
- import 'package:liftmanager/internal/work/model/banner_entity.dart';
- import 'package:liftmanager/internal/work/model/count_doing_item.dart';
- import 'package:liftmanager/internal/work/provider/work_page_provider.dart';
- import 'package:liftmanager/internal/work/work_router.dart';
- import 'package:liftmanager/internal/yearly/yearly_router.dart';
- import 'package:liftmanager/net/api_service.dart';
- import 'package:liftmanager/res/resources.dart';
- import 'package:liftmanager/routers/fluro_navigator.dart';
- import 'package:liftmanager/utils/theme_utils.dart';
- import 'package:liftmanager/utils/toast.dart';
- import 'package:liftmanager/utils/utils.dart';
- import 'package:liftmanager/widgets/load_image.dart';
- import 'package:liftmanager/widgets/my_card.dart';
- import 'package:liftmanager/widgets/my_flexible_space_bar.dart';
- import 'package:oktoast/oktoast.dart';
- import 'package:provider/provider.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart' as su;
- const timeout = const Duration(seconds: 5);
- CountDoingItem countDoingItem = CountDoingItem();
- int caseNum = 0;
- class WorkPage extends StatefulWidget {
- @override
- State<StatefulWidget> createState() {
- return _WorkPageState();
- }
- }
- class _WorkPageState extends State<WorkPage> with TickerProviderStateMixin {
- WorkPageProvider provider = WorkPageProvider();
- TabController _tabController;
- PageController _pageController = PageController();
- int _index = 0;
- Timer _timer;
- List<BannerEntity> bannerList = [];
- // FToast fToast;
- @override
- void initState() {
- _tabController = TabController(length: 0, vsync: this);
- _timer = Timer.periodic(timeout, _handleTimeout);
- getBanner();
- countDoing();
- getCaseNum();
- super.initState();
- // fToast = FToast(context);
- }
- @override
- void dispose() {
- _tabController?.dispose();
- _timer.cancel();
- _pageController.dispose();
- super.dispose();
- }
- void getBanner() {
- ApiService(context: context).getBanner(onSuccess: (data) {
- if (!mounted) {
- return;
- }
- bannerList = data; //todo
- if (bannerList.length > 0) {
- _pageController.jumpToPage(0);
- _tabController = TabController(length: bannerList.length, vsync: this);
- setState(() {});
- }
- }, onError: (code, msg) {
- showToast(msg);
- });
- }
- void countDoing() {
- ApiService(context: context).countDoing(onSuccess: (data) {
- if (!mounted) return;
- setState(() {
- countDoingItem = data; //todo
- });
- }, onError: (code, msg) {
- // showToast(msg);
- });
- }
- void getCaseNum() {
- // liftCases/getUndealedCaseNum
- ApiService(context: context).getcaseNum(onSuccess: (data) {
- if (!mounted) return;
- setState(() {
- caseNum = data ?? 0;
- // countDoingItem = data; //todo
- });
- }, onError: (code, msg) {
- // showToast(msg);
- });
- }
- _handleTimeout(Timer timer) {
- _index++;
- _pageController.animateToPage(
- _index % (bannerList.length == 0 ? 1 : bannerList.length),
- duration: Duration(milliseconds: 16),
- curve: Curves.fastOutSlowIn,
- );
- }
- void _onPageChanged(int index) {
- _index = index;
- _tabController.animateTo(index);
- }
- goToPage(pagePath) {
- NavigatorUtils.pushResult(context, pagePath, (res) {
- countDoing();
- });
- }
- @override
- Widget build(BuildContext context) {
- return ChangeNotifierProvider<WorkPageProvider>(
- create: (_) => provider,
- child: Scaffold(
- backgroundColor: ThemeUtils.getTabsBg(context),
- body: CustomScrollView(
- key: const Key('statistic_list'),
- physics: ClampingScrollPhysics(),
- slivers: _sliverBuilder(),
- ),
- ));
- }
- Widget bannerWidget() {
- bool isDark = ThemeUtils.isDark(context);
- return Container(
- // height: 280,
- child: Stack(
- children: <Widget>[
- Container(
- height: 210,
- child: PageView(
- children: bannerList.map((item) {
- return GestureDetector(
- onTap: () {
- if (item.url.length > 0) {
- goToPage("${WorkRouter.webview}?title=" +
- Uri.encodeComponent("详情") +
- "&url=" +
- Uri.encodeComponent(item.url));
- }
- },
- child: Image.network(
- item.image ?? "",
- fit: BoxFit.fill, //使照片占满整个屏幕
- ),
- );
- }).toList(),
- onPageChanged: _onPageChanged,
- controller: _pageController,
- ),
- ),
- // Align(
- // alignment: Alignment(0.0, 0.9),
- // child: TabPageSelector(
- // color: Colors.white,
- // selectedColor: Colours.app_main,
- // controller: _tabController,
- // ),
- // ),
- Positioned(
- right: 10,
- left: 10,
- bottom: 0,
- child: MyCard(
- // shadowColor: Colors.red,
- child: Container(
- color: isDark ? Colours.dark_bg_color : Colors.white,
- height: 90.0,
- padding: const EdgeInsets.only(top: 8.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: <Widget>[
- _TabView(
- 0,
- '待保养',
- onTap: () {
- if (SpUtil.getString(Constant.companyId).length == 0) {
- showAlert(
- context,
- "提示",
- "尚未加入团队,是否立即加入?",
- "确定",
- () {
- NavigatorUtils.goBack(context);
- // NavigatorUtils.goBackWithParams(context, true);
- goToPage(TeamRouter.teamListPage);
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- // NavigatorUtils.goBackWithParams(context, true);
- });
- } else {
- goToPage(
- "${MaintenanceRouter.maintenanceListPage}?top_into=0");
- }
- },
- ),
- _TabView(
- 1,
- '待急修',
- onTap: () {
- if (SpUtil.getString(Constant.companyId).length == 0) {
- showAlert(
- context,
- "提示",
- "尚未加入团队,是否立即加入?",
- "确定",
- () {
- NavigatorUtils.goBack(context);
- goToPage(TeamRouter.teamListPage);
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- });
- } else {
- goToPage("${RepairRouter.repairListPage}?top_into=1");
- }
- },
- ),
- _TabView(
- 2,
- '待年检',
- onTap: () {
- if (SpUtil.getString(Constant.companyId).length == 0) {
- showAlert(
- context,
- "提示",
- "尚未加入团队,是否立即加入?",
- "确定",
- () {
- NavigatorUtils.goBack(context);
- goToPage(TeamRouter.teamListPage);
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- });
- } else {
- goToPage("${YearlyRouter.yearlyListPage}?top_into=1");
- }
- },
- ),
- _TabView(
- 3,
- '待大修',
- onTap: () {
- if (SpUtil.getString(Constant.companyId).length == 0) {
- showAlert(
- context,
- "提示",
- "尚未加入团队,是否立即加入?",
- "确定",
- () {
- NavigatorUtils.goBack(context);
- goToPage(TeamRouter.teamListPage);
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- });
- } else {
- goToPage("${HeavyRouter.heavyListPage}?top_into=1");
- }
- },
- ),
- ],
- )),
- ),
- )
- ],
- ));
- }
- List<Widget> _sliverBuilder() {
- bool isDark = ThemeUtils.isDark(context);
- return <Widget>[
- SliverAppBar(
- brightness: Brightness.dark,
- leading: Gaps.empty,
- backgroundColor: Colors.transparent,
- elevation: 0.0,
- centerTitle: true,
- expandedHeight: 240.0,
- pinned: true,
- flexibleSpace: MyFlexibleSpaceBar(
- background: bannerWidget(),
- // const LoadAssetImage(
- // "work/statistic_bg",
- // width: double.infinity,
- // height: 138.0,
- // fit: BoxFit.fill,
- // ),
- centerTitle: true,
- titlePadding:
- const EdgeInsetsDirectional.only(start: 16.0, bottom: 14.0),
- collapseMode: CollapseMode.pin,
- title: Text(
- '',
- style: TextStyle(color: ThemeUtils.getIconColor(context)),
- ),
- ),
- ),
- // SliverPersistentHeader(
- // pinned: true,
- // delegate: SliverAppBarDelegate(
- // DecoratedBox(
- // decoration: BoxDecoration(
- // // image: DecorationImage(
- // // image: ImageUtils.getAssetImage("work/statistic_bg1"),
- // // fit: BoxFit.fill)
- // ),
- // child: Column(
- // children: <Widget>[
- // MyCard(
- // child: Container(
- // color: isDark?Colours.dark_bg_color:Colors.white,
- // height: 90.0,
- // padding: const EdgeInsets.only(top: 8.0),
- // child: Row(
- // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- // children: <Widget>[
- // _TabView(0, '待保养',onTap: (){
- // if (SpUtil.getString(Constant.companyId).length == 0) {
- // showAlert(
- // context,
- // "提示",
- // "尚未加入团队,是否立即加入?",
- // "确定",
- // () {
- // NavigatorUtils.goBack(context);
- // // NavigatorUtils.goBackWithParams(context, true);
- // goToPage(TeamRouter.teamListPage);
- // },
- // txt2: "取消",
- // onPre2: () {
- // NavigatorUtils.goBack(context);
- // // NavigatorUtils.goBackWithParams(context, true);
- // });
- // }else{
- // goToPage("${MaintenanceRouter.maintenanceListPage}?top_into=0");
- // }
- // },),
- // _TabView(1, '待急修',onTap: (){
- // if (SpUtil.getString(Constant.companyId).length == 0) {
- // showAlert(
- // context,
- // "提示",
- // "尚未加入团队,是否立即加入?",
- // "确定",
- // () {
- // NavigatorUtils.goBack(context);
- // goToPage(TeamRouter.teamListPage);
- // },
- // txt2: "取消",
- // onPre2: () {
- // NavigatorUtils.goBack(context);
- // });
- // }else{
- // goToPage("${RepairRouter.repairListPage}?top_into=1");
- // }
- // },),
- // _TabView(2, '待年检',onTap: (){
- // if (SpUtil.getString(Constant.companyId).length == 0) {
- // showAlert(
- // context,
- // "提示",
- // "尚未加入团队,是否立即加入?",
- // "确定",
- // () {
- // NavigatorUtils.goBack(context);
- // goToPage(TeamRouter.teamListPage);
- // },
- // txt2: "取消",
- // onPre2: () {
- // NavigatorUtils.goBack(context);
- // });
- // }else{
- // goToPage("${YearlyRouter.yearlyListPage}?top_into=1");
- // }
- // },),
- // _TabView(3, '待大修',onTap: (){
- // if (SpUtil.getString(Constant.companyId).length == 0) {
- // showAlert(
- // context,
- // "提示",
- // "尚未加入团队,是否立即加入?",
- // "确定",
- // () {
- // NavigatorUtils.goBack(context);
- // goToPage(TeamRouter.teamListPage);
- // },
- // txt2: "取消",
- // onPre2: () {
- // NavigatorUtils.goBack(context);
- // });
- // }else{
- // goToPage("${HeavyRouter.heavyListPage}?top_into=1");
- // }
- // },),
- // ],
- // )),
- // ),
- // ],
- // ),
- // ),
- // 90.0),
- // ),
- SliverToBoxAdapter(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- // Gaps.vGap16,
- Gaps.vGap16,
- Container(
- padding: EdgeInsets.only(left: 20, right: 20),
- child: const Text("必备工具", style: TextStyles.textBold15),
- ),
- Gaps.vGap10,
- _ToolsItem(menuTitle, menuImage, (index) {
- if (index == 7) {
- if (Utils.getAuthByRouter(
- context, "expert_workbench", false)) {
- NavigatorUtils.push(context, BbsRouter.workPlace);
- } else {
- toastsF(context, "暂无权限,请申请成为专家", timeInSecForIos: 3);
- // fToast.showToast(
- // child: ClipRRect(
- // borderRadius: BorderRadius.circular(50),
- // child: Container(
- // color: Color(0xffcccccc),
- // padding: EdgeInsets.only(left:15,right:15,top:8,bottom:10),
- // child: Text(
- // "暂无权限,请申请成为专家",
- // style: TextStyle(
- // fontSize: 13,
- // color: Color(0xffffffff),
- // ),
- // ),
- // ),
- // )
- // ,
- // gravity: ToastGravity.BOTTOM,
- // toastDuration: Duration(seconds: 3),
- // );
- }
- return;
- }
- if (SpUtil.getString(Constant.companyId).length == 0) {
- showAlert(
- context,
- "提示",
- "尚未加入团队,是否立即加入?",
- "确定",
- () {
- NavigatorUtils.goBack(context);
- goToPage(TeamRouter.teamListPage);
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- });
- } else {
- if (index == 0) {
- goToPage(ProjectRouter.projectPage);
- } else if (index == 1) {
- goToPage(MaintenanceRouter.maintenanceListPage);
- } else if (index == 2) {
- goToPage(RepairRouter.repairListPage);
- } else if (index == 3) {
- goToPage(YearlyRouter.yearlyListPage);
- } else if (index == 4) {
- goToPage(MessageRouter.messageListPage);
- } else if (index == 5) {
- goToPage(SignRouter.signPage);
- } else if (index == 6) {
- goToPage(HeavyRouter.heavyListPage);
- }
- }
- }),
- Container(
- padding: EdgeInsets.only(left: 20, right: 20),
- child: const Text("常用工具", style: TextStyles.textBold15),
- ),
- Gaps.vGap10,
- _ToolsItem(
- menuTitle2,
- menuImage2,
- (index) {
- if (SpUtil.getString(Constant.companyId).length == 0) {
- showAlert(
- context,
- "提示",
- "尚未加入团队,是否立即加入?",
- "确定",
- () {
- NavigatorUtils.goBack(context);
- goToPage(TeamRouter.teamSearchPage);
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- });
- } else {
- if (index == 0) {
- goToPage(TeamRouter.teamListPage);
- } else if (index == 1) {
- goToPage(TeamRouter.teamUserPage);
- }
- }
- },
- ),
- ],
- ),
- ),
- )
- ];
- }
- }
- List<String> menuTitle = [
- "项目电梯",
- "日常保养",
- "紧急召修",
- "年度检验",
- "消息中心",
- "签到打卡",
- "大修",
- "专家工单"
- ];
- List<String> menuImage = [
- "icon_xmdt",
- "icon_rcby",
- "icon_jxgl",
- "icon_njgl",
- "icon_xxzx",
- "icon_dkqd",
- "icon_dx",
- "icon_zjgzt"
- ];
- List<String> menuTitle2 = ["团队管理", "团队成员"];
- List<String> menuImage2 = ["icon_tdgl", "icon_tdmp"];
- class _ToolsItem extends StatelessWidget {
- _ToolsItem(this.titles, this.imgs, this.onTap, {Key key}) : super(key: key);
- List<String> titles;
- List<String> imgs;
- Function onTap;
- @override
- Widget build(BuildContext context) {
- return GridView.builder(
- shrinkWrap: true,
- padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 8.0),
- physics: NeverScrollableScrollPhysics(),
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 4, childAspectRatio: 1.1, crossAxisSpacing: 2),
- itemCount: titles.length,
- itemBuilder: (_, index) {
- return Stack(
- alignment: Alignment.center,
- children: [
- InkWell(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- LoadAssetImage(
- "work/${imgs[index]}",
- width: 38,
- height: 38,
- ),
- Gaps.vGap10,
- Text(
- titles[index],
- style: TextStyles.textSize13,
- )
- ],
- ),
- onTap: () {
- onTap(index);
- }),
- Positioned(
- right: su.ScreenUtil().setWidth(15),
- top: 0,
- child: (index == 7 && caseNum > 0)
- ? DecoratedBox(
- decoration: BoxDecoration(
- border: Border.all(color: Colors.red),
- // color: Theme.of(context).errorColor,
- borderRadius: BorderRadius.circular(11.0),
- ),
- child: Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 5.5, vertical: 2.0),
- child: Text(
- "$caseNum",
- style: TextStyle(
- color: Colors.red, fontSize: Dimens.font_sp12),
- ),
- ),
- )
- : Gaps.empty,
- )
- ],
- );
- },
- );
- }
- }
- class SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
- final Widget widget;
- final double height;
- SliverAppBarDelegate(this.widget, this.height);
- // minHeight 和 maxHeight 的值设置为相同时,header就不会收缩了
- @override
- double get minExtent => height;
- @override
- double get maxExtent => height;
- @override
- Widget build(
- BuildContext context, double shrinkOffset, bool overlapsContent) {
- return widget;
- }
- @override
- bool shouldRebuild(SliverAppBarDelegate oldDelegate) {
- return true;
- }
- }
- class _TabView extends StatelessWidget {
- const _TabView(this.index, this.text, {this.onTap});
- final int index;
- final String text;
- final Function onTap;
- @override
- Widget build(BuildContext context) {
- var imgList = [
- // "work/icon_bywc",
- "work/icon_byz",
- "work/icon_jx",
- "work/icon_nj",
- "work/icon_dxx",
- ];
- return Consumer<WorkPageProvider>(
- builder: (_, provider, child) {
- return InkWell(
- onTap: this.onTap,
- child: Stack(
- children: <Widget>[
- Container(
- width: 70.0,
- padding: const EdgeInsets.symmetric(vertical: 8.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- LoadAssetImage(
- imgList[index],
- width: 27.0,
- height: 27.0,
- ),
- Gaps.vGap4,
- Text(text)
- ],
- ),
- ),
- child
- ],
- ),
- );
- },
- child: Positioned(
- right: 10.0,
- child: (index == 0 && countDoingItem.maintain > 0) ||
- (index == 1 && countDoingItem.repair > 0) ||
- (index == 2 && countDoingItem.inspection > 0) ||
- (index == 3 && countDoingItem.capital > 0)
- ? DecoratedBox(
- decoration: BoxDecoration(
- border: Border.all(color: Colors.red),
- // color: Theme.of(context).errorColor,
- borderRadius: BorderRadius.circular(11.0),
- ),
- child: Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 5.5, vertical: 2.0),
- child: Text(
- "${index == 0 ? countDoingItem.maintain : index == 1 ? countDoingItem.repair : index == 2 ? countDoingItem.inspection : countDoingItem.capital}",
- style: TextStyle(
- color: Colors.red, fontSize: Dimens.font_sp12),
- ),
- ),
- )
- : Gaps.empty,
- ));
- }
- }
|