import 'package:deus_app/common/event/RefreshPatrol.dart'; import 'package:deus_app/common/event/RefreshPatrolEdit.dart'; import 'package:deus_app/common/style/TitleBar.dart'; import 'package:deus_app/common/style/gsy_style.dart'; import 'package:deus_app/common/utils/ConstantString.dart'; import 'package:deus_app/common/utils/ToastUtils.dart'; import 'package:deus_app/main.dart'; import 'package:deus_app/page/patrol/patrol_job_list.dart'; import 'package:flutter/material.dart'; import '../../common/dialog/CloseTaskDialog.dart'; import '../../common/utils/DioUtil.dart'; import '../../generated/json/patrol_job_detail_response_entity_helper.dart'; import '../../model/patrol_job_detail_response_entity.dart'; /** * 巡检任务详情页面 */ class PatrolJobDetail extends StatefulWidget { var id; PatrolJobDetail({super.key, @required this.id}); static var routeName = '/PatrolJobDetail'; @override State createState() { print(id); return new _PatrolJobDetail(id); } } class _PatrolJobDetail extends State { var _event; var id; bool type = false; _PatrolJobDetail(this.id); List patrolItemVOS = []; List equipmentVOS = []; List fileUrls = []; PatrolJobDetailResponseData responseData = PatrolJobDetailResponseData(); _load() async { var result = await DioUtil().request('patrolJob/appGetJobDetail', method: DioMethod.get, params: {'id': id}); PatrolJobDetailResponseEntity patrolJobResponse = patrolJobDetailResponseEntityFromJson( PatrolJobDetailResponseEntity(), result); if (patrolJobResponse.code == 0) { setState(() { responseData = patrolJobResponse.data; patrolItemVOS.addAll(responseData.patrolItemVOS); equipmentVOS.addAll(responseData.equipmentVOS); fileUrls.addAll(responseData.fileUrls); if (responseData.status == 1 || responseData.status == 4) { type = true; } }); } else { showToast(patrolJobResponse.msg); } } closeJob(String msg) async { var result = await DioUtil().request('patrolJob/closeJob', method: DioMethod.post, data: {'id': id, 'closeReason': msg}); if (0 == result['code']) { setState(() { eventBus.fire(RefreshPatrol()); Navigator.pop(context); }); } else { showToast(result['msg']); } } @override void initState() { super.initState(); _load(); _event = eventBus.on().listen((event) { setState(() { _load(); }); }); } @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, appBar: TitleBar() .backAppbar("巡检任务详情"), backgroundColor: const Color(0xfff2f2f2), body: Stack( children: [ Container( margin: EdgeInsets.only(bottom: type?60:0), child: ListView( children: _Ws(), ), ), Visibility( visible: type, child: Positioned( left: 0, right: 0, bottom: 0, // flex: 7, child: Row( children: [ Expanded( child: SizedBox( height: 50, child: TextButton( onPressed: () { CloseTaskDialog.showCupertinoAlertDialog(context, (msg) { closeJob(msg); }); }, style: ButtonStyle( backgroundColor: MaterialStateProperty.all( Color(0xFF4875EC)), shape: MaterialStateProperty.all( BeveledRectangleBorder( borderRadius: BorderRadius.circular(0))), foregroundColor: MaterialStateProperty.all( Colors.white), // padding: MaterialStateProperty.all(EdgeInsets.zero) ), child: const Text(ConstantString.close_task), ), ), ), Expanded( child: SizedBox( height: 50, child: TextButton( onPressed: () { if (type) { Navigator.push( context, MaterialPageRoute( builder: (context) => PatrolJobList(responseData: responseData))); } }, style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.blue), foregroundColor: MaterialStateProperty.all(Colors.white), shape: MaterialStateProperty.all( BeveledRectangleBorder( borderRadius: BorderRadius.circular(0))), // padding: MaterialStateProperty.all(EdgeInsets.zero) ), child: const Text(ConstantString.registration), ), )), ], ), )) ], )); } List _Ws() { List ws = []; ws.add(_patrolJobDetail(responseData)); ws.add(_device()); ws.add(_item()); ws.add(_remark()); ws.add(_url()); return ws; } Widget _patrolJobDetail(PatrolJobDetailResponseData patrolJobDetailData) { if ('' != patrolJobDetailData.name) { return Column( children: [ Row( children: [ Container( margin: EdgeInsets.only(top: 10, left: 12), // padding: EdgeInsets.fromLTRB(12, 0, 0, 0), alignment: Alignment.bottomLeft, child: Text( patrolJobDetailData.name ?? "", style: TextStyle( fontSize: GSYConstant.middleTextWhiteSize, fontWeight: FontWeight.bold), ), ), Container( margin: EdgeInsets.only(top: 10, left: 10), padding: EdgeInsets.fromLTRB(3, 2, 3, 2), alignment: Alignment.centerLeft, child: Text( patrolJobDetailData.status == 0 ? '已关闭' : patrolJobDetailData.status == 1 ? '执行中' : patrolJobDetailData.status == 2 ? '已完成' : patrolJobDetailData.status == 3 ? '待执行' : patrolJobDetailData.status == 4 ? '已逾期' : '未知', style: TextStyle( fontSize: GSYConstant.minTextSize, color:patrolJobDetailData.status == 0 || patrolJobDetailData.status == 4 ? Colors.red : patrolJobDetailData.status == 1 ? Colors.orange : patrolJobDetailData.status == 2 ? Colors.blue : Colors.black), ), decoration: BoxDecoration( border: new Border.all( color:patrolJobDetailData.status == 0 || patrolJobDetailData.status == 4 ? Colors.red : patrolJobDetailData.status == 1 ? Colors.orange : patrolJobDetailData.status == 2 ? Colors.blue : Colors.black, //边框颜色 width: 1.0, //边框粗细 ), borderRadius: const BorderRadius.all( const Radius.circular(3.0)), //边框的弧度 ), ) ], ), Container( margin: EdgeInsets.only(top: 10, left: 12, bottom: 12), alignment: Alignment.centerLeft, child: Text( '任务编号: ' + patrolJobDetailData.number, style: TextStyle( fontSize: GSYConstant.smallTextSize, ), ), ), // Divider( // height: 0.8, // indent: 5.0, // endIndent: 5.0, // color: Colors.grey, // ), Container( decoration: BoxDecoration(color: Colors.white), child: Column( children: [ Container( padding: EdgeInsets.fromLTRB(12, 20, 12, 0), alignment: Alignment.centerLeft, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '巡检任务名称:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.name!, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ], ), ), Container( padding: EdgeInsets.fromLTRB(12, 15, 12, 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '巡检任务编号:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.number, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ], ), ), Container( padding: EdgeInsets.fromLTRB(12, 15, 12, 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '巡检计划名称:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.planName ?? "", style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ])), Container( padding: EdgeInsets.fromLTRB(12, 15, 12, 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '巡检计划编号:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.planNumber!, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ])), Container( padding: EdgeInsets.fromLTRB(12, 15, 12, 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '周期类型:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.termType == 1 ? '日计划' : '暂无', style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ])), Container( padding: EdgeInsets.fromLTRB(12, 15, 12, 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '任务开始时间:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.startDate!, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ])), Container( padding: EdgeInsets.fromLTRB(12, 15, 12, 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '任务结束时间:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.endDate!, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ])), Container( padding: EdgeInsets.fromLTRB(12, 15, 12, 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '实际完成时间:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.finishTime!, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ])), Container( padding: EdgeInsets.fromLTRB(12, 15, 12, 15), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '巡检人员:', style: GSYConstant.smallTextLight, ), Container( child: Text( patrolJobDetailData.personnel!, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ])), ], ), ), ], ); } else { return Text('暂无数据'); } } Widget _device() { return ExpansionTile( title: Container( child: Text( '巡检设备', style: GSYConstant.normalTextActionWhiteBold, )), children: equipmentVOS.map((e) => _buildDevice(e)).toList(), initiallyExpanded: true); } Widget _buildDevice(PatrolJobDetailResponseDataEquipmentVOS device) { return FractionallySizedBox( widthFactor: 1, child: Container( margin: device.id == responseData .equipmentVOS![responseData.equipmentVOS!.length - 1].id ? EdgeInsets.only(bottom: 0) : EdgeInsets.only(bottom: 5), decoration: BoxDecoration(color: Colors.white), padding: const EdgeInsets.fromLTRB(12, 12, 12, 12), child: Column( children: [ Container( // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 0.0), alignment: Alignment.centerLeft, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(device.showName, style: GSYConstant.smallTextBold), Text( device.isComplete == 0 ? '未完成' : '已完成', style: TextStyle( fontSize: GSYConstant.smallTextSize, color: device.isComplete == 0 ? Colors.red : Colors.blue), ), ]), ), Container( margin: const EdgeInsets.only(top: 10), // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 10.0), // alignment: Alignment.centerLeft, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text( '完成时间:', style: GSYConstant.smallTextLight, ), Container( child: Text( device.itemCompleteTime, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ]), ), // Divider( // height: 0.8, // indent: 10.0, // endIndent: 10.0, // color: Colors.grey, // ), ], ), )); } Widget _item() { return ExpansionTile( title: Container( child: Text( '巡检项目', style: GSYConstant.normalTextActionWhiteBold, )), children: patrolItemVOS.map((e) => _buildItem(e)).toList(), initiallyExpanded: true); } Widget _buildItem(PatrolJobDetailResponseDataPatrolItemVOS item) { return FractionallySizedBox( widthFactor: 1, child: Container( margin: item.id == responseData .patrolItemVOS[responseData.patrolItemVOS.length - 1].id ? EdgeInsets.only(bottom: 0) : EdgeInsets.only(bottom: 5), padding: const EdgeInsets.fromLTRB(12, 15, 15, 0), decoration: BoxDecoration(color: Colors.white), child: Column( children: [ Container( alignment: Alignment.centerLeft, child: Text(item.name, style: TextStyle( fontSize: GSYConstant.middleTextWhiteSize, fontWeight: FontWeight.bold)), ), Container( margin: const EdgeInsets.fromLTRB(0, 10.0, 0, 0), alignment: Alignment.centerLeft, child: Text( item.result, style: GSYConstant.smallTextLight, ), ), // Divider( // height: 0.8, // indent: 10.0, // endIndent: 10.0, // color: Colors.grey, // ), ], ), )); } Widget _remark() { return ExpansionTile( title: Container( child: Text( '任务结果备注', style: GSYConstant.normalTextActionWhiteBold, )), children: [_buildRemark(responseData)], initiallyExpanded: true); } Widget _buildRemark(PatrolJobDetailResponseData patrolJobDetailData) { return FractionallySizedBox( widthFactor: 1, child: Container( decoration: BoxDecoration(color: Colors.white), child: Column( children: [ Container( margin: const EdgeInsets.fromLTRB(12, 15.0, 12, 15.0), alignment: Alignment.centerLeft, child: Text(patrolJobDetailData.remarks, style: TextStyle(fontSize: 14)), ) ], ), )); } Widget _url() { return ExpansionTile( title: Container( child: Text( '任务图片', style: GSYConstant.normalTextActionWhiteBold, )), children: [ Wrap(children: fileUrls.map((e) => _buildImage(e)).toList()), ], initiallyExpanded: true); } Widget _buildImage(String imageData) { return Container( width: MediaQuery.of(context).size.width / 2, margin: EdgeInsets.only(bottom: 5), padding: EdgeInsets.only(left: 12, right: 12), alignment: Alignment.center, decoration: BoxDecoration(color: Colors.white), child: Image.network(imageData)); } @override void dispose() { super.dispose(); _event.cancel(); } }