repair_list.dart 8.5 KB

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