QinGang_interested/lib/pages/home/hiddenDanger/hidden_danger_deawer.dart

636 lines
20 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.

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:qhd_prevention/customWidget/ItemWidgetFactory.dart';
import 'package:qhd_prevention/customWidget/MultiDictValuesPicker.dart';
import 'package:qhd_prevention/customWidget/bottom_picker_two.dart';
import 'package:qhd_prevention/customWidget/department_person_picker.dart';
import 'package:qhd_prevention/customWidget/department_picker.dart';
import 'package:qhd_prevention/customWidget/department_picker_three.dart';
import 'package:qhd_prevention/customWidget/department_picker_two.dart';
import 'package:qhd_prevention/customWidget/item_list_widget.dart';
import 'package:qhd_prevention/customWidget/toast_util.dart';
import 'package:qhd_prevention/http/ApiService.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../../../customWidget/bottom_picker.dart';
import '../../../tools/h_colors.dart';
import '/customWidget/custom_button.dart';
import '../../../tools/tools.dart';
/// 自定义抽屉
class HiddenDangerDeawer extends StatefulWidget {
const HiddenDangerDeawer(this.searchData, {super.key,required this.onClose});
final Function(Map<String, dynamic>) onClose; // 回调函数
final Map<String, dynamic> searchData;
// final DangerWaitBean waitBean;
@override
_HiddenDangerDeawerState createState() => _HiddenDangerDeawerState();
}
class _HiddenDangerDeawerState extends State<HiddenDangerDeawer> {
Map<String, dynamic> allData={};
DateTime? _startDate;
DateTime? _endDate;
// 存储各单位的人员列表
List<Map<String, dynamic>> _personCache = [];
// 转换为List<Map<String, dynamic>>
late List<Map<String, dynamic>> departmentList ;
late List<dynamic> _HazardPersonlist = [];
dynamic _hazardLeve;
// final List<String> investigationMethod = ["隐患快报", "隐患排查", "标准排查", "专项检查", "安全检查"];
final List<String> investigationMethod = ["风险排查隐患", "隐患排查隐患"];
final List<String> hazardLevel = [" 一般风险 ", " 重大风险 "];
final List<String> dangerStatus = ["未整改", "已整改", "已验收", "已过期"];
final List<String> laiYuanStatus = ["隐患快报", "隐患排查", "标准排查", "专项检查", "安全检查", "NFC设备巡检"];
@override
void initState() {
// TODO: implement initState
super.initState();
setState(() {
allData=widget.searchData;
if(allData['beginTIme']!=''){
_startDate= DateTime.parse(allData['beginTIme']);
}
if(allData['endTime']!='') {
_endDate = DateTime.parse(allData['endTime']);
}
});
// if(allData['findUserName']==''){
// _getUserData();
// }
}
@override
Widget build(BuildContext context) {
return SafeArea(
child:
// SingleChildScrollView( // 添加这一行
// child:
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"高级查询",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const Divider(height: 20, color: Colors.grey),
// 开始时间 - 结束时间 —— //
Column(
children: [
_buildDatePickerBox(
label: "隐患发现开始时间",
date: _startDate,
onTap: _pickStartDate,
),
const SizedBox(height: 10),
_buildDatePickerBox(
label: "隐患发现结束时间",
date: _endDate,
onTap: _pickEndDate,
),
],
),
const SizedBox(height: 10),
Column(
children: [
GestureDetector(
onTap: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
barrierColor: Colors.black54,
backgroundColor: Colors.transparent,
builder:
(ctx) => DepartmentPickerTwo(
onSelected: (id, name,pdId) async {
setState(() {
allData['buMenId']= id;
allData['buMenName']= name;
allData['findUserId']= "";
allData['findUserName']= "";
});
// 拉取该单位的人员列表并缓存
final result = await HiddenDangerApi.getListTreePersonList(id);
_personCache=List<Map<String, dynamic>>.from(
result['data'] as List,
);
},
),
);
},
child: _buildSectionContainer(
child: ListItemFactory.createRowSpaceBetweenItem(
isRequired:false,
leftText: "隐患发现部门",
rightText: allData['buMenName'].isNotEmpty ? allData['buMenName'] : "请选择",
isRight: true,
),
),
),
const SizedBox(height: 10),
// GestureDetector(
// onTap: () async {
// if(_personCache.isEmpty){
// // 拉取该单位的人员列表并缓存
// final result = await HiddenDangerApi.getListTreePersonList(allData['buMenId']);
// _personCache=List<Map<String, dynamic>>.from(
// result['data'] as List,
// );
// }
// if ( allData['buMenName'].isEmpty) {
// ToastUtil.showNormal(context, '请先选择部门');
// return;
// }
// DepartmentPersonPicker.show(
// context,
// personsData: _personCache,
// onSelected: (userId, name) {
// setState(() {
//
// allData['findUserId']= userId;
// allData['findUserName']= name;
//
// });
//
// },
// );
// },
// child:Container(
// padding: EdgeInsets.symmetric(horizontal: 0),
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(4),
// border: Border.all(color: Colors.grey.shade400),
// color: Colors.white,
// ),
// child: ListItemFactory.createRowSpaceBetweenItem(
// isRequired:false,
// leftText: "隐患发现人",
// rightText: allData['findUserName'].isNotEmpty?allData['findUserName']:"请选择",
// isRight: true,
// ),
// ),
// ),
Container(
padding: EdgeInsets.symmetric(horizontal: 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
border: Border.all(color: Colors.grey.shade400),
color: Colors.white,
),
child: ItemListWidget.singleLineTitleText(
label: '隐患发现人',
isEditable: true,
isRequired:false,
isTextFont:false,
hintText: '',
text: allData['confirmUserName'] ?? '',
onChanged: (value) {
setState(() {
allData['confirmUserName'] = value;
});
},
),
),
],
),
const SizedBox(height: 10),
Container(
padding: EdgeInsets.symmetric(horizontal: 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
border: Border.all(color: Colors.grey.shade400),
color: Colors.white,
),
child: ItemListWidget.singleLineTitleText(
label: '隐患确认人',
isEditable: true,
isRequired:false,
isTextFont:false,
hintText: '',
text: allData['trueUserName'] ?? '',
onChanged: (value) {
setState(() {
allData['trueUserName'] = value;
});
},
),
),
// GestureDetector(
// onTap: () async {
//
// if(_HazardPersonlist.isEmpty){
// await _getHazardPersonlist();
// }
// String choice = await BottomPickerTwo.show<String>(
// context,
// items: _HazardPersonlist,
// itemName: "name",
// itemBuilder: (item) => Text(item["name"], textAlign: TextAlign.center),
// initialIndex: 0,
// );
// if (choice != null) {
// for(int i=0;i<_HazardPersonlist.length;i++){
// if(choice==_HazardPersonlist[i]["name"]){
// _hazardLeve = _HazardPersonlist[i];
// }
// }
//
// setState(() {
// allData['trueUserId']=_hazardLeve["userId"];
// allData['trueUserName']=_hazardLeve["name"];
//
// // addData['confirmDeptId']=_hazardLeve["deptId"];
// // addData['confirmDeptName']=_hazardLeve["deptName"];
//
// });
// }
// },
// child:Container(
// padding: EdgeInsets.symmetric(horizontal: 0),
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(4),
// border: Border.all(color: Colors.grey.shade400),
// color: Colors.white,
// ),
// child: ListItemFactory.createRowSpaceBetweenItem(
// isRequired:false,
// leftText: "隐患确认人",
// rightText: allData['trueUserName'].isNotEmpty?allData['trueUserName']:"请选择",
// isRight: true,
// ),
// ),
// ),
const SizedBox(height: 10),
GestureDetector(
onTap: () {
_getHiddenDangerType();
},
child: _buildSectionContainer(
child: ListItemFactory.createRowSpaceBetweenItem(
isRequired:false,
leftText: "隐患类型",
rightText: allData['hiddenTypeName'].isNotEmpty?allData['hiddenTypeName']:"请选择",
isRight: true,
),
),
),
Expanded(child: SizedBox(height: 20),),
Row(
children: [
Flexible(
flex: 1,
child: CustomButton(
text: "重置",
buttonStyle:ButtonStyleType.secondary,
backgroundColor: h_backGroundColor(),
textStyle: const TextStyle(color: Colors.black45),
onPressed: () {
setState(() {
_startDate = null;
_endDate = null;
allData={
"beginTIme": "",
"endTime": "",
"buMenId": "",
"buMenName": "",
"findUserId": "",
"findUserName": "",
"trueUserId": "",
"trueUserName": "",
"type": "",
'hiddenTypeName': "",
'confirmUserName': "",
};
setResult();
// widget.onClose("","","","","","","");
});
},
),
),
const SizedBox(width: 12),
Flexible(
flex: 2,
child: CustomButton(
text: "完成",
backgroundColor: Colors.blue,
onPressed: () {
setResult();
// TODO: 提交筛选条件
Navigator.pop(context); // 关闭加载对话框
},
),
),
],
),
],
),
),
// ),
);
}
Widget _buildSectionContainer({required Widget child}) {
return Container(
margin: const EdgeInsets.only(top: 1),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
border: Border.all(color: Colors.grey.shade400),
color: Colors.white,
),
// color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 0),
child: child,
);
}
Future<void> _pickStartDate() async {
final now = DateTime.now();
final picked = await showDatePicker(
context: context,
initialDate: _startDate ?? now,
firstDate: DateTime(now.year - 5),
lastDate: DateTime(now.year + 5),
);
if (picked != null) {
setState(() {
_startDate = picked;
final dateFormat = DateFormat('yyyy-MM-dd');
allData['beginTIme']=dateFormat.format(picked);
// 保证开始 <= 结束
if (_endDate != null && _endDate!.isBefore(picked)) {
_endDate = null;
}
// setResult();
});
}
}
Future<void> _pickEndDate() async {
final now = DateTime.now();
final initial = _endDate ??
(_startDate != null && _startDate!.isAfter(now)
? _startDate!
: now);
final picked = await showDatePicker(
context: context,
initialDate: initial,
firstDate: _startDate ?? DateTime(now.year - 5),
lastDate: DateTime(now.year + 5),
);
if (picked != null) {
setState(() {
_endDate = picked;
final dateFormat = DateFormat('yyyy-MM-dd');
allData['endTime']=dateFormat.format(picked);
// setResult();
});
}
}
Widget _buildDatePickerBox({
required String label,
DateTime? date,
required VoidCallback onTap,
}) {
final display = date != null
? "${date.year.toString().padLeft(4, '0')}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}"
: label;
return GestureDetector(
onTap: onTap,
child: Container(
height: 35,
padding: const EdgeInsets.symmetric(horizontal: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
border: Border.all(color: Colors.grey.shade400),
color: Colors.white,
),
child: Row(
children: [
const Icon(Icons.calendar_today, size: 18, color: Colors.grey),
const SizedBox(width: 6),
Text(display, style: const TextStyle(fontSize: 14, color: Colors.black38)),
],
),
),
);
}
Future<void> _getHiddenDangerType() async {
showModalBottomSheet(
context: context,
isScrollControlled: true,
barrierColor: Colors.black54,
backgroundColor: Colors.transparent,
builder:
(_) => MultiDictValuesPicker(
title: '隐患类型',
dictType: 'hiddenType',
allowSelectParent: false,
onSelected: (id, name, extraData) {
setState(() {
allData['type'] = extraData?['dictValue'];
allData['hiddenTypeName'] = name;
//顶层
// allData['hiddenType2'] = extraData?['dingValue'];
// allData['hiddenType2Name'] = extraData?['dingName'];
});
},
),
).then((_) {
// 可选FocusHelper.clearFocus(context);
});
// try {
// LoadingDialogHelper.show();
// final raw = await HiddenDangerApi.getHiddenDangerType( );
// if (raw['success'] ) {
// final newList = raw['data'] ?? [];
// LoadingDialogHelper.hide();
//
// for(int i=0;i<newList.length;i++){
// newList[i]["dataId"] = newList[i]["id"];
// newList[i]["dataName"] = newList[i]["dictLabel"];
//
// if(newList[i]['children']!=null&&newList[i]['children'].isNotEmpty){
// for(int m=0;m<newList[i]["children"].length;m++){
// newList[i]["children"][m]["dataId"] = newList[i]["children"][m]["id"];
// newList[i]["children"][m]["dataName"] = newList[i]["children"][m]["dictLabel"];
//
// if(newList[i]['children'][m]['children']!=null&&newList[i]['children'][m]['children'].isNotEmpty){
// for(int n=0;n<newList[i]["children"][m]['children'].length;n++){
// newList[i]["children"][m]['children'][n]["dataId"] = newList[i]["children"][m]['children'][n]["id"];
// newList[i]["children"][m]['children'][n]["dataName"] = newList[i]["children"][m]['children'][n]["dictLabel"];
// }
// }
// }
// }
// }
//
//
// showModalBottomSheet(
// context: context,
// isScrollControlled: true,
// barrierColor: Colors.black54,
// backgroundColor: Colors.transparent,
// builder: (ctx) => DepartmentPickerThree(
// listdata: newList,
// onSelected: (id, name,pdId) async {
// setState(() {
// allData['type']=id;
// allData['hiddenTypeName']=name;
//
// });
//
// },
// ),
// );
//
// }else{
// ToastUtil.showNormal(context, "获取列表失败");
// LoadingDialogHelper.hide();
// }
//
// } catch (e) {
// // 出错时可以 Toast 或者在页面上显示错误状态
// print('加载首页数据失败:$e');
// LoadingDialogHelper.hide();
// }
}
Future<void> _getUserData() async {
try {
final raw = await AuthApi.getUserData( );
if (raw['success'] ) {
setState(() {
allData['findUserId']=raw['data']['id'];
allData['findUserName']=raw['data']['name'];
allData['buMenId']=raw['data']['departmentId'];
allData['buMenName']=raw['data']['departmentName'];
});
}else{
ToastUtil.showNormal(context, "获取个人信息失败");
}
} catch (e) {
// 出错时可以 Toast 或者在页面上显示错误状态
print('加载首页数据失败:$e');
}
}
Future<void> _getHazardPersonlist() async {
try {
LoadingDialogHelper.show();
final raw = await HiddenDangerApi.getHazardPersonlist( );
if (raw['success'] ) {
_HazardPersonlist = raw['data'] ?? [];
LoadingDialogHelper.hide();
}else{
ToastUtil.showNormal(context, "获取列表失败");
LoadingDialogHelper.hide();
}
} catch (e) {
// 出错时可以 Toast 或者在页面上显示错误状态
print('加载首页数据失败:$e');
LoadingDialogHelper.hide();
}
}
void setResult(){
widget.onClose(
allData
); // 触发回调
}
}