| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- //巡检任务列表
- import 'package:deus_app/common/event/RefreshPatrol.dart';
- import 'package:deus_app/common/style/TitleBar.dart';
- import 'package:deus_app/main.dart';
- import 'package:deus_app/page/patrol/patrol_job_detail.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:pull_to_refresh/pull_to_refresh.dart';
- import '../../common/style/gsy_style.dart';
- import '../../common/utils/ConstantString.dart';
- import '../../common/utils/DioUtil.dart';
- import '../../common/utils/ToastUtils.dart';
- import '../../model/patrol_response_entity.dart';
- import '../../widget/PatrolJobDrawer.dart';
- class PatrolJobPage extends StatefulWidget {
- const PatrolJobPage({super.key});
- static var routeName = '/PatrolJobPage';
- @override
- State createState() {
- return _PatrolJobPage();
- }
- }
- List<PatrolJobData> patrol_job_list = <PatrolJobData>[];
- PatrolJobData query = PatrolJobData();
- class _PatrolJobPage extends State<PatrolJobPage> {
- final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
- final RefreshController _refreshController =
- RefreshController(initialRefresh: false);
- int index = 1;
- PatrolJobResponse patrolJobResponse=PatrolJobResponse();
- var _event;
- _load() async {
- var result = await DioUtil().request('patrolJob/appPatrolJobList',
- method: DioMethod.post, data: {'query': query, 'index': index, 'size': 20});
- _refreshController.loadComplete();
- _refreshController.refreshCompleted();
- patrolJobResponse = PatrolJobResponse.fromJson(result);
- if(patrolJobResponse.code==0){
- setState(() {
- if(index==1){
- patrol_job_list.clear();
- }
- patrol_job_list.addAll(patrolJobResponse.data!.patrolJobVOS!);
- });
- }else{
- if(index>1){
- index--;
- }
- showToast(patrolJobResponse.msg!);
- }
- //var patrolJobResponse = PatrolJobResponse.fromJson(result);
- //print(patrolJobResponse);
- }
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- _load();
- _event = eventBus.on<RefreshPatrol>().listen((event) {
- setState(() {
- index=1;
- _load();
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- key: _scaffoldKey,
- appBar: TitleBar().drawAppBar(ConstantString.patrolJobText, () {
- _scaffoldKey.currentState?.openEndDrawer();
- }),
- endDrawer: PatrolJobDrawer(callback: (String deviceName, String deviceNo,dynamic stase,dynamic termType){
- setState(() {
- query.name=deviceName;
- query.number=deviceNo;
- query.status=stase;
- query.termType=termType;
- index=1;
- _load();
- });
- }),
- //抽屉
- backgroundColor: const Color(0xfff2f2f2),
- body: Column(
- children: [
- SizedBox(
- height: 10,
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- SizedBox(
- width: 15,
- ),
- Text(ConstantString.patrolJobTitle,
- style: GSYConstant.smallActionLightText),
- ],
- ),
- Expanded(
- child: Container(
- child: SmartRefresher(
- enablePullDown: true,
- enablePullUp: true,
- header: WaterDropHeader(),
- footer: CustomFooter(
- builder: (BuildContext context, LoadStatus? mode) {
- Widget body;
- if (mode == LoadStatus.idle) {
- body = Text("上拉加载");
- } else if (mode == LoadStatus.loading) {
- body = CupertinoActivityIndicator();
- } else if (mode == LoadStatus.failed) {
- body = Text("加载失败!点击重试!");
- } else if (mode == LoadStatus.canLoading) {
- body = Text("松手,加载更多!");
- } else {
- body = Text("没有更多数据了!");
- }
- return Container(
- height: 55.0,
- child: Center(child: body),
- );
- },
- ),
- controller: _refreshController,
- onRefresh: _onRefresh,
- onLoading: _onLoading,
- child: ListView.builder(
- itemCount: patrol_job_list.length,
- itemBuilder: (context, index) {
- PatrolJobData patrolJobData = patrol_job_list[index];
- return _patrol_job_list(patrolJobData);
- },
- ),
- )))
- ],
- ));
- }
- Widget _patrol_job_list(PatrolJobData patrolJobData) {
- 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: [
- Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
- Container(
- child: Text(
- patrolJobData.name!,
- style: TextStyle(
- color: Colors.black,
- fontSize: GSYConstant.middleTextWhiteSize,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- Container(
- padding:
- EdgeInsets.only(top: 3, bottom: 3, left: 5, right: 5),
- child: Text(
- patrolJobData.status == 0
- ? '已关闭'
- : patrolJobData.status == 1
- ? '执行中'
- : patrolJobData.status == 2
- ? '已完成'
- : patrolJobData.status == 3
- ? '待执行'
- : patrolJobData.status == 4
- ? '已逾期'
- : '未知',
- textAlign: TextAlign.right,
- style: TextStyle(
- color:
- patrolJobData.status == 0 || patrolJobData.status == 4
- ? Colors.red
- : patrolJobData.status == 1
- ? Colors.orange
- : patrolJobData.status == 2
- ? Colors.blue
- : Colors.black, //边框颜色
- fontSize: GSYConstant.minTextSize,
- ),
- ),
- decoration: BoxDecoration(
- border: new Border.all(
- color:
- patrolJobData.status == 0 || patrolJobData.status == 4
- ? Colors.red
- : patrolJobData.status == 1
- ? Colors.orange
- : patrolJobData.status == 2
- ? Colors.blue
- : Colors.black, //边框颜色
- width: 1.0, //边框粗细
- ),
- borderRadius: const BorderRadius.all(
- const Radius.circular(3.0)), //边框的弧度
- ),
- )
- ]),
- SizedBox(
- height: 12,
- ),
- Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
- Container(
- child: Text(
- '任务编号:',
- style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.smallTextSize,
- ),
- ),
- ),
- Container(
- child: Text(
- patrolJobData.number!,
- textAlign: TextAlign.right,
- style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.smallTextSize,
- ),
- ),
- ),
- ]),
- SizedBox(
- height: 10,
- ),
- Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
- Container(
- child: Text(
- '任务开始时间:',
- style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.smallTextSize,
- ),
- ),
- ),
- Container(
- child: Text(
- patrolJobData.startDate!,
- textAlign: TextAlign.right,
- style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.smallTextSize,
- ),
- ),
- ),
- ]),
- SizedBox(
- height: 10,
- ),
- Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
- Container(
- child: Text(
- '任务结束时间:',
- style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.smallTextSize,
- ),
- ),
- ),
- Container(
- child: Text(
- patrolJobData.endDate!,
- textAlign: TextAlign.right,
- style: TextStyle(
- color: GSYColors.primaryLightValue,
- fontSize: GSYConstant.smallTextSize,
- ),
- ),
- ),
- ]),
- SizedBox(
- height: 5,
- ),
- ],
- ),
- onTap: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) =>
- new PatrolJobDetail(id: patrolJobData.id)));
- },
- ));
- }
- void _onRefresh() async {
- // monitor network fetch
- // await Future.delayed(Duration(milliseconds: 1000));
- // if failed,use refreshFailed()
- if (mounted) {
- setState(() {
- index = 0;
- _load();
- });
- }
- }
- void _onLoading() async {
- // monitor network fetch
- // await Future.delayed(Duration(milliseconds: 1000));
- // if failed,use loadFailed(),if no data return,use LoadNodata()
- // items.add((items.length+1).toString());
- if (mounted) {
- setState(() {
- if (patrolJobResponse.data!.total! > patrol_job_list.length) {
- index++;
- _load();
- } else {
- _refreshController.loadNoData();
- }
- });
- }
- }
- @override
- void dispose() {
- super.dispose();
- _event.cancel();
- }
- }
|