repair_list.dart 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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/repair/model/repair_list_entity.dart';
  6. import 'package:liftmanager/internal/repair/repair_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 RepairList extends StatefulWidget {
  16. RepairList({Key key, @required this.index, this.callback}) : super(key: key);
  17. int index;
  18. RepairListState mState;
  19. Function callback;
  20. @override
  21. RepairListState createState() {
  22. mState = RepairListState();
  23. return mState;
  24. }
  25. }
  26. class RepairListState extends State<RepairList>
  27. with
  28. AutomaticKeepAliveClientMixin<RepairList>,
  29. SingleTickerProviderStateMixin {
  30. List<RepairItem> _list = [];
  31. int _page = 1;
  32. int _maxPage = 999;
  33. StateType _stateType = StateType.loading;
  34. @override
  35. void initState() {
  36. super.initState();
  37. //Item数量
  38. // _maxPage = widget.index == 0 ? 1 : (widget.index == 1 ? 2 : 3);
  39. onRefresh();
  40. getHasRole();
  41. }
  42. bool noRole = true;
  43. getHasRole() async {
  44. var role = await User().getCompanyRole();
  45. if (role == Constant.RoleAdmin ||
  46. role == Constant.RoleRegion ||
  47. role == Constant.RoleWork) {
  48. noRole = false;
  49. setState(() {});
  50. }
  51. }
  52. goToPage(pagePath) {
  53. NavigatorUtils.pushResult(context, pagePath, (res) {
  54. onRefresh();
  55. widget.callback();
  56. });
  57. }
  58. Future onRefresh() async {
  59. _stateType = StateType.loading;
  60. _page = 1;
  61. _maxPage = 999;
  62. ApiService(context: context).repairList(_page, 10, widget.index,
  63. onSuccess: (RepairListEntity data) {
  64. _stateType = StateType.empty;
  65. if (_page == 1) {
  66. _list.clear();
  67. }
  68. if (data.rows.length < 10) {
  69. _maxPage = _page;
  70. }
  71. _list.addAll(data.rows);
  72. setState(() {});
  73. }, onError: (code, msg) {
  74. showToast(msg);
  75. });
  76. }
  77. Future _loadMore() async {
  78. _stateType = StateType.loading;
  79. _page += 1;
  80. ApiService(context: context).repairList(_page, 10, widget.index,
  81. onSuccess: (RepairListEntity data) {
  82. _stateType = StateType.empty;
  83. if (data.rows.length < 10) {
  84. _maxPage = _page;
  85. }
  86. _list.addAll(data.rows);
  87. _page++;
  88. setState(() {});
  89. }, onError: (code, msg) {
  90. showToast(msg);
  91. });
  92. }
  93. _repairDetail(int index) {
  94. RepairItem item = _list[index];
  95. String jsonString = convert.jsonEncode(item);
  96. goToPage(
  97. "${RepairRouter.repairDetailPage}?item=${Uri.encodeComponent(jsonString)}");
  98. }
  99. @override
  100. Widget build(BuildContext context) {
  101. super.build(context);
  102. return MyListView(
  103. itemCount: _list.length,
  104. stateType: _stateType,
  105. onRefresh: onRefresh,
  106. loadMore: _loadMore,
  107. hasMore: _page < _maxPage,
  108. itemBuilder: (_, index) {
  109. return Container(
  110. margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
  111. decoration: BoxDecoration(
  112. color: ThemeUtils.getTabsBg(context),
  113. borderRadius: BorderRadius.circular(6.0),
  114. ),
  115. child: Column(
  116. children: <Widget>[
  117. Container(
  118. decoration: BoxDecoration(
  119. border: Border(
  120. bottom: BorderSide(width: 0.5, color: Colours.line),
  121. )),
  122. padding: EdgeInsets.only(left: 12),
  123. child: Row(
  124. children: <Widget>[
  125. Text(
  126. "${_list[index].projectName}",
  127. style: TextStyle(
  128. fontSize: 15,
  129. color: ThemeUtils.isDark(context)
  130. ? Colours.dark_text
  131. : Colours.text),
  132. overflow: TextOverflow.ellipsis,
  133. softWrap: false, //单行显示
  134. ),
  135. Offstage(
  136. offstage: _list[index].isCritical != 1,
  137. child: Container(
  138. margin: EdgeInsets.only(left: 12),
  139. width: 32,
  140. height: 18,
  141. decoration: BoxDecoration(
  142. borderRadius: BorderRadius.circular(4),
  143. color: Color(0xFFFF3B30)),
  144. child: Center(
  145. child: Text("紧急",
  146. style: TextStyle(
  147. color: Colors.white, fontSize: 11))),
  148. )),
  149. Expanded(
  150. flex: 1,
  151. child: Container(
  152. padding: EdgeInsets.all(12),
  153. child: Row(
  154. // crossAxisAlignment: CrossAxisAlignment.end,
  155. mainAxisAlignment: MainAxisAlignment.end,
  156. children: [
  157. Text(
  158. '来自:',
  159. style: TextStyle(
  160. fontSize: 13, color: Colours.text_gray),
  161. ),
  162. Text(
  163. _list[index].source == 1
  164. ? "物业端"
  165. : _list[index].source == 2
  166. ? "维保端"
  167. : "物联端",
  168. style: TextStyle(
  169. fontSize: 13,
  170. color: Colours.blue_app_main),
  171. textAlign: TextAlign.right,
  172. overflow: TextOverflow.ellipsis,
  173. softWrap: false, //单行显示
  174. ),
  175. ],
  176. ))),
  177. ],
  178. ),
  179. ),
  180. lineTxt("发起时间", "${_list[index].createDate}"),
  181. lineTxt("电梯注册代码", "${_list[index].registrationCode}"),
  182. lineTxt("电梯类型", "${_list[index].getLiftCategory()}"),
  183. lineTxt("设备内部编号", "${_list[index].useCompanyCode}"),
  184. lineTxt("维保负责人", "${_list[index].workerName}"),
  185. SizedBox(
  186. height: 10,
  187. ),
  188. Container(
  189. decoration: BoxDecoration(
  190. border: Border(
  191. top: BorderSide(width: 0.5, color: Colours.line),
  192. )),
  193. child: Row(children: <Widget>[
  194. Expanded(
  195. flex: 1,
  196. child: Container(
  197. padding: EdgeInsets.all(12),
  198. child: Text(
  199. "${_list[index].status == -1 ? "暂停中" : _list[index].status == 0 ? "待修理" : _list[index].status == 1 ? "修理中" : _list[index].status == 2 ? _list[index].hasEvaluate == 0 ? '未评价' : "已完成" : "已关闭"}",
  200. style: TextStyle(
  201. fontSize: 13, color: Colours.dark_text_gray),
  202. overflow: TextOverflow.ellipsis,
  203. softWrap: false, //单行显示
  204. ),
  205. )),
  206. Offstage(
  207. offstage: noRole && _list[index].status < 2,
  208. child: MyButton(
  209. onPressed: () {
  210. _repairDetail(index);
  211. },
  212. height: 25,
  213. fontSize: 11,
  214. colors: [Colours.app_main, Colours.app_main],
  215. borderWidth: 0.5,
  216. borderColor: Colours.app_main,
  217. text:
  218. "${_list[index].status == -1 ? "开始修理" : _list[index].status == 0 ? "确认修理" : _list[index].status == 1 ? "继续修理" : _list[index].hasEvaluate == 0 ? "查看" : "查看详情"}",
  219. ))
  220. ]))
  221. ],
  222. ),
  223. );
  224. });
  225. }
  226. Widget lineTxt(title, value) {
  227. return Container(
  228. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  229. child: Row(
  230. children: <Widget>[
  231. Text("${title}",
  232. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  233. Expanded(
  234. flex: 1,
  235. child: Text(
  236. "${value}",
  237. textAlign: TextAlign.right,
  238. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  239. ),
  240. )
  241. ],
  242. ),
  243. );
  244. }
  245. @override
  246. bool get wantKeepAlive => true;
  247. }