import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:qhd_prevention/customWidget/custom_button.dart'; import 'package:qhd_prevention/customWidget/search_bar_widget.dart'; import 'package:qhd_prevention/customWidget/toast_util.dart'; import 'package:qhd_prevention/http/ApiService.dart'; import 'package:qhd_prevention/pages/home/hiddenDanger/hidden_record_detail_page.dart'; import 'package:qhd_prevention/pages/my_appbar.dart'; import 'package:qhd_prevention/tools/h_colors.dart'; import 'package:qhd_prevention/tools/tools.dart'; import 'dart:async'; enum DangerType { detailsHiddenInvestigationRecord("排查隐患记录", "排查隐患记录-详情"), ristRecord("隐患记录", "隐患记录详情"), waitAcceptance("隐患验收", "隐患验收详情"), acceptance("已验收隐患", "已验收隐患"), acceptanced("已验收隐患", "已验收隐患-详情"), hiddenIdentification("隐患确认", "隐患确认详情"), wait("隐患整改", "隐患整改详情"), expired("特殊处置审核", "特殊处置审核详情"), delayReview("延期审核", "延期审核详情"), ignoreHiddenDangers("忽略隐患", "忽略隐患详情"), // 安全环保检查 safeCheckHiddenAssign("隐患指派", "指派"), safeCheckHiddenAccept("隐患验收", "验收"); // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ final String displayName; final String detailTitle; const DangerType(this.displayName, this.detailTitle); } class HiddenDangerAcceptance extends StatefulWidget { const HiddenDangerAcceptance(this.dangerType, this.appItem, {super.key}); final DangerType dangerType; final int appItem; @override State createState() => _HiddenDangerAcceptanceState(); } class _HiddenDangerAcceptanceState extends State { int _page = 1; String searchKey = ""; int _totalPage = 1; late List _list = []; bool _isLoading = false; bool _hasMore = true; Timer? _debounceTimer; String buttonTextOne = '查看'; String buttonTextTwo = '确认'; final TextEditingController _searchController = TextEditingController(); @override void initState() { super.initState(); // 初始均为空 _searchController.addListener(_onSearchChanged); switch (widget.appItem) { case 1: buttonTextTwo = '确认'; break; case 2: buttonTextTwo = '查看'; break; case 3: buttonTextOne = '延期申请'; buttonTextTwo = '整改'; break; case 4: buttonTextTwo = '特殊处理审核'; break; case 5: buttonTextTwo = '延期审核'; break; case 6: buttonTextTwo = '验收'; break; } _getListData(false); } @override void dispose() { _debounceTimer?.cancel(); _searchController.removeListener(_onSearchChanged); _searchController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { // 取屏幕宽度 final double screenWidth = MediaQuery.of(context).size.width; return Scaffold( appBar: MyAppbar(title: widget.dangerType.displayName), body: SafeArea( child: NotificationListener( onNotification: _onScroll, child: _vcDetailWidget(), ), ), backgroundColor: Colors.white, ); } Widget _vcDetailWidget() { return Column( children: [ Padding( padding: EdgeInsets.all(10), child: SearchBarWidget( controller: _searchController, isShowSearchButton: false, hintText: '请输入隐患描述', onTextChanged: (value) { if (_debounceTimer?.isActive ?? false) { _debounceTimer!.cancel(); } _debounceTimer = Timer(const Duration(milliseconds: 500), () { print('搜索关键词: ${_searchController.text}'); _performSearch(_searchController.text); }); }, onSearch: (keyboard) { // _performSearch(_searchController.text); }, ), ), Container(height: 5, color: h_backGroundColor()), Expanded( child: _list.isEmpty ? NoDataWidget.show() : ListView.builder( itemCount: _list.length, itemBuilder: (context, index) { final item = _list[index]; return _fxitemCell(item); }, ), ), ], ); } Widget _fxitemCell(pageData) { // 使用GestureDetector包裹整个列表项以添加点击事件 return GestureDetector( onTap: () {}, child: Container( margin: EdgeInsets.all(6), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.3), spreadRadius: 2, blurRadius: 5, offset: Offset(0, 3), ), ], ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // 标题 Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, // 添加这一行 children: [ Expanded( child: Padding( padding: EdgeInsets.only(left: 10, top: 15, right: 8), child: Text( '隐患描述: ${pageData['hiddenDesc'] ?? ''}', style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, color: Colors.black87, ), maxLines: 1, // 只显示一行 overflow: TextOverflow.ellipsis, // 超出部分显示省略号 ), ), ), // 状态标签 Container( padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6), decoration: BoxDecoration( color: _getLevelColor(pageData), borderRadius: BorderRadius.only( bottomLeft: Radius.circular(12), topRight: Radius.circular(12), // 改为右上角 ), ), child: Text( pageData['hiddenLevelName'] ?? '', style: TextStyle( color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold, ), ), ), ], ), SizedBox(height: 16), Padding( padding: EdgeInsets.only(left: 10, right: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ // 来源 Expanded( child: Text( _getSourceDangers(pageData), style: TextStyle(fontSize: 14, color: Colors.black87), ), ), // 隐患状态 // Expanded( // child: Text( // '隐患状态: ${_getState(pageData)}', // style: TextStyle(fontSize: 14, color: Colors.black87), // ), // ), ], ), ), SizedBox(height: 8), Padding( padding: EdgeInsets.only(left: 10, right: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ // 来源 // Expanded( // child: Text( // _getSourceDangers(pageData), // style: TextStyle(fontSize: 14, color: Colors.black87), // ), // ), // 隐患状态 Expanded( child: Text( '隐患状态: ${_getState(pageData)}', style: TextStyle(fontSize: 14, color: Colors.black87), ), ), ], ), ), SizedBox(height: 8), Padding( padding: EdgeInsets.only(left: 10, right: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ // 隐患发现人 - 使用 Expanded 包裹 Expanded( child: Text( '发现人:${truncateString(pageData['createName'] ?? '')}', style: TextStyle(fontSize: 14, color: Colors.black87), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), // 隐患发现时间 - 使用 Expanded 包裹 Expanded( child: Text( '发现时间:${_changeTime(pageData['hiddenFindTime'] ?? '')}', style: TextStyle(fontSize: 14, color: Colors.black87), // maxLines: 1, // overflow: TextOverflow.ellipsis, ), ), ], ), ), if (widget.appItem != 1) SizedBox(height: 8), if (widget.appItem != 1) Padding( padding: EdgeInsets.only(left: 10, right: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ // 隐患确认人 Expanded( child: Text( '确认人:${pageData['confirmUserName'] ?? ''}', style: TextStyle(fontSize: 14, color: Colors.black87), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), Expanded( child: Text( '确认时间:${_changeTime(pageData['hiddenFindTime'] ?? '')}', style: TextStyle(fontSize: 14, color: Colors.black87), // maxLines: 1, // overflow: TextOverflow.ellipsis, ), ), ], ), ), if (widget.appItem == 6) SizedBox(height: 8), if (widget.appItem == 6) Padding( padding: EdgeInsets.only(left: 10, right: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ // 整改人 Expanded( child: Text( '整改人:${pageData['rectifyUserName'] ?? ''}', style: TextStyle(fontSize: 14, color: Colors.black87), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), Expanded( child: Text( '整改时间:${_changeTime(pageData['rectificationTime'] ?? '')}', style: TextStyle(fontSize: 14, color: Colors.black87), // maxLines: 1, // overflow: TextOverflow.ellipsis, ), ), ], ), ), if (pageData['hiddenYUserName'] != null && pageData['hiddenYUserName'].isNotEmpty) SizedBox(height: 8), if (pageData['hiddenYUserName'] != null && pageData['hiddenYUserName'].isNotEmpty) Padding( padding: EdgeInsets.only(left: 10, right: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ // 整改人 Text( '验收人: ${pageData['hiddenYUserName'] ?? ''}', style: TextStyle(fontSize: 14, color: Colors.black87), ), // Text( // '隐患验收时间: ${_changeTime(pageData['hiddenYTime']??'')}', // style: TextStyle( // fontSize: 14, // color: Colors.black87, // ), // ), ], ), ), SizedBox(height: 8), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ // 验收按钮 if (widget.appItem != 2 && (widget.appItem != 3 || pageData['noReviewExtensionNum'] == 0)) Expanded( child: CustomButton( height: 35, onPressed: () async { // print('查看: ${pageData['title']}'); if (widget.appItem == 3) { await pushPage( HiddenRecordDetailPage( widget.dangerType, 8, pageData['id'], pageData['hiddenId'], true, ), context, ); _page=1; _getListData(false); } else { pushPage( HiddenRecordDetailPage( widget.dangerType, widget.appItem, pageData['id'], pageData['hiddenId'], false, ), context, ); } }, backgroundColor: h_backGroundColor(), textStyle: const TextStyle(color: Colors.black), buttonStyle: ButtonStyleType.secondary, text: buttonTextOne, ), ), // Expanded( // child: Container( // height: 35, // margin: EdgeInsets.only(left: 10, right: 5), // 调整间距 // decoration: BoxDecoration( // border: Border.all(color: Colors.blue, width: 1.0), // borderRadius: BorderRadius.circular(8), // ), // child: ElevatedButton( // onPressed: () { // // print('查看: ${pageData['title']}'); // if (widget.appItem == 3) { // pushPage( // HiddenRecordDetailPage( // widget.dangerType, // 8, // pageData['id'], // pageData['hiddenId'], // true, // ), // context, // ); // } else { // pushPage( // HiddenRecordDetailPage( // widget.dangerType, // widget.appItem, // pageData['id'], // pageData['hiddenId'], // false, // ), // context, // ); // } // }, // style: ElevatedButton.styleFrom( // backgroundColor: Colors.white, // foregroundColor: Colors.blue, // shape: RoundedRectangleBorder( // borderRadius: BorderRadius.circular(8), // ), // elevation: 0, // ), // child: Text(buttonTextOne), // ), // ), // ), SizedBox(width: 10), // 使用width而不是height // 查看详情按钮 Expanded( child: CustomButton( height: 35, onPressed: () async { // print('查看详情: ${pageData['title']}'); String text = await pushPage( HiddenRecordDetailPage( widget.dangerType, widget.appItem, pageData['id'], pageData['hiddenId'], widget.appItem != 2, ), context, ); if (text == '1') { _page = 1; _getListData(false); } }, backgroundColor: h_AppBarColor(), textStyle: const TextStyle(color: Colors.white), buttonStyle: ButtonStyleType.primary, text: buttonTextTwo, ), ), // Expanded( // child: Container( // height: 35, // margin: EdgeInsets.only(left: 5, right: 10), // child: ElevatedButton( // onPressed: () async { // // print('查看详情: ${pageData['title']}'); // String text = await pushPage( // HiddenRecordDetailPage( // widget.dangerType, // widget.appItem, // pageData['id'], // pageData['hiddenId'], // widget.appItem != 2, // ), // context, // ); // if (text == '1') { // _page = 1; // _getListData(false); // } // }, // style: ElevatedButton.styleFrom( // backgroundColor: Colors.blue, // foregroundColor: Colors.white, // shape: RoundedRectangleBorder( // borderRadius: BorderRadius.circular(8), // ), // ), // child: Text(buttonTextTwo), // ), // ), // ), ], ), SizedBox(height: 10), ], ), ), ); } void _performSearch(String keyword) { // 执行搜索逻辑 // if (keyword.isNotEmpty) { // print('执行搜索: $keyword'); // 调用API或其他搜索操作 // 输入请求接口 _page = 1; searchKey = keyword; _getListData(false); // } } bool _onScroll(ScrollNotification n) { if (n.metrics.pixels > n.metrics.maxScrollExtent - 100 && _hasMore && !_isLoading) { _page++; _getListData(true); } return false; } void _onSearchChanged() { final query = _searchController.text.toLowerCase().trim(); setState(() { print("=====>" + query); // filtered = query.isEmpty ? original : _filterCategories(original, query); }); } Future _getListData(bool loadMore) async { try { if (_isLoading) return; _isLoading = true; LoadingDialogHelper.show(); final Map result; if (widget.appItem == 2) { result = await HiddenDangerApi.getIgnoreList(_page, searchKey); } else if (widget.appItem == 3) { result = await HiddenDangerApi.getRectificationList(_page, searchKey); } else if (widget.appItem == 4) { result = await HiddenDangerApi.getSpecialHandlingList( _page, searchKey, // isJGD ? '1' : '2', ); } else if (widget.appItem == 5) { result = await HiddenDangerApi.getDelayReviewList( _page, searchKey, // isJGD ? '1' : '2', ); } else if (widget.appItem == 6) { result = await HiddenDangerApi.getHiddenDangerAcceptanceList( _page, searchKey, ); } else { result = await HiddenDangerApi.getConfirmationList(_page, searchKey); } LoadingDialogHelper.hide(); if (result['success']) { _totalPage = result['totalPages'] ?? 1; final List newList = result['data'] ?? []; // setState(() { // _list.addAll(newList); // }); setState(() { if (loadMore) { _list.addAll(newList); } else { _list = newList; } _hasMore = _page < _totalPage; // if (_hasMore) _page++; }); } else { ToastUtil.showNormal(context, "加载数据失败"); // _showMessage('加载数据失败'); } } catch (e) { LoadingDialogHelper.hide(); // 出错时可以 Toast 或者在页面上显示错误状态 print('加载数据失败:$e'); } finally { // if (!loadMore) LoadingDialogHelper.hide(); _isLoading = false; } } String _getSourceDangers(final item) { int type = item["source"] ?? 0; if (1 == type) { return "隐患来源:隐患快报"; } else if (2 == type) { return "隐患来源:清单排查"; } else if (3 == type) { return "隐患来源:标准排查"; } else if (4 == type) { return "隐患来源:安全环保检查(监管端)"; } else if (5 == type) { return "隐患来源:安全环保检查(企业端)"; } else if (6 == type) { return "隐患来源:消防点检"; } else if (7 == type) { return "隐患来源:视频巡屏"; } else { return "隐患来源:"; } } // 隐患等级颜色 Color _getLevelColor(final item) { String type = item["hiddenLevelName"] ?? ''; if ("重大隐患" == type) { return Colors.red; } else if ("较大隐患" == type) { return Color(0xFFFF6A4D); } else if ("一般隐患" == type) { return Colors.orange; } else if ("轻微隐患" == type) { return h_AppBarColor(); } else { return Colors.green; } } String _getState(final item) { int type = item["state"]; if(100==type){ return "待确认"; }else if(200==type){ return "未整改"; }else if(201==type){ return "确认打回"; }else if(202==type){ return "待处理特殊隐患"; }else if(300==type){ return "待验收"; }else if(301==type){ return "已验收"; }else if(302==type){ return "验收打回"; }else if(303==type){ return "验收打回"; }else if(400==type){ return "已处理特殊隐患"; }else if(99==type){ return "强制关闭(人员变动)"; }else if(98==type){ return "安全环保检查/清单排查暂存"; }else if(102==type){ return "安全环保检查,隐患待指派"; }else if(97==type){ return "已过期"; }else if(101==type){ return "忽略隐患"; }else{ return "已过期"; } } String _changeTime(String time) { try { // 解析 ISO 8601 格式的时间字符串 DateTime dateTime = DateTime.parse(time); // 格式化为年月日 return DateFormat('yyyy-MM-dd').format(dateTime); } catch (e) { // 如果解析失败,返回原字符串或默认值 return ' '; } } String truncateString(String input) { if (input.length > 10) { return '${input.substring(0, 10)}...'; } return input; } }