repair_list.dart 8.5 KB

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