123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- import 'dart:convert' as convert;
- import 'package:flutter/material.dart';
- import 'package:liftmanager/common/common.dart';
- import 'package:liftmanager/common/user_db.dart';
- import 'package:liftmanager/internal/yearly/model/yearly_list_entity.dart';
- import 'package:liftmanager/internal/yearly/yearly_router.dart';
- import 'package:liftmanager/net/api_service.dart';
- import 'package:liftmanager/res/resources.dart';
- import 'package:liftmanager/routers/fluro_navigator.dart';
- import 'package:liftmanager/utils/theme_utils.dart';
- import 'package:liftmanager/widgets/my_button.dart';
- import 'package:liftmanager/widgets/my_refresh_list.dart';
- import 'package:liftmanager/widgets/state_layout.dart';
- import 'package:oktoast/oktoast.dart';
- class YearlyList extends StatefulWidget {
- YearlyList({Key key, @required this.index, this.callback}) : super(key: key);
- Function callback;
- final int index;
- @override
- _YearlyListState createState() => _YearlyListState();
- }
- class _YearlyListState extends State<YearlyList>
- with
- AutomaticKeepAliveClientMixin<YearlyList>,
- SingleTickerProviderStateMixin {
- List<YearlyListItem> _list = [];
- int _page = 1;
- int _maxPage = 999;
- StateType _stateType = StateType.loading;
- @override
- void initState() {
- super.initState();
- //Item数量
- _onRefresh();
- getHasRole();
- }
- bool noRole = true;
- getHasRole() async {
- var role = await User().getCompanyRole();
- if (role == Constant.RoleAdmin ||
- role == Constant.RoleRegion ||
- role == Constant.RoleWork) {
- noRole = false;
- setState(() {});
- }
- }
- goToPage(pagePath) {
- NavigatorUtils.pushResult(context, pagePath, (res) {
- _onRefresh();
- widget.callback();
- });
- }
- Future _onRefresh() async {
- _stateType = StateType.loading;
- _page = 1;
- _maxPage = 999;
- if (widget.index == 0) {
- ApiService(context: context).yearlyNoConfirmList(_page, 10, widget.index,
- onSuccess: (YearlyListEntity data) {
- _stateType = StateType.empty;
- if (_page == 1) {
- _list.clear();
- }
- if (data.rows.length < 10) {
- _maxPage = _page;
- }
- _list.addAll(data.rows);
- setState(() {});
- }, onError: (code, msg) {
- showToast(msg);
- });
- } else {
- ApiService(context: context).yearlyList(_page, 10, widget.index - 1,
- onSuccess: (YearlyListEntity data) {
- _stateType = StateType.empty;
- if (_page == 1) {
- _list.clear();
- }
- if (data.rows.length < 10) {
- _maxPage = _page;
- }
- _list.addAll(data.rows);
- setState(() {});
- }, onError: (code, msg) {
- showToast(msg);
- });
- }
- }
- Future _loadMore() async {
- _stateType = StateType.loading;
- _page += 1;
- if (widget.index == 0) {
- ApiService(context: context).yearlyNoConfirmList(_page, 10, widget.index,
- onSuccess: (YearlyListEntity data) {
- _stateType = StateType.empty;
- if (data.rows.length < 10) {
- _maxPage = _page;
- }
- _list.addAll(data.rows);
- _page++;
- setState(() {});
- }, onError: (code, msg) {
- showToast(msg);
- });
- } else {
- ApiService(context: context).yearlyList(_page, 10, widget.index - 1,
- onSuccess: (YearlyListEntity data) {
- _stateType = StateType.empty;
- if (data.rows.length < 10) {
- _maxPage = _page;
- }
- _list.addAll(data.rows);
- _page++;
- setState(() {});
- }, onError: (code, msg) {
- showToast(msg);
- });
- }
- }
- ///确认年检计划
- _yearlyConfirm(index) {
- String jsonString = convert.jsonEncode(_list[index]);
- print(jsonString);
- goToPage(
- "${YearlyRouter.yearlyDetailPage}?item=${Uri.encodeComponent(jsonString)}");
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- return MyListView(
- itemCount: _list.length,
- stateType: _stateType,
- onRefresh: _onRefresh,
- loadMore: _loadMore,
- hasMore: _page < _maxPage,
- itemBuilder: (_, index) {
- return Container(
- margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
- decoration: BoxDecoration(
- color: ThemeUtils.getTabsBg(context),
- borderRadius: BorderRadius.circular(6.0),
- ),
- child: Column(
- children: <Widget>[
- Container(
- decoration: BoxDecoration(
- border: Border(
- bottom: BorderSide(width: 0.5, color: Colours.line),
- )),
- padding: EdgeInsets.only(left: 12),
- child: Row(
- children: <Widget>[
- Text(
- "${_list[index].projectName}",
- style: TextStyle(
- fontSize: 15,
- color: ThemeUtils.isDark(context)
- ? Colours.dark_text
- : Colours.text),
- overflow: TextOverflow.ellipsis,
- softWrap: false, //单行显示
- ),
- Expanded(
- flex: 1,
- child: Container(
- padding: EdgeInsets.all(12),
- child: Text(
- getStepName(_list[index].stepName),
- style: TextStyle(
- fontSize: 13, color: Colours.app_main),
- textAlign: TextAlign.right,
- overflow: TextOverflow.ellipsis,
- softWrap: false, //单行显示
- ),
- )),
- ],
- ),
- ),
- lineTxt("注册代码", "${_list[index].registrationCode}"),
- lineTxt("区域", "${_list[index].areaName}"),
- lineTxt("设备内部编号", "${_list[index].useCompanyCode}"),
- lineTxt("电梯地址", "${_list[index].devicePosition}"),
- lineTxt("区域主管", "${_list[index].directorName}"),
- lineTxt("计划时间", "${_list[index].planDate}"),
- lineTxt("是否检查限速器",
- "${_list[index].isCheckGoverner == 1 ? "是" : "否"}"),
- lineTxt("荷载年检设置",
- "${_list[index].loadInspectionSetting == 1 ? "是" : "否"}"),
- SizedBox(
- height: 10,
- ),
- Container(
- decoration: BoxDecoration(
- border: Border(
- top: BorderSide(width: 0.5, color: Colours.line),
- )),
- child: Row(children: <Widget>[
- Expanded(
- flex: 1,
- child: Container(
- padding: EdgeInsets.all(12),
- child: Text(
- getStepTitle(_list[index].stepStatus),
- // "${_list[index].status == 0 ? "待完成" : _list[index].status == 1 ? "已完成" : "超期"}",
- style: TextStyle(
- fontSize: 13,
- color: _list[index].status == 0
- ? Colors.amber
- : _list[index].status == 1
- ? Colours.app_main
- : Colours.red),
- overflow: TextOverflow.ellipsis,
- softWrap: false, //单行显示
- ),
- )),
- Offstage(
- offstage: noRole && _list[index].status != 1,
- child: MyButton(
- onPressed: () {
- _yearlyConfirm(index);
- },
- height: 25,
- fontSize: 11,
- colors: [Colours.app_main, Colours.app_main],
- borderWidth: 0.5,
- borderColor: Colours.app_main,
- text: _list[index].status == 1 ? "年检详情" : "提交年检进度",
- ))
- ]))
- ],
- ),
- );
- });
- }
- String getStepName(int i) {
- String str = "";
- switch (i) {
- case 0:
- str = "未开始";
- break;
- case 1:
- str = "自检";
- break;
- case 2:
- str = "报检";
- break;
- case 3:
- str = "场检";
- break;
- case 4:
- str = "确认";
- break;
- }
- return str;
- }
- String getStepTitle(int i) {
- String str = "";
- switch (i) {
- case 0:
- str = "开启年检";
- break;
- case 1:
- str = "请上传自检报告";
- break;
- case 2:
- str = "请等待自检审核";
- break;
- case 3:
- str = "请等待报检结果";
- break;
- case 4:
- str = "请上传检验结果";
- break;
- case 5:
- str = "请等待场检审核";
- break;
- case 6:
- case 7:
- str = "请上传年检报告和合格证";
- break;
- case 8:
- case 9:
- case 10:
- str = "请等待确认审核";
- break;
- }
- // switch(i){
- // case 0:
- // str = "请开启年检";
- // break;
- // case 1:
- // str = "请上传自检报告";
- // break;
- // case 2:
- // str = "请等待自检审核";
- // break;
- // case 3:
- // str = "请等待报检结果";
- // break;
- // case 4:
- // str = "请等待";
- // break;
- // }
- return str;
- }
- Widget lineTxt(title, value) {
- return Container(
- padding: EdgeInsets.only(left: 12, top: 5, right: 12),
- child: Row(
- children: <Widget>[
- Text("${title}",
- style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
- Expanded(
- flex: 1,
- child: Text(
- "${value}",
- textAlign: TextAlign.right,
- style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
- ),
- )
- ],
- ),
- );
- }
- @override
- bool get wantKeepAlive => true;
- }
|