import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:qhd_prevention/customWidget/ItemWidgetFactory.dart'; import 'package:qhd_prevention/customWidget/bottom_picker.dart'; import 'package:qhd_prevention/customWidget/custom_alert_dialog.dart'; import 'package:qhd_prevention/customWidget/custom_button.dart'; import 'package:qhd_prevention/customWidget/toast_util.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 SafecheckDetail extends StatefulWidget { const SafecheckDetail({ super.key, required this.OUTSOURCED_ID, required this.KEYPROJECTCHECK_ID, required this.isEdit, }); final String OUTSOURCED_ID; final String KEYPROJECTCHECK_ID; final bool isEdit; @override State createState() => _SafecheckDetailState(); } class _SafecheckDetailState extends State { late Map info = {}; /// 被检查单位负责人 late List personList = []; /// 检查类型 late List typeList = []; /// 被检查单位 late List toCheckUnitList = []; bool? chooseTitleType = null; final TextEditingController _unitController = TextEditingController(); final TextEditingController _locationController = TextEditingController(); final TextEditingController _personController = TextEditingController(); @override void initState() { // TODO: implement initState super.initState(); _getData(); } Future _getData() async { LoadingDialogHelper.show(); final result = await ApiService.addSafeCheckReciord(widget.OUTSOURCED_ID); final personData = await ApiService.getSafeCheckPersonList(info['UNITS_ID']??'', '1'); final typeListData = await ApiService.getSafeCheckTypeList(); final toUnitListData = await ApiService.getSafeCheckToUnitList(widget.OUTSOURCED_ID); try { setState(() { info = result['pd'] ?? {}; personList = personData['varList']; typeList = jsonDecode(typeListData['zTreeNodes']); toCheckUnitList = toUnitListData['varList']; if (!FormUtils.hasValue(info, 'UNITS_NAME') && toCheckUnitList.isNotEmpty) { info['UNITS_NAME'] = toCheckUnitList.first['UNITS_NAME']; } if (!FormUtils.hasValue(info, 'UNITS_ID') && toCheckUnitList.isNotEmpty) { info['UNITS_ID'] = toCheckUnitList.first['UNITS_ID']; } }); } catch (e) { print('加载数据失败:$e'); ToastUtil.showNormal(context, '加载数据失败:$e'); } LoadingDialogHelper.hide(); } Future onUpdateState(String state) async { // 提示文案 String content = ''; if (state == '1') { content = '确定同意开工吗?'; } else if (state == '2') { content = '确定同意结束吗?'; } else { content = '确定操作吗?'; } final bool confirmed = await showDialog( context: context, builder: (ctx) => CustomAlertDialog( title: '提示', content: content, onConfirm: () => Navigator.of(ctx).pop(false), ), ) ?? false; if (!confirmed) return; LoadingDialogHelper.show(); try { final response = await ApiService.sureKeyProjectState( widget.OUTSOURCED_ID, state, ); LoadingDialogHelper.hide(); if (response['result'] == 'success') { Navigator.of(context).pop(); } else { ToastUtil.showNormal(context, '请求失败'); } } catch (e) { ToastUtil.showNormal(context, '请求异常:$e'); } } Widget lineItem({ required String label, required bool isEditable, String? text, }) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ ItemListWidget.singleLineTitleText( label: label, isEditable: isEditable, text: text ?? '', ), const Divider(height: 1, thickness: 1), ], ); } Future _choosePerson() async { final choice = await BottomPicker.show( context, items: personList.map((val) => val['NAME'] as String).toList(), itemBuilder: (item) => Text(item, textAlign: TextAlign.center), initialIndex: 0, ); if (choice != null) { // 用户点击确定并选择了 choice setState(() { info['PERSON_NAME'] = choice; FocusHelper.clearFocus(context); }); } } @override Widget build(BuildContext context) { return Scaffold( appBar: MyAppbar(title: "安全检查发起"), body: SafeArea( child: Padding( padding: EdgeInsets.symmetric(horizontal: 12, vertical: 12), child: Column( children: [ ItemListWidget.itemContainer( horizontal: 0, Column( children: [ ListItemFactory.createYesNoSection( title: '检查题目:', groupValue: chooseTitleType, yesLabel: '安全', noLabel: '综合', horizontalPadding: 5, verticalPadding: 0, onChanged: (val) { setState(() { chooseTitleType = val; }); }, isEdit: true, text: info['INSPECTION_CATEGORY'] ?? '', ), const Divider(), ItemListWidget.singleLineTitleText( label: '被检查单位:', isEditable: false, text: info['UNITS_NAME'], controller: _unitController, ), const Divider(), ItemListWidget.selectableLineTitleTextRightButton( label: '被检查单位现场负责人:', isEditable: widget.isEdit, onTap: () { _choosePerson(); }, text: info['PERSON_NAME'] ?? '', ), const Divider(), ItemListWidget.singleLineTitleText( label: '检查场所:', isEditable: widget.isEdit, text: info['INSPECTION_PLACE'], hintText: '请输入检查场所', controller: _locationController, ), const Divider(), ItemListWidget.selectableLineTitleTextRightButton( label: '检查类型:', isEditable: widget.isEdit, text: info['INSPECTION_TYPE_NAME'] ?? '', ), const Divider(), ItemListWidget.selectableLineTitleTextRightButton( label: '检查开始时间:', isEditable: widget.isEdit, text: info['INSPECTION_TIME_START'] ?? '', ), ], ), ), SizedBox(height: 20), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( width: 200, child: CustomButton( text: '提交', textStyle: TextStyle(color: Colors.white, fontSize: 17), backgroundColor: Colors.blue, onPressed: () => Navigator.pop(context), ), ), ], ), ], ), ), ), ); } }