diff --git a/android/app/src/main/res/drawable/background.png b/android/app/src/main/res/drawable/background.png new file mode 100644 index 0000000..4ebb677 Binary files /dev/null and b/android/app/src/main/res/drawable/background.png differ diff --git a/lib/http/ApiService.dart b/lib/http/ApiService.dart index 762e5f8..a0e7cc7 100644 --- a/lib/http/ApiService.dart +++ b/lib/http/ApiService.dart @@ -1511,6 +1511,28 @@ U6Hzm1ninpWeE+awIDAQAB }, ); } + /// 更新签字信息 + static Future> refreshSignInfo(String imagePath) async{ + final file = File(imagePath); + if (!await file.exists()) { + throw ApiException('file_not_found', '图片不存在:$imagePath'); + } + final fileName = file.path.split(Platform.pathSeparator).last; + + return HttpManager().uploadFaceImage( + baseUrl: basePath, + path: '/app/user/updateUserSign', + fromData: { + 'CORPINFO_ID': SessionService.instance.corpinfoId, + 'USER_ID': SessionService.instance.loginUserId, + 'FFILE': await MultipartFile.fromFile( + file.path, + filename: fileName + ), + } + ); + } + /// 问题反馈图片 static Future> reloadFeedBack(String imagePath) async { @@ -3444,8 +3466,8 @@ U6Hzm1ninpWeE+awIDAQAB }, ); } - ///NFC任务详情列表 - static Future> nfcTaskDetailList(int showCount, int currentPage) { + ///NFC任务详情 + static Future> nfcTaskDetailList(int showCount, int currentPage, String PATROL_TASK_ID) { return HttpManager().request( baseNFCPath, '/pipelineInspection/getPatrolTaskDetailList?showCount=$showCount¤tPage=$currentPage', @@ -3453,7 +3475,7 @@ U6Hzm1ninpWeE+awIDAQAB data: { "CORPINFO_ID":SessionService.instance.corpinfoId, "USER_ID":SessionService.instance.loginUserId, - + "PATROL_TASK_ID":PATROL_TASK_ID }, ); } diff --git a/lib/pages/home/NFC/home_nfc_detail_page.dart b/lib/pages/home/NFC/home_nfc_detail_page.dart index 2ee6431..2367a6a 100644 --- a/lib/pages/home/NFC/home_nfc_detail_page.dart +++ b/lib/pages/home/NFC/home_nfc_detail_page.dart @@ -1,8 +1,15 @@ +import 'dart:async'; +import 'dart:convert'; + import 'package:flutter/material.dart'; +import 'package:qhd_prevention/http/ApiService.dart'; +import 'package:qhd_prevention/pages/home/tap/item_list_widget.dart'; import 'package:qhd_prevention/pages/my_appbar.dart'; +import 'package:qhd_prevention/tools/tools.dart'; class HomeNfcDetailPage extends StatefulWidget { const HomeNfcDetailPage({super.key, required this.info}); + final Map info; @override @@ -10,26 +17,146 @@ class HomeNfcDetailPage extends StatefulWidget { } class _HomeNfcDetailPageState extends State { + List items = []; + int currentPage = 1; + final int pageSize = 10; - final List demoData = const [ - ProgressItem(status: '未查', location: '到期哦i维护经费欺废气阀我废费欺废气阀我废费欺废气阀我废气阀', code: 'XJ1001'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), - ProgressItem(status: '已查', location: 'B区-配电室', code: 'XJ1002', checkTime: '2025-07-28 15:32'), + bool isLoading = false; // 当前请求中 + bool hasMore = true; // 是否还有更多数据 + bool firstLoad = true; // 第一次加载标志 + + final ScrollController _scrollController = ScrollController(); + + @override + void initState() { + super.initState(); + _loadInitial(); + + // 监听滚动到底部触发加载更多 + _scrollController.addListener(() { + if (_scrollController.position.pixels >= + _scrollController.position.maxScrollExtent - 200 && + !isLoading && + hasMore) { + _getTaskDetail(); // 加载下一页 + } + }); + } + + Future _loadInitial() async { + await _getTaskDetail(refresh: true); + firstLoad = false; + } + + /// pageSize: 每页条数;currentPage 初始为 1 + Future _getTaskDetail({bool refresh = false}) async { + if (isLoading) return; + setState(() { + isLoading = true; + }); + + if (refresh) { + currentPage = 1; + hasMore = true; + } + + try { + // 调用后端 API:我保持你原来的签名 ApiService.nfcTaskDetailList(pageSize, page) + final result = await ApiService.nfcTaskDetailList( + pageSize, + currentPage, + widget.info['PATROL_TASK_ID'] ?? '', + ); + + if (result == null) { + _showMessage('请求失败:结果为 null'); + return; + } + printLongString(jsonEncode(result)); + if (result['result'] == 'success') { + // 兼容常见返回字段,尽量从 data / rows / list 里取 + final dynamic rawList = result['varList']; + + List fetched = []; + if (rawList is List) { + fetched = + rawList.map((e) { + if (e is ProgressItem) return e; + if (e is Map) return ProgressItem.fromJson(e); + return ProgressItem( + status: '未查', + location: e?.toString() ?? '', + code: '', + checkTime: null, + ); + }).toList(); + } + + setState(() { + if (refresh) { + items = fetched; + } else { + items.addAll(fetched); + } + // 如果本次返回少于 pageSize 则说明没有更多 + if (fetched.length < pageSize) { + hasMore = false; + } else { + // 成功拿到一页,页码自增 + currentPage++; + } + }); + } else { + final msg = result['message'] ?? result['msg'] ?? '加载失败'; + _showMessage('请求出错:$msg'); + } + } catch (e) { + _showMessage('请求异常:$e'); + } finally { + if (mounted) { + setState(() { + isLoading = false; + }); + } + } + } + + void _showMessage(String msg) { + if (!mounted) return; + ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg))); + } + + Future _startCheckItem(ProgressItem item, int index) async { + // TODO: 根据业务替换为真实逻辑(例如跳转到检查页面或调用写 NFC) + // 这里示例:将当前项标记为已查并设置检查时间(仅本地更新) + final now = DateTime.now(); + setState(() { + items[index] = items[index].copyWith( + status: '已查', + checkTime: + '${now.year}-${_two(now.month)}-${_two(now.day)} ${_two(now.hour)}:${_two(now.minute)}', + ); + }); + + // 额外:你可能需要调用后端接口上报检查结果 + // await ApiService.reportCheck(items[index].code, ...); + } + + String _two(int v) => v.toString().padLeft(2, '0'); + + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } - ]; Widget _pendingTopCard(Map item) { return SizedBox( height: 180, child: Stack( clipBehavior: Clip.none, children: [ + // 背景图片(上部) ClipRRect( borderRadius: BorderRadius.circular(10), child: Image.asset( @@ -45,7 +172,7 @@ class _HomeNfcDetailPageState extends State { top: 12, left: 12, child: Text( - item['title']!, + item['TASK_NAME']?.toString() ?? '', style: const TextStyle( color: Colors.black87, fontSize: 18, @@ -53,37 +180,42 @@ class _HomeNfcDetailPageState extends State { ), ), ), - Positioned( - top: 12, - right: 12, - child: Container( - height: 30, - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), - decoration: BoxDecoration( - color: Colors.blue.withOpacity(0.7), - borderRadius: BorderRadius.circular(4), - ), + Positioned( + top: 12, + right: 12, + child: Container( + height: 30, + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + decoration: BoxDecoration( + color: Colors.blue.withOpacity(0.3), + borderRadius: BorderRadius.circular(4), + ), + child: Center( child: Center( child: Text( - item['status']!, - style: const TextStyle(color: Colors.white, fontSize: 14), + item['PATROL_TYPE_NAME'] ?? '', + style: TextStyle( + color: Colors.blue, + fontWeight: FontWeight.bold, + ), ), ), ), ), + ), - // 白色信息区域(盖住图片部分) + // 白色信息区域(覆盖图片底部) Positioned( left: 0, right: 0, - top: 50, // 盖住图片底部 + top: 50, // 覆盖图片底部 child: Container( margin: const EdgeInsets.symmetric(horizontal: 0), - padding: const EdgeInsets.all(16), + padding: const EdgeInsets.symmetric(vertical: 10), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(10), - boxShadow: [ + boxShadow: const [ BoxShadow( color: Colors.black12, blurRadius: 4, @@ -98,196 +230,80 @@ class _HomeNfcDetailPageState extends State { ), ); } + /// 构建信息网格 Widget _buildInfoGrid(Map item) { - return Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('负责部门:${item['DEPARTMENT_NAME'] ?? ''}'), - const SizedBox(height: 8), - Text('巡检类型:${item['PATROL_TYPE_NAME'] ?? ''}'), - const SizedBox(height: 8), - Text('已巡点位:${item['INSPECTED_POINTS'] ?? '0'}'), - ], - ), - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Text('负责人:${item['USER_NAME'] ?? ''}'), - const SizedBox(height: 8), - Text('巡检周期:${item['PATROL_PERIOD_NAME'] ?? ''}'), - - // isFinish - // ? Text('涉及管道区域:${item['department'] ?? ''}') - // : const SizedBox(height: 25), - ], - ), - ), - ], - ); - } - Future _startCheckItem(ProgressItem item) async { - - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: MyAppbar(title: '任务详情'), - body: SafeArea(child: Padding(padding: EdgeInsets.all(16), child: Column( + return Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - _pendingTopCard(widget.info), - Expanded(child: Container( - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(10), - boxShadow: [ - BoxShadow( - color: Colors.black12, - blurRadius: 4, - offset: Offset(0, 1), - ), - ], - ), - - child: SingleChildScrollView( - child: ProgressList( - items: demoData, - onStartCheck: (idx) { - _startCheckItem(demoData[idx]); - print('开始检查第 $idx 项'); - }, - ), - ) - )) - ], - ),)), - ); - } -} -/// 单条进度数据模型 -class ProgressItem { - final String status; // “未查” 或 “已查” - final String location; // 地点 - final String code; // 编码 - final String? checkTime; // 检查时间(已查时有值) - - const ProgressItem({ - required this.status, - required this.location, - required this.code, - this.checkTime, - }); -} - -/// 进度列表组件 -class ProgressList extends StatelessWidget { - /// 数据源 - final List items; - - /// 点击“开始检查”后的回调,index 对应 items 的下标 - final void Function(int index) onStartCheck; - - const ProgressList({ - Key? key, - required this.items, - required this.onStartCheck, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - // 整体用 Column 包裹标题和列表 - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // 标题 - const Padding( - padding: EdgeInsets.all(16), - child: Text( - '已查点位1/5', - style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + // const SizedBox(height: 8), + ItemListWidget.singleLineTitleText( + label: '负责部门', + isEditable: false, + text: item['DEPARTMENT_NAME'] ?? '', ), - ), - const Divider(height: 1), - - // 列表 - ListView.builder( - physics: const NeverScrollableScrollPhysics(), // 让父级滚动 - shrinkWrap: true, - itemCount: items.length, - itemBuilder: (ctx, idx) { - return _ProgressListItem( - item: items[idx], - onStart: () => onStartCheck(idx), - ); - }, - ), - ], + ItemListWidget.singleLineTitleText( + label: '负责人', + isEditable: false, + text: item['USER_NAME'] ?? '', + ), + ItemListWidget.singleLineTitleText( + label: '涉及管道区域:', + isEditable: false, + text: item['PIPELINE_AREAS_NAMES'] ?? '', + ), + ItemListWidget.singleLineTitleText( + label: '巡检周期', + isEditable: false, + text: item['PATROL_PERIOD_NAME'] ?? '', + ), + ItemListWidget.singleLineTitleText( + label: '任务时间', + isEditable: false, + text: item['OPERATTIME'] ?? '', + ), + ], + ), ); } -} -/// 单行进度条目 -class _ProgressListItem extends StatelessWidget { - final ProgressItem item; - final VoidCallback onStart; - - const _ProgressListItem({ - Key? key, - required this.item, - required this.onStart, - }) : super(key: key); - - @override - Widget build(BuildContext context) { + Widget _buildListItem(BuildContext context, int idx) { + final item = items[idx]; final bool unchecked = item.status == '未查'; return Container( height: 100, margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ // 左侧状态区 - Column(children: [ - Stack( - alignment: Alignment.center, - children: [ - Image.asset( - unchecked - ? 'assets/images/xj_wait.png' - : 'assets/images/xj_finish.png', - width: 50, - height: 30, - fit: BoxFit.cover, - ), - Positioned( - top: 2, - child: Text( - item.status, - style: const TextStyle(color: Colors.white, fontSize: 14), + Column( + children: [ + Stack( + alignment: Alignment.center, + children: [ + Image.asset( + unchecked + ? 'assets/images/xj_wait.png' + : 'assets/images/xj_finish.png', + width: 50, + height: 30, + fit: BoxFit.cover, ), - ), - - ], - ), - SizedBox(height: 15,), - Positioned( - // bottom: 0, - // right: 17, - child: Image.asset( - 'assets/images/xjjd_top.png', - width: 15, - height: 30, + Positioned( + top: 2, + child: Text( + item.status, + style: const TextStyle(color: Colors.white, fontSize: 14), + ), + ), + ], ), - ), - ],), - + const SizedBox(height: 8), + Image.asset('assets/images/xjjd_top.png', width: 15, height: 30), + ], + ), const SizedBox(width: 20), @@ -295,7 +311,6 @@ class _ProgressListItem extends StatelessWidget { Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisAlignment: MainAxisAlignment.center, children: [ Text( item.location, @@ -303,19 +318,16 @@ class _ProgressListItem extends StatelessWidget { fontSize: 16, fontWeight: FontWeight.bold, ), - maxLines: 1, // 最多一行 - overflow: TextOverflow.ellipsis, // 超出省略号 + maxLines: 1, // 最多一行 + overflow: TextOverflow.ellipsis, // 超出省略号 ), const SizedBox(height: 4), Text('NFC编码:${item.code}'), - + const SizedBox(height: 6), unchecked ? InkWell( - onTap: onStart, - child: Column( - children: [ - SizedBox(height: 5,), - Container( + onTap: () => _startCheckItem(item, idx), + child: Container( height: 35, alignment: Alignment.center, padding: const EdgeInsets.symmetric(vertical: 1), @@ -330,29 +342,203 @@ class _ProgressListItem extends StatelessWidget { style: TextStyle(color: Colors.white, fontSize: 14), ), ), - ], - ) - ) + ) : Text( - '检查时间:' + (item.checkTime ?? ''), - style: const TextStyle(fontSize: 14), - textAlign: TextAlign.center, - ), + '检查时间:${item.checkTime ?? ''}', + style: const TextStyle(fontSize: 14), + textAlign: TextAlign.center, + ), ], ), ), - // 操作区或时间 + // 右侧箭头 const SizedBox(width: 8), - Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Icon(Icons.chevron_right, color: Colors.grey), - SizedBox() - ], - ) + const Icon(Icons.chevron_right, color: Colors.grey), ], ), ); } -} \ No newline at end of file + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: MyAppbar(title: '任务详情'), + body: SafeArea( + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + children: [ + _pendingTopCard(widget.info), + const SizedBox(height: 60), + Expanded( + child: Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + boxShadow: const [ + BoxShadow( + color: Colors.black12, + blurRadius: 4, + offset: Offset(0, 1), + ), + ], + ), + child: RefreshIndicator( + onRefresh: () => _getTaskDetail(refresh: true), + child: + firstLoad && isLoading + ? const Center( + child: Padding( + padding: EdgeInsets.all(16.0), + child: CircularProgressIndicator(), + ), + ) + : items.isEmpty + ? ListView( + controller: _scrollController, + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox(height: 80), + Center( + child: Text(isLoading ? '加载中...' : '暂无数据'), + ), + ], + ) + : ListView.builder( + controller: _scrollController, + physics: const AlwaysScrollableScrollPhysics(), + itemCount: items.length + 1, // 多一个用于加载状态/底部提示 + itemBuilder: (ctx, idx) { + if (idx < items.length) { + return _buildListItem(ctx, idx); + } else { + // 底部加载/没有更多提示 + if (hasMore) { + // 触发加载(以防没有触发) + if (!isLoading) { + // 预防性触发下一页 + // _getTaskDetail(); // 不在此直接调用,scroll listener 会负责 + } + return const Padding( + padding: EdgeInsets.symmetric( + vertical: 12, + ), + child: Center( + child: CircularProgressIndicator(), + ), + ); + } else { + return const Padding( + padding: EdgeInsets.symmetric( + vertical: 12, + ), + child: Center(child: Text('没有更多了')), + ); + } + } + }, + ), + ), + ), + ), + ], + ), + ), + ), + ); + } +} + +/// 单条进度数据模型 +class ProgressItem { + final String status; // “未查” 或 “已查” + final String location; // 地点 + final String code; // 编码 + final String? checkTime; // 检查时间(已查时有值) + + ProgressItem({ + required this.status, + required this.location, + required this.code, + this.checkTime, + }); + + ProgressItem copyWith({ + String? status, + String? location, + String? code, + String? checkTime, + }) { + return ProgressItem( + status: status ?? this.status, + location: location ?? this.location, + code: code ?? this.code, + checkTime: checkTime ?? this.checkTime, + ); + } + + /// 宽容解析后端返回(根据常见字段名) + factory ProgressItem.fromJson(Map json) { + String status = + (json['status'] ?? + json['STATUS'] ?? + (json['checked'] == true ? '已查' : null) ?? + (json['is_checked'] == 1 ? '已查' : null) ?? + json['state'] ?? + json['check_status']) + ?.toString() ?? + ''; + + if (status.isEmpty) { + // 有些 API 用 0/1 表示 + final s = json['status'] ?? json['STATUS'] ?? json['check_status']; + if (s is num) { + status = (s == 0) ? '未查' : '已查'; + } else if (s is String && (s == '0' || s == '1')) { + status = (s == '0') ? '未查' : '已查'; + } + } + if (status.isEmpty) status = '未查'; + + final location = + (json['location'] ?? + json['LOCATION'] ?? + json['point_name'] ?? + json['address'] ?? + json['point'] ?? + '') + .toString(); + final code = + (json['code'] ?? + json['CODE'] ?? + json['nfcCode'] ?? + json['nfc_code'] ?? + json['NFC_CODE'] ?? + json['id'] ?? + '') + .toString(); + final checkTime = + (json['checkTime'] ?? + json['CHECK_TIME'] ?? + json['checked_at'] ?? + json['check_time'] ?? + json['inspect_time'] ?? + null) + ?.toString(); + + return ProgressItem( + status: status, + location: location, + code: code, + checkTime: checkTime, + ); + } + + Map toJson() => { + 'status': status, + 'location': location, + 'code': code, + 'checkTime': checkTime, + }; +} diff --git a/lib/pages/home/NFC/home_nfc_list_page.dart b/lib/pages/home/NFC/home_nfc_list_page.dart index e66b662..b370c67 100644 --- a/lib/pages/home/NFC/home_nfc_list_page.dart +++ b/lib/pages/home/NFC/home_nfc_list_page.dart @@ -57,7 +57,7 @@ class _HomeNfcListPageState extends State // 滚动监听,上拉触底加载更多 _pendingScrollController.addListener(() { if (_pendingScrollController.position.pixels >= - _pendingScrollController.position.maxScrollExtent - 80 && + _pendingScrollController.position.maxScrollExtent - 80 && !_pendingLoading && _pendingHasMore) { _loadMorePending(); @@ -66,7 +66,7 @@ class _HomeNfcListPageState extends State _recordScrollController.addListener(() { if (_recordScrollController.position.pixels >= - _recordScrollController.position.maxScrollExtent - 80 && + _recordScrollController.position.maxScrollExtent - 80 && !_recordLoading && _recordHasMore) { _loadMoreRecord(); @@ -86,14 +86,15 @@ class _HomeNfcListPageState extends State _recordScrollController.dispose(); super.dispose(); } + String _checkStatusName(String status) { if (status == '0') { return '已巡检'; - }else if (status == '1') { + } else if (status == '1') { return '超期未巡检'; - }else if (status == '2') { + } else if (status == '2') { return '巡检中'; - }else{ + } else { return '待巡检'; } } @@ -155,34 +156,39 @@ class _HomeNfcListPageState extends State if (res['result'] == 'success') { List list = res['varList']; - final parsed = list.map>((e) { - return e; - }).toList(); + final parsed = + list.map>((e) { + return e; + }).toList(); - // - // 判断是否还有更多:如果返回数量 < pageSize 则没有更多 - final bool gotLessThanPage = parsed.length < _pageSize; + // + // 判断是否还有更多:如果返回数量 < pageSize 则没有更多 + final bool gotLessThanPage = parsed.length < _pageSize; - if (replace) { - setState(() { - _pendingList.clear(); - _pendingList.addAll(parsed); - _pendingPage = 1; - _pendingHasMore = !gotLessThanPage; - }); - } else { - setState(() { - _pendingList.addAll(parsed); - _pendingPage = page; - if (parsed.isEmpty) _pendingHasMore = false; - else if (parsed.length < _pageSize) _pendingHasMore = false; - }); - } + if (replace) { + setState(() { + _pendingList.clear(); + _pendingList.addAll(parsed); + _pendingPage = 1; + _pendingHasMore = !gotLessThanPage; + }); + } else { + setState(() { + _pendingList.addAll(parsed); + _pendingPage = page; + if (parsed.isEmpty) + _pendingHasMore = false; + else if (parsed.length < _pageSize) + _pendingHasMore = false; + }); + } } } catch (e) { // 错误处理 if (mounted) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('获取待巡检列表失败:$e'))); + ScaffoldMessenger.of( + context, + ).showSnackBar(SnackBar(content: Text('获取待巡检列表失败:$e'))); } } finally { if (mounted) { @@ -193,12 +199,15 @@ class _HomeNfcListPageState extends State } } - Future _getTaskDetailList({required int page, required bool replace}) async { + Future _getTaskDetailList({ + required int page, + required bool replace, + }) async { setState(() { _recordLoading = true; }); try { - final res = await ApiService.nfcTaskDetailList(_pageSize, page); + // final res = await ApiService.nfcTaskDetailList(_pageSize, page); List? list; // if (res == null) { // list = []; @@ -253,7 +262,9 @@ class _HomeNfcListPageState extends State // } } catch (e) { if (mounted) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('获取巡检记录失败:$e'))); + ScaffoldMessenger.of( + context, + ).showSnackBar(SnackBar(content: Text('获取巡检记录失败:$e'))); } } finally { if (mounted) { @@ -269,17 +280,20 @@ class _HomeNfcListPageState extends State @override Widget build(BuildContext context) { return Scaffold( - appBar: MyAppbar(title: '巡检列表', actions: [ - TextButton( - onPressed: () { - pushPage(const HomeNfcAddPage(), context); - }, - child: const Text( - "NFC绑定", - style: TextStyle(color: Colors.white, fontSize: 16), + appBar: MyAppbar( + title: '巡检列表', + actions: [ + TextButton( + onPressed: () { + pushPage(const HomeNfcAddPage(), context); + }, + child: const Text( + "NFC绑定", + style: TextStyle(color: Colors.white, fontSize: 16), + ), ), - ) - ]), + ], + ), body: SafeArea( child: Column( children: [ @@ -435,7 +449,10 @@ class _HomeNfcListPageState extends State right: 12, child: Container( height: 30, - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 4, + ), decoration: BoxDecoration( color: Colors.white.withOpacity(0.5), borderRadius: BorderRadius.circular(15), @@ -443,7 +460,13 @@ class _HomeNfcListPageState extends State child: Center( child: Text( item['INSPECTED_POINTS'] > 0 ? '巡检中' : '待巡检', - style: TextStyle(color: item['INSPECTED_POINTS'] as int > 0 ? Colors.blue : Colors.deepOrange, fontSize: 14), + style: TextStyle( + color: + item['INSPECTED_POINTS'] as int > 0 + ? Colors.blue + : Colors.deepOrange, + fontSize: 14, + ), ), ), ), @@ -483,7 +506,6 @@ class _HomeNfcListPageState extends State /// 构建信息网格 Widget _buildInfoGrid(Map item, bool isFinish) { - return Row( children: [ Expanded( diff --git a/lib/pages/home/work/danger_project_page.dart b/lib/pages/home/work/danger_project_page.dart index f849077..6c60917 100644 --- a/lib/pages/home/work/danger_project_page.dart +++ b/lib/pages/home/work/danger_project_page.dart @@ -22,9 +22,6 @@ class DangerProjectPage extends StatefulWidget { } class _DangerProjectPageState extends State { - // 单选按钮的值 - // String? _selectedValue; - // 单选按钮选项 final List> _options = [ { @@ -49,63 +46,53 @@ class _DangerProjectPageState extends State { List listDates = []; List listDatesSelect = []; - String unqualifiedInspectionItemID=""; - Map nullResult={}; - List upDataItemList=[]; + String unqualifiedInspectionItemID = ""; + Map nullResult = {}; + List upDataItemList = []; - String yinHuanText=""; + String yinHuanText = ""; @override void initState() { - // TODO: implement initState super.initState(); SessionService.instance.setUnqualifiedInspectionItemIDJson(""); _getData(); - - - } - void _getData(){ + void _getData() { listDates.clear(); - switch(widget.type ){ - case 1://隐患排查 + switch (widget.type) { + case 1: //隐患排查 _getInvestigationItemsYinHuan(); break; - case 2://标准排查 + case 2: //标准排查 _getInvestigationItems(); break; - } } - Future _getInvestigationItemsYinHuan( ) async { + Future _getInvestigationItemsYinHuan() async { try { - final result = await ApiService.getInvestigationItemsYinHuan(widget.item); if (result['result'] == 'success') { final List newList = result['varList'] ?? []; final List newListTwo = result['records'] ?? []; setState(() { - listDates.addAll(newList); - if(newListTwo.isNotEmpty){ + if (newListTwo.isNotEmpty) { listDatesSelect.addAll(newListTwo); } - - // listDatesTwo.addAll(newListTwo);option1 - for(int i=0;i)["REFERENCE_BASIS"] = "option1"; break; @@ -116,46 +103,38 @@ class _DangerProjectPageState extends State { (listDates[i] as Map)["REFERENCE_BASIS"] = "option3"; break; } - }else { + } else { (listDates[i] as Map)["REFERENCE_BASIS"] = ""; } - if(listDatesSelect[m].containsKey("HIDDEN_ID")){ + if (listDatesSelect[m].containsKey("HIDDEN_ID")) { (listDates[i] as Map)["ids"] = listDatesSelect[m]["HIDDEN_ID"]; SessionService.instance.setUnqualifiedInspectionItemIDJson(listDatesSelect[m]["HIDDEN_ID"]); - }else{ + } else { (listDates[i] as Map)["ids"] = ""; } - - }else{ + } else { (listDates[i] as Map)["ids"] = ""; } - }else{ + } else { (listDates[i] as Map)["ids"] = ""; } } - }else{ + } else { (listDates[i] as Map)["ids"] = ""; } } - - }); - - }else{ + } else { ToastUtil.showNormal(context, result['msg']); - // _showMessage('加载数据失败'); } } catch (e) { - // 出错时可以 Toast 或者在页面上显示错误状态 print('加载数据失败:$e'); - } } - Future _getInvestigationItems( ) async { + Future _getInvestigationItems() async { try { - final result = await ApiService.getInvestigationItems(widget.item); if (result['result'] == 'success') { final List newList = result['varList'] ?? []; @@ -163,19 +142,17 @@ class _DangerProjectPageState extends State { setState(() { listDates.addAll(newList); - if(newListTwo.isNotEmpty){ + if (newListTwo.isNotEmpty) { listDatesSelect.addAll(newListTwo); } - - for(int i=0;i)["REFERENCE_BASIS"] = "option1"; break; @@ -186,42 +163,33 @@ class _DangerProjectPageState extends State { (listDates[i] as Map)["REFERENCE_BASIS"] = "option3"; break; } - }else { + } else { (listDates[i] as Map)["REFERENCE_BASIS"] = ""; } - if(listDatesSelect[m].containsKey("HIDDEN_ID")){ + if (listDatesSelect[m].containsKey("HIDDEN_ID")) { (listDates[i] as Map)["ids"] = listDatesSelect[m]["HIDDEN_ID"]; SessionService.instance.setUnqualifiedInspectionItemIDJson(listDatesSelect[m]["HIDDEN_ID"]); - }else{ + } else { (listDates[i] as Map)["ids"] = ""; } - - }else{ + } else { (listDates[i] as Map)["ids"] = ""; } - }else{ + } else { (listDates[i] as Map)["ids"] = ""; } } - }else{ + } else { (listDates[i] as Map)["ids"] = ""; } - - - } - }); - - }else{ + } else { ToastUtil.showNormal(context, result['msg']); - // _showMessage('加载数据失败'); } } catch (e) { - // 出错时可以 Toast 或者在页面上显示错误状态 print('加载数据失败:$e'); - } } @@ -233,29 +201,29 @@ class _DangerProjectPageState extends State { backgroundColor: h_backGroundColor(), appBar: MyAppbar(title: "排查项"), body: SafeArea( - child:Column( + child: Column( children: [ - Expanded(child: listDates.isEmpty - ? NoDataWidget.show() - : ListView.separated( - itemCount: listDates.length, - separatorBuilder: (_, __) => const SizedBox(), - itemBuilder: (context, index) { - final item = listDates[index]; - return GestureDetector( - // onTap: () => _selectItem(item), - child: _itemCell(screenWidth,item), - ); - }, - )), + Expanded( + child: listDates.isEmpty + ? NoDataWidget.show() + : ListView.separated( + itemCount: listDates.length, + separatorBuilder: (_, __) => const SizedBox(), + itemBuilder: (context, index) { + final item = listDates[index]; + return GestureDetector( + child: _itemCell(screenWidth, item), + ); + }, + )), // 下一步按钮 Container( margin: const EdgeInsets.only(bottom: 20), height: 50, decoration: BoxDecoration( - color: Colors.green , + color: Colors.green, borderRadius: BorderRadius.circular(10), - boxShadow: [ + boxShadow: const [ BoxShadow( color: Colors.black12, blurRadius: 6, @@ -263,36 +231,30 @@ class _DangerProjectPageState extends State { ), ], ), - child: - SizedBox( + child: SizedBox( width: screenWidth - 30, height: 50, child: TextButton( - onPressed: _submit,//_selectedValue != null ? _submit : null, - child: Text( - "提交", - style: TextStyle( - color: Colors.white, - fontSize: 18, - fontWeight: FontWeight.bold, + onPressed: _submit, + child: const Text( + "提交", + style: TextStyle( + color: Colors.white, + fontSize: 18, + fontWeight: FontWeight.bold, + ), ), ), - ), ), ), - ], ), - - // _itemCell(screenWidth), ), ); } - - - Widget _itemCell(final screenWidth,final item) { - return Padding( + Widget _itemCell(final screenWidth, final item) { + return Padding( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, @@ -305,15 +267,15 @@ class _DangerProjectPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - if(widget.type==1) - Text( - "存在风险:${item["RISK_DESCR"]}", - style: TextStyle( - fontSize: 16, - color: Colors.grey[700], - height: 1.5, + if (widget.type == 1) + Text( + "存在风险:${item["RISK_DESCR"]}", + style: TextStyle( + fontSize: 16, + color: Colors.grey[700], + height: 1.5, + ), ), - ), // 问题描述 Text( "检查内容:${item["CHECK_CONTENT"]}", @@ -323,21 +285,20 @@ class _DangerProjectPageState extends State { height: 1.5, ), ), - if(widget.type==2) - Text( - "检查标准:${item["CHECK_STANDARD"]}", - style: TextStyle( - fontSize: 16, - color: Colors.grey[700], - height: 1.5, + if (widget.type == 2) + Text( + "检查标准:${item["CHECK_STANDARD"]}", + style: TextStyle( + fontSize: 16, + color: Colors.grey[700], + height: 1.5, + ), ), - ), // 单选按钮组 Row( mainAxisAlignment: MainAxisAlignment.spaceAround, - children: - _options.map((option) { + children: _options.map((option) { return _buildOptionButton( context: context, value: option['value'], @@ -347,63 +308,57 @@ class _DangerProjectPageState extends State { screenWidth: screenWidth, item: item, onImageTap: () { - if(item["REFERENCE_BASIS"]=="option1") { - _getAlreadyUpImages(item); - }else if(item["REFERENCE_BASIS"]=="option2") { - _goUnqualifiedPage(item); - } + if (item["REFERENCE_BASIS"] == "option1") { + _getAlreadyUpImages(item); + } else if (item["REFERENCE_BASIS"] == "option2") { + _goUnqualifiedPage(item); + } }, ); }).toList(), ), - if(item["REFERENCE_BASIS"]=="option1"&& widget.type==2) + if (item["REFERENCE_BASIS"] == "option1" && widget.type == 2) Card( - color: const Color(0xFFF1F1F1), - child: Container( - width: screenWidth, - padding: EdgeInsets.all(10), - child: Text(item["CHECK_QUALIFIED"],style:TextStyle(color: Colors.black,fontSize: 12)), - ) - ), - - + color: const Color(0xFFF1F1F1), + child: Container( + width: screenWidth, + padding: const EdgeInsets.all(10), + child: + Text(item["CHECK_QUALIFIED"], style: const TextStyle(color: Colors.black, fontSize: 12)), + )), ], ), ), ), - // Spacer(), - ], ), ); } + Future _getAlreadyUpImages(Map item) async { try { final result = await ApiService.getAlreadyUpImages(item["RECORDITEM_ID"]); if (result['result'] == 'success') { final List newList = result['imgs'] ?? []; - List imgList = []; - for (Map item in newList) { - String id = item['IMGFILES_ID'] ?? ''; - String filePath = item['FILEPATH'] ?? ''; - imgList.add( - PhotoItem( - id: id, // 新图片没有ID - filePath: ApiService.baseImgPath+filePath, - type: "1", - ), - ); - } + List imgList = []; + for (Map item in newList) { + String id = item['IMGFILES_ID'] ?? ''; + String filePath = item['FILEPATH'] ?? ''; + imgList.add( + PhotoItem( + id: id, // 新图片没有ID + filePath: ApiService.baseImgPath + filePath, + type: "1", + ), + ); + } pushPage(DangerImageUpdataPage(item["RECORDITEM_ID"], imgList: imgList), context); - } else { ToastUtil.showNormal(context, "加载数据失败"); - // _showMessage('加载数据失败'); } } catch (e) { - // 出错时可以 Toast 或者在页面上显示错误状态 print('加载数据失败:$e'); } } @@ -425,50 +380,59 @@ class _DangerProjectPageState extends State { return GestureDetector( onTap: () { setState(() { - if(value!="option2") { + if (value != "option2") { SessionService.instance.setUnqualifiedInspectionItemIDJson(""); - // _selectedValue = value; - item["REFERENCE_BASIS"]=value; - }else{ + item["REFERENCE_BASIS"] = value; + } else { _goUnqualifiedPage(item); - // pushPage(HazardRegistrationPage(item), context); } }); }, + behavior: HitTestBehavior.opaque, child: Container( width: buttonWidth, padding: const EdgeInsets.symmetric(vertical: 12), - - child: Expanded(child: Row( + // 不要在这里放 Expanded(非 Flex 父组件) + child: Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, children: [ - Row(children: [ - Icon(icon, color: isSelected ? color : Colors.grey, size: 30), - const SizedBox(width: 8), - Text( - label, - style: TextStyle( - fontSize: 14, - fontWeight: isSelected ? FontWeight.bold : FontWeight.normal, - color: isSelected ? color : Colors.grey[600], - ), + SizedBox( + height: 30, + width: 90, + child: Row( + children: [ + Icon(icon, color: isSelected ? color : Colors.grey, size: 30), + const SizedBox(width: 8), + Flexible( + child: Text( + label, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 14, + fontWeight: isSelected ? FontWeight.bold : FontWeight.normal, + color: isSelected ? color : Colors.grey[600], + ), + ), + ), + ], ), - ],), - if((value=="option1"&&item["REFERENCE_BASIS"]=="option1")|| - (value=="option2"&&item["REFERENCE_BASIS"]=="option2"&&item.containsKey("ids")&&item["ids"].toString().isNotEmpty)) - // 添加图片点击处理 + ), + const SizedBox(width: 6), + if ((value == "option1" && item["REFERENCE_BASIS"] == "option1") || + (value == "option2" && + item["REFERENCE_BASIS"] == "option2" && + item.containsKey("ids") && + item["ids"].toString().isNotEmpty)) GestureDetector( onTap: () { - - // 防止事件冒泡到父级 GestureDetector if (onImageTap != null) { onImageTap(); } }, - behavior: HitTestBehavior.opaque, // 确保透明区域也能点击 + behavior: HitTestBehavior.opaque, child: Transform.translate( - offset: Offset(0, -6), // Y轴负值向上移动 + offset: const Offset(0, -6), child: Image.asset( "assets/images/gantan-blue.png", width: 15, @@ -477,220 +441,154 @@ class _DangerProjectPageState extends State { ), ), ], - )), + ), ), ); } - void _goUnqualifiedPage(item) { - // String hiddenId=SessionService.instance.unqualifiedInspectionItemID.toString(); - String hiddenId=item["ids"]; - if(hiddenId.isNotEmpty) { - switch(widget.type ){ - case 1://隐患排查 - _getTemporaryStorageOfHiddenYinHuan(item,hiddenId); + String hiddenId = item["ids"] ?? ""; + if (hiddenId.isNotEmpty) { + switch (widget.type) { + case 1: //隐患排查 + _getTemporaryStorageOfHiddenYinHuan(item, hiddenId); break; - case 2://标准排查 - _getTemporaryStorageOfHidden(item,hiddenId); + case 2: //标准排查 + _getTemporaryStorageOfHidden(item, hiddenId); break; - } - - }else{ - pushPage(HazardRegistrationPage( - item,nullResult,widget.type, - onClose: (String departmentId,String yinHuanText) { + } else { + pushPage( + HazardRegistrationPage(item, nullResult, widget.type, onClose: (String departmentId, String yinHuanText) { setState(() { - this.yinHuanText=yinHuanText; - item["REFERENCE_BASIS"]="option2"; - // _selectedValue="option2"; - // unqualifiedInspectionItemID=departmentId; - item["ids"]=departmentId; + this.yinHuanText = yinHuanText; + item["REFERENCE_BASIS"] = "option2"; + item["ids"] = departmentId; }); - - }, - ), context); + }), context); } } - Future _getTemporaryStorageOfHiddenYinHuan(Map item,String hiddenId) async { - + Future _getTemporaryStorageOfHiddenYinHuan(Map item, String hiddenId) async { try { final result = await ApiService.getTemporaryStorageOfHiddenYinHuan(hiddenId); if (result['result'] == 'success') { - try{ - dynamic pd=result["pd"]; - if(pd["HIDDEN_CATEGORY"]!=null){ - if(pd["HIDDEN_CATEGORY"]=='aa0b9abb642146588bc71a12272942db'){ - result["pd"]["HIDDEN_CATEGORY_NAME"]= "技术负责人登记隐患"; - }else if(pd["HIDDEN_CATEGORY"]=='355ff0ead356428fa83a01330cfe10c6'){ - result["pd"]["HIDDEN_CATEGORY_NAME"]= "主要负责人登记隐患"; - }else if(pd["HIDDEN_CATEGORY"]=='a92911891ea847cc8f4cfac2455170bd'){ - result["pd"]["HIDDEN_CATEGORY_NAME"]= "其他隐患"; - }else if(pd["HIDDEN_CATEGORY"]=='44f8ce46372d4616a654cd07f1ec9a48'){ - result["pd"]["HIDDEN_CATEGORY_NAME"]= "操作负责人登记隐患"; + try { + dynamic pd = result["pd"]; + if (pd["HIDDEN_CATEGORY"] != null) { + if (pd["HIDDEN_CATEGORY"] == 'aa0b9abb642146588bc71a12272942db') { + result["pd"]["HIDDEN_CATEGORY_NAME"] = "技术负责人登记隐患"; + } else if (pd["HIDDEN_CATEGORY"] == '355ff0ead356428fa83a01330cfe10c6') { + result["pd"]["HIDDEN_CATEGORY_NAME"] = "主要负责人登记隐患"; + } else if (pd["HIDDEN_CATEGORY"] == 'a92911891ea847cc8f4cfac2455170bd') { + result["pd"]["HIDDEN_CATEGORY_NAME"] = "其他隐患"; + } else if (pd["HIDDEN_CATEGORY"] == '44f8ce46372d4616a654cd07f1ec9a48') { + result["pd"]["HIDDEN_CATEGORY_NAME"] = "操作负责人登记隐患"; } - } - }catch(e){ + } catch (e) { print('数据获取失败:$e'); } - pushPage(HazardRegistrationPage( - item,result,widget.type, - onClose: (String departmentId,String yinHuanText) { - setState(() { - this.yinHuanText=yinHuanText; - item["REFERENCE_BASIS"]="option2"; - // _selectedValue="option2"; - // unqualifiedInspectionItemID=departmentId; - item["ids"]=departmentId; - }); - - }, - ), context); - + pushPage(HazardRegistrationPage(item, result, widget.type, onClose: (String departmentId, String yinHuanText) { + setState(() { + this.yinHuanText = yinHuanText; + item["REFERENCE_BASIS"] = "option2"; + item["ids"] = departmentId; + }); + }), context); } else { ToastUtil.showNormal(context, "加载数据失败"); - // _showMessage('加载数据失败'); } } catch (e) { - // 出错时可以 Toast 或者在页面上显示错误状态 print('加载数据失败:$e'); } } - Future _getTemporaryStorageOfHidden(Map item,String hiddenId) async { - + Future _getTemporaryStorageOfHidden(Map item, String hiddenId) async { try { final result = await ApiService.getTemporaryStorageOfHidden(hiddenId); if (result['result'] == 'success') { - - pushPage(HazardRegistrationPage( - item,result,widget.type, - onClose: (String departmentId,String yinHuanText) { - setState(() { - this.yinHuanText=yinHuanText; - item["REFERENCE_BASIS"]="option2"; - // _selectedValue="option2"; - // unqualifiedInspectionItemID=departmentId; - item["ids"]=departmentId; - }); - - }, - ), context); - - // final List newList = result['imgs'] ?? []; - // List imgList = []; - // for (Map item in newList) { - // String id = item['IMGFILES_ID'] ?? ''; - // String filePath = item['FILEPATH'] ?? ''; - // imgList.add( - // PhotoItem( - // id: id, // 新图片没有ID - // filePath: ApiService.baseImgPath+filePath, - // type: "1", - // ), - // ); - // } - // pushPage(DangerImageUpdataPage(item["RECORDITEM_ID"], imgList: imgList), context); - + pushPage(HazardRegistrationPage(item, result, widget.type, onClose: (String departmentId, String yinHuanText) { + setState(() { + this.yinHuanText = yinHuanText; + item["REFERENCE_BASIS"] = "option2"; + item["ids"] = departmentId; + }); + }), context); } else { ToastUtil.showNormal(context, "加载数据失败"); - // _showMessage('加载数据失败'); } } catch (e) { - // 出错时可以 Toast 或者在页面上显示错误状态 print('加载数据失败:$e'); } } - - void _submit() { - // if (_selectedValue == null) return; LoadingDialogHelper.show(); _submitInvestigationItems(); - // 这里可以添加导航到下一页的代码 - // Navigator.push(context, MaterialPageRoute(builder: (_) => NextPage())); } - Future _submitInvestigationItems() async { - - //获取定位 Position position = await _determinePosition(); - String longitude=position.longitude.toString(); - String latitude=position.latitude.toString(); + String longitude = position.longitude.toString(); + String latitude = position.latitude.toString(); upDataItemList.clear(); - bool hasNoSelectItem=false; - String ids=""; - for(int i=0;i result; - if(widget.type==1){ - result = await ApiService.submitInvestigationItemsYinHuan( - widget.item,longitude,latitude,itemsString,ids,CHECKRECORD_ID); - }else{ - result = await ApiService.submitInvestigationItems( - widget.item,longitude,latitude,itemsString,ids,CHECKRECORD_ID); + if (widget.type == 1) { + result = await ApiService.submitInvestigationItemsYinHuan(widget.item, longitude, latitude, itemsString, ids, CHECKRECORD_ID); + } else { + result = await ApiService.submitInvestigationItems(widget.item, longitude, latitude, itemsString, ids, CHECKRECORD_ID); } if (result['result'] == 'success') { @@ -699,16 +597,12 @@ class _DangerProjectPageState extends State { Navigator.pop(context); LoadingDialogHelper.hide(); }); - - } else { ToastUtil.showNormal(context, "加载数据失败"); LoadingDialogHelper.hide(); - // _showMessage('加载数据失败'); } } catch (e) { LoadingDialogHelper.hide(); - // 出错时可以 Toast 或者在页面上显示错误状态 print('加载数据失败:$e'); } } @@ -717,13 +611,11 @@ class _DangerProjectPageState extends State { bool serviceEnabled; LocationPermission permission; - // 检查定位服务是否启用 serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { return Future.error('Location services are disabled.'); } - // 获取权限 permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); @@ -733,11 +625,9 @@ class _DangerProjectPageState extends State { } if (permission == LocationPermission.deniedForever) { - return Future.error( - 'Location permissions are permanently denied, we cannot request permissions.'); + return Future.error('Location permissions are permanently denied, we cannot request permissions.'); } - // 获取当前位置 return await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); } @@ -745,11 +635,8 @@ class _DangerProjectPageState extends State { if (text.length <= maxLength) return text; return '${text.substring(0, maxLength)}...'; } - - } - // 模拟数据模版 class UpDataItem { final String CUSTOM_ITEM_ID; @@ -757,24 +644,9 @@ class UpDataItem { final String ISNORMAL; final String CHECK_RESULT; - UpDataItem( - this.CUSTOM_ITEM_ID, - this.RECORDITEM_ID, - this.ISNORMAL, - this.CHECK_RESULT, - ); + UpDataItem(this.CUSTOM_ITEM_ID, this.RECORDITEM_ID, this.ISNORMAL, this.CHECK_RESULT); - factory UpDataItem.fromJson( - String CUSTOM_ITEM_ID, - String RECORDITEM_ID, - String ISNORMAL, - String CHECK_RESULT, - ) { - return UpDataItem( - CUSTOM_ITEM_ID, // 直接传递参数,不使用命名参数语法 - RECORDITEM_ID, - ISNORMAL, - CHECK_RESULT, - ); + factory UpDataItem.fromJson(String CUSTOM_ITEM_ID, String RECORDITEM_ID, String ISNORMAL, String CHECK_RESULT) { + return UpDataItem(CUSTOM_ITEM_ID, RECORDITEM_ID, ISNORMAL, CHECK_RESULT); } } diff --git a/lib/pages/mine/mine_first_sign_page.dart b/lib/pages/mine/mine_first_sign_page.dart index 425563e..41f5fd7 100644 --- a/lib/pages/mine/mine_first_sign_page.dart +++ b/lib/pages/mine/mine_first_sign_page.dart @@ -1,34 +1,42 @@ import 'package:flutter/material.dart'; import 'dart:io'; import 'package:flutter/services.dart'; +import 'package:qhd_prevention/customWidget/toast_util.dart'; +import 'package:qhd_prevention/http/ApiService.dart'; import 'package:qhd_prevention/pages/my_appbar.dart'; import '../../tools/tools.dart'; import 'mine_sign_page.dart'; - - - class FirstSignPage extends StatefulWidget { const FirstSignPage({super.key}); - @override State createState() => _SignatureUpdatePageState(); } class _SignatureUpdatePageState extends State { - String imagePath=""; - - + String imagePath = ""; + Future refreshSign() async { + if (imagePath.isEmpty) { + ToastUtil.showNormal(context, '请签字'); + return; + } + LoadingDialogHelper.show(); + final result = await ApiService.refreshSignInfo(imagePath); + LoadingDialogHelper.hide(); + if (result['result'] == 'success') { + ToastUtil.showSuccess(context, '保存成功'); + Navigator.pop(context); + } + } @override Widget build(BuildContext context) { return Scaffold( appBar: MyAppbar(title: "更新签字信息"), - body: - Container( + body: Container( margin: EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -36,7 +44,7 @@ class _SignatureUpdatePageState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text("用户",style: TextStyle(color: Colors.black,fontSize: 16)), + Text("用户", style: TextStyle(color: Colors.black, fontSize: 16)), _buildConfirmButton(), ], ), @@ -45,7 +53,8 @@ class _SignatureUpdatePageState extends State { Row( children: [ if (imagePath.isNotEmpty) - Text('签字照片:', + Text( + '签字照片:', style: TextStyle( fontSize: 14, fontWeight: FontWeight.bold, @@ -54,8 +63,12 @@ class _SignatureUpdatePageState extends State { ), const SizedBox(width: 15), if (imagePath.isNotEmpty) - Image.file(File(imagePath),width: 230,height: 150,fit: BoxFit.cover,), - + Image.file( + File(imagePath), + width: 230, + height: 150, + fit: BoxFit.fill, + ), ], ), @@ -66,19 +79,23 @@ class _SignatureUpdatePageState extends State { ], ), ), - - ); } - - - - - - - - - + Widget _buildTrueButton() { + return Center( + child: ElevatedButton( + onPressed: () { + refreshSign(); + }, + style: ElevatedButton.styleFrom( + backgroundColor: const Color(0xFF4285F4), + padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 80), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), + ), + child: Text('确认', style: TextStyle(fontSize: 14, color: Colors.white)), + ), + ); + } Widget _buildConfirmButton() { return SizedBox( width: 80, @@ -97,14 +114,11 @@ class _SignatureUpdatePageState extends State { setState(() { imagePath = path ?? ''; }); - }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF4285F4), padding: const EdgeInsets.symmetric(vertical: 5), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), ), child: Text( '手写签字', @@ -116,27 +130,3 @@ class _SignatureUpdatePageState extends State { } -Widget _buildTrueButton() { - return Center( - - child: ElevatedButton( - onPressed: () { - - }, - style: ElevatedButton.styleFrom( - backgroundColor: const Color(0xFF4285F4), - padding: const EdgeInsets.symmetric(vertical:5,horizontal: 80), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - ), - child: Text( - '确认', - style: TextStyle(fontSize: 14, color: Colors.white), - ), - ), - - - ); - -} \ No newline at end of file