patrol_job_select.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import 'package:deus_app/common/style/TitleBar.dart';
  2. import 'package:deus_app/common/style/gsy_style.dart';
  3. import 'package:deus_app/common/utils/DioUtil.dart';
  4. import 'package:deus_app/common/utils/ToastUtils.dart';
  5. import 'package:deus_app/generated/json/patrol_job_select_entity_entity_helper.dart';
  6. import 'package:deus_app/model/patrol_job_select_entity_entity.dart';
  7. import 'package:deus_app/page/patrol/patrol_job_add.dart';
  8. import 'package:flutter/cupertino.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:pull_to_refresh/pull_to_refresh.dart';
  11. class PatrolJobSelect extends StatefulWidget {
  12. var id;
  13. @override
  14. State createState() {
  15. return _PatrolJobSelect(id);
  16. }
  17. PatrolJobSelect({super.key, required this.id});
  18. }
  19. class _PatrolJobSelect extends State<PatrolJobSelect> {
  20. var id;
  21. _PatrolJobSelect(this.id);
  22. final RefreshController _refreshController =
  23. RefreshController(initialRefresh: false);
  24. int index = 1;
  25. List<PatrolJobSelectEntityDataPatrolItemModelVOS> patrolItemModelVOS = [];
  26. PatrolJobSelectEntityEntity jobEdit = PatrolJobSelectEntityEntity();
  27. @override
  28. void initState() {
  29. super.initState();
  30. patrolItemModel();
  31. }
  32. patrolItemModel() async {
  33. var result = await DioUtil().request('patrolItemModel/list',
  34. method: DioMethod.post, data: {'index': index, 'size': 20});
  35. _refreshController.loadComplete();
  36. _refreshController.refreshCompleted();
  37. if (0 == result['code']) {
  38. setState(() {
  39. jobEdit = patrolJobSelectEntityEntityFromJson(
  40. PatrolJobSelectEntityEntity(), result);
  41. patrolItemModelVOS.clear();
  42. patrolItemModelVOS.addAll(jobEdit.data.patrolItemModelVOS);
  43. });
  44. } else {
  45. if (index > 1) {
  46. index--;
  47. }
  48. showToast(result['msg']);
  49. }
  50. }
  51. @override
  52. Widget build(BuildContext context) {
  53. return Scaffold(
  54. appBar: TitleBar().backAppbar("选择巡检项目"),
  55. backgroundColor: const Color(0xfff2f2f2),
  56. body: Stack(
  57. children: [
  58. Container(
  59. child: SmartRefresher(
  60. enablePullDown: true,
  61. enablePullUp: true,
  62. header: WaterDropHeader(),
  63. footer: CustomFooter(
  64. builder: (BuildContext context, LoadStatus? mode) {
  65. Widget body;
  66. if (mode == LoadStatus.idle) {
  67. body = Text("上拉加载");
  68. } else if (mode == LoadStatus.loading) {
  69. body = CupertinoActivityIndicator();
  70. } else if (mode == LoadStatus.failed) {
  71. body = Text("加载失败!点击重试!");
  72. } else if (mode == LoadStatus.canLoading) {
  73. body = Text("松手,加载更多!");
  74. } else {
  75. body = Text("没有更多数据了!");
  76. }
  77. return Container(
  78. height: 55.0,
  79. child: Center(child: body),
  80. );
  81. },
  82. ),
  83. controller: _refreshController,
  84. onRefresh: _onRefresh,
  85. onLoading: _onLoading,
  86. child: ListView.builder(
  87. itemCount: patrolItemModelVOS.length,
  88. itemBuilder: (context, index) {
  89. return _patrol_job_list(index);
  90. },
  91. ),
  92. ))
  93. ],
  94. ));
  95. }
  96. void _onRefresh() async {
  97. if (mounted) {
  98. setState(() {
  99. index = 1;
  100. patrolItemModel();
  101. });
  102. }
  103. }
  104. void _onLoading() async {
  105. if (mounted) {
  106. setState(() {
  107. if (jobEdit.data.total > patrolItemModelVOS.length) {
  108. index++;
  109. patrolItemModel();
  110. } else {
  111. _refreshController.loadNoData();
  112. }
  113. });
  114. }
  115. }
  116. Widget _patrol_job_list(int index) {
  117. return Container(
  118. margin: EdgeInsets.only(top: 12, left: 10, right: 10),
  119. padding: EdgeInsets.only(top: 12, bottom: 10),
  120. color: Colors.white,
  121. child: ListTile(
  122. title: Column(
  123. children: [
  124. Container(
  125. // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 0.0),
  126. alignment: Alignment.centerLeft,
  127. child: Text(
  128. patrolItemModelVOS[index].name,
  129. style: const TextStyle(
  130. fontSize: GSYConstant.smallTextSize,
  131. color: Colors.black,
  132. ),
  133. ),
  134. ),
  135. Container(
  136. margin: const EdgeInsets.only(top: 10),
  137. // padding: const EdgeInsets.fromLTRB(30.0, 0.0, 0.0, 10.0),
  138. // alignment: Alignment.centerLeft,
  139. alignment: Alignment.centerLeft,
  140. child: Text(
  141. patrolItemModelVOS[index].params,
  142. style: GSYConstant.smallTextLight,
  143. textAlign: TextAlign.left,
  144. ),
  145. ),
  146. SizedBox(
  147. height: 10,
  148. ),
  149. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  150. Container(
  151. child: Text(
  152. '类型:',
  153. style: TextStyle(
  154. color: GSYColors.primaryLightValue,
  155. fontSize: GSYConstant.smallTextSize,
  156. ),
  157. ),
  158. ),
  159. Container(
  160. child: Text(
  161. patrolItemModelVOS[index].type == 0
  162. ? '数值'
  163. : patrolItemModelVOS[index].type == 1
  164. ? '长文本'
  165. : patrolItemModelVOS[index].type == 2
  166. ? '单选'
  167. : '多选',
  168. textAlign: TextAlign.right,
  169. style: TextStyle(
  170. color: GSYColors.primaryLightValue,
  171. fontSize: GSYConstant.smallTextSize,
  172. ),
  173. ),
  174. ),
  175. ]),
  176. ],
  177. ),
  178. onTap: () {
  179. Navigator.push(
  180. context,
  181. MaterialPageRoute(
  182. builder: (context) =>
  183. PatrolJobAdd(responseData: patrolItemModelVOS[index], id: id,)));
  184. },
  185. ));
  186. }
  187. }