yearly_list.dart 11 KB

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