QinGang_interested/lib/pages/home/keyTasks/key_tasks_tab_page.dart

397 lines
13 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// lib/pages/application_template.dart
import 'dart:ffi';
import 'package:flutter/material.dart';
import 'package:qhd_prevention/pages/home/doorAndCar/doorCar_tab_page.dart';
import 'package:qhd_prevention/pages/home/keyTasks/key_tasks_check_list_page.dart';
import 'package:qhd_prevention/pages/home/keyTasks/key_tasks_confirm_list_page.dart';
import 'package:qhd_prevention/pages/my_appbar.dart';
import 'package:qhd_prevention/tools/tools.dart';
class KeyTasksTabPage extends StatefulWidget {
const KeyTasksTabPage({super.key});
@override
State<KeyTasksTabPage> createState() => _DoorcarTabPageState();
}
class _DoorcarTabPageState extends State<KeyTasksTabPage> {
final String bannerAsset = 'assets/images/door_banner.png';
late List<AppSection> defaultSections;
@override
void initState() {
// TODO: implement initState
super.initState();
_initSections(); // 初始化 sections
_getDoorCarCount();
}
// 初始化 sections 的方法
void _initSections() {
defaultSections = [
AppSection(title: '重点作业管理', items: [
AppSectionItem(
title: '重点作业申请',
icon: 'assets/images/door_ico9.png',
badge: 0,
onTap: () async {
await pushPage(KeyTasksConfirmListPage(), context);
_getDoorCarCount();
},
),
AppSectionItem(
title: '被检查确认',
icon: 'assets/images/door_ico9.png',
badge: 0,
onTap: () async {
await pushPage(KeyTasksCheckListPage(), context);
_getDoorCarCount();
},
),
AppSectionItem(
title: '隐患整改',
icon: 'assets/images/door_ico9.png',
badge: 0,
onTap: () async {
// await pushPage(KeyTasksHiddenList(1), context);
_getDoorCarCount();
},
),
AppSectionItem(
title: '隐患记录',
icon: 'assets/images/door_ico9.png',
badge: 0,
onTap: () async {
// await pushPage(KeyTasksHiddenList(2), context);
_getDoorCarCount();
},
),
]),
];
}
Future<void> _getDoorCarCount() async {
// try {
// final result = await DoorAndCarApi.getDoorCarCount();
// if (result['success'] ) {
// List< dynamic> data = result['data']??[] ;
//
// int stakeholderPersonCount =0;
// int stakeholderCarCount =0;
// int temporaryPersonCount =0;
// int temporaryCarCount =0;
// int companyCarCount =0;
// int closureLongPersonCount =0;
// int closureLongCarCount =0;
// int closureTemporaryPersonCount =0;
// int closureTemporaryCarCount =0;
// for(int i=0;i<data.length;i++){
// if(data[i]['type']=='one_level_person'){
// if(data[i]['belongType']=='3'){
// stakeholderPersonCount=data[i]['waitAuditCount']??0;
// }
// if(data[i]['belongType']=='4'){
// temporaryPersonCount=data[i]['waitAuditCount']??0;
// }
// }
//
// if(data[i]['type']=='one_level_car'){
// if(widget.isLoginJGD&&data[i]['belongType']=='2'){
// stakeholderCarCount=data[i]['waitAuditCount']??0;
// }
// if(!widget.isLoginJGD&&data[i]['belongType']=='4'){
// temporaryCarCount=data[i]['waitAuditCount']??0;
// }
// }
//
//
// if(data[i]['type']=='one_level_car'){//公司车辆审批
// if(data[i]['belongType']=='2'){
// companyCarCount=data[i]['waitAuditCount']??0;
// }
// if(data[i]['belongType']=='4'){
// companyCarCount=data[i]['waitAuditCount']??0;
// }
// }
//
// if(data[i]['type']=='two_level_person'){
// if(data[i]['belongType']=='1'||data[i]['belongType']=='2'||data[i]['belongType']=='3'){
// closureLongPersonCount=closureLongPersonCount+((data[i]['waitAuditCount']??0)as int);
// }
// if(data[i]['belongType']=='4'){
// closureTemporaryPersonCount=data[i]['waitAuditCount']??0;
// }
// }
//
// if(data[i]['type']=='two_level_car'){
// if(data[i]['belongType']=='1'||data[i]['belongType']=='2'||data[i]['belongType']=='3'){
// closureLongCarCount=closureLongCarCount+((data[i]['waitAuditCount']??0)as int);
// }
// if(data[i]['belongType']=='4'){
// closureTemporaryCarCount=data[i]['waitAuditCount']??0;
// }
// }
//
// }
//
// setState(() {
// // 更新一级口门审核管理的 badge
// final gateSection = defaultSections[0];
//
// // 相关方人员审核
// gateSection.items[0].badge = stakeholderPersonCount;
// // 相关方车辆审核
// gateSection.items[1].badge = stakeholderCarCount;
// // 临时访客审核
// gateSection.items[3].badge = temporaryPersonCount;
// // 临时车辆审核
// gateSection.items[4].badge = temporaryCarCount;
//
// // 公司车辆审核
// gateSection.items[7].badge = companyCarCount;
//
// // 如果有封闭区域审核管理部分非JGD用户
// if (!widget.isLoginJGD && defaultSections.length > 2) {
// final closureSection = defaultSections[2];
// // 长期人员审核
// closureSection.items[0].badge = closureLongPersonCount;
// // 长期车辆审核
// closureSection.items[1].badge = closureLongCarCount;
// // 临时访客审核
// closureSection.items[2].badge = closureTemporaryPersonCount;
// // 临时车辆审核
// closureSection.items[3].badge = closureTemporaryCarCount;
// }
// });
// }
// // else {
// // ToastUtil.showNormal(context, result['errMessage'] ?? "加载数据失败");
// // }
// } catch (e) {
// LoadingDialogHelper.hide();
// print('加载数据失败:$e');
// }
}
@override
Widget build(BuildContext context) {
final double bannerHeight = (730.0 / 1125.0) * MediaQuery.of(context).size.width;
final double iconSectionHeight =
MediaQuery.of(context).size.height - bannerHeight - 30.0;
const double iconOverlapBanner = 30.0;
// 过滤掉没有可见 items 的分组
final visibleSections = defaultSections
.map((s) => AppSection(
title: s.title,
items: s.items.where((it) => it.visible).toList()))
.where((s) => s.items.isNotEmpty)
.toList();
return Scaffold(
extendBodyBehindAppBar: true,
appBar: MyAppbar(title: '重点作业', backgroundColor: Colors.transparent,),
body: ListView(
physics: const AlwaysScrollableScrollPhysics(),
padding: EdgeInsets.zero,
children: [
SizedBox(
height: bannerHeight + iconSectionHeight,
child: Stack(
clipBehavior: Clip.none,
children: [
Positioned(
top: 0,
left: 0,
right: 0,
height: bannerHeight,
child: _buildBannerSection(bannerHeight, context),
),
Positioned(
left: 10,
right: 10,
top: bannerHeight - iconOverlapBanner,
height: iconSectionHeight,
child: _buildIconSection(context, visibleSections),
),
],
),
),
],
),
);
}
Widget _buildBannerSection(double bannerHeight, BuildContext context) {
return Stack(
children: [
Image.asset(
bannerAsset,
width: MediaQuery.of(context).size.width,
height: bannerHeight,
fit: BoxFit.fitWidth,
errorBuilder: (c, e, s) {
return Container(
color: Colors.blueGrey,
height: bannerHeight,
alignment: Alignment.center,
child: const Text('Banner', style: TextStyle(color: Colors.white)),
);
},
),
],
);
}
Widget _buildIconSection(BuildContext context, List<AppSection> buttonInfos) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(color: Colors.black12, blurRadius: 6, offset: Offset(0, 2)),
],
),
child: ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.all(0),
itemCount: buttonInfos.length,
itemBuilder: (context, index) {
final section = buttonInfos[index];
final items = section.items;
if (items.isEmpty) return const SizedBox.shrink();
return Padding(
padding: const EdgeInsets.only(top: 10, left: 10, right: 10),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 5),
child: Row(
children: [
Container(width: 2, height: 10, color: Colors.blue),
const SizedBox(width: 5),
Text(section.title,
style: const TextStyle(
fontSize: 14, fontWeight: FontWeight.bold)),
],
),
),
// icons
Padding(
padding: const EdgeInsets.all(10),
child: LayoutBuilder(
builder: (context, constraints) {
const spacing = 20.0;
final totalWidth = constraints.maxWidth;
final itemWidth = (totalWidth - spacing * 2) / 3;
return Wrap(
spacing: spacing,
runSpacing: spacing,
children: items.map<Widget>((item) {
return SizedBox(
width: itemWidth,
child: _buildItem(
item,
onTap: item.onTap ??
() => debugPrint('Tapped ${item.title}'),
),
);
}).toList(),
);
},
),
),
],
),
),
);
},
),
);
}
Widget _buildItem(AppSectionItem item, {VoidCallback? onTap}) {
const double iconSize = 30;
final int badgeNum = item.badge;
final String title = item.title;
final String iconPath = item.icon;
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(8),
child: SizedBox(
width: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
clipBehavior: Clip.none,
children: [
SizedBox(
width: iconSize,
height: iconSize,
child: Image.asset(
iconPath,
fit: BoxFit.contain,
errorBuilder: (c, e, s) {
return Container(
color: Colors.grey.shade200,
child: const Center(child: Icon(Icons.image, size: 18)),
);
},
),
),
if (badgeNum > 0)
Positioned(
top: -6,
right: -6,
child: Container(
padding:
const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
decoration:
const BoxDecoration(color: Colors.red, shape: BoxShape.circle),
constraints: const BoxConstraints(minWidth: 16, minHeight: 16),
child: Center(
child: Text(
badgeNum > 99 ? '99+' : badgeNum.toString(),
style: const TextStyle(color: Colors.white, fontSize: 10, height: 1),
textAlign: TextAlign.center,
),
),
),
),
],
),
const SizedBox(height: 4),
Text(
title,
style: const TextStyle(fontSize: 13),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
);
}
}