yearly_list.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/common/common.dart';
  3. import 'package:liftmanager/common/user_db.dart';
  4. import 'package:liftmanager/internal/yearly/model/yearly_list_entity.dart';
  5. import 'package:liftmanager/internal/yearly/yearly_router.dart';
  6. import 'package:liftmanager/net/api_service.dart';
  7. import 'package:liftmanager/res/resources.dart';
  8. import 'package:liftmanager/routers/fluro_navigator.dart';
  9. import 'package:liftmanager/utils/theme_utils.dart';
  10. import 'package:liftmanager/utils/toast.dart';
  11. import 'package:liftmanager/widgets/my_button.dart';
  12. import 'package:liftmanager/widgets/my_refresh_list.dart';
  13. import 'package:liftmanager/widgets/state_layout.dart';
  14. import 'dart:convert' as convert;
  15. import 'package:oktoast/oktoast.dart';
  16. class YearlyList extends StatefulWidget {
  17. YearlyList({Key key, @required this.index, this.callback}) : super(key: key);
  18. Function callback;
  19. final int index;
  20. @override
  21. _YearlyListState createState() => _YearlyListState();
  22. }
  23. class _YearlyListState extends State<YearlyList>
  24. with
  25. AutomaticKeepAliveClientMixin<YearlyList>,
  26. SingleTickerProviderStateMixin {
  27. List<YearlyListItem> _list = [];
  28. int _page = 1;
  29. int _maxPage = 999;
  30. StateType _stateType = StateType.loading;
  31. @override
  32. void initState() {
  33. super.initState();
  34. //Item数量
  35. _onRefresh();
  36. getHasRole();
  37. }
  38. bool noRole = true;
  39. getHasRole() async {
  40. var role = await User().getCompanyRole();
  41. if (role == Constant.RoleAdmin ||
  42. role == Constant.RoleRegion ||
  43. role == Constant.RoleWork) {
  44. noRole = false;
  45. setState(() {});
  46. }
  47. }
  48. goToPage(pagePath) {
  49. NavigatorUtils.pushResult(context, pagePath, (res) {
  50. _onRefresh();
  51. widget.callback();
  52. });
  53. }
  54. Future _onRefresh() async {
  55. _stateType = StateType.loading;
  56. _page = 1;
  57. _maxPage = 999;
  58. if (widget.index == 0) {
  59. ApiService(context: context).yearlyNoConfirmList(_page, 10, widget.index,
  60. onSuccess: (YearlyListEntity data) {
  61. _stateType = StateType.empty;
  62. if (_page == 1) {
  63. _list.clear();
  64. }
  65. if (data.rows.length < 10) {
  66. _maxPage = _page;
  67. }
  68. _list.addAll(data.rows);
  69. setState(() {});
  70. }, onError: (code, msg) {
  71. showToast(msg);
  72. });
  73. } else {
  74. ApiService(context: context).yearlyList(_page, 10, widget.index - 1,
  75. onSuccess: (YearlyListEntity data) {
  76. _stateType = StateType.empty;
  77. if (_page == 1) {
  78. _list.clear();
  79. }
  80. if (data.rows.length < 10) {
  81. _maxPage = _page;
  82. }
  83. _list.addAll(data.rows);
  84. setState(() {});
  85. }, onError: (code, msg) {
  86. showToast(msg);
  87. });
  88. }
  89. }
  90. Future _loadMore() async {
  91. _stateType = StateType.loading;
  92. _page += 1;
  93. if (widget.index == 0) {
  94. ApiService(context: context).yearlyNoConfirmList(_page, 10, widget.index,
  95. onSuccess: (YearlyListEntity data) {
  96. _stateType = StateType.empty;
  97. if (data.rows.length < 10) {
  98. _maxPage = _page;
  99. }
  100. _list.addAll(data.rows);
  101. _page++;
  102. setState(() {});
  103. }, onError: (code, msg) {
  104. showToast(msg);
  105. });
  106. } else {
  107. ApiService(context: context).yearlyList(_page, 10, widget.index - 1,
  108. onSuccess: (YearlyListEntity data) {
  109. _stateType = StateType.empty;
  110. if (data.rows.length < 10) {
  111. _maxPage = _page;
  112. }
  113. _list.addAll(data.rows);
  114. _page++;
  115. setState(() {});
  116. }, onError: (code, msg) {
  117. showToast(msg);
  118. });
  119. }
  120. }
  121. ///确认年检计划
  122. _yearlyConfirm(index) {
  123. String jsonString = convert.jsonEncode(_list[index]);
  124. print(jsonString);
  125. goToPage(
  126. "${YearlyRouter.yearlyDetailPage}?item=${Uri.encodeComponent(jsonString)}");
  127. }
  128. @override
  129. Widget build(BuildContext context) {
  130. super.build(context);
  131. return MyListView(
  132. itemCount: _list.length,
  133. stateType: _stateType,
  134. onRefresh: _onRefresh,
  135. loadMore: _loadMore,
  136. hasMore: _page < _maxPage,
  137. itemBuilder: (_, index) {
  138. return Container(
  139. margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
  140. decoration: BoxDecoration(
  141. color: ThemeUtils.getTabsBg(context),
  142. borderRadius: BorderRadius.circular(6.0),
  143. ),
  144. child: Column(
  145. children: <Widget>[
  146. Container(
  147. decoration: BoxDecoration(
  148. border: Border(
  149. bottom: BorderSide(width: 0.5, color: Colours.line),
  150. )),
  151. padding: EdgeInsets.only(left: 12),
  152. child: Row(
  153. children: <Widget>[
  154. Text(
  155. "${_list[index].projectName}",
  156. style: TextStyle(
  157. fontSize: 15,
  158. color: ThemeUtils.isDark(context)
  159. ? Colours.dark_text
  160. : Colours.text),
  161. overflow: TextOverflow.ellipsis,
  162. softWrap: false, //单行显示
  163. ),
  164. Expanded(
  165. flex: 1,
  166. child: Container(
  167. padding: EdgeInsets.all(12),
  168. child: Text(
  169. getStepName(_list[index].stepName),
  170. style: TextStyle(
  171. fontSize: 13, color: Colours.app_main),
  172. textAlign: TextAlign.right,
  173. overflow: TextOverflow.ellipsis,
  174. softWrap: false, //单行显示
  175. ),
  176. )),
  177. ],
  178. ),
  179. ),
  180. lineTxt("注册代码", "${_list[index].registrationCode}"),
  181. lineTxt("区域", "${_list[index].areaName}"),
  182. lineTxt("设备内部编号", "${_list[index].useCompanyCode}"),
  183. lineTxt("电梯地址", "${_list[index].devicePosition}"),
  184. lineTxt("区域主管", "${_list[index].directorName}"),
  185. lineTxt("计划时间", "${_list[index].planDate}"),
  186. lineTxt("是否检查限速器",
  187. "${_list[index].isCheckGoverner == 1 ? "是" : "否"}"),
  188. lineTxt("荷载年检设置",
  189. "${_list[index].loadInspectionSetting == 1 ? "是" : "否"}"),
  190. SizedBox(
  191. height: 10,
  192. ),
  193. Container(
  194. decoration: BoxDecoration(
  195. border: Border(
  196. top: BorderSide(width: 0.5, color: Colours.line),
  197. )),
  198. child: Row(children: <Widget>[
  199. Expanded(
  200. flex: 1,
  201. child: Container(
  202. padding: EdgeInsets.all(12),
  203. child: Text(
  204. getStepTitle(_list[index].stepStatus),
  205. // "${_list[index].status == 0 ? "待完成" : _list[index].status == 1 ? "已完成" : "超期"}",
  206. style: TextStyle(
  207. fontSize: 13,
  208. color: _list[index].status == 0
  209. ? Colors.amber
  210. : _list[index].status == 1
  211. ? Colours.app_main
  212. : Colours.red),
  213. overflow: TextOverflow.ellipsis,
  214. softWrap: false, //单行显示
  215. ),
  216. )),
  217. Offstage(
  218. offstage: noRole && _list[index].status != 1,
  219. child: MyButton(
  220. onPressed: () {
  221. _yearlyConfirm(index);
  222. },
  223. height: 25,
  224. fontSize: 11,
  225. colors: [Colours.app_main, Colours.app_main],
  226. borderWidth: 0.5,
  227. borderColor: Colours.app_main,
  228. text: _list[index].status == 1 ? "年检详情" : "提交年检进度",
  229. ))
  230. ]))
  231. ],
  232. ),
  233. );
  234. });
  235. }
  236. String getStepName(int i) {
  237. String str = "";
  238. switch (i) {
  239. case 0:
  240. str = "未开始";
  241. break;
  242. case 1:
  243. str = "自检";
  244. break;
  245. case 2:
  246. str = "报检";
  247. break;
  248. case 3:
  249. str = "场检";
  250. break;
  251. case 4:
  252. str = "确认";
  253. break;
  254. }
  255. return str;
  256. }
  257. String getStepTitle(int i) {
  258. String str = "";
  259. switch (i) {
  260. case 0:
  261. str = "开启年检";
  262. break;
  263. case 1:
  264. str = "请上传自检报告";
  265. break;
  266. case 2:
  267. str = "请等待自检审核";
  268. break;
  269. case 3:
  270. str = "请等待报检结果";
  271. break;
  272. case 4:
  273. str = "请上传检验结果";
  274. break;
  275. case 5:
  276. str = "请等待场检审核";
  277. break;
  278. case 6:
  279. case 7:
  280. str = "请上传年检报告和合格证";
  281. break;
  282. case 8:
  283. case 9:
  284. case 10:
  285. str = "请等待确认审核";
  286. break;
  287. }
  288. // switch(i){
  289. // case 0:
  290. // str = "请开启年检";
  291. // break;
  292. // case 1:
  293. // str = "请上传自检报告";
  294. // break;
  295. // case 2:
  296. // str = "请等待自检审核";
  297. // break;
  298. // case 3:
  299. // str = "请等待报检结果";
  300. // break;
  301. // case 4:
  302. // str = "请等待";
  303. // break;
  304. // }
  305. return str;
  306. }
  307. Widget lineTxt(title, value) {
  308. return Container(
  309. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  310. child: Row(
  311. children: <Widget>[
  312. Text("${title}",
  313. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  314. Expanded(
  315. flex: 1,
  316. child: Text(
  317. "${value}",
  318. textAlign: TextAlign.right,
  319. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  320. ),
  321. )
  322. ],
  323. ),
  324. );
  325. }
  326. @override
  327. bool get wantKeepAlive => true;
  328. }