import 'package:deus_app/common/event/RefreshMaintDetail.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/DioUtil.dart'; import 'package:deus_app/common/utils/ToastUtils.dart'; import 'package:deus_app/main.dart'; import 'package:deus_app/model/maint_job_detail_response.dart'; import 'package:deus_app/page/maint/maint_job_edit.dart'; import 'package:flutter/material.dart'; class MaintlJobList extends StatefulWidget { final MaintJobDetailData responseData; const MaintlJobList({super.key, required this.responseData}); @override State createState() { return _MaintlJobList(responseData); } } class _MaintlJobList extends State { MaintJobDetailData responseData; _MaintlJobList(this.responseData); @override Widget build(BuildContext context) { return WillPopScope(child: Scaffold( appBar: TitleBar().backAppbar("维保设备详情"), backgroundColor: const Color(0xfff2f2f2), body: Stack( children: [ Column( children: [ SizedBox( height: 10, ), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox( width: 15, ), Text(ConstantString.patrolJobTitle, style: GSYConstant.smallActionLightText), ], ), Expanded( child: Container( margin: EdgeInsets.only(bottom: 60), child: ListView.builder( itemCount: responseData.deviceList!.length, itemBuilder: (context, index) { return Container( margin: EdgeInsets.only(top: 12, left: 10, right: 10), padding: EdgeInsets.only(top: 12, bottom: 10), color: Colors.white, child: ListTile( title: 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(responseData.deviceList![index].showName!, style: GSYConstant.smallTextBold), Text( responseData .deviceList![index].isMainted==0?'未完成':'已完成', style: TextStyle( fontSize: GSYConstant.smallTextSize, color: responseData.deviceList![index].isMainted==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( responseData.deviceList![index].finishTime!, style: GSYConstant.smallTextLight, textAlign: TextAlign.right, ), ), ]), ), SizedBox( height: 5, ), ], ), onTap: () { completeEquipment(index); }, )); }, ) ), ) ], ), Positioned( left: 0, right: 0, bottom:0, // flex: 7, child:SizedBox( height: 50, width: double.infinity, child: TextButton( onPressed: () { if(next()){ Navigator.push( context, MaterialPageRoute( builder: (context) => MairintJobEdit(id: responseData.id))); } }, 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.next), ), ), ) ], )) , onWillPop: () async{ eventBus.fire(RefreshMaintDetail()); return true; }); } completeEquipment(int index) async { if (responseData.deviceList![index].isMainted == 0) { var result = await DioUtil().request("maintJob/device", method: DioMethod.post, data: {'id': responseData.deviceList![index].id}); if (result['code'] == 0) { setState(() { responseData.deviceList![index].isMainted = 1; responseData.deviceList![index].finishTime=result['data']; }); } else { showToast(result['msg']); } } } bool next(){ bool isNext=true; for (var element in responseData.deviceList!) { if(element.isMainted==0){ isNext=false; break; } } return isNext; } }