maintenance_list.dart 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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/lift/lift_router.dart';
  6. import 'package:liftmanager/internal/maintenance/maintenance_router.dart';
  7. import 'package:liftmanager/internal/maintenance/model/maintenance_list_entity.dart';
  8. import 'package:liftmanager/net/api_service.dart';
  9. import 'package:liftmanager/res/resources.dart';
  10. import 'package:liftmanager/routers/fluro_navigator.dart';
  11. import 'package:liftmanager/utils/theme_utils.dart';
  12. import 'package:liftmanager/utils/toast.dart';
  13. import 'package:liftmanager/widgets/my_button.dart';
  14. import 'package:liftmanager/widgets/my_refresh_list.dart';
  15. import 'package:liftmanager/widgets/state_layout.dart';
  16. import 'package:oktoast/oktoast.dart';
  17. class MaintenanceList extends StatefulWidget {
  18. MaintenanceList({Key key, @required this.index, this.date,this.callback})
  19. : super(key: key);
  20. final int index;
  21. DateTime date;
  22. Function callback;
  23. MaintenanceListState mState;
  24. @override
  25. MaintenanceListState createState() {
  26. mState = MaintenanceListState();
  27. return mState;
  28. }
  29. }
  30. class MaintenanceListState extends State<MaintenanceList>
  31. with
  32. AutomaticKeepAliveClientMixin<MaintenanceList>,
  33. SingleTickerProviderStateMixin {
  34. List<MaintenanceListItem> _list = [];
  35. int _page = 1;
  36. int _maxPage = 999;
  37. StateType _stateType = StateType.loading;
  38. @override
  39. void initState() {
  40. super.initState();
  41. //Item数量
  42. // _maxPage = widget.index == 0 ? 1 : (widget.index == 1 ? 2 : 3);
  43. onRefresh();
  44. getHasRole();
  45. }
  46. bool noRole = true;
  47. getHasRole() async {
  48. var role = await User().getCompanyRole();
  49. if (role == Constant.RoleAdmin || role == Constant.RoleRegion ||
  50. role == Constant.RoleWork) {
  51. noRole = false;
  52. setState(() {
  53. });
  54. }
  55. }
  56. static String _twoDigits(int n) {
  57. if (n >= 10) return "${n}";
  58. return "0${n}";
  59. }
  60. Future onRefresh() async {
  61. _stateType = StateType.loading;
  62. _page = 1;
  63. _maxPage = 999;
  64. ApiService(context: context).maintenanceList(_page, 10, widget.index,
  65. "${widget.date.year}-${_twoDigits(widget.date.month)}-${_twoDigits(
  66. widget.date.day)}",
  67. onSuccess: (MaintenanceListEntity data) {
  68. _stateType = StateType.empty;
  69. if (data != null) {
  70. if (_page == 1) {
  71. _list.clear();
  72. }
  73. if (data.rows.length < 10) {
  74. _maxPage = _page;
  75. }
  76. if (data != null) {
  77. _list.addAll(data.rows);
  78. }
  79. }
  80. setState(() {});
  81. }, onError: (code, msg) {
  82. showToast(msg);
  83. });
  84. }
  85. Future _loadMore() async {
  86. _stateType = StateType.loading;
  87. _page += 1;
  88. ApiService(context: context).maintenanceList(_page, 10, widget.index,
  89. "${widget.date.year}-${_twoDigits(widget.date.month)}-${_twoDigits(
  90. widget.date.day)}",
  91. onSuccess: (MaintenanceListEntity data) {
  92. _stateType = StateType.empty;
  93. if (data.rows.length < 10) {
  94. _maxPage = _page;
  95. }
  96. _list.addAll(data.rows);
  97. _page++;
  98. setState(() {});
  99. }, onError: (code, msg) {
  100. showToast(msg);
  101. });
  102. }
  103. goToPage(pagePath){
  104. NavigatorUtils.pushResult(context, pagePath, (res){
  105. onRefresh();
  106. widget.callback();
  107. });
  108. }
  109. ///保养详情
  110. startMaintenance(int index) {
  111. String jsonString = convert.jsonEncode(_list[index]);
  112. if (_list[index].recordId.length > 0) {
  113. if (_list[index].status == "2") {
  114. if (_list[index].hasEvaluate == "0") {
  115. goToPage("${MaintenanceRouter.maintenanceEvaluate}?id=${_list[index]
  116. .recordId}&category=${_list[index]
  117. .category}&type=${_list[index].maintenanceType}");
  118. } else {
  119. goToPage("${MaintenanceRouter.maintenanceDetail}?item=${Uri
  120. .encodeComponent(jsonString)}");
  121. }
  122. } else {
  123. goToPage(
  124. "${MaintenanceRouter.maintenanceSubmit}?item=${Uri.encodeComponent(
  125. jsonString)}");
  126. }
  127. } else {
  128. if (_list[index].coordinate.length == 0) {
  129. showAlert(context, "提示", "电梯未定位,是否立即定位", "去定位", () {
  130. goToPage(
  131. "${LiftRouter.liftDetailPage}?project_id=" +
  132. _list[index].projectId + "&id=" + _list[index].liftId);
  133. }, txt2: "取消", onPre2: () {
  134. NavigatorUtils.goBack(context);
  135. });
  136. } else {
  137. goToPage(
  138. "${MaintenanceRouter.maintenanceRecordInfo}?item=${Uri
  139. .encodeComponent(jsonString)}");
  140. }
  141. }
  142. }
  143. @override
  144. Widget build(BuildContext context) {
  145. bool isDark = ThemeUtils.isDark(context);
  146. super.build(context);
  147. return MyListView(
  148. itemCount: _list.length,
  149. stateType: _stateType,
  150. onRefresh: onRefresh,
  151. loadMore: _loadMore,
  152. hasMore: _page < _maxPage,
  153. itemBuilder: (_, index) {
  154. return Container(
  155. margin: EdgeInsets.fromLTRB(15, 5, 5, 5),
  156. padding: EdgeInsets.only(bottom: 10),
  157. decoration: BoxDecoration(
  158. color: isDark ? Colors.black : Colors.white,
  159. borderRadius: BorderRadius.circular(6.0),
  160. ),
  161. child: Column(
  162. children: <Widget>[
  163. Container(
  164. // decoration: BoxDecoration(
  165. // border: Border(
  166. // bottom: BorderSide(
  167. // width: 0.5, color: Colours.text_gray_c),
  168. // )),
  169. padding: EdgeInsets.only(left: 12),
  170. child: Row(
  171. children: <Widget>[
  172. Expanded(
  173. flex: 1,
  174. child: Text(
  175. _list[index].projectName,
  176. style: TextStyle(fontSize: 15, color: isDark
  177. ? Colours.dark_text
  178. : Colours.text,),
  179. overflow: TextOverflow.ellipsis,
  180. softWrap: false, //单行显示
  181. )),
  182. MyButton(
  183. key: const Key('lift_list'),
  184. onPressed: () {
  185. if (noRole && _list[index].status != "2") {
  186. toasts("保养未开始或未完成,暂不可查看");
  187. return;
  188. }else if(noRole && _list[index].status == "2"){
  189. String jsonString = convert.jsonEncode(_list[index]);
  190. goToPage(
  191. "${MaintenanceRouter.maintenanceDetail}?item=${Uri
  192. .encodeComponent(jsonString)}");
  193. }else{
  194. startMaintenance(index);
  195. }
  196. },
  197. height: 25,
  198. fontSize: 11,
  199. colors: noRole && _list[index].status != "2"?[
  200. Colours.text_gray,
  201. // Colours.text_gray
  202. ]:null,
  203. borderWidth: 0.5,
  204. text: _list[index].status == "-1" ? "补录" : _list[index]
  205. .status == "0" ? (DateTime.parse(_list[index]
  206. .planDate).isAfter(DateTime.now())
  207. ? '提前保养'
  208. : '开始保养') : _list[index].status == "1"
  209. ? "继续保养"
  210. : _list[index].status == "2" ? _list[index]
  211. .hasEvaluate == "0" ? "待评价" : "保养详情" : "保养详情",
  212. )
  213. ],
  214. ),
  215. ),
  216. Container(
  217. color: Color(0xffF8F8F8),
  218. padding: EdgeInsets.only(bottom: 5,top: 5),
  219. // color: Color(0xF1F1F1),
  220. child: Column(
  221. children: [
  222. lineTxt("电梯注册代码", "${_list[index].registrationCode}"),
  223. lineTxt("设备内部编号", "${_list[index].useCompanyCode}"),
  224. lineTxt("电梯类型", "${_list[index].liftTypeName}"),
  225. lineTxt("维保负责人", "${_list[index].workerName}"),
  226. lineTxt("计划日期", "${_list[index].planDate}"),
  227. lineTxt("保养类型", "${_list[index].maintenanceTypeName}"),
  228. ],
  229. ),
  230. )
  231. ],
  232. ),
  233. );
  234. });
  235. }
  236. Widget lineTxt(title, value) {
  237. return Container(
  238. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  239. child: Row(
  240. children: <Widget>[
  241. Text("${title}",
  242. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  243. Expanded(
  244. flex: 1,
  245. child: Text(
  246. "${value}",
  247. textAlign: TextAlign.right,
  248. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  249. ),
  250. )
  251. ],
  252. ),
  253. );
  254. }
  255. @override
  256. bool get wantKeepAlive => true;
  257. }