repair_safe_page.dart 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
  5. import 'package:keyboard_actions/keyboard_actions.dart';
  6. import 'package:liftmanager/internal/repair/model/repair_list_entity.dart';
  7. import 'package:liftmanager/internal/repair/page/repair_submit_page.dart';
  8. import 'package:liftmanager/internal/repair/repair_router.dart';
  9. import 'package:liftmanager/internal/repair/widgets/time_axis.dart';
  10. import 'package:liftmanager/net/api_service.dart';
  11. import 'package:liftmanager/res/resources.dart';
  12. import 'package:liftmanager/routers/fluro_navigator.dart';
  13. import 'package:liftmanager/utils/theme_utils.dart';
  14. import 'package:liftmanager/utils/toast.dart';
  15. import 'package:liftmanager/widgets/app_bar.dart';
  16. import 'package:liftmanager/widgets/click_item.dart';
  17. import 'package:liftmanager/widgets/my_button.dart';
  18. import 'package:liftmanager/widgets/radio_item.dart';
  19. import 'dart:convert' as convert;
  20. class RepairSafePage extends StatefulWidget {
  21. RepairSafePage(this.repairItem);
  22. RepairItem repairItem;
  23. @override
  24. State<StatefulWidget> createState() {
  25. return RepairSafePageState();
  26. }
  27. }
  28. class RepairSafePageState extends State<RepairSafePage> {
  29. List<String> groupValue = ["", "", "", "", "", ""];
  30. String _stopTime = "";
  31. ///全选
  32. _allSelected() {
  33. groupValue = ["1", "1", "1", "1", "1", "1"];
  34. setState(() {});
  35. }
  36. /// 选择时间
  37. Future<void> _selectTime() async {
  38. DatePicker.showDateTimePicker(context,
  39. showTitleActions: true, onChanged: (date) {}, onConfirm: (date) {
  40. _stopTime = "${date.toString().split(".")[0]}";
  41. setState(() {});
  42. }, currentTime: DateTime.now(), locale: LocaleType.zh);
  43. }
  44. ///确认
  45. _stopAndSafe() {
  46. if(_stopTime.length == 0){
  47. toasts("请选择停梯时间");
  48. return;
  49. }
  50. showLoading(context, "正在执行...");
  51. ApiService(context: context)
  52. .repairStop(widget.repairItem.id, _stopTime, groupValue.toString(),
  53. onSuccess: (data) {
  54. dismissLoading(context);
  55. if (data != null && data) {
  56. String jsonString = convert.jsonEncode(widget.repairItem);
  57. NavigatorUtils.pushResult(context,"${RepairRouter.repairSubmitPage}?item=${Uri.encodeComponent(jsonString)}",(res){
  58. if(res != null && res){
  59. NavigatorUtils.goBackWithParams(context,res);
  60. }
  61. });
  62. }
  63. }, onError: (code, msg) {
  64. dismissLoading(context);
  65. toasts(msg);
  66. });
  67. }
  68. @override
  69. Widget build(BuildContext context) {
  70. return Scaffold(
  71. //resizeToAvoidBottomPadding: false,
  72. appBar: const MyAppBar(
  73. centerTitle: "安全确认",
  74. ),
  75. body: SafeArea(
  76. child: Container(
  77. color: ThemeUtils.getBackgroundColor(context),
  78. child: Column(
  79. children: <Widget>[
  80. Expanded(
  81. flex: 1,
  82. child: defaultTargetPlatform == TargetPlatform.iOS
  83. ? FormKeyboardActions(child: _buildBody())
  84. : SingleChildScrollView(child: _buildBody()),
  85. ),
  86. Container(
  87. // color: Colours.bg_color,
  88. child: Padding(
  89. padding: const EdgeInsets.all(16),
  90. child: MyButton(
  91. fontSize: 14,
  92. onPressed: () {
  93. _stopAndSafe();
  94. },
  95. text: "确定",
  96. ),
  97. ))
  98. ],
  99. ),
  100. ),
  101. ));
  102. }
  103. _buildBody() {
  104. return Padding(
  105. padding: EdgeInsets.only(bottom: 30),
  106. child: Column(
  107. crossAxisAlignment: CrossAxisAlignment.start,
  108. children: <Widget>[
  109. ClickItem(
  110. title: "停梯时间",
  111. hintText: "请选择",
  112. content: "${_stopTime}",
  113. onTap: () {
  114. _selectTime();
  115. },
  116. ),
  117. Container(
  118. color: ThemeUtils.getTabsBg(context),
  119. padding: EdgeInsets.only(left: 15, right: 15),
  120. height: 32.5,
  121. child: Row(
  122. children: <Widget>[
  123. Expanded(
  124. flex: 1,
  125. child: Text(
  126. "安全防护确认",
  127. style: TextStyle(
  128. fontSize: 12, color: Colours.dark_text_gray),
  129. )),
  130. GestureDetector(
  131. onTap: _allSelected,
  132. child: Text(
  133. "全选",
  134. style: TextStyle(fontSize: 12, color: Colours.app_main),
  135. )),
  136. ],
  137. )),
  138. RadioItem(
  139. title: "用电安全",
  140. value: "1",
  141. groupValue: groupValue[0],
  142. onTap: () {
  143. groupValue[0] = groupValue[0] == "1" ? "0" : "1";
  144. setState(() {});
  145. }),
  146. RadioItem(
  147. title: "护栏",
  148. value: "1",
  149. groupValue: groupValue[1],
  150. onTap: () {
  151. groupValue[1] = groupValue[1] == "1" ? "0" : "1";
  152. setState(() {});
  153. }),
  154. RadioItem(
  155. title: "手套",
  156. value: "1",
  157. groupValue: groupValue[2],
  158. onTap: () {
  159. groupValue[2] = groupValue[2] == "1" ? "0" : "1";
  160. setState(() {});
  161. }),
  162. RadioItem(
  163. title: "安全帽",
  164. value: "1",
  165. groupValue: groupValue[3],
  166. onTap: () {
  167. groupValue[3] = groupValue[3] == "1" ? "0" : "1";
  168. setState(() {});
  169. }),
  170. RadioItem(
  171. title: "电器防护",
  172. value: "1",
  173. groupValue: groupValue[4],
  174. onTap: () {
  175. groupValue[4] = groupValue[4] == "1" ? "0" : "1";
  176. setState(() {});
  177. }),
  178. RadioItem(
  179. title: "照明",
  180. value: "1",
  181. groupValue: groupValue[5],
  182. onTap: () {
  183. groupValue[5] = groupValue[5] == "1" ? "0" : "1";
  184. setState(() {});
  185. }),
  186. Container(
  187. color: ThemeUtils.getTabsBg(context),
  188. padding: EdgeInsets.only(left: 15, right: 15),
  189. height: 32.5,
  190. child: Row(
  191. children: <Widget>[
  192. Expanded(
  193. flex: 1,
  194. child: Text(
  195. "请对已安全防护选项进行勾选,确保已做好安",
  196. style: TextStyle(fontSize: 12, color: Colours.app_main),
  197. ))
  198. ],
  199. )),
  200. ],
  201. ),
  202. );
  203. }
  204. }